Re: File format conversion
Re: File format conversion
- Subject: Re: File format conversion
- From: Fredrik <email@hidden>
- Date: Wed, 4 Feb 2009 07:36:29 +0100
Thanks William
you probably need to set the IsPacked bit in the format flags - if I
do afinfo on an aiff file:
File: /System/Library/Sounds/Submarine.aiff
File type ID: AIFF
Data format: 2 ch, 44100 Hz, 'lpcm' (0x0000000E) 16-bit big-
endian signed integer
no channel layout.
estimated duration: 0.975 sec
audio bytes: 171992
audio packets: 42998
bit rate: 1411200 bits per second
packet size upper bound: 4
audio data file offset: 54
optimized
----
So, your format flags aren't complete. You need:
kAudioFormatFlagIsBigEndian
kAudioFormatFlagIsSignedInteger
kAudioFormatFlagIsPacked
Yes, that makes sense. I added these flags. What is the proper way to
do that though? I just separated them by commas now, and that compiled
fine. Like this:
OutFormat.mFormatFlags = kAudioFormatFlagIsBigEndian,
kAudioFormatFlagIsSignedInteger,
kAudioFormatFlagIsPacked;
Are you checking result codes from your AudioFile... calls - I could
imagine you have an error being returned somewhere
AudioFileCreate and AudioFileWriteBytes both return 0 right now if
there is no file with the same name in the path.
The third arg to AudioFileWriteBytes is the byte offset to put the
data at - you would need to increment it as you write (it doesn't
work like a stream)
What I did actually wrote the buffer correctly to disk but the size of
the sound data isn´t written in the header.
This is how I created the file:
AudioFileID convertedFile;
status = AudioFileCreate(
&path, // FSRef, destination directory
outName, // CFStringRef, the name of the file
kAudioFileAIFFType, // aiff
&OutFormat, // Format, pointer to AudioStreamDesc
0, // Relevant flags, set to 0
&path, // pointer to location
&convertedFile); // pointer to the file(AudioFileID)
printf("Bytes written: %d\n", propertyData);
printf("status: %d\n", status);
Fredrik
Also, yes, you'll need an audio converter to convert the little
endian wav data to the big endian AIFF data
Bill
On Feb 3, 2009, at 3:29 PM, Fredrik wrote:
Hi,
I´m trying to make a format converter that converts from two
uncompressed formats, in this case wav to aif.
I have managed to create the new file (aif) with the correct header
but some of the fields in the header doesn´t reflect
the actual size of the data but only an empty header. So in this
case the FORM chunk size is 4088 bytes, number of sample frames is
0 and the SSND chunk size is 8.
I don´t get where the problem could be, I have looked over the
AudioStreamBascDescription struct that I have filled in like this:
AudioStreamBasicDescription OutFormat;
OutFormat.mSampleRate = 44100;
OutFormat.mFormatID = kAudioFormatLinearPCM;
OutFormat.mFormatFlags = kAudioFormatFlagIsBigEndian;
OutFormat.mBytesPerPacket = 2;
OutFormat.mFramesPerPacket = 1;
OutFormat.mBytesPerFrame = 2;
OutFormat.mChannelsPerFrame = 1;
OutFormat.mBitsPerChannel = 16;
The file is mono, 16 bit 44.1
I then write the file like this, I have checked the size of
propertyData and it´s correct.
AudioFileWriteBytes(convertedFile,
false,
0,
&propertyData,
&buf.mData);
I guess that I also need a AudioConverter to perform endian
conversion on the data but is that the reason that the size
fields of the header is missed?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
@apple.com
This email sent to email@hidden
_______________________________________________
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