c# - Six channel output with NAudio? (Or suggestions for other .NET library that supports it?) -
i've written method in c# using naudio outputs 2 channel sound, fails @ 6 channel sound.
when using waveout, 'mmexception unhandled: invalidparameter calling waveoutopen'
here's code:
public class audiooutput { private waveout latestaudioout = null; private wavememorystream latestmemorystream = null; public void playaudio (byte[][] buffers, waveformat format) { if (latestaudioout != null) { latestaudioout.stop(); latestaudioout.dispose(); } latestaudioout = new waveout(); if (latestmemorystream != null) { latestmemorystream.dispose(); } int longestchannellength = 0; foreach (byte[] b in buffers) { if (b != null) if (b.length > longestchannellength) longestchannellength = b.length; } byte[][] finalisedbuffers = new byte[buffers.length][]; (int = 0; < buffers.length; ++) { finalisedbuffers[i] = new byte[longestchannellength]; if (buffers[i] != null) buffers[i].copyto(finalisedbuffers[i], 0); } buffers = finalisedbuffers; byte[] interleavedbuffer = new byte[longestchannellength * buffers.length]; int bytespersample = format.bitspersample / 8; int framelength = buffers.length * bytespersample; int numberofframes = longestchannellength / bytespersample; int position = 0; int framestart = 0; (int f = 0; f < numberofframes; f ++) { (int c = 0; c < buffers.length; c ++) { (int b = 0; b < bytespersample; b ++) { interleavedbuffer[position] = buffers[c][framestart + b]; position ++; } } framestart += bytespersample; } memorystream bufferstream = new memorystream(interleavedbuffer); latestmemorystream = new wavememorystream(bufferstream, format); latestaudioout.init(latestmemorystream); latestaudioout.play(); }
i suppose need use waveformatextensible
instead of waveformat
.
Comments
Post a Comment