1

I have a problem with Audio Units in MonoTouch/Xamarin.

It seems like I can't get a callback on recording, just playback. I used this example: https://github.com/xamarin/monotouch-samples/blob/master/AUSoundTriggeredPlayingSoundMemoryBased/ExtAudioBufferPlayer.cs

and looked for Obj C examples. The Obj C examples are pretty much the same like my code so Im a little bit confused about this thing.

The output if running my example is:

INPUT0

Which is the bus number for output.

So the expected output should be:

INPUT1

So my question is: How do I get a recording callback and a playback callback running the same time, or just how do I get a recording callback.

My Code:

void prepareAudioUnit()
{
    // AudioSession
    AudioSession.Initialize();
    AudioSession.Category = AudioSessionCategory.PlayAndRecord;
    AudioSession.PreferredHardwareIOBufferDuration = Config.packetLength;
    AudioSession.PreferredHardwareSampleRate = Format.samplingRate;
    //AudioSession.SetActive (false);
    AudioSession.SetActive(true);
    Logger.log("HWSR:" + AudioSession.CurrentHardwareSampleRate);

    // Getting AudioComponent Remote output 
    _audioComponent = AudioComponent.FindComponent(AudioTypeOutput.VoiceProcessingIO);

    // creating an audio unit instanc
    _audioUnit = new AudioUnit(_audioComponent);

    // turning on microphone
    _audioUnit.SetEnableIO(true,
                            AudioUnitScopeType.Input,
                            1 // Remote Input
                            );
    _audioUnit.SetEnableIO(true,
                            AudioUnitScopeType.Output,
                            0 // Remote output
                            );

    // setting audio format
    _audioUnit.SetAudioFormat(Format.AudioStreamBasicDescription,
                               AudioUnitScopeType.Output,
                               1
                               );
    _audioUnit.SetAudioFormat(Format.AudioStreamBasicDescription,
                               AudioUnitScopeType.Input,
                               0
                               );

    // setting callback method
    _audioUnit.SetRenderCallback(_audioUnit_OutputCallback, AudioUnitScopeType.Global, 0);
    _audioUnit.SetRenderCallback(_audioUnit_InputCallback, AudioUnitScopeType.Global, 1);
}

AudioUnitStatus _audioUnit_OutputCallback(AudioUnitRenderActionFlags actionFlags, AudioTimeStamp timeStamp, uint busNumber, uint numberFrames, AudioBuffers data)
{
    Logger.log("OUTPUT" + busNumber);
    return AudioUnitStatus.NoError;
}

AudioUnitStatus _audioUnit_InputCallback(AudioUnitRenderActionFlags actionFlags, AudioTimeStamp timeStamp, uint busNumber, uint numberFrames, AudioBuffers data)
{
    Logger.log("INPUT" + busNumber);
    return AudioUnitStatus.NoError;
}
Marc
  • 3,905
  • 4
  • 21
  • 37
Michiluki
  • 505
  • 3
  • 17
  • Maybe post a link to the Objective-C sample to try to reproduce and understand the differences. – miguel.de.icaza Sep 14 '13 at 16:31
  • @miguel.de.icaza This example works 100% http://atastypixel.com/blog/using-remoteio-audio-unit/comment-page-1/ I tried to open a ticket but somehow your ticket system is ignoring my emails. – Michiluki Sep 17 '13 at 15:12
  • Did you ever get this working, I'm having the same issue. – trampster Jun 10 '20 at 01:52

1 Answers1

0

This problem is a bug in Xamarin, they forgot to add a method for InputCallbacks.

I reported the bug but for the people needing the same:

http://nopaste.info/8d0aca98d9.html

Its not good, but it shows how to solve the problem to write a fix yourself till Xamarin updates this.

Michiluki
  • 505
  • 3
  • 17