hola gente.
Estoy tratando de grabar desde PCM a MP3 usando la DLL de blade.
Resulta que anda mas o menos, es decir me graba en el mp3 pero cuando lo escucho es como si fueran ardillitas , es decir el audio esta muy rapido y la verdad que ya no se q modificar!
Les pego el codigo aca para que me den una mano y de paso ya queda aca para alguien mas que lo necesite.
Por favor
Gracias
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, mmsystem, msacm, bladedll;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button2Click(Sender: TObject);
private
public
Device: HWAVEIN;
waveIn: array [0..6999] of Byte;
waveHeader: WAVEHDR;
WaveInOK, BladeOK: Boolean;
Cont: integer;
BeConfig: TBEConfig;
Mp3Buffer, RawBuffer: pointer;
mp3bufferSize, NumSamples: DWORD;
BladeHandle: THbeStream;
Mp3File: TFileStream;
procedure WaveInCallBack(var Msg: TMessage); message MM_WIM_DATA;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
waveFormat: tWAVEFORMATEX;
Result: MMRESULT;
Err: TBeErr;
resultado: integer;
begin
waveFormat.wFormatTag := WAVE_FORMAT_PCM; waveFormat.nChannels := 2;
waveFormat.nSamplesPerSec := 44100;
waveFormat.wBitsPerSample := 16;
waveFormat.nBlockAlign := 4;
waveFormat.nAvgBytesPerSec := 4 * 44100;
waveFormat.cbSize := 0;
Result := 0;
if Result = 0 then
begin
WaveInOK := true;
if waveInOpen(@Device, WAVE_MAPPER, @waveFormat, Form1.handle,0,CALLBACK_WINDOW) = MMSYSERR_NOERROR then
begin
waveHeader.lpData := @waveIn;
waveHeader.dwBufferLength := sizeof(waveIn);
if waveInPrepareHeader(Device, @waveHeader, sizeof(TWAVEHDR)) <> MMSYSERR_NOERROR then
begin
waveInReset(Device);
waveInClose(Device);
exit;
end;
if waveInAddBuffer(Device, @waveHeader, sizeof(TWAVEHDR)) <> MMSYSERR_NOERROR then
begin
waveInReset(Device);
waveInClose(Device);
exit;
end;
if waveInStart(Device) <> MMSYSERR_NOERROR then
begin
waveInReset(Device);
waveInClose(Device);
exit;
end;
end
else
showmessage('waveInOpen ERROR');
end
else
showmessage('ERROR');
if WaveInOK then
begin
Mp3Buffer := nil;
Mp3File := TFileStream.Create('xxx.mp3',fmCreate or fmShareDenyNone);
FillChar(BeConfig,SizeOf(BeConfig),#0);
With BeConfig.Format do begin
dwConfig := BE_CONFIG_MP3; mp3.dwSampleRate := 44100;
mp3.byMode := BE_MP3_MODE_STEREO;
mp3.wBitrate := 128;
mp3.bPrivate := False;
mp3.bCRC := false;
mp3.bCopyright := False;
mp3.bOriginal := False;
end;
Err := BeInitStream(BeConfig, NumSamples, Mp3BufferSize, BladeHandle);
if Err <> BE_ERR_SUCCESSFUL then
begin
BladeOK := false;
MessageDlg('Error opening encoding stream '+IntToStr(Err),MtError,[MbOk],0);
Exit;
end;
BladeOK := true;
GetMem(Mp3Buffer,mp3BufferSize);
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if WaveInOK then
begin
waveInReset(Device);
waveInClose(Device);
end;
if BladeOK then
begin
BladeOK := false;
FreeMem(Mp3Buffer);
beCloseStream(BladeHandle);
Mp3File.Free;
end;
end;
procedure TForm1.WaveInCallBack(var Msg: TMessage);
var
hdr: PWaveHdr;
Pasadas: integer;
Err: TBeErr;
toWrite: DWORD;
begin
waveHeader.lpData := @waveIn;
waveHeader.dwBufferLength := sizeof(waveIn);
waveInPrepareHeader(Device, @waveHeader, sizeof(TWAVEHDR));
waveInAddBuffer(Device, @waveHeader, sizeof(TWAVEHDR));
Label1.Caption := inttostr(Cont);
inc(Cont);
hdr := PWaveHdr(Msg.LParam);
if BladeOK then
begin
Err := beEncodeChunk(BladeHandle,hdr.dwBytesRecorded, pointer(hdr.lpdata), mp3Buffer, toWrite);
if Err <> BE_ERR_SUCCESSFUL then begin
Label2.Caption := 'beEncodeChunk failed '+IntToStr(Err);
BladeOK := false;
end;
mp3File.Write(mp3buffer^,ToWrite);
end;
waveInUnPrepareHeader(Device,hdr,sizeof(TWAVEHDR));
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Version : TBeVersion;
begin
beVersion(Version);
ShowMessage(
'BladeEnc DLL version : '+IntToStr(Version.byDLLMajorVersion)+'.'+IntToStr(Version.byDLLMinorVersion)+#13+
'BladeEnc version : '+IntToStr(Version.byMajorVersion)+'.'+IntToStr(Version.byMinorVersion)+#13+
'BladeEnc date : '+IntToStr(Version.byDay)+'-'+IntToStr(Version.byMonth)+'/'+IntToStr(Version.wYear)+#13+
'BladeEnc Homepage : '+Version.zHomepage);
end;
end.