Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
 protected bool Equals(CachedSound other)
 {
     return(SourcePath == other.SourcePath);
 }
Ejemplo n.º 3
0
 public CachedSoundSampleProvider(CachedSound cachedSound)
 {
     SourceSound = cachedSound;
     //Length = cachedSound.Length;
 }