Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8248731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:17:34+00:00 2026-06-07T23:17:34+00:00

I am working on an iOS project that needs to encode and decode Speex

  • 0

I am working on an iOS project that needs to encode and decode Speex audio using a remoteIO audio unit as input / output.

The problem I am having is although speex doesn’t print any errors, the audio I get is somewhat recognizable as voice but very distorted, sort of sounds like the gain was just cranked up in a robotic way.

Here are the encode and decode functions (Input to encode is 320 bytes of signed integers from the audio unit render function, Input to decode is 62 bytes of compressed data ):

#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(200);

    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, 200);


    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;
}

And the audio unit format:

// Describe format
audioFormat.mSampleRate         = 8000.00;
audioFormat.mFormatID           = kAudioFormatLinearPCM;
audioFormat.mFormatFlags        =  kAudioFormatFlagIsSignedInteger |
kAudioFormatFlagsNativeEndian |
kAudioFormatFlagIsPacked;
audioFormat.mFramesPerPacket    = 1;
audioFormat.mChannelsPerFrame   = 1;
audioFormat.mBitsPerChannel     = 16;
audioFormat.mBytesPerPacket     = 2;
audioFormat.mBytesPerFrame      = 2;

No errors are reported anywhere and I have confirmed that the Audio Unit is processing at a sample rate of 8000

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:17:36+00:00Added an answer on June 7, 2026 at 11:17 pm

    After a few days of going crazy over this I finally figured it out. The trick with Speex is that you must initialize a SpeexBit and encoder void* and use them throughout the entire session. Because I was recreating them for every piece of the encode it was causing strange sounding results.

    Once I moved:

     speex_bits_init(&bits);
     enc_state = speex_encoder_init(&speex_nb_mode);
    

    Out of the while loop everything worked great.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an iOS application that needs to play some sounds using the
I'm working on an iOS project that has to work from iOS4. I have
I'm working on a project that generates a iOS static library, and some sample
I am using PhoneGap for an iOS project and everything is working except I
I'm new to ios i'm working in a small project in that i need
I am working on an iOS project that loads UIImages from URLs in a
i'm working on a little iOS project, and i stumbled across a problem with
I'm new to iOS programming and I am working on a easy project that
I have been working on reading in an audio asset using AVAssetReader so that
I am doing iOS project in Xcode . It was working properly but now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.