• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
16 bit short array to AIFF
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

16 bit short array to AIFF


  • Subject: 16 bit short array to AIFF
  • From: Marco Bambini <email@hidden>
  • Date: Sat, 13 Jun 2009 10:47:02 +0200

Hello,

I have an array of short int (16 bit) filled with values in the -32768, 32767 range and I need to write this array into an AIFF file.
So far the function I am using is:


void generareAIFF (short *chirp, int samples, double durationParam, int sampleRateParam)
{
NSString *realPath = [NSString stringWithFormat: @"file:// %@",AIFF_PATH];

// setup audio stream description
AudioStreamBasicDescription aiffFormat;
aiffFormat.mSampleRate = sampleRateParam; // sample rate data
aiffFormat.mFormatID = kAudioFormatLinearPCM; // linear pulse-code modulation data

// importing my stream data in Audacity I need to set the endianess parameter
// so you need to convert between big->little endian before saving data
aiffFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked | kLinearPCMFormatFlagIsBigEndian;
aiffFormat.mFramesPerPacket = 1;
aiffFormat.mChannelsPerFrame = 1;
aiffFormat.mBitsPerChannel = 16;
aiffFormat.mBytesPerPacket = aiffFormat.mBytesPerFrame = (aiffFormat.mBitsPerChannel / 8) * aiffFormat.mChannelsPerFrame;

AudioFileID audioFileID;
CFURLRef url = CFURLCreateWithString(NULL, (CFStringRef)realPath, NULL);

// create AIFF audio file structure (headers only)
OSStatus status = AudioFileCreateWithURL(url, kAudioFileAIFFType, &aiffFormat, 0, &audioFileID);

//
UInt32 total_fileSize = (UInt32)(durationParam * sampleRateParam);
AudioStreamPacketDescription asbd;
asbd.mDataByteSize = total_fileSize;
asbd.mStartOffset = 0;
asbd.mVariableFramesInPacket = 0;
UInt32 pullPackets = total_fileSize;

// AIFF data needs to be in BIG ENDIAN format
if (CFByteOrderGetCurrent() != CFByteOrderBigEndian) {
for (int i = 0; i < samples; i++) chirp[i] = CFSwapInt16HostToBig(chirp[i]);
}

status = AudioFileWritePackets(audioFileID, NO, total_fileSize, &asbd, 0, &pullPackets, chirp);
AudioFileClose(audioFileID);
}


my questions are:
1) does that code seem correct?
2) why when I open that AIFF file in audacity it says 32bit float instead of the correct 16bit PCM?


Thanks a lot,
Marco Bambini

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: 16 bit short array to AIFF
      • From: tahome izwah <email@hidden>
  • Prev by Date: More Re: Playing standard kit with DLS synth
  • Next by Date: Re: 16 bit short array to AIFF
  • Previous by thread: Re: More Re: Playing standard kit with DLS synth
  • Next by thread: Re: 16 bit short array to AIFF
  • Index(es):
    • Date
    • Thread