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 8767571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:50:57+00:00 2026-06-13T16:50:57+00:00

I am working on a C++ program that records audio and compresses it to

  • 0

I am working on a C++ program that records audio and compresses it to GSM. I am able to record audio and write the raw data to a file. But I cannot get the GSM compression to work. I am trying to use a source code for compression that I found at this website ftp://ftp.cs.cmu.edu/project/fgdata/speech-compression/GSM/gsm_13200bps.

I think my problem is when using the gsm_encode() function. After encoding and saving the compressed data to the file when you play this file it is inaudible. I know that the raw audio data is correct but the compressed audio data is incorrect.

gsm_encode() encodes an array of 160 13-bit samples (given as
gsm_signal’s, signed integral values of at least 16 bits) into
a gsm_frame of 33 bytes.

Here is my function am I sending the data into gsm_encode() incorrectly? Or is there another problem with my function? Thank you for your help 🙂

int CAudioGSM::CompressAudio(unsigned char * pRawBuffer, _int32 uiRawBufferSize, unsigned char  * pCompressedBuffer, _int32 uiCompressedBufferSize)
{
// Note: uiRawBufferSize must be a multiple of 640 (AUDIO_DMA_DESCRITOR_LEN)
if(!pRawBuffer || uiRawBufferSize == 0 || !pCompressedBuffer || uiCompressedBufferSize == 0 ||  uiRawBufferSize % AUDIO_DMA_DESCRITOR_LEN != 0)
{
    return -1; //invalid parameters
}

_int32 uiBytesCompressed = 0; // Number of bytes that have been compressed. At the end of the function this should be equal to iRawBufferSize meaning we have compressed the whole raw buffer
_int32 uiCompBuffOffset = 0; // Offset into the compressed buffer

while(uiBytesCompressed < uiRawBufferSize)
{
    if(uiCompressedBufferSize - uiCompBuffOffset < GSM_OUTPUT_SIZE || uiCompBuffOffset >= uiCompressedBufferSize)
    {
       return -2; // Compressed buffer is too small
    }

    gsm_encode(&m_GSM_EncodeStruture,(long *)pRawBuffer,m_Buffer);
    //Now we need to move the data to compressed buffer
    if(m_bFirstHalfOfBlockRecord)
    {
       //Just copy the data over
       memcpy(&pCompressedBuffer[uiCompBuffOffset],m_Buffer,GSM_OUTPUT_SIZE_FIRST_HALF);
       m_bFirstHalfOfBlockRecord = false;
       uiCompBuffOffset += GSM_OUTPUT_SIZE_FIRST_HALF;
    }
    else
    {
       memcpy(&pCompressedBuffer[uiCompBuffOffset],m_Buffer,GSM_OUTPUT_SIZE);
       m_bFirstHalfOfBlockRecord = true;
       uiCompBuffOffset += GSM_OUTPUT_SIZE;
    }

    uiBytesCompressed += AUDIO_DMA_DESCRITOR_LEN;
}

return uiCompBuffOffset; // Success, we have compressed the buffer return compressed data size
}
  • 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-13T16:50:58+00:00Added an answer on June 13, 2026 at 4:50 pm

    nevermind I figured it out it the pRawBuffer never gets incremented it should be

    gsm_encode(&m_GSM_EncodeStruture,(long *)&pRawBuffer[uiBytesCompressed],m_Buffer);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a program that takes in a Wavefront .obj file and eventually
I'm working on a program that records date metadata from files, such as creation
I am working on a C# console program that grabs large numbers of records
I'm working on a C program that generates a doubly linked list of records.
I'm working on a program that needs to record and play back keystrokes. The
I am working on a multitouch program that needs to record only the movements
I'm working on a program that takes in book records in the form <book
Hello I've reached a stump that I cannot pull out. My program records the
I'm working on a program that will sort files based on extension I currently
I'm working on a program that reads in users input as a string, which

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.