Example #1
0
        private PcmData ReadWavFile(string path)
        {
            PcmData pcmData = new PcmData();

            using (BinaryReader br = new BinaryReader(
                       File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))) {
                var  wavR        = new WavReader();
                bool readSuccess = wavR.ReadHeaderAndSamples(br, 0, -1);
                if (!readSuccess)
                {
                    return(null);
                }
                pcmData.SetFormat(wavR.NumChannels, wavR.BitsPerSample, wavR.BitsPerSample,
                                  wavR.SampleRate, wavR.SampleValueRepresentationType, wavR.NumFrames);
                pcmData.SetSampleArray(wavR.GetSampleArray());
            }

            return(pcmData);
        }
Example #2
0
        public static PcmData ReadWav(BinaryReader br)
        {
            var reader = new WavReader();

            if (!reader.ReadHeaderAndSamples(br, 0, -1))
            {
                return(null);
            }

            var pcm = new PcmData();

            pcm.AlbumTitle  = reader.AlbumName;
            pcm.ArtistName  = reader.ArtistName;
            pcm.DisplayName = reader.Title;

            pcm.SetFormat(reader.NumChannels, reader.BitsPerSample,
                          reader.ValidBitsPerSample, reader.SampleRate,
                          reader.SampleValueRepresentationType, reader.NumFrames);

            pcm.SetSampleArray(reader.GetSampleArray());

            return(pcm);
        }