[Speex-dev] iPhone distorted audio
Thomas Leavy
tom at the-all-nighters.com
Sat Jul 14 21:33:31 PDT 2012
I'm not sure if anyone is experienced with this but i'm having very strange issues with implementing speex in my iOS application.
I have written a encode and decode function basically exactly like the example files online. To process audio I am using an iOS VoiceProcessingIO Audio Unit which is set at 16bit pcm with 8000 sample rate. After buffering 320 bytes of PCM audio I feed it into my encode function set at quality 10 (comes out to about 62 bytes of compressed audio). Then after sending it across the net I buffer 62 byte chunks and feed them into the decode function for playback. Unfortunately playback is strange as it sounds very distorted and robotic, although I can clearly recognize what was said and the encode and decode functions go through without any errors. I bypassed the speex functions and just sent uncompressed PCM using the same app and its crystal clear. Where am I going wrong here? Anyone got any suggestions?
My code is as follows
#define AUDIO_QUALITY 10
#define FRAME_SIZE 160
#define COMP_FRAME_SIZE 62
char *encodeSpeexWithBuffer(spx_int16_t *buffer, int *insize) {
SpeexBits bits;
void *enc_state;
char *outputBuffer = (char *)malloc(COMP_FRAME_SIZE);
speex_bits_init(&bits);
enc_state = speex_encoder_init(&speex_nb_mode);
int quality = AUDIO_QUALITY;
speex_encoder_ctl(enc_state, SPEEX_SET_QUALITY, &quality);
speex_bits_reset(&bits);
speex_encode_int(enc_state, buffer, &bits);
*insize = speex_bits_write(&bits, outputBuffer, COMP_FRAME_SIZE);
speex_bits_destroy(&bits);
speex_encoder_destroy(enc_state);
return outputBuffer;
}
short *decodeSpeexWithBuffer(char *buffer) {
SpeexBits bits;
void *dec_state;
speex_bits_init(&bits);
dec_state = speex_decoder_init(&speex_nb_mode);
short *outTemp = (short *)malloc(FRAME_SIZE * 2);
speex_bits_read_from(&bits, buffer, COMP_FRAME_SIZE);
speex_decode_int(dec_state, &bits, outTemp);
speex_decoder_destroy(dec_state);
speex_bits_destroy(&bits);
return outTemp;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20120715/e6806ee2/attachment.htm
More information about the Speex-dev
mailing list