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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:18:57+00:00 2026-06-09T20:18:57+00:00

I am using OpenAL in the iOS app that I’m working on and our

  • 0

I am using OpenAL in the iOS app that I’m working on and our client gave us a bunch of audio files that are all in big-endian format. My problem is that OpenAL only plays little-endian formats.

So I figure all I need to do is find the audio data, and reverse it, correct?

My code for extracting the audio data (taken from the OpenAL tutorial):

-(void)addSound:(NSString*)theSound
{
// get the full path of the file
NSString* fileName = [[NSBundle mainBundle] pathForResource:theSound ofType:@"caf"];
// first, open the file
NSLog(@"fileNAme is ===== %@", fileName);
AudioFileID fileID = [self openAudioFile:fileName];

// find out how big the actual audio data is
UInt32 fileSize = [self audioFileSize:fileID];

// this is where the audio data will live for the moment
unsigned char * outData = malloc(fileSize);

// this where we actually get the bytes from the file and put them
// into the data buffer
OSStatus result = noErr;
result = AudioFileReadBytes(fileID, false, 0, &fileSize, outData);
NSLog(@"OUT DATA IS == %d", outData);
AudioFileClose(fileID); //close the file

if (result != 0) NSLog(@"cannot load effect: %@",fileName);

NSUInteger bufferID;
// grab a buffer ID from openAL
alGenBuffers(1, &bufferID);

// jam the audio data into the new buffer
alBufferData(bufferID,AL_FORMAT_STEREO16,outData,fileSize,44100);

// save the buffer so I can release it later
[bufferStorageArray addObject:[NSNumber numberWithUnsignedInteger:bufferID]];

NSUInteger sourceID;

// grab a source ID from openAL
alGenSources(1, &sourceID);

// attach the buffer to the source
alSourcei(sourceID, AL_BUFFER, bufferID);
// set some basic source prefs
alSourcef(sourceID, AL_PITCH, 1.0f);
alSourcef(sourceID, AL_GAIN, 1.0f);

//alSourcei(sourceID, AL_LOOPING, AL_TRUE);

// store this for future use
[soundDictionary setObject:[NSNumber numberWithUnsignedInt:sourceID] forKey:theSound];

// clean up the buffer
if (outData)
{
    free(outData);
    outData = NULL;
}
}

I figure unsigned char * outdata;
is what I need to reverse (after the audio file data is loaded into it, of course), but I have no idea how to do so. Can anyone help me out with this please?

  • 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-09T20:18:58+00:00Added an answer on June 9, 2026 at 8:18 pm

    in this case, you should use ExtAudioFileRead after configuring the ExtAudioFile‘s AudioConvertor‘s format. it will save you a lot of time. you might swap yourself if you know all your input files have the same sample format.

    ExtAudioFile is in AudioToolbox.framework on OS X and iOS (basically a layer above AudioFile with more high level capabilities), and you can create one by wrapping an AudioFile.

    AudioConvertor could also be used without ExtAudioFile.

    in some cases, you can just use the OS X afonvert utility to swap them to LE, and be done with it without adding (unnecessary) programming challenges.

    writing your own endian-swapping routines for arrays isn’t hard – it’s just time consuming, tedious, and you typically need to make sure it’s fast and capable of supporting unnaturally aligned sample data. this involves:

    for (each sample) {
      reverse order of bytes in sample
    }
    

    W’rkncacnter furnished this link: Convert big endian to little endian when reading from a binary file

    you can use that approach it if is naturally aligned. and you would need variants for each size and sample description you would see on input. the OS also offers OSSwap routines, but these don’t handle all sample formats — they focus on builtin types.

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

Sidebar

Related Questions

In My app i am using openAl to cut the portion of audio song
In my app I am using OpenAl to trim the audio song, now how
I'm working on a cocoa-touch app using OpenAL, but I'm willing to switch to
I'm using Core Audio / OpenAL to play CAF audio files. From Apple I
In my iOS app I wan't to play sounds using OpenAL. I have AudioManager
I tried writing an app that samples the microphone using code from http://code.google.com/p/ios-coreaudio-example/ (Core
I'm developing an ios app that's very basic and uses objective almost all of
Back Story: I was approached to write an app, but iOS isn't something that
For the past few weeks I have been working on an app that uses
I have recently spotted that it is possible in iOS to use OpenAL to

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.