c# - change wav file ( to 16KHz and 8bit ) with using NAudio -
c# - change wav file ( to 16KHz and 8bit ) with using NAudio -
i want alter wav file 8khz , 8bit using naudio.
waveformat format1 = new waveformat(8000, 8, 1); byte[] wavebyte = helperclass.readfully(file.openread(wavfile)); wave using (wavefilewriter author = new wavefilewriter(outputfile, format1)) { writer.writedata(wavebyte, 0, wavebyte.length); }
but when play output file, sound sizzle. code right or wrong?
if set waveformat waveformat(44100, 16, 1), works fine.
thanks.
a few pointers:
you need utilize waveformatconversionstream convert 1 sample rate / bit depth - putting original sound new file wrong wave format. you may need convert in 2 steps - first changing sample rate, changing bit depth / channel count. because underlying acm codecs can't conversion want in single step. you should utilize wavefilereader read input file - want actual sound info part of file converted, copying including riff chunks though sound info new file. 8 bit pcm sound sounds horrible. utilize 16 bit, or if must have 8 bit, utilize g.711 u-law or a-law downsampling sound can result in aliasing. need implement low-pass filter first. unfortunately isn't easy, there sites help generate coefficients chebyshev low pass filter specific downsampling doing.here's illustration code showing how convert 1 format another. remember might need conversion in multiple steps depending on format of input file:
using (var reader = new wavefilereader("input.wav")) { var newformat = new waveformat(8000, 16, 1); using (var conversionstream = new waveformatconversionstream(newformat, reader)) { wavefilewriter.createwavefile("output.wav", conversionstream); } }
c# .net audio wav naudio
Comments
Post a Comment