Skip to content

Instantly share code, notes, and snippets.

@chamons
Created June 29, 2015 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chamons/0b07314ffcd20734ff09 to your computer and use it in GitHub Desktop.
Save chamons/0b07314ffcd20734ff09 to your computer and use it in GitHub Desktop.
// Something not null here!
AudioConverter a = null; //AudioConverter.Create (srcFormat, dstFormat, out ce);
SetProperty (a, 0x73726361, (uint)AudioConverterSampleRateConverterComplexity.Linear);// 'srca'
SetProperty (a, 0x73726371, (uint)AudioConverterQuality.Max); // 'srcq'
}
[DllImport ("/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox")]
static extern AudioConverterError AudioConverterSetProperty (IntPtr inAudioConverter, UInt32 inPropertyID,
int inPropertyDataSize, ref uint inPropertyData);
// This is ghetto
void SetProperty (AudioConverter c, UInt32 propertyID, uint value)
{
// Unlike the rest of our bindings, we don't make this public for some unknown reason...
FieldInfo fi = typeof(AudioConverter).GetField("handle", BindingFlags.NonPublic | BindingFlags.Instance);
IntPtr handle = (IntPtr)fi.GetValue (c);
var res = AudioConverterSetProperty (handle, propertyID, sizeof (uint), ref value);
if (res != AudioConverterError.None)
throw new ArgumentException (res.ToString ());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment