The issue was related to the mixer I used. Originally I used the AU3DMixerEmbedded
which was in the code that I copied. When I replaced that mixer with MultiChannelMixer
, then everything started to work fine. I still don't know why AU3DMixerEmbedded
didn't work.
AUAudioFilePlayer silences whole graph after playing
-
02-06-2022 - |
문제
In order to play sound fragments from a file, I have setup a Audio Graph with three units, a AUAudioFilePlayer
unit, a mixer unit, and an output unit, according to the code in this SO question. That works fine, and plays my sound fragments perfectly.
Then I have added another AUAudioFilePlayer
unit, and fed its output in the mixer as well, so I can play from two files in parallel and mix them together. That also works fine, as long as I keep scheduling fragments on both AUAudioFilePlayer
units (that is, I have a timer that schedules a new 2-second fragment every 2 seconds). But as soon as I stop scheduling fragments on one of the AUAudioFilePlayer
units, the whole graph falls silent. My timer still happily schedules a new fragment on the first AUAudioFilePlayer
unit, and I don't get any errors on any of the system calls, but no sound comes through.
Anybody knows how to prevent this?
I have tried doing an AudioUnitReset
on the second player, and even to remove it from the graph with AUGraphDisconnectNodeInput
, all to no avail.
My code to schedule a fragment is here:
CheckError(AudioUnitReset(fileAU, kAudioUnitScope_Global, 0), "AudioUnitReset");
ScheduledAudioFileRegion rgn;
memset (&rgn.mTimeStamp, 0, sizeof(rgn.mTimeStamp));
rgn.mTimeStamp.mFlags = kAudioTimeStampSampleTimeValid;
rgn.mTimeStamp.mSampleTime = -1;
rgn.mCompletionProc = NULL;
rgn.mCompletionProcUserData = NULL;
rgn.mAudioFile = inputFile;
rgn.mLoopCount = 0;
rgn.mStartFrame = startFrame;
rgn.mFramesToPlay = 88200;
CheckError(AudioUnitSetProperty(fileAU, kAudioUnitProperty_ScheduledFileRegion, kAudioUnitScope_Global, 0,&rgn, sizeof(rgn)), "AudioUnitSetProperty[kAudioUnitProperty_ScheduledFileRegion] failed");
해결책