Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 14947 [details]
I'm attempting to resolve a customer issue with extracting Int16ChannelData from a buffer using AVAudioEngine.InputNode.InstallTapOnBus().
As a last resort trying to fix the issue in their code, I took a reference sample in Objective C and transcoded it into C# line by line.
Both the reference code and the Xamarin solution throw the same error on the simulator:
2016-02-08 17:45:59.149 AudioTest[7773:2330675] Unable to set preferred number of channels
2016-02-08 17:45:59.502 AudioTest[7773:2330675] 17:45:59.493 ERROR: [0x3930b000] AVAudioNode.mm:564: CreateRecordingTap: required condition is false: IsFormatSampleRateAndChannelCountValid(format)
However, the reference code runs on the device, but the Xamarin solution doesn't - instead it throws the same error as on the simulator.
Attached are the reference sample and the C# version up to the point where the code crashes. In both cases it seems to occur at the point of the input.InstallTapOnBus line, but the problem may be related to an earlier issue in the code where the channelcount is set:
okState= [audioSession setPreferredInputNumberOfChannels:kNumChannel error:&outError];
okState = audioSession.SetPreferredInputNumberOfChannels(audioSession.CurrentHardwareInputNumberOfChannels, out error);
I haven't fully implemented the entire reference sample in C# as this is just to show the issue.
Created attachment 14948 [details]
C# partial implementation
You didn't port the audioSessionManagement method from the ObjC sample, which is important.
Adding the following lines to ViewDidLoad fixes the C# sample:
var audioSession = AVAudioSession.SharedInstance();
audioSession.SetCategory (AVAudioSessionCategory.PlayAndRecord, AVAudioSessionCategoryOptions.MixWithOthers);