AudioObjectGetPropertyData not found in xamarin..

renanjegouzorenanjegouzo FRMember
edited February 2016 in Xamarin.Mac

I don't know how to translate this code in xamarin, I can't find the API..

http://pastebin.com/raw/QvgcSUse

Posts

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    I've fixed the formatting issue (our forum sometimes has trouble with code that has { and } marks and edited your post.

    I'll take a look at your question shortly.

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    Our AudioUnit API does some wrapping around the low level "C" style API to make it a bit more C# friendly. However, sometimes that causes issues finding what API you exactly need.

    Try AudioUnit.AudioUnit.GetCurrentInputDevice ()

  • I want to list all audio devices inputs and outputs.
    to setup the output device for OutputAudioQueue and input device for InpuAudioQueue
    kinda like this http://stackoverflow.com/questions/20051529/audioqueue-change-audio-device-while-audioqueue-is-running (but without running ;)

  • I need a DeviceID to setup the "device" property on both InputAudioQueue and OutputAudioQueue

  • AudioQueue service is completely independent from audiounit

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    I believe we have all of the relevant APIs bound. Please feel free to ask here or file bugs if you can confirm a given API is missing.

    Use of the Audio APIs is non-trivial and will require much trial and error.

    It appears our current binding for AudioQueue / InputAudioStream are:

    InputAudioQueue (AudioStreamBasicDescription desc)
    InputAudioQueue (AudioStreamBasicDescription desc, CFRunLoop runLoop, string runMode)

  • I have no problem using AudioQueue, what I'm seeking is the c# binding for AudioObjectGetPropertyData()

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    So, we don't in general expose the "raw" get property data like APIs for many of the AudioAPIs. Normally things are wrapped in C# safe properties. If you really want it, something like this should work:

        [DllImport ("/System/Library/Frameworks/AudioUnit.framework/AudioUnit")]
            static extern int AudioObjectGetPropertyData (
            uint inObjectID,
            ref AudioObjectPropertyAddress inAddress,
            ref uint inQualifierDataSize,
            ref IntPtr inQualifierData,
            ref uint ioDataSize,
            out uint outData
        );
    

    But if you need that, then likely our binding has missing sections and you should file a bug (https://bugzilla.xamarin.com) as well.

  • renanjegouzorenanjegouzo FRMember

    I think it's here the real problem with xamarin, you should try to support the apple API directly, as the apple API is well documented, and yours not.

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    In general, the mapping from objective-c to C# is straightforward. I admit in this case it is less so.

    We'll keep your feedback in mind.

  • DamianMehersDamianMehers CHBeta ✭✭

    @ChrisHamons said:
    Our AudioUnit API does some wrapping around the low level "C" style API to make it a bit more C# friendly. However, sometimes that causes issues finding what API you exactly need.

    Try AudioUnit.AudioUnit.GetCurrentInputDevice ()

    Hi Chris, any reason why you didn't create a GetCurrentOutputDevice wrapper (using kAudioHardwarePropertyDefaultOutputDevice)?

    I see from the source that it should be pretty straight-forward, and will try to do it myself and submit a pull request if it works.

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    Two years ago when I wrote this we weren't even open source yet (if I remember my dates right March was before build). In addition, getting builds out with changes was significantly more difficult, thus working around the API flaws was a better short term plan.

    I did neglect to patch the hole, likely because I forgot after the fact. A PR with that change would be welcome. Feel free to assign it to me once you make it and I'll take a look.

  • DamianMehersDamianMehers CHBeta ✭✭

    @ChrisHamons said:
    Two years ago when I wrote this we weren't even open source yet (if I remember my dates right March was before build). In addition, getting builds out with changes was significantly more difficult, thus working around the API flaws was a better short term plan.

    I did neglect to patch the hole, likely because I forgot after the fact. A PR with that change would be welcome. Feel free to assign it to me once you make it and I'll take a look.

    Sorry - didn't mean to sound accusatory, just wanted to check if there was a technical hitch.

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    No worries, just explaining the context. :)

  • DamianMehersDamianMehers CHBeta ✭✭

    I have GetCurrentOutputDevice working hacked together locally. I'm working on a proper pull request. In case I screw up the pull request, here is my local code, for reference:

    public class MyAudioUnit {
    
        [DllImport(ObjCRuntime.Constants.AudioUnitLibrary)]
        static extern int AudioObjectGetPropertyData(
          uint inObjectID,
          ref AudioObjectPropertyAddress inAddress,
          ref uint inQualifierDataSize,
          ref IntPtr inQualifierData,
          ref uint ioDataSize,
          out uint outData
        );
    
        [StructLayout(LayoutKind.Sequential)]
        struct AudioObjectPropertyAddress {
          public uint /* UInt32 */ Selector;
          public uint /* UInt32 */ Scope;
          public uint /* UInt32 */ Element;
    
          public AudioObjectPropertyAddress(uint selector, uint scope, uint element) {
            Selector = selector;
            Scope = scope;
            Element = element;
          }
    
          public AudioObjectPropertyAddress(AudioUnit.AudioObjectPropertySelector selector, AudioUnit.AudioObjectPropertyScope scope, AudioUnit.AudioObjectPropertyElement element) {
            Selector = (uint)selector;
            Scope = (uint)scope;
            Element = (uint)element;
          }
    
        }
    
        public static uint GetCurrentOutputDevice() {
          uint outputDevice;
          var size = (uint) Marshal.SizeOf (typeof (uint));
          var theAddress = new AudioObjectPropertyAddress (
            AudioUnit.AudioObjectPropertySelector.DefaultOutputDevice,
            AudioUnit.AudioObjectPropertyScope.Global,
            AudioUnit.AudioObjectPropertyElement.Master);
          uint inQualifierDataSize = 0;
          IntPtr inQualifierData = IntPtr.Zero;
    
          var err = AudioObjectGetPropertyData (1, ref theAddress, ref inQualifierDataSize, ref inQualifierData, ref size, out outputDevice);
    
          if (err != 0) throw new Exception("Error: " + err);
            //throw new AudioUnit.AudioUnitException()(int) err);
          return outputDevice;
        }  
      }
    
Sign In or Register to comment.