[Speex-dev] Problems with stereo data

Jean-Marc Valin jean-marc.valin at usherbrooke.ca
Mon Apr 2 15:13:15 PDT 2007


Hi,

How about you test on speexenc/speexdec before posting your code on the
list?

	Jean-Marc

Peter Mosedal Laursen a écrit :
> Hi all,
> 
> I have a problem when I am encoding (or decoding) stereo audio.
> 
> With mono data, things are fine and everything works without any problems.
> 
> When I try to decode stereo data, all I get is a static sound - similar to that of a radio not tuned to any specific station. I wonder what might be wrong?
> 
> Below is the code, first, of the encoder and next that of the decoder. Any information or help would be very much appreciated. I have looked through the sampleenc.c and sampledec.c distributed with the speex 1.2 Beta 1 source code, but in that regard, that code was of little help.
> 
> My test data are sampled at 16 Khz and it is a stereo file.
> 
> I look forward to any reply or information on how to deal with stereo data in Speex.
> 
> I am on Windows, using Microsoft Visual C++ 2005 Express Edition.
> 
> Best regards,
> 
> Peter.
> 
> // Encoder
> 
> #include <speex/speex.h>
> 
> #include <speex/speex_stereo.h>
> 
> #include <stdio.h>
> 
> #pragma comment(lib, "libspeex.lib")
> 
> int main(int argc, char* argv[]) {
> 
> const int FrameSize = 320;
> 
> void* State = speex_encoder_init(&speex_wb_mode);
> 
> int Temp;
> 
> float Tmp;
> 
> Temp = 1;
> 
> Tmp = 2;
> 
> speex_encoder_ctl(State, SPEEX_SET_VBR, &Temp);
> 
> speex_encoder_ctl(State, SPEEX_SET_VBR_QUALITY, &Tmp);
> 
> FILE* fin = fopen(argv[1], "rb");
> 
> FILE* fout = fopen(argv[2], "wb");
> 
> SpeexBits Bits;
> 
> speex_bits_init(&Bits);
> 
> short Frame[FrameSize];
> 
> char Cbits[200];
> 
> while (!feof(fin)) {
> 
> speex_bits_reset(&Bits);
> 
> fread(Frame, sizeof(short), FrameSize, fin);
> 
> speex_encode_stereo_int(Frame, FrameSize, &Bits);
> 
> speex_encode_int(State, Frame, &Bits);
> 
> short BytesToWrite = speex_bits_write(&Bits, Cbits, 200);
> 
> fwrite(&BytesToWrite, sizeof(short), 1, fout);
> 
> fwrite(Cbits, 1, BytesToWrite, fout);
> 
> }
> 
> speex_encoder_destroy(State);
> 
> speex_bits_destroy(&Bits);
> 
> fclose(fout);
> 
> fclose(fin);
> 
> }
> 
> // Decoder
> 
> #include <stdio.h>
> 
> #include <speex/speex.h>
> 
> #include <speex/speex_stereo.h>
> 
> #pragma comment(lib, "libspeex.lib")
> 
> int main(int argc, char* argv[]) {
> 
> FILE* fin = fopen(argv[1], "rb");
> 
> FILE* fout = fopen(argv[2], "wb");
> 
> void* State = speex_decoder_init(&speex_wb_mode);
> 
> SpeexBits Bits;
> 
> speex_bits_init(&Bits);
> 
> const int FrameSize = 320;
> 
> short Output[FrameSize];
> 
> short BytesToRead;
> 
> char Buffer[1024];
> 
> SpeexStereoState StereoState = SPEEX_STEREO_STATE_INIT;
> 
> while (!feof(fin)) {
> 
> fread(&BytesToRead, sizeof(short), 1, fin);
> 
> fread(Buffer, 1, BytesToRead, fin);
> 
> speex_bits_read_from(&Bits, Buffer, BytesToRead);
> 
> speex_decode_int(State, &Bits, Output);
> 
> speex_decode_stereo_int(Output, FrameSize, &StereoState);
> 
> fwrite(Output, sizeof(short), FrameSize, fout);
> 
> }
> 
> fclose(fout);
> 
> fclose(fin);
> 
> speex_decoder_destroy(State);
> 
> speex_bits_destroy(&Bits);
> 
> }
> 
> _______________________________________________
> Speex-dev mailing list
> Speex-dev at xiph.org
> http://lists.xiph.org/mailman/listinfo/speex-dev
> 
> 


More information about the Speex-dev mailing list