c# - Changing wave format at runtime with NAudio -


i have initialized device using:

static  iwaveplayer     waveout; static  waveformat      waveformat; static  bufferedwaveprovider    waveprovider;  private static int audiodeviceinit() {             waveout = new directsoundout();             waveformat = new waveformat(44100, 2);             waveprovider = new bufferedwaveprovider(waveformat);              waveout.init(waveprovider);             waveout.play();              return 0; } 

i adding pcm stream using:

waveprovider.addsamples(samples, 0, size);

the above working fine long stream data of same configuration.

i have function receives sample rate , number of channels , want reconfigure waveprovider use newly provided configuration. here code using:

private static void audioconfigcallback(int rate, int channel) {     waveformat = new waveformat(rate, channel);     waveprovider = new bufferedwaveprovider(waveformat);     waveout.init(waveprovider);     return; } 

this not working , believe not correct way of doing well. idea how can reconfigure device use new sample_rate , num_channels

thanks.

this not possible. when open output device, whether waveout, direct sound, wasapi or asio, @ point must specify format @ work. must close output device , re-open new waveformat.

an alternative approach convert fixed waveformat, , use waveformatconversionstream convert correct format whenever incoming format changes. allow avoid opening , closing output device.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -