Delphi 如何混合Mp3文件

Delphi 如何混合Mp3文件,delphi,mp3,delphi-2010,mixing,Delphi,Mp3,Delphi 2010,Mixing,我想混合MP3文件与德尔福2010 这可能吗?有人知道我可以用组件(set)来完成这项工作吗?或者是运行库?有混合MP3文件经验的人有什么建议吗?Bass.dll,FFmpeg有pascal头,显然您可以从delphi使用: 这将允许您轻松加载mp3或任何其他文件类型。如果混合两个mp3文件意味着混合音频信号,则需要先解码mp3 虽然mp3包含一个分解的信号结构(音频信号的fft),但两个独立的mp3文件在编码格式上可能差异太大,无法尝试混合未编码的音频 对于解码和编码,您需要像lame这样的编

我想混合MP3文件与德尔福2010


这可能吗?有人知道我可以用
组件
(set)来完成这项工作吗?或者是运行库?有混合MP3文件经验的人有什么建议吗?

Bass.dll,

FFmpeg有pascal头,显然您可以从delphi使用:


这将允许您轻松加载mp3或任何其他文件类型。

如果混合两个mp3文件意味着混合音频信号,则需要先解码mp3

虽然mp3包含一个分解的信号结构(音频信号的fft),但两个独立的mp3文件在编码格式上可能差异太大,无法尝试混合未编码的音频

对于解码和编码,您需要像lame这样的编码器将mp3转换为wav文件。虽然流式传输(DirectShow过滤器)很好,但通过调用命令行界面,解码、混合、编码应该相当容易处理


lame编码器/解码器二进制文件可用于windows。混音wav不是很复杂,因为基本上每个通道都叠加(a+b)/2。

您也可以使用gstreamer来实现这一点。

我使用newAc:

它有一个混音器组件,支持mp3输入


干杯

如果你的混音/解码/播放,我会使用libmad库,因为它是最快最精确的mp3解码库,因为它使用整数数学进行解码

这里有一个delphi pas文件:

它的使用非常简单。然后您需要混合两个流,这取决于您选择使用的数据格式,我建议使用float,这样您就不会失去精度

for i = 0 to samples do
  out[i] = (in1[i] + in2[i]) * 0.5;

乘以0.5与除以2相同,但速度要快得多。

MP3文件操作几乎没有可能的选择:

在我看来,音频工具库看起来是最有前途的一个,因为其中包括MPEG解析。。。我没有使用过任何这样的工具,但它是在我的时间表虽然

同样,如前所述,MP3是压缩格式,这意味着您需要在实际活动之前对文件中的二进制信息进行解压缩

希望有帮助

干杯,HX.

也可用于此任务。在名为的包中有Directshow的Delphi头文件

从DSPack页面:

DSPack是一组组件和 类编写多媒体应用程序 使用MS Direct Show和DirectX 技术

由于两个输入文件的声音重叠,因此要生成mp3文件,您需要解压缩两个音频文件,进行混音,然后重新压缩。在这两种情况下,您都需要检查两个文件的音频样本,分别处理每个通道,并平均输出文件中input1和input2的值。它类似于:
outsamples[i]:=insample1[i]/2+insample2[i]/2。为了获得更好的性能,表达式
优于样本[i]:=insample1[i]shr1+insample2[i]shr1可以改为使用

对于同时最大化性能和音频质量的方法,我建议这样做,它基本上建议使用以下表达式(A和B是0-1标准化音频样本):


Z=2·A·B如果A两者都可以使用bass、Bassenc和lame编码器进行此操作

从下载lame编码器 贝斯从哪里来 将bass.dll、bass.pas、Bassenc.dll、Bassenc.pas和lime.exe与项目exe文件放在同一文件夹中。 要使用示例代码,请在表单上放置一个列表框、opendialog和两个按钮

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, bass, bassenc,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    OpenDialog1: TOpenDialog;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  //
  if OpenDialog1.Execute then
    ListBox1.items.add(OpenDialog1.FileName);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  decoder, encoder, newdecoder: dword;
  I, R: Integer;
  buf: array [1 .. 204800] of byte;


begin
  for I := 0 to ListBox1.items.count - 1 do
  begin
    if I = 0 then
    begin
      decoder := BASS_StreamCreateFile(FALSE, PChar(ListBox1.items.strings[0]),
        0, 0, BASS_STREAM_DECODE or BASS_UNICODE);
      encoder := BASS_Encode_Start(decoder,
        'lame.exe --alt-preset standard - fulltrack.mp3',
        BASS_ENCODE_AUTOFREE or BASS_UNICODE, nil, nil);

    end
    else
    begin
      newdecoder := BASS_StreamCreateFile(FALSE, PChar(ListBox1.items.strings[I]
        ), 0, 0, BASS_STREAM_DECODE or BASS_UNICODE);



      if not BASS_Encode_SetChannel(encoder, newdecoder) then
      begin
        showmessage(inttostr(BASS_ErrorGetCode));
        BASS_StreamFree(decoder);
        continue;
      end;
      BASS_StreamFree(decoder);

   // free the old decoder
      decoder := newdecoder;
    end;

    R := 1;
    while R > 0 do
    begin
      R := BASS_ChannelGetData(decoder, @buf, sizeof(buf));
    end;

  end;

  BASS_StreamFree(decoder); // free the decoder
  BASS_Encode_Stop(encoder); // stop the encoder
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  if not BASS_Init(-1, 44100, 0, handle, nil) then
    showmessage('Error initializing audio!');
end;

end.

我很想知道这件事@Kermia你想怎么混音?有一种FL Studio(果味循环)的方式,可以将块拖动到位,每个块都包含一个wav或mp3样本,并且可以无缝播放。另一种方式可以在Ejay(虚拟DJ)等程序中看到,在该程序中,您可以在每个面板上加载mp3曲目。如果您提供有关如何混合曲目的其他信息,这可能会很有用。这回答了您的问题。你是在要求在不做任何工作的情况下为你完成这件事,克里米亚?:-)@沃伦+1,我也在想这个。也许Kermia如果您提供更多信息,我们可能会给您更好的建议。混合mp3文件有几种方法,您需要更具体一点。你想让它像Audacity、Fruity Loops、Virtual DJ等一样工作吗?Kermia,如果你不知道如何使用它,那么你怎么知道它不工作?有这个questin和这些评论(下面)的家伙怎么会有银色(!!!)徽章。。。我是说…这完全是胡说八道。。。所以徽章系统确实需要重新制作,因为它显然没有复制任何东西。。。。
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, bass, bassenc,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    OpenDialog1: TOpenDialog;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  //
  if OpenDialog1.Execute then
    ListBox1.items.add(OpenDialog1.FileName);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  decoder, encoder, newdecoder: dword;
  I, R: Integer;
  buf: array [1 .. 204800] of byte;


begin
  for I := 0 to ListBox1.items.count - 1 do
  begin
    if I = 0 then
    begin
      decoder := BASS_StreamCreateFile(FALSE, PChar(ListBox1.items.strings[0]),
        0, 0, BASS_STREAM_DECODE or BASS_UNICODE);
      encoder := BASS_Encode_Start(decoder,
        'lame.exe --alt-preset standard - fulltrack.mp3',
        BASS_ENCODE_AUTOFREE or BASS_UNICODE, nil, nil);

    end
    else
    begin
      newdecoder := BASS_StreamCreateFile(FALSE, PChar(ListBox1.items.strings[I]
        ), 0, 0, BASS_STREAM_DECODE or BASS_UNICODE);



      if not BASS_Encode_SetChannel(encoder, newdecoder) then
      begin
        showmessage(inttostr(BASS_ErrorGetCode));
        BASS_StreamFree(decoder);
        continue;
      end;
      BASS_StreamFree(decoder);

   // free the old decoder
      decoder := newdecoder;
    end;

    R := 1;
    while R > 0 do
    begin
      R := BASS_ChannelGetData(decoder, @buf, sizeof(buf));
    end;

  end;

  BASS_StreamFree(decoder); // free the decoder
  BASS_Encode_Stop(encoder); // stop the encoder
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  if not BASS_Init(-1, 44100, 0, handle, nil) then
    showmessage('Error initializing audio!');
end;

end.