Пример #1
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);
                }
            }
        }
Пример #2
0
 static unsafe void ReadBufferProc(void *pUserData, AudioQueue *pQueue, AudioQueueBuffer *pBuffer)
 {
     lock (API.StopLock)
     {
         try
         {
             ReadBufferInternal(pUserData, pQueue, pBuffer);
         }
         catch (Exception e)
         {
             Console.WriteLine(e.ToString());
         }
     }
 }
Пример #3
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());
         }
     }
 }
Пример #4
0
        static unsafe void ReadBufferInternal(void *pUserData, AudioQueue *pQueue, AudioQueueBuffer *pBuffer)
        {
            AudioStream *pThis = (AudioStream *)pUserData;

            if (pThis == null)
            {
                Console.WriteLine("ReadBufferProc: pThis is null");
            }

            if (!pThis->IsRunning)
            {
                return;
            }

            if (pQueue == null)
            {
                Console.WriteLine("ReadBufferProc: pQueue is null");
            }

            if (pBuffer == null)
            {
                Console.WriteLine("ReadBufferProc: pBuffer is null");
            }

            if (pBuffer->AudioData == null)
            {
                Console.WriteLine("ReadBufferProc: pBuffer->AudioData is null");
            }

            if (pBuffer->PacketDescriptors == null)
            {
                Console.WriteLine("ReadBufferProc: pBuffer->PacketDescriptors is null");
            }

            if (pThis->AudioFile == null)
            {
                Console.WriteLine("ReadBufferProc: pThis->AudioFile is null");
            }

            int numPacketsReadFromFile = pThis->NumPacketsToRead;
            int numBytesReadFromFile   = 0;

            OSStatus status = API.AudioFileReadPackets(pThis->AudioFile, 0, &numBytesReadFromFile, pBuffer->PacketDescriptors, pThis->CurrentPacket, &numPacketsReadFromFile, pBuffer->AudioData);

            API.CheckStatus(status);

            if (status == 0 &&
                numPacketsReadFromFile == 0 &&
                pThis->Looping)
            {
                // we ran out of packets and they are
                // asking to loop, so try and reset
                pThis->CurrentPacket   = 0;
                numPacketsReadFromFile = pThis->NumPacketsToRead;
                numBytesReadFromFile   = 0;
                status = API.AudioFileReadPackets(pThis->AudioFile, 0, &numBytesReadFromFile, pBuffer->PacketDescriptors, pThis->CurrentPacket, &numPacketsReadFromFile, pBuffer->AudioData);
                API.CheckStatus(status);
            }

            if (numPacketsReadFromFile > 0)
            {
                pBuffer->AudioDataByteSize     = numBytesReadFromFile;
                pBuffer->PacketDescriptorCount = numPacketsReadFromFile;

                status = API.AudioQueueEnqueueBuffer(pThis->Queue, pBuffer, (pBuffer->PacketDescriptors != null ? pBuffer->PacketDescriptorCount : 0), pBuffer->PacketDescriptors);
                API.CheckStatus(status);

                pThis->CurrentPacket += numPacketsReadFromFile;
            }
            else
            {
                status = API.AudioQueueStop(pThis->Queue, 0);
                API.CheckStatus(status);
            }
        }
Пример #5
0
 public static extern unsafe OSStatus AudioQueueDispose(AudioQueue *pQueue, int immediate);
Пример #6
0
 public static extern unsafe OSStatus AudioQueueFreeBuffer(AudioQueue *pQueue, AudioQueueBuffer *pBuffer);
Пример #7
0
 public static extern unsafe OSStatus AudioQueueStart(AudioQueue *pQueue, AudioTimeStamp *startTime);
Пример #8
0
 public static extern unsafe OSStatus AudioQueueSetProperty(AudioQueue *pQueue, AudioQueueProperty propertyId, void *pCookie, int cookieSize);
Пример #9
0
 public static extern unsafe OSStatus AudioQueueAllocateBufferWithPacketDescriptions(AudioQueue *pQueue, int byteCount, int descriptorCount, AudioQueueBuffer **ppBuffer);
Пример #10
0
 public static extern unsafe OSStatus AudioQueueSetParameter(AudioQueue *pQueue, AudioQueueParameter paramId, float paramVal);
Пример #11
0
 public static extern unsafe OSStatus AudioQueueAllocateBuffer(AudioQueue *pQueue, int byteCount, AudioQueueBuffer **ppBuffer);
Пример #12
0
 public static extern unsafe OSStatus AudioQueueGetProperty(AudioQueue *pQueue, AudioQueueProperty propertyId, void *pResult, int *dataSize);
Пример #13
0
 public static extern unsafe OSStatus AudioQueueAddPropertyListener(AudioQueue *pQueue, AudioQueueProperty propertyId, AudioQueuePropertyChangeCallback callback, void *pUserData);
Пример #14
0
 public static extern unsafe OSStatus AudioQueueStop(AudioQueue *pQueue, int immediate);
Пример #15
0
 public static extern unsafe OSStatus AudioQueueEnqueueBuffer(AudioQueue *pQueue, AudioQueueBuffer *pBuffer, int numPacketDescs, AudioStreamPacketDescription *pDescriptors);