Good day! I've got a problem using Lame with Borland C++ Builder and Delphi.
Here is an example of function I
wrote on C++(Visual Studio) which just encode a WAV file to an MP3 file:
int CDECL wavtomp3(const char *wavfilename,const char *mp3filename)
{
lame_global_struct *gf1;
short int wavbuf[2304*2];
unsigned char mp3buf[10000];
FILE *hr;
FILE *hw;
int rres;
int encr;
encr=0;rres=0;
hr=fopen(wavfilename,"rb");
hw=fopen(mp3filename,"wb+");
fseek(hr,44,0);//skip wave header
gf1=lame_init();//init
lame_set_VBR(gf1,vbr_default);//set default VBR method
lame_set_bWriteVbrTag(gf1,1);//enable writing VBR tag
//suppose that other parameters are set by default:
//max bitrate=320,min bitrate=32,VBR quality=4;input,output freq=44100.
lame_init_params(gf1);
//start the encoding loop
while ((rres=fread(wavbuf,2,2304,hr))>0)
{
encr=lame_encode_buffer_interleaved(gf1,wavbuf,rres/2,mp3buf,10000);
fwrite(mp3buf,1,encr,hw);
}
encr=lame_encode_flush(gf1,mp3buf,10000);
fwrite(mp3buf,1,encr,hw);
fclose(hr);
fclose(hw);
hw=fopen(mp3filename,"rb+");
lame_mp3_tags_fid(gf1,hw);//write VBR tag
fclose(hw);
lame_close(gf1);
return 0;
};
This function was exported in lame_enc.dll (i've just add it to
BladeMP3EncDll.def and build the project using
MSVC 2003).
The problem is that when I call this function from Visual Studio - it's ok it
works correctly and produces an MP3
file equivalent to which produces console frontend lame.exe (lame.exe -v *.wav
*.mp3) but when I call my
function from Delphi or C++ Builder it create MP3 file which size is bigger,
for example:
input file:WAV, filesize=37196924 bytes
output file:MP3,
filesize=4117113 bytes(lame.exe,wavtomp3 calling from MSVC)
filesize=4117450 bytes(wavtomp3 calling from Delphi and C++ Builder),
difference=337 bytes.
Viewing these MP3 files in FAR Manager I found that 337 bytes was added before
calling lame_encode_flush.
Maybe it doesn't matter because I don't hear these 337 bytes at the end of the
file and if the file is quite big?
This problem appears only when I use VBR, with CBR is all OK.
The same problem appears when I use lame_enc.dll library (by A. L. Faber) with
it's own functions
(beInitStream, beEncodeChunk etc) in Delphi or C++ Builder but never when I use
it in MSVC.
Is there any way out from this situation except writing applications on MSVC or
not? I want to use Delphi.
Thank you.
Alexey, Russia.
_______________________________________________
mp3encoder mailing list
[email protected]
http://minnie.tuhs.org/mailman/listinfo/mp3encoder