Beispiel #1
0
        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();
        }
Beispiel #4
0
 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);
     }
 }
Beispiel #5
0
 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);
     }
 }
Beispiel #6
0
 // 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);
     }
 }
Beispiel #7
0
 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());
         }
     }
 }
Beispiel #8
0
        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);
                }
            }
        }
Beispiel #9
0
        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);
            }
        }
Beispiel #10
0
 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));
         }
     }
 }
Beispiel #11
0
        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);
        }
Beispiel #12
0
 public static extern unsafe OSStatus AudioQueueAddPropertyListener(AudioQueue *pQueue, AudioQueueProperty propertyId, AudioQueuePropertyChangeCallback callback, void *pUserData);
Beispiel #13
0
 public static extern unsafe OSStatus AudioQueueSetProperty(AudioQueue *pQueue, AudioQueueProperty propertyId, void *pCookie, int cookieSize);
Beispiel #14
0
        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);
                }
            }
        }
Beispiel #15
0
        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);
            }
        }
Beispiel #16
0
 public bool GetProperty(AudioQueueProperty property, ref int dataSize, IntPtr outdata)
 {
     return(AudioQueueGetProperty(handle, property, outdata, ref dataSize) == 0);
 }
Beispiel #17
0
 public bool SetProperty(AudioQueueProperty property, int dataSize, IntPtr propertyData)
 {
     return(AudioQueueSetProperty(handle, property, propertyData, dataSize) == 0);
 }
Beispiel #18
0
 extern static AudioQueueStatus AudioQueueGetPropertySize(IntPtr AQ, AudioQueueProperty id, out int size);
Beispiel #19
0
 extern static AudioQueueStatus AudioQueueSetProperty(
     IntPtr AQ, AudioQueueProperty id, IntPtr data, int size);
Beispiel #20
0
 extern static AudioQueueStatus AudioQueueGetProperty(IntPtr AQ, AudioQueueProperty id, IntPtr outdata, ref int dataSize);
Beispiel #21
0
 extern static OSStatus AudioQueueRemovePropertyListener(IntPtr AQ, AudioQueueProperty id, AudioQueuePropertyListenerProc proc, IntPtr data);
Beispiel #22
0
 public static extern unsafe OSStatus AudioQueueGetProperty(AudioQueue *pQueue, AudioQueueProperty propertyId, void *pResult, int *dataSize);
		void IsRunningChanged(AudioQueueProperty property)
		{
			if(queue.IsRunning == false)
				readyToReFire = true;
		}
Beispiel #24
0
		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");
					}
				}
			}
		}