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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:48:58+00:00 2026-05-13T22:48:58+00:00

Total noob to anything lower-level than Java, diving into iPhone audio, and realing from

  • 0

Total noob to anything lower-level than Java, diving into iPhone audio, and realing from all of the casting/pointers/raw memory access.

I’m working with some example code wich reads a WAV file from disc and returns stereo samples as single UInt32 values. If I understand correctly, this is just a convenient way to return the 32 bits of memory required to create two 16 bit samples. Eventually this data gets written to a buffer, and an audio unit picks it up down the road. Even though the data is written in UInt32-sized chunks, it eventually is interpreted as pairs of 16-bit samples.

What I need help with is splitting these UInt32 frames into left and right samples. I’m assuming I’ll want to convert each UInt32 into an SInt16, since an audio sample is a signed value. It seems to me that for efficiency’s sake, I ought to be able to simply point to the same blocks in memory, and avoid any copying.

So, in pseudo-code, it would be something like this:

UInt32 myStereoFrame = getFramefromFilePlayer;

SInt16* leftChannel = getFirst16Bits(myStereoFrame);
SInt16* rightChannel = getSecond16Bits(myStereoFrame);

Can anyone help me turn my pseudo into real code?

Edit:

Much thanks to zneak for this answer, which works great:

SInt16* left = (SInt16*)&myUInt32Chunk;
SInt16* right = left + 1;

Now, to reassemble my SInt16s into a UInt32 (assuming I don’t want to just use my original variable, myStereoFrame), I’ll need to do more or less the same in reverse: line up my two SInt16s in contiguous memory slots and then cast that memory to a UInt32.

So I make an array:

SInt16 newFrameInMemory[2] = {*left, *right}

And then copy the entire length of that array into a UInt32

UInt32 newFrame32 = newFrameInMemory

That doesn’t work though, but if I do this bit of ugliness — cast the array to a pointer, then dereference the pointer, it does work.

UInt32 newFrame32 = *((UInt32*)&newFrameInMemory)

Is there a prettier way to do this?

  • 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-13T22:48:59+00:00Added an answer on May 13, 2026 at 10:48 pm

    It’s quite easy:

    SInt16* left = (SInt16*)&myUInt32Chunk;
    SInt16* right = left + 1;
    

    Unless the iPhone is little-endian, in which case you’ll have to invert right and left.

    Since an int can be seen as two contiguous shorts, you just have to get the address to it, and then do exactly as if it was, indeed, two shorts.

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

Sidebar

Ask A Question

Stats

  • Questions 338k
  • Answers 338k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Specifying the version of the embedded Jetty used by Cargo… May 14, 2026 at 4:16 am
  • Editorial Team
    Editorial Team added an answer You should be able to solve your problem by setting… May 14, 2026 at 4:16 am
  • Editorial Team
    Editorial Team added an answer because the http redirect instructs the browser to find the… May 14, 2026 at 4:16 am

Related Questions

I have a beginner iPhone project going. I have a TableView, which is just
I'm a total noob to iPhone programming, and I've run into an exception being
I am working on a project in C# to create a forms application. I
I'm a total noob when it comes to jQuery but I am trying to
Hey all, I'm a total noob when it comes to Objective-C / iPhone development.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.