예제 #1
0
        private static async Task <CachedSound> CreateFromFile(string filePath)
        {
            using (var audioFileReader = await WaveFormatFactory.GetResampledAudioFileReader(filePath,
                                                                                             WaveStreamType).ConfigureAwait(false))
            {
                var wholeData = new List <float>((int)(audioFileReader.Length / 4));

                var readBuffer =
                    new float[audioFileReader.WaveFormat.SampleRate * audioFileReader.WaveFormat.Channels];
                int samplesRead;
                while ((samplesRead = audioFileReader.Read(readBuffer, 0, readBuffer.Length)) > 0)
                {
                    wholeData.AddRange(readBuffer.Take(samplesRead));
                }

                var cachedSound = new CachedSound(filePath)
                {
                    AudioData  = wholeData.ToArray(),
                    Duration   = audioFileReader.TotalTime,
                    WaveFormat = audioFileReader.WaveFormat,
                };
                return(cachedSound);
            }
        }
예제 #2
0
 protected bool Equals(CachedSound other)
 {
     return(SourcePath == other.SourcePath);
 }
예제 #3
0
 public CachedSoundSampleProvider(CachedSound cachedSound)
 {
     SourceSound = cachedSound;
     //Length = cachedSound.Length;
 }