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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:31:34+00:00 2026-05-19T03:31:34+00:00

I’ve got an array of PCM data; it can be 16-bit, 24-bit packed, 32-bit,

  • 0

I’ve got an array of PCM data; it can be 16-bit, 24-bit packed, 32-bit, etc. It can be signed, or unsigned, and it can be 32 or 64-bit floating point. It is currently stored as a void** matrix, indexed first by channel, then by frame. The goal is to allow my library to take in any PCM format and buffer it, without requiring manipulation of the data to fit a designated structure. If the A/D converter spits out 24-bit packed arrays of interleaved PCM, I need to accept it gracefully. I also need to support 16-bit non-interleaved, as well as any permutation of the above formats.

I know the bit depth and other information at runtime, and I’m trying to code efficiently while not duplicating code. What I need is an effective way to cast the matrix, put PCM data into the matrix, and then pull it out later.

I can cast the matrix to int32_t, or int16_t for the 32 and 16-bit signed PCM respectively; I’ll probably have to store the 24-bit PCM in an int32_t for 32-bit, 8-bit byte systems as well.

Can anyone recommend a good way to put data into this array, and pull it out later? I’d like to avoid large sections of code which look like:

switch (mFormat) {
case 1:  // unsigned 8 bit
  for (int i = 0; i < mChannels; i++)
    framesArray = (uint8_t*)pcm[i];
  break;
case 2:  // signed 8 bit
  for (int i = 0; i < mChannels; i++)
    framesArray = (int8_t*)pcm[i];
  break;
case 3:  // unsigned 16 bit
...

Limitations: I’m working in C/C++, no templates, no RTTI, no STL. Think embedded. Things get trickier when I have to port this to a DSP with 16-bit bytes.

Does anybody have any useful macros they might be willing to share?

  • 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-05-19T03:31:35+00:00Added an answer on May 19, 2026 at 3:31 am

    This one will match typecodes to casting functions. The basic idea is that it creates a set of tiny conversion functions for each type, and an array of function pointers, and then indexes into that array based on the data format in order to find the correct conversion function to call.

    Usage example:

    int main ()
    {   
        void** pcm;
        int currentChannel;
        int currentFrame;
        int mFormat;
    
        // gets data casted to our type
        STORETYPE translatedFrameData = GET_FRAMEDATA(pcm, currentChannel, currentFrame, mFormat);  
    
        return 0;
    }
    

    The header file:

    // this is a big type, we cast to this one
    #define STORETYPE int32_t
    
    // these functions get a single frame
    typedef STORETYPE (*getterFunction)(void**, int, int);
    
    // this macros make an array that maps format codes to cast functions
    #define BEGIN_RESERVE_FORMAT_CODES getterFunction __getter_array[] = {
    #define RESERVE_FORMAT_CODE(code) __get__##code##__,
    #define END_RESERVE_FORMAT_CODES };
    
    //
    #define FORMAT_DEFINITION(code, format) STORETYPE __get__##code##__(void**pcm, int channel, int frame) \
    { return (STORETYPE) ((format**)pcm)[channel][frame]; }
    
    // get corresponding function 
    #define GET_FRAMEDATA( pcm, channel, frame, format ) __getter_array[format](pcm,channel,frame)
    
    //serious part, define needed types
    FORMAT_DEFINITION(0, uint8_t)
    FORMAT_DEFINITION(1, int8_t)
    FORMAT_DEFINITION(2, uint16_t)
    FORMAT_DEFINITION(3, int16_t)
    
    //actually this makes the array which binds types
    BEGIN_RESERVE_FORMAT_CODES
        RESERVE_FORMAT_CODE(0)
        RESERVE_FORMAT_CODE(1)
        RESERVE_FORMAT_CODE(2)
        RESERVE_FORMAT_CODE(3)
    END_RESERVE_FORMAT_CODES
    
    //WATCH OUT FOR SEQUENCE
    

    hope helps

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

Sidebar

Related Questions

I got an array that outputs data into an xml. It looks like this:
I've got an array of uniq numbers. Like this: [1,2,3,4,7,8,10,12]. It can be unsorted.
I got array which has one,two,three,four,five. values.. in my array....says countListArray. I need to
i got this array. array(24) { [0]=> array(3) { [id]=> string(1) 1 [category]=> string(5)
I got an array like this $value = {array('id'=>$id, 'email'=>$email, 'token'=>$token)} I want to
I've got an array of images, which I want to display in a gallery.
I've got an array with nested arrays, and I was trying to use the
I'm trying to add a fields_for attribute to a nested rails form. Any time
I am using the following to check if links exist on file.php: $fopen =

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.