Brian thank you so much for your quick and clear answer. So to set the right stream format, I just need to connect the audio units and only after I could do
AudioUnitSetProperty( audio_unit_, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Global, 0, &my_stream_format, sizeof(my_stream_format); or even AudioUnitSetProperty( audio_unit_, kAudioUnitProperty_SampleRate, kAudioUnitScope_Global, 0, &new_sample_rate, sizeof(new_sample_rate); Indeed it worked, I didn’t manage to make it working before because I used theses functions before the connections between the nodes… I think I use the default sample rate and convert every AUFilePlayer. But, : 1°) what do I need to use to have the AUFilePlayer providing sample rate conversion? Is it an other audio unit connected to the output of the AUFilePlayer? 2°) does this approach is expensive? And since you told me that using a callback and tracking the frames wasn’t a good solution, what’s your option to know when the end of a file is reached? I don’t see any callback called at the end, and using mSamplingTime is not accurate since when I pause the AUFilePlayer I just set the field `mFramesToPlay` of an ScheduledAudioFileRegion to 0. Indeed since I use an AUGraph, I start this one only once so all my audio unit are rendering every time and when i want to pause one I use the trick I described. I do this because I manage to stop one with `AudioUnitReset` but I don’t see any other function to play except `AudioUnitRender`but ask many parameters that I don’t have like `AudioBufferList* ioData` since I use AUGraph to handle it… 2017-07-20 22:27 GMT+02:00 Brian Willoughby <[email protected]>: > > On Jul 20, 2017, at 4:02 AM, Laurent Noudohounsi < > [email protected]> wrote: > > But I've some question about the behaviour of a custom callback within > an AUGraph. > > Indeed, I've the feeling that the AUGraph use default settings for the > callback options. Like all the graph is in 44100kHz with 2 channels. > > Yes, the documentation states that all AudioUnits have 44.1kHz stereo > 32-bit float as the format. You must change the format after connecting all > nodes, but before starting the graph. Note that each AU has both an input > format and an output format. Those should all be set (there are some > shortcuts, but when in doubt set them all). > > > > I use a file with a sampling rate of 11025 (= 1/4 * 441000). The > callback tell me that the frame position reach the number of frames too > early. For a 16sec file, I reach the end at 4sec (btw the 1/4 of 16sec) > > It seems that 99% of your problem is the mismatch of sample rates. > However, even after you solve this problem you should be wary of using this > technique for file playback. The FilePlayer AudioUnit will still load from > your file in advance of the playback time, which can lead to your code > reacting too early. You need to account for the latency of your graph, and > not stop the audio until all the samples are flushed. If you do not do > this, your code will cut off the end of the audio file, which won't be > heard. In other words, even after you get rid of the 1/4 rate error, you > will still see the frame position reach the number of frames too early. > > > > So how can I handle this problem? Can I set global setting to the > AUGraph or should I set the format for every audio units? > > There is no global setting for an AUGraph with regard to sample rate or > bit depth. A global setting is impossible because some nodes can have > sample rate conversion, such that their input and output are different. > > You need to choose either 44.1 kHz or 11.025 kHz, and then set all of the > AU nodes to have your chosen rate on both input and output. If you run your > graph at 44.1 kHz, then the FilePlayer should provide sample rate > conversion. If you run your graph at 11.025 kHz, then your output AU will > handle conversion to the hardware sample rate. > > Brian Willoughby > >
_______________________________________________ Do not post admin requests to the list. They will be ignored. Coreaudio-api mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/coreaudio-api/archive%40mail-archive.com This email sent to [email protected]
