Re: Writing an AudioFile with callbacks doesn't update the Chunk Data Size
Re: Writing an AudioFile with callbacks doesn't update the Chunk Data Size
- Subject: Re: Writing an AudioFile with callbacks doesn't update the Chunk Data Size
- From: William Stewart <email@hidden>
- Date: Wed, 1 Aug 2007 11:12:50 -0700
I've previously written an email about the use of the
AudioFileInitializeWithCallbacks call and some of its shortcomings -
please see that post (about a week or so ago)
Bill
On 31/07/2007, at 10:51 PM, Dave Fernandes wrote:
I am using AudioFileInitializeWithCallbacks to create a memory
based (WAVE format) AudioFile. When I try to write my
playbackBufferList to this file, the data and header are correctly
written to memory, however the chunk size for the data chunk is 0
(even though the actual data bytes get written correctly). Also,
the chunk data size for the RIFF chunk header is consistent with a
data chunk size of 0.
When I use this same code, but create a disk based file using
ExtAudioFileCreateNew, then everything works correctly.
Is there something else I need to do to fill in the correct chunk
sizes?
Dave Fernandes
--- Code Snippet ---
// Open an audio file based on an NSMutableData object.
AudioFileTypeID fileType = kAudioFileWAVEType;
NSMutableData* encodedAudio = [NSMutableData dataWithCapacity:0];
AudioFileID audioFileID;
AudioStreamBasicDescription fileFormat =
{
playbackStreamFormat.mSampleRate,
kAudioFormatLinearPCM,
kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked,
6,
1,
6,
playbackStreamFormat.mChannelsPerFrame,
24,
0
};
OSStatus err = AudioFileInitializeWithCallbacks(encodedAudio,
readAudioFromDataObject, writeAudioToDataObject,
getSizeOfDataObject, setSizeOfDataObject,
fileType, &fileFormat, 0, &audioFileID);
if (err != noErr) return;
ExtAudioFileRef audioFile;
err = ExtAudioFileWrapAudioFileID(audioFileID, true, &audioFile);
if (err != noErr) return;
// Inform the file what format data we are going to supply.
err = ExtAudioFileSetProperty(audioFile,
kExtAudioFileProperty_ClientDataFormat, sizeof
(AudioStreamBasicDescription), &playbackStreamFormat);
if (err != noErr) return;
// Write the audio data.
err = ExtAudioFileWrite(audioFile, nFrames, playbackBufferList);
err = ExtAudioFileDispose(audioFile);
// Print out the file bytes.
UInt32* words = (UInt32*)[encodedAudio bytes];
UInt32 length = [encodedAudio length] / 16;
printf("Encoded length = %i\n", [encodedAudio length]);
for (int i = 0; i < length; i++)
{
printf("%8x %8x %8x %8x %8x\n", i*16, *(words + 0), *(words +
1), *(words + 2), *(words + 3));
words += 4;
}
// Encode this object.
[encoder encodeObject:encodedAudio forKey:@"data"];
_______________________________________________
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
--
mailto:email@hidden
tel: +1 408 974 4056
________________________________________________________________________
__
"Much human ingenuity has gone into finding the ultimate Before.
The current state of knowledge can be summarized thus:
In the beginning, there was nothing, which exploded" - Terry Pratchett
________________________________________________________________________
__
_______________________________________________
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