Hello,<br><br>I'm having a problem using Speex - I'm getting white noise/static from the following process:<br>(Load File) -> (Encode) -> (Decode) -> (Play)<br><br>I know there's no issue with the loading or playing because (Load File)-> (Play) plays the file properly.
<br><br>I believe the problem lies with the speex_bits_write and speex_bits_read_from functions, because if I change my encode function to return the whole SpeexBits struct and my decode function to accept a SpeexBits struct, it plays the vocoded audio without any problem.
<br><br><br>****************** Managed C++ Code ***********************************<br><br>//Public function -- m_encoderState is a void* member, m_bits is a SpeexBits* member<br>array<Byte>^ SpeexEncoder::Encode(array<short>^ inputFrame)
<br>{<br> <br> //begin lazy man's way of converting to regular C<br> unsigned int numSamples = inputFrame->Length;<br> short* inputptr = (short*) malloc(numSamples*sizeof(short));<br><br> unsigned int i = 0;
<br> for(i = 0; i<numSamples; i++)<br> inputptr[i] = (short) inputFrame[i];<br> <br> //end lazy man's conversion<br> <br> speex_bits_reset(m_bits);<br> <br> //preprocess the input<br> //speex_preprocess(m_preprocess, inputptr);
<br> <br> <br> //encode<br> speex_encode_int(m_encoderState, inputptr, m_bits); <br><br><br> char outputFrame[SPEEX_MAX_ENCODE_SIZE_PER_FRAME];<br> <br> free(inputptr);<br><br> unsigned int numBytes = speex_bits_write(m_bits, outputFrame, SPEEX_MAX_ENCODE_SIZE_PER_FRAME);
<br><br> //begin lazy man's conversion to Managed C++<br> array<Byte>^ output = gcnew array<Byte>(numBytes);<br> for(i = 0; i< numBytes; i++)<br> output[i] = (unsigned char)outputFrame[i];
<br> //end lazy man's conversion<br> <br> return output;<br>}<br><br><br><br><br>//Public function -- m_decoderState is a void* member, m_bits is a SpeexBits* member<br>
array<short>^ SpeexDecoder::Decode(array<Byte>^ inputBytes)<br>{<br> <br>
short* outputFrame = (short*) malloc(m_frameSize*sizeof(short));<br> speex_bits_reset(m_bits);<br> if(inputBytes != nullptr)<br> {<br> //begin lazy man's way of converting to regular C<br>
std::string input;<br> unsigned int inputLength = inputBytes->Length;<br> input.resize(inputLength);<br> unsigned int i = 0;<br> for(i = 0; i<inputLength; i++)<br> input[i] = (unsigned char) inputBytes[i];
<br> //end lazy man's conversion<br><br> speex_bits_read_from(m_bits, (char*) input.c_str(), inputLength);<br> }<br> else<br> {<br> speex_bits_read_from(m_bits, NULL, 0);<br> }<br><br> //decode the data
<br> speex_decode_int(m_decoderState, m_bits, (spx_int16_t*) outputFrame); <br><br> //begin lazy man's conversion to Managed C++<br> array<short>^ output = gcnew array<short>(m_frameSize);<br> int i = 0;
<br> for(i = 0; i<m_frameSize; i++)<br> output[i] = outputFrame[i];<br> free(outputFrame);<br> //end lazy man's conversion<br><br> return output;<br>}<br><br><br>************<br><br><br>Thanks for any help,
<br><br>Mark<br><br><br><br><br><br><br>