예제 #1
0
 private static void SourcePlayAsync(CompressedSoundSource source)
 {
     Task.Run(async() =>
     {
         var playMe = await source.ReadyToPlay.Task;
         if (playMe)
         {
             AudioLayer.SourcePlay(source.SoundInstance.Source);
         }
     });
 }
예제 #2
0
        private static void SourcePrepare(CompressedSoundSource source)
        {
            source.compressedSoundStream.Position = 0;
            source.begin = true;
            source.currentPacketIndex  = 0;
            source.startPktSampleIndex = 0;
            source.endPktSampleIndex   = 0;
            source.endPacketIndex      = source.numberOfPackets;

            PlayRange range;

            lock (source.rangeLock)
            {
                range = source.playRange;
            }

            if (range.Start != TimeSpan.Zero || range.Length != TimeSpan.Zero)
            {
                var frameSize = SamplesPerFrame * source.channels;
                //ok we need to handle this case properly, this means that the user wants to use a different then full audio stream range...
                var sampleStart = source.sampleRate * (double)source.channels * range.Start.TotalSeconds;
                source.startPktSampleIndex = (int)Math.Floor(sampleStart) % (frameSize);

                var sampleStop = source.sampleRate * (double)source.channels * range.End.TotalSeconds;
                source.endPktSampleIndex = frameSize - (int)Math.Floor(sampleStart) % frameSize;

                var skipCounter = source.startingPacketIndex = (int)Math.Floor(sampleStart / frameSize);
                source.endPacketIndex = (int)Math.Floor(sampleStop / frameSize);

                // skip to the starting packet
                if (source.startingPacketIndex < source.numberOfPackets && source.endPacketIndex < source.numberOfPackets && source.startingPacketIndex < source.endPacketIndex)
                {
                    //valid offsets.. process it
                    while (skipCounter-- > 0)
                    {
                        //skip data to reach starting packet
                        var len = source.reader.ReadInt16();
                        source.compressedSoundStream.Position = source.compressedSoundStream.Position + len;
                        source.currentPacketIndex++;
                    }
                }
            }
        }
        private static void SourcePrepare(CompressedSoundSource source)
        {
            source.compressedSoundStream.Position = 0;
            source.begin = true;
            source.currentPacketIndex = 0;
            source.startPktSampleIndex = 0;
            source.endPktSampleIndex = 0;
            source.endPacketIndex = source.numberOfPackets;

            PlayRange range;
            lock (source.rangeLock)
            {
                range = source.playRange;
            }

            if (range.Start != TimeSpan.Zero || range.Length != TimeSpan.Zero)
            {
                var frameSize = SamplesPerFrame * source.channels;
                //ok we need to handle this case properly, this means that the user wants to use a different then full audio stream range...
                var sampleStart = source.sampleRate * (double)source.channels * range.Start.TotalSeconds;
                source.startPktSampleIndex = (int)Math.Floor(sampleStart) % (frameSize);

                var sampleStop = source.sampleRate * (double)source.channels * range.End.TotalSeconds;
                source.endPktSampleIndex = frameSize - (int)Math.Floor(sampleStart) % frameSize;

                var skipCounter = source.startingPacketIndex = (int)Math.Floor(sampleStart / frameSize);
                source.endPacketIndex = (int)Math.Floor(sampleStop / frameSize);

                // skip to the starting packet
                if (source.startingPacketIndex < source.numberOfPackets && source.endPacketIndex < source.numberOfPackets && source.startingPacketIndex < source.endPacketIndex)
                {
                    //valid offsets.. process it
                    while (skipCounter-- > 0)
                    {
                        //skip data to reach starting packet
                        var len = source.reader.ReadInt16();
                        source.compressedSoundStream.Position = source.compressedSoundStream.Position + len;
                        source.currentPacketIndex++;
                    }
                }
            }
        }
 private static void SourcePlayAsync(CompressedSoundSource source)
 {
     Task.Run(async () =>
     {
         var playMe = await source.ReadyToPlay.Task;
         if(playMe) AudioLayer.SourcePlay(source.SoundInstance.Source);
     });
 }