开发者

Speex voice chat: EXC_BAD_ACCESS crash when trying to decode

开发者 https://www.devze.com 2023-03-27 20:31 出处:网络
I\'m developing a voice chat and I used speex to开发者_Python百科 compress the data that is being transmitted.

I'm developing a voice chat and I used speex to开发者_Python百科 compress the data that is being transmitted. But I encountered a crash when I try to decode the received data. I compress the data using this code:

Init method (runs only one time):

/*Create a new encoder state in narrowband mode*/
state = speex_encoder_init(&speex_nb_mode);

/*Set the quality to 8 (15 kbps)*/
int tmp=8;
speex_encoder_ctl(state, SPEEX_SET_QUALITY, &tmp);

speex_bits_init(&bits);

Compress method:

AudioBuffer sourceBuffer = bufferList->mBuffers[0];
speex_bits_reset(&bits);
/*Encode the frame*/
speex_encode(state, sourceBuffer.mData, &bits);
char cbits[200];
int nbBytes = speex_bits_write(&bits, cbits, 200);

NSData *result = [[NSData alloc] initWithBytes:cbits length:200];

Decompress method:

NSLog(@"Lenght %d", [data length]);
speex_bits_reset(&bits);

/*Copy the data into the bit-stream struct*/
speex_bits_read_from(&bits, (void*)[data bytes], [data length]);

/*Decode the data*/
speex_decode(state, &bits, tempBuffer.mData);

Same initialization as before

It crashes with no error at speex_decode. I checked the length of the input NSData and the output one and they are the same. Bytes inside are the same.


Euh, so are you actually passing the encoder state to speex_decode()??

0

精彩评论

暂无评论...
验证码 换一张
取 消