混音播放问题(200分)

  • 主题发起人 菜鸟黄
  • 开始时间

菜鸟黄

Unregistered / Unconfirmed
GUEST, unregistred user!
//怎么我用下面的代码,没有声音输出呢?(1.txt中的内容是E:/音乐/情书.mp3)
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
MMSystem, DirectSound, Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;


var
Form1: TForm1;
lpDirectSound: IDirectSound;
lpDirectSoundBuffer: IDirectSoundBuffer;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
audiobuf: array[0..160000-1] of byte;
stream: TFileStream;
format: TWAVEFORMATEX;
BufferDesc: DSBUFFERDESC;
ptr1, ptr2: pointer;
pdw1, pdw2: dword;
begin

stream:=TFileStream.Create('1.txt',fmOpenRead);
stream.ReadBuffer(audiobuf, stream.Size);

fillchar(format, sizeof(format), 0);
format.wFormatTag:=WAVE_FORMAT_PCM;
format.nChannels:=1;
format.nSamplesPerSec:=8000;
format.nAvgBytesPerSec:=16000;
format.nBlockAlign:=2;
format.wBitsPerSample:=16;


fillchar(bufferdesc, sizeof(bufferdesc), 0);
bufferdesc.dwSize:=sizeof(bufferdesc);
bufferdesc.dwBufferBytes:=stream.Size;
bufferdesc.lpwfxFormat:=@format;

DirectSoundCreate(nil, lpDirectSound, nil);
lpDirectSound.SetCooperativeLevel(Handle, DSSCL_NORMAL);
lpDirectSound.CreateSoundBuffer(bufferdesc, lpDirectSoundBuffer, nil);
lpDirectSoundBuffer.Lock(0, stream.Size, ptr1, pdw1, ptr2, pdw2, 0);
copymemory(ptr1, @audiobuf, pdw1);
copymemory(ptr2, pchar(@audiobuf)+pdw1, pdw2);
lpDirectSoundBuffer.Unlock(ptr1, pdw1, ptr2, pdw2);
lpDirectSoundBuffer.Play(0, 0, 0);

stream.Free;
end;


end.
 
呵呵!你调用的是WAV的播放,播放MP3要用空间,例如ACM
 
我晕~ACM就是因为实现不了混音,我才用DirectSound的,论坛里就没有人会这个吗?
 
代码都贴出来了~怎么就没人来帮一下忙解决啊[:D]
 
将MP3转换成WAV格式不就用你的方法达到目的了。
 
顶部