예제 #1
0
 /// <summary>
 /// If CanFillis true with this method you can fill the next free buffer
 /// </summary>
 /// <param name="pcm">The array containing PCM data</param>
 /// <param name="bufferSize">The full size in bytes of PCM data</param>
 /// <param name="type">If this buffer is the last buffer of the stream set to true, if not false</param>
 protected unsafe void FillBuffer(byte[] pcm, int bufferSize, AudioLayer.BufferType type)
 {
     fixed(void *pcmBuffer = pcm)
     {
         FillBuffer(new IntPtr(pcmBuffer), bufferSize, type);
     }
 }
예제 #2
0
        /// <summary>
        /// If CanFillis true with this method you can fill the next free buffer
        /// </summary>
        /// <param name="pcm">The pointer to PCM data</param>
        /// <param name="bufferSize">The full size in bytes of PCM data</param>
        /// <param name="type">If this buffer is the last buffer of the stream set to true, if not false</param>
        protected void FillBuffer(IntPtr pcm, int bufferSize, AudioLayer.BufferType type)
        {
            var buffer = freeBuffers.Dequeue();

            AudioLayer.SourceQueueBuffer(SoundInstance.Source, buffer, pcm, bufferSize, type);
            if (readyToPlay)
            {
                return;
            }

            prebufferedCount++;
            if (prebufferedCount < prebufferedTarget)
            {
                return;
            }
            readyToPlay = true;
            ReadyToPlay.TrySetResult(true);
        }
예제 #3
0
        /// <summary>
        /// If CanFillis true with this method you can fill the next free buffer
        /// </summary>
        /// <param name="pcm">The array containing PCM data</param>
        /// <param name="bufferSize">The full size in bytes of PCM data</param>
        /// <param name="type">If this buffer is the last buffer of the stream set to true, if not false</param>
        protected unsafe void FillBuffer(short[] pcm, int bufferSize, AudioLayer.BufferType type)
        {
            var buffer = freeBuffers.Dequeue();

            fixed(short *pcmBuffer = pcm)
            AudioLayer.SourceQueueBuffer(SoundInstance.Source, buffer, new IntPtr(pcmBuffer), bufferSize, type);

            if (readyToPlay)
            {
                return;
            }

            prebufferedCount++;
            if (prebufferedCount < prebufferedTarget)
            {
                return;
            }
            readyToPlay = true;
            ReadyToPlay.TrySetResult(true);
        }
예제 #4
0
        private unsafe void SendExtractedAudioDataToAudioBuffer(AudioLayer.BufferType bufferType)
        {
            {
                //Update the average number of bytes per buffer
                sentBuffersCount++;
                accumulatedSentBytesCount += storageBuffer.CountDataBytes;
                var countAverageBytesPerBuffer = (accumulatedSentBytesCount / sentBuffersCount);
                if (sentBuffersCount >= 10000)
                {
                    //To prevent overflow
                    sentBuffersCount          = 10;
                    accumulatedSentBytesCount = countAverageBytesPerBuffer * sentBuffersCount;
                }

                //new buffer's estimated time
                var bufferDuration = TimeSpan.FromSeconds(storageBuffer.CountDataBytes / byteRatePerSecond);

                //compute an estimate of the time left before this new buffer can be played
                var playTimeLeft = TimeSpan.FromSeconds((NumberOfBuffers - freeBuffers.Count) * countAverageBytesPerBuffer / byteRatePerSecond);

                //Normally: if the buffer are continuous: bufferStartingTimeUs should be very close from the previous MediaPresentationTimeUsMax value
                //This could help us debug in the case of the audio timeFrame is incorrect

                var currentTime         = MediaCurrentTime;
                var mediaCurrentTimeMin = storageBuffer.PresentationTime - playTimeLeft;
                mediaCurrentTimeMax = storageBuffer.PresentationTime + bufferDuration;

                //A buffer was being played, so we expect the currentTime to be between [min, bufferStartingTime]
                if (currentTime > mediaCurrentTimeMin && mediaCurrentTimeMin < storageBuffer.PresentationTime)
                {
                    mediaCurrentTimeMin = MediaCurrentTime;
                }

                MediaCurrentTime = mediaCurrentTimeMin;
            }

            FillBuffer(storageBuffer.Data, storageBuffer.CountDataBytes, bufferType);
        }
예제 #5
0
        /// <summary>
        /// If CanFillis true with this method you can fill the next free buffer
        /// </summary>
        /// <param name="pcm">The pointer to PCM data</param>
        /// <param name="bufferSize">The full size in bytes of PCM data</param>
        /// <param name="type">If this buffer is the last buffer of the stream set to true, if not false</param>
        protected void FillBuffer(IntPtr pcm, int bufferSize, AudioLayer.BufferType type)
        {
            if (bufferSize > nativeBufferSizeBytes)
            {
                Logger.Error("Provided buffer size is bigger than native buffer. Data will be cut.");
                bufferSize = nativeBufferSizeBytes;
            }

            var buffer = freeBuffers.Dequeue();

            AudioLayer.SourceQueueBuffer(SoundInstance.Source, buffer, pcm, bufferSize, type);
            if (readyToPlay)
            {
                return;
            }

            prebufferedCount++;
            if (prebufferedCount < prebufferedTarget)
            {
                return;
            }
            readyToPlay = true;
            ReadyToPlay.TrySetResult(true);
        }