It isn't that big a deal, and I don't really care as long as it works.
And it does work, except that my sounds are all clipped off around the halfway mark. Anyone know why that would happen? I think these are all mono sounds and are being treated as such, from what I can tell.
I started with the MixerHost sample code, and it uses this function to read in its guitar and beats loops. I just use the same function for my 'aiff', 'wave' and 'aif' files. Because it sounds pretty much like exactly half the sound is playing, I stuck in a line to double the 'totalFramesInFile' received by ExtAudioFileGetProperty w/ kExtAudioFileProperty_FileLengthFrames.
And it works! Sounds like the whole sound is being played. But why? In this case I do care, because I should not have to artificially double my frame count.
- (void) readAudioFilesIntoMemory {
for (int audioFile = 0; audioFile < NUM_FILES; ++audioFile) {
NSLog (@"readAudioFilesIntoMemory - file %i", audioFile);
// Instantiate an extended audio file object.
ExtAudioFileRef audioFileObject = 0;
// Open an audio file and associate it with the extended audio file object.
OSStatus result = ExtAudioFileOpenURL (sourceURLArray[audioFile], &audioFileObject);
if (noErr != result || NULL == audioFileObject) {[self printErrorMessage: @"ExtAudioFileOpenURL" withStatus: result]; return;}
// Get the audio file's length in frames.
UInt64 totalFramesInFile = 0;
UInt32 frameLengthPropertySize = sizeof (totalFramesInFile);
result = ExtAudioFileGetProperty (
audioFileObject,
kExtAudioFileProperty_FileLengthFrames,
&frameLengthPropertySize,
&totalFramesInFile
);
if (noErr != result) {[self printErrorMessage: @"ExtAudioFileGetProperty (audio file length in frames)" withStatus: result]; return;}
if (audioFile >= 2) // << Here is where I double the framecount
totalFramesInFile *= 2;
// Assign the frame count to the soundStructArray instance variable
soundStructArray[audioFile].frameCount = totalFramesInFile;
printf("file has %lld frames\n",totalFramesInFile);
// Get the audio file's number of channels.
AudioStreamBasicDescription fileAudioFormat = {0};
UInt32 formatPropertySize = sizeof (fileAudioFormat);
result = ExtAudioFileGetProperty (
audioFileObject,
kExtAudioFileProperty_FileDataFormat,
&formatPropertySize,
&fileAudioFormat
);
if (noErr != result) {[self printErrorMessage: @"ExtAudioFileGetProperty (file audio format)" withStatus: result]; return;}
UInt32 channelCount = fileAudioFormat.mChannelsPerFrame;