Quantcast
Channel: NAudio
Viewing all articles
Browse latest Browse all 5831

New Post: how to resample pcm audio in a byte array

$
0
0
cool! thanks very much mark. i was still on version 1.6 so i've updated to 1.7.

for anyone else, here's a fragment of my code to resample to a hard-coded 8khz. seemed to work for many different input rates. ("sigpdu" carries the incoming audio information; it's an OpenDIS Signal PDU.)
BufferedWaveProvider resampler_waveProvider = new BufferedWaveProvider(new WaveFormat((int)sigpdu.SampleRate, bitdepth, 1));

// compute the length of the resampled audio
int resampled_length = (int)((Double)sigpdu.Data.Length * ((Double)8000 / (Double)sigpdu.SampleRate));

// move the pcm data from the pdu to the resampler_waveProvider 
resampler_waveProvider.AddSamples(sigpdu.Data, 0, sigpdu.Data.Length);

// init the resampler
var resampler = new MediaFoundationResampler(resampler_waveProvider , 8000);
resampler.ResamplerQuality = 60;

// get the resampled pcm
resampler.Read(sigpdu.Data, 0, resampled_length);

// copy the resampled pcm data to the playback_waveProvider
playback_waveProvider.AddSamples(sigpdu.Data, 0, resampled_length);

Viewing all articles
Browse latest Browse all 5831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>