Пример #1
0
        /// <summary>
        /// Request a new chunk of audio samples from the stream source.
        /// </summary>
        /// <param name="samples">The audio chunk that contains audio samples.</param>
        /// <returns><code>true</code> if reach the end of stream, otherwise false.</returns>
        protected override bool OnGetData(out short[] samples)
        {
            lock (_mutex)
            {
                // Fill the chunk parameters
                samples = new short[_sampleCount];
                long count = _reader.Read(samples, samples.Length);

                // Check if we have reached the end of the audio file
                return(count == samples.Length);
            }
        }
Пример #2
0
        private void Initialize(SoundReader reader, SampleInfo info)
        {
            // Retrieve the sound parameters
            long sampleCount  = info.SampleCount;
            int  channelCount = info.ChannelCount;
            int  sampleRate   = info.SampleRate;

            // Read the samples from the provided file
            using (reader)
            {
                _samples = new short[sampleCount];
                if (reader.Read(_samples, sampleCount) == sampleCount)
                {
                    // Update the internal buffer with the new samples
                    Update(channelCount, sampleRate);
                }
                else
                {
                    throw new Exception("Failed to decode the sound data.");
                }
            }
        }
Пример #3
0
        private void Initialize(SoundReader reader, SampleInfo info)
        {
            // Retrieve the sound parameters
            long sampleCount  = info.SampleCount;
            int  channelCount = info.ChannelCount;
            int  sampleRate   = info.SampleRate;

            // Read the samples from the provided file
            using (reader)
            {
                _samples = new short[sampleCount];
                if (reader.Read(_samples, sampleCount) == sampleCount)
                {
                    // Update the internal buffer with the new samples
                    Update(channelCount, sampleRate);
                }
                else
                {
                    throw new Exception("Failed to decode the sound data.");
                }
            }
        }