Exemplo n.º 1
0
        PAStreamCallbackResult Callback(IntPtr input, IntPtr output, uint frameCount, ref PAStreamCallbackTimeInfo timeInfo, PAStreamCallbackFlags statusFlags, IntPtr userData)
        {
            int byteCount = (int)frameCount * Configuration.BytesPerTick;

            lock (m_SyncRoot)
            {
                // fill output buffer
                while (m_StreamData.Length < byteCount)
                {
                    if (m_Buffers.Count > 0)
                    {
                        IAudioData audioData = m_Buffers.Dequeue();
                        if (Volume != 1)
                        {
                            audioData = audioData.ChangeVolume(Volume);
                        }

                        m_StreamData.Enqueue(audioData.Data);
                        continue;
                    }
                    int silenceBytes = byteCount - m_StreamData.Length;
                    m_BufferUnderflowCount++;
                    m_BytesQueued += silenceBytes;
                    m_StreamData.Enqueue(new byte[silenceBytes]);
                }
                m_StreamData.Dequeue(byteCount, output);
                m_BytesPassed    += m_InProgressBytes;
                m_InProgressBytes = byteCount;
                return(m_Exit ? PAStreamCallbackResult.Complete : PAStreamCallbackResult.Continue);
            }
        }
Exemplo n.º 2
0
        PAStreamCallbackResult Callback(IntPtr input, IntPtr output, uint frameCount, ref PAStreamCallbackTimeInfo timeInfo, PAStreamCallbackFlags statusFlags, IntPtr userData)
        {
            var byteCount = (int)frameCount * Configuration.BytesPerTick;

            lock (syncRoot)
            {
                // fill output buffer
                while (streamData.Length < byteCount)
                {
                    if (buffers.Count > 0)
                    {
                        var audioData = buffers.Dequeue();
                        if (Volume != 1)
                        {
                            audioData = audioData.ChangeVolume(Volume);
                        }

                        streamData.Enqueue(audioData.Data, true);
                        continue;
                    }
                    var silenceBytes = byteCount - streamData.Length;
                    bufferUnderflowCount++;
                    bytesQueued += silenceBytes;
                    streamData.Enqueue(new byte[silenceBytes], true);
                }
                streamData.Dequeue(byteCount, output);
                bytesPassed    += inProgressBytes;
                inProgressBytes = byteCount;
                return(exit ? PAStreamCallbackResult.Complete : PAStreamCallbackResult.Continue);
            }
        }