示例#1
1
 public static SampleSource CreateFromWaveFile(string fileName)
 {
     using (var reader = new WaveFileReader(fileName))
     {
         ISampleProvider sp;
         int sourceSamples;
         if (reader.WaveFormat.Encoding == WaveFormatEncoding.Pcm)
         {
             if (reader.WaveFormat.BitsPerSample == 16)
             {
                 sp = new Pcm16BitToSampleProvider(reader);
                 sourceSamples = (int)(reader.Length / 2);
             }
             else if (reader.WaveFormat.BitsPerSample == 24)
             {
                 sp = new Pcm24BitToSampleProvider(reader);
                 sourceSamples = (int)(reader.Length / 3);
             }
             else
             {
                 throw new ArgumentException("Currently only 16 or 24 bit PCM samples are supported");
             }
         }
         else if (reader.WaveFormat.Encoding == WaveFormatEncoding.IeeeFloat)
         {
             sp = new WaveToSampleProvider(reader);
             sourceSamples = (int)(reader.Length / 4);
         }
         else
         {
             throw new ArgumentException("Must be PCM or IEEE float");
         }
         float[] sampleData = new float[sourceSamples];
         int n = sp.Read(sampleData, 0, sourceSamples);
         if (n != sourceSamples)
         {
             throw new InvalidOperationException(String.Format("Couldn't read the whole sample, expected {0} samples, got {1}", n, sourceSamples));
         }
         SampleSource ss = new SampleSource(sampleData, sp.WaveFormat);
         return ss;
     }
 }
示例#2
0
        public DrumKit()
        {
            var kickSample       = SampleSource.CreateFromWaveFile("Samples\\kick-trimmed.wav");
            var snareSample      = SampleSource.CreateFromWaveFile("Samples\\snare-trimmed.wav");
            var closedHatsSample = SampleSource.CreateFromWaveFile("Samples\\closed-hat-trimmed.wav");
            var openHatsSample   = SampleSource.CreateFromWaveFile("Samples\\open-hat-trimmed.wav");

            sampleSources = new List <SampleSource> {
                kickSample, snareSample, closedHatsSample, openHatsSample
            };

            WaveFormat = WaveFormat.CreateIeeeFloatWaveFormat(openHatsSample.SampleWaveFormat.SampleRate, openHatsSample.SampleWaveFormat.Channels);
        }
示例#3
0
文件: DrumKit.cs 项目: tabjin0/audio
        public DrumKit()
        {
            SampleSource kickSample       = SampleSource.CreateFromWaveFile("Samples\\kick-trimmed.wav");
            SampleSource snareSample      = SampleSource.CreateFromWaveFile("Samples\\snare-trimmed.wav");
            SampleSource closedHatsSample = SampleSource.CreateFromWaveFile("Samples\\closed-hat-trimmed.wav");
            SampleSource openHatsSample   = SampleSource.CreateFromWaveFile("Samples\\open-hat-trimmed.wav");

            sampleSources = new List <SampleSource>();

            sampleSources.Add(kickSample);
            sampleSources.Add(snareSample);
            sampleSources.Add(closedHatsSample);
            sampleSources.Add(openHatsSample);
            this.waveFormat = WaveFormat.CreateIeeeFloatWaveFormat(openHatsSample.SampleWaveFormat.SampleRate, openHatsSample.SampleWaveFormat.Channels);
        }
示例#4
0
 public static SampleSource CreateFromWaveFile(string fileName)
 {
     using (var reader = new WaveFileReader(fileName))
     {
         var sp = reader.ToSampleProvider();
         var sourceSamples = (int)(reader.Length / (reader.WaveFormat.BitsPerSample / 8));
         var sampleData = new float[sourceSamples];
         int n = sp.Read(sampleData, 0, sourceSamples);
         if (n != sourceSamples)
         {
             throw new InvalidOperationException(String.Format("Couldn't read the whole sample, expected {0} samples, got {1}", n, sourceSamples));
         }
         var ss = new SampleSource(sampleData, sp.WaveFormat);
         return ss;
     }
 }
示例#5
0
 public static SampleSource CreateFromWaveFile(string fileName)
 {
     using (var reader = new WaveFileReader(fileName))
     {
         var sp            = reader.ToSampleProvider();
         var sourceSamples = (int)(reader.Length / (reader.WaveFormat.BitsPerSample / 8));
         var sampleData    = new float[sourceSamples];
         int n             = sp.Read(sampleData, 0, sourceSamples);
         if (n != sourceSamples)
         {
             throw new InvalidOperationException(String.Format("Couldn't read the whole sample, expected {0} samples, got {1}", n, sourceSamples));
         }
         var ss = new SampleSource(sampleData, sp.WaveFormat);
         return(ss);
     }
 }
示例#6
0
 public static SampleSource CreateFromWaveFile(string fileName)
 {
     using (var reader = new WaveFileReader(fileName))
     {
         ISampleProvider sp;
         int             sourceSamples;
         if (reader.WaveFormat.Encoding == WaveFormatEncoding.Pcm)
         {
             if (reader.WaveFormat.BitsPerSample == 16)
             {
                 sp            = new Pcm16BitToSampleProvider(reader);
                 sourceSamples = (int)(reader.Length / 2);
             }
             else if (reader.WaveFormat.BitsPerSample == 24)
             {
                 sp            = new Pcm24BitToSampleProvider(reader);
                 sourceSamples = (int)(reader.Length / 3);
             }
             else
             {
                 throw new ArgumentException("Currently only 16 or 24 bit PCM samples are supported");
             }
         }
         else if (reader.WaveFormat.Encoding == WaveFormatEncoding.IeeeFloat)
         {
             sp            = new WaveToSampleProvider(reader);
             sourceSamples = (int)(reader.Length / 4);
         }
         else
         {
             throw new ArgumentException("Must be PCM or IEEE float");
         }
         float[] sampleData = new float[sourceSamples];
         int     n          = sp.Read(sampleData, 0, sourceSamples);
         if (n != sourceSamples)
         {
             throw new InvalidOperationException(String.Format("Couldn't read the whole sample, expected {0} samples, got {1}", n, sourceSamples));
         }
         SampleSource ss = new SampleSource(sampleData, sp.WaveFormat);
         return(ss);
     }
 }
 public MusicSampleProvider(SampleSource sampleSource)
 {
     this.sampleSource = sampleSource;
 }
示例#8
0
 public MusicSampleProvider(SampleSource sampleSource)
 {
     this.sampleSource = sampleSource;
 }