public T GetProperty <T> (AudioQueueProperty property) { int size; var r = AudioQueueGetPropertySize(handle, property, out size); if (r != 0) { throw new AudioQueueException(r); } var buffer = Marshal.AllocHGlobal(size); if (buffer == IntPtr.Zero) { return(default(T)); } try { r = AudioQueueGetProperty(handle, property, buffer, ref size); if (r == 0) { return((T)Marshal.PtrToStructure(buffer, typeof(T))); } throw new AudioQueueException(r); } finally { Marshal.FreeHGlobal(buffer); } }
void IsRunningChanged(AudioQueueProperty property) { if (queue.IsRunning == false) { readyToReFire = true; } }
public void Setup() { if (soundEffect.IsDisposed) { throw new ObjectDisposedException(soundEffect.ToString()); } buffers = new IntPtr[numberOfBuffers]; queue = new OutputAudioQueue(soundEffect.description); queue.OutputCompleted += new EventHandler <OutputCompletedEventArgs>(HandleOutputBuffer); IsRunningChangedCallback = new AudioQueue.AudioQueuePropertyChanged(IsRunningChanged); queue.AddListener(AudioQueueProperty.IsRunning, IsRunningChangedCallback); // Set hardware mode unsafe { const AudioQueueProperty HardwareCodecPolicy = (AudioQueueProperty)1634820976; // 'aqcp' const uint PreferSoftware = 3, PreferHardware = 4; uint policy = hardware ? PreferHardware : PreferSoftware; queue.SetProperty(HardwareCodecPolicy, Marshal.SizeOf(typeof(uint)), new IntPtr(&policy)); } AllocatePacketDescriptionsArray(); queue.MagicCookie = audioFile.MagicCookie; AllocateBuffers(); queue.Volume = 1; PrimeBuffers(); }
int SetInt(AudioQueueProperty property, int val) { unsafe { int size = 4; var k = AudioQueueSetProperty(handle, property, (IntPtr)(&val), size); if (k == 0) { return(val); } throw new AudioQueueException(k); } }
double GetDouble(AudioQueueProperty property) { unsafe { double val = 0; int size = 8; var k = AudioQueueGetProperty(handle, property, (IntPtr)(&val), ref size); if (k == 0) { return(val); } throw new AudioQueueException(k); } }
// Not currently in use. long GetLong(AudioQueueProperty property) { unsafe { long val = 0; int size = 8; int k = AudioQueueGetProperty(handle, property, (IntPtr)(&val), ref size); if (k == 0) { return(val); } throw new AudioQueueException(k); } }
static unsafe void PropertyChangeProc(void *pUserData, AudioQueue *pQueue, AudioQueueProperty id) { lock (API.StopLock) { try { PropertyChangeInternal(pUserData, pQueue, id); } catch (Exception e) { Console.WriteLine(e.ToString()); } } }
static void property_changed(IntPtr userData, IntPtr AQ, AudioQueueProperty id) { GCHandle gch = GCHandle.FromIntPtr(userData); var aq = gch.Target as AudioQueue; lock (aq.listeners){ ArrayList a = (ArrayList)aq.listeners [id]; if (a == null) { return; } foreach (AudioQueuePropertyChanged cback in a) { cback(id); } } }
public void AddListener(AudioQueueProperty id, AudioQueuePropertyChanged callback) { if (callback == null) { throw new ArgumentNullException("callback"); } if (listeners == null) { listeners = new Hashtable(); } lock (listeners){ var a = (ArrayList)listeners [id]; if (a == null) { AudioQueueAddPropertyListener(handle, id, property_changed, GCHandle.ToIntPtr(gch)); listeners [id] = a = new ArrayList(); } a.Add(callback); } }
public void RemoveListener(AudioQueueProperty id, AudioQueuePropertyChanged callback) { if (callback == null) { throw new ArgumentNullException("callback"); } if (listeners == null) { return; } lock (listeners){ var a = (ArrayList)listeners [id]; if (a == null) { return; } a.Remove(callback); if (a.Count == 0) { AudioQueueRemovePropertyListener(handle, id, property_changed, GCHandle.ToIntPtr(gch)); } } }
public IntPtr GetProperty(AudioQueueProperty property, out int size) { var r = AudioQueueGetPropertySize(handle, property, out size); if (r != 0) { throw new AudioQueueException(r); } var buffer = Marshal.AllocHGlobal(size); if (buffer == IntPtr.Zero) { return(IntPtr.Zero); } r = AudioQueueGetProperty(handle, property, buffer, ref size); if (r == 0) { return(buffer); } Marshal.FreeHGlobal(buffer); return(IntPtr.Zero); }
public static extern unsafe OSStatus AudioQueueAddPropertyListener(AudioQueue *pQueue, AudioQueueProperty propertyId, AudioQueuePropertyChangeCallback callback, void *pUserData);
public static extern unsafe OSStatus AudioQueueSetProperty(AudioQueue *pQueue, AudioQueueProperty propertyId, void *pCookie, int cookieSize);
static unsafe void PropertyChangeInternal(void *pUserData, AudioQueue *pQueue, AudioQueueProperty id) { AudioStream *pThis = (AudioStream *)pUserData; if (pThis == null) { Console.WriteLine("PropertyChangeProc: pThis is null"); } if (pQueue == null) { Console.WriteLine("PropertyChangeProc: pQueue is null"); } int size = sizeof(uint); uint iIsRunning = 0; OSStatus status = API.AudioQueueGetProperty(pQueue, AudioQueueProperty.IsRunning, &iIsRunning, &size); API.CheckStatus(status); bool isRunning = iIsRunning != 0; if (status == 0) { if (pThis->IsRunning && !isRunning) { AudioStream.Stop(pThis); } } }
private static unsafe void CopyPropertyFromFileToQueue(AudioStream *pThis, AudioFileProperty fileProp, AudioQueueProperty queueProp) { int size = sizeof(uint); OSStatus status = API.AudioFileGetPropertyInfo(pThis->AudioFile, fileProp, &size, null); if (status == 0 && size > 0) { void *pData = (void *)Marshal.AllocHGlobal(size); API.AudioFileGetProperty(pThis->AudioFile, fileProp, &size, pData); API.AudioQueueSetProperty(pThis->Queue, queueProp, pData, size); Marshal.FreeHGlobal((IntPtr)pData); } }
public bool GetProperty(AudioQueueProperty property, ref int dataSize, IntPtr outdata) { return(AudioQueueGetProperty(handle, property, outdata, ref dataSize) == 0); }
public bool SetProperty(AudioQueueProperty property, int dataSize, IntPtr propertyData) { return(AudioQueueSetProperty(handle, property, propertyData, dataSize) == 0); }
extern static AudioQueueStatus AudioQueueGetPropertySize(IntPtr AQ, AudioQueueProperty id, out int size);
extern static AudioQueueStatus AudioQueueSetProperty( IntPtr AQ, AudioQueueProperty id, IntPtr data, int size);
extern static AudioQueueStatus AudioQueueGetProperty(IntPtr AQ, AudioQueueProperty id, IntPtr outdata, ref int dataSize);
extern static OSStatus AudioQueueRemovePropertyListener(IntPtr AQ, AudioQueueProperty id, AudioQueuePropertyListenerProc proc, IntPtr data);
public static extern unsafe OSStatus AudioQueueGetProperty(AudioQueue *pQueue, AudioQueueProperty propertyId, void *pResult, int *dataSize);
void IsRunningChanged(AudioQueueProperty property) { if(queue.IsRunning == false) readyToReFire = true; }
void EmitFinishedEvent (AudioQueueProperty property) { var finished = Finished; if (finished != null) { if (!Paused && !outputQueue.IsRunning) { try { finished (this, EventArgs.Empty); } catch (Exception ex) { LoggingService.LogError (ex, "Unhandled exception emitting the Finished event"); } } } }