[speex-dev] Please 30 second to look a my code
Jean-Marc Valin
Jean-Marc.Valin at USherbrooke.ca
Fri Dec 19 08:14:05 PST 2003
Well, you seem to be using FRAME_SIZE but only defining frame_size.
Otherwise, the code looks OK, but it's always hard to tell. I suggest
you start from speexenc/speexdec or from the example I wrote in the
manual at: http://www.speex.org/manual/node12.html
Jean-Marc
Le ven 19/12/2003 à 05:22, Fabio a écrit :
> Hi
> i'm developing a sort of VoIP application
> for my ipaq using speex...
> I'm still at beginning and i have many problems encoding and decoding
> my
> wav files....output is only noise! Why?
>
> I'm using
> Libspeex 1.1.3,
> Embedded VisualC++ 3.0,
> Ipaq 3850(206 MHz Intel® Strong ARM 32-bit RISC Processor) PocketPC
> 2002 (Windows CE 3.0).
>
> Libspeex is complied with the definition of FIXED_POINT...
>
> Regards
> Fabio
>
> P.S.
> Rodrigo did u do something similar?
>
> This is the code, what could be wrong?
> void CRegistratoreDlg::OnEncode()
> {
> Sleep(500); //Wait because drawing send window
>
> SpeexBits bits;
>
> void *state;
>
> short InBuffer[FRAME_SIZE];
> char OutBuffer[200];
> char waveheader[WAVEHEADER];
>
> HANDLE WaveFile;
> HANDLE SpeexFile;
>
> DWORD NrOfBytesRead, NrOfBytesWritten;
>
> char nrBytes = 0;
> int nbBytes = 0;
> int bit_rate, frame_size, test=0;
> bool first=true;
>
> WaveFile = CreateFile(_T("\\Temp\\tempsound.wav"), GENERIC_READ, 0,
> NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
> SpeexFile = CreateFile(_T("\\Temp\\tempsound.spx"), GENERIC_WRITE, 0,
> NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
>
> speex_bits_init(&bits); //init encoded bits buffer
> state = speex_encoder_init(&speex_nb_mode); //Init encoder in
> narrowband mode
> speex_encoder_ctl(state, SPEEX_GET_FRAME_SIZE, &frame_size);//Get
> frame size
>
> int tmp=0;
> speex_encoder_ctl(state, SPEEX_SET_VBR, &tmp);
> tmp=1;
> speex_encoder_ctl(state, SPEEX_SET_COMPLEXITY, &tmp);
>
> bit_rate=24000;
> speex_encoder_ctl(state, SPEEX_SET_BITRATE, &bit_rate);
> ReadFile(WaveFile, waveheader, WAVEHEADER, &NrOfBytesRead, NULL);
> WriteFile(SpeexFile, waveheader, WAVEHEADER, &NrOfBytesWritten,
> NULL); //Raw copy of waveheader from speexfile to wavefile
>
> while(true)
> {
> ReadFile(WaveFile, InBuffer, FRAME_SIZE, &NrOfBytesRead, NULL);
> //Fabio: Somewhere i found FRAME_SIZE * 2
>
> speex_bits_reset(&bits); //Reset out bits buffer
> speex_encode(state, InBuffer, &bits); //Encode bits
>
> nbBytes = speex_bits_write(&bits, OutBuffer, 200); //Save
> encoded bits to buffer
>
> if(first){ //First frame save the first byte, nrBytes, to
> outfile
> nrBytes = nbBytes;
> WriteFile(SpeexFile, &nrBytes, 1, &NrOfBytesWritten, NULL);
> first=false;
> }
>
> WriteFile(SpeexFile, &OutBuffer, nbBytes, &NrOfBytesWritten,
> NULL); //Write encoded buffer to outfile
>
> if(NrOfBytesRead<FRAME_SIZE) //Break if end of file
> break;
> }
>
> speex_bits_destroy(&bits); //Deallocate
> speex_encoder_destroy(state);
>
> CloseHandle(WaveFile);
> CloseHandle(SpeexFile);
>
> MessageBox(_T("Encoding Done"));
> }
>
>
> void CRegistratoreDlg::OnDecode()
> {
>
> SpeexBits bits;
>
> void *state;
>
> char InBuffer[200];
> short OutBuffer[FRAME_SIZE];
> char waveheader[50];
>
> HANDLE InFile;
> HANDLE OutFile;
>
> char nrBytes = 0;
> int nbBytes = 0;
>
> DWORD NrOfBytesRead;
> DWORD NrOfBytesWritten;
>
> InFile = CreateFile(_T("\\Temp\\tempsound.spx"), GENERIC_READ, 0,
> NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
>
> //Create file to decode
> OutFile = CreateFile(_T("\\Temp\\Dai.wav"), GENERIC_WRITE, 0, NULL,
> CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); // Create out wave file
>
> state = speex_decoder_init(&speex_nb_mode); //Init decoder in
> //narrowband mode
>
> int tmp=0;
> speex_decoder_ctl(state, SPEEX_SET_ENH, &tmp);
>
> speex_bits_init(&bits); //Init out bit buffer
>
> ReadFile(InFile, waveheader, WAVEHEADER, &NrOfBytesRead, NULL); //Raw
> copy of wave header
>
> WriteFile(OutFile, &waveheader, WAVEHEADER, &NrOfBytesWritten, NULL);
> //from wave file to speexfile
>
> ReadFile(InFile, &nrBytes, 1, &NrOfBytesRead, NULL); //Read first
> byte in frame to "nrBytes"
>
> nbBytes=nrBytes; //"nrBytes" gives info about used code rate
>
> while(1){ //Decode until end of file
> ReadFile(InFile, InBuffer, nbBytes, &NrOfBytesRead, NULL);
> //Read bits to decode
>
> speex_bits_read_from(&bits, InBuffer, nbBytes);
>
> speex_decode(state, &bits, OutBuffer); //Decode bits
>
> WriteFile(OutFile, OutBuffer, FRAME_SIZE*2, &NrOfBytesWritten,
> NULL);
>
> if(NrOfBytesRead<nbBytes) //Break if end of file
> break;
> }
>
> speex_bits_destroy(&bits); //Deallocate
> speex_decoder_destroy(state);
>
> CloseHandle(InFile);
> CloseHandle(OutFile);
>
> MessageBox(_T("Decoding Done"));
> }
--
Jean-Marc Valin, M.Sc.A., ing. jr.
LABORIUS (http://www.gel.usherb.ca/laborius)
Université de Sherbrooke, Québec, Canada
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: Ceci est une partie de message numériquement signée.
Url : http://lists.xiph.org/pipermail/speex-dev/attachments/20031219/07c5f3fe/signature.pgp
More information about the Speex-dev
mailing list