Re: Streaming Graph to file
Re: Streaming Graph to file
- Subject: Re: Streaming Graph to file
- From: Doug Wyatt <email@hidden>
- Date: Mon, 6 Mar 2006 11:45:57 -0800
On Mar 6, 2006, at 11:05, Geoff Hufford wrote:
I am trying the ExtAudioFile approach to export a sound file from
my graph,
but I get hung up at one point.
I attach a kAudioUnitSubType_GenericOutput output unit to the end
of the
graph (after the mixer) so I can set it to convert the data format
for the
file writer.
Set the output unit format as follows:
CAStreamBasicDescription casbd;
casbd.mFormatID = 'lpcm';
casbd.mSampleRate = 48000;
casbd.mChannelsPerFrame = 2;
casbd.SetCanonical(2, true);
AudioUnitSetProperty (m_output, kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output, 0, &casbd, size);
...
ExtAudioFileCreateNew - works
Get AudioStreamBasicDescription from the output unit and then set
the file
writer input format.
result = ExtAudioFileSetProperty(outfile,
kExtAudioFileProperty_ClientDataFormat, dataSize, &inputStreamFormat);
==> This is where I hit a wall. The call returns 'fmt?' as the
result. So I
guess I am not planning to send the writer a format it likes.
To understand why this is failing, let's see inputStreamFormat and
the format you've set on the file. Also, what type of audio file is
it? Either one of the two formats is incorrectly specified (and the
error's coming from the creation of an internal audio converter) or
it could be that the format you've specified for the file is not
supported for that file type.
I do not
understand the blurb in the header file:
The format must be linear PCM (kAudioFormatLinearPCM).
You must set this in order to encode or decode a non-PCM file
data format.
You may set this on PCM files to specify the data format used in
your
calls to read/write.
The client format is the format used for all reads/writes through the
ExtendedAudioFile API. Floats are most convenient when dealing with
AU's. An AudioConverter internal to the file object translates to/
from the file data format (e.g. 16-bit stereo big-endian integer).
What the comment is saying is that if the file is non-PCM, you have
to specify a client format to encode/decode to/from. If the file is
PCM, it's possible not to set a client format, in which case your
reads and writes are expected to be in the same format as the file
data format.
I also am unsure if using kAudioUnitSubType_GenericOutput is going
to be a
successful way to convert the data flowing in the graph to a format
that the
file writer wants. It would be simpler if the file writer will
accept the
non-interleaved float format that I can pull out of the mixer in
the graph,
but I got the impression that isnt possible. Please correct me if
the output
unit conversion is an unnecessary step.
It's simplest just to use the converter internal to the ExtAudioFile.
On 3/6/06 4:40 AM, "Karim Morsy" <email@hidden> wrote:
just a hint in case you haven't already done so... use
ExtAudioFileWriteAsync
instead of ExtAudioFileWrite. It is much easier to use, as it
performs the
write for you on an internal thread very efficiently and you don't
have to
worry about managing buffers and threads.
before starting your audio capture you should initialize the async
write: ExtAudioFileWriteAsync(outfile, 0, NULL).
whenever your graph is running and you want to start recording,
just add a
render notification call back function to the audio unit from
which you want
to save the audio data to file. and in the audio unit's post render
notification perform the write:
Thanks, I will try it when I get the issue above resolved. Doesn't
this
approach require that the graph is playing real-time through the
output
unit? I like that I don’t have to manage the process, but I need to
have a
fast as possible export of the file that isnt clocked by the output
device.
If a faster than real-time export is possible, Do I have to be
concerned
about calling ExtAudioFileWriteAsync too many times before it is
ready for
more data?
Yes. Karim's approach is good if you're trying to write in realtime,
but if you want to write offline (faster-than-realtime), call
ExtAudioFileWrite, which is synchronous.
Doug
--
Doug Wyatt
Core Audio, Apple
_______________________________________________
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