public void PerformanceTest() { var input1 = new TestSampleProvider(32000, 1); var input2 = new TestSampleProvider(32000, 1); var input3 = new TestSampleProvider(32000, 1); var input4 = new TestSampleProvider(32000, 1); var mp = new MultiplexingSampleProvider(new ISampleProvider[] { input1, input2, input3, input4 }, 4); mp.ConnectInputToOutput(0, 3); mp.ConnectInputToOutput(1, 2); mp.ConnectInputToOutput(2, 1); mp.ConnectInputToOutput(3, 0); float[] buffer = new float[input1.WaveFormat.AverageBytesPerSecond / 4]; Stopwatch s = new Stopwatch(); var duration = s.Time(() => { // read one hour worth of audio for (int n = 0; n < 60 * 60; n++) { mp.Read(buffer, 0, buffer.Length); } }); Console.WriteLine("Performance test took {0}ms", duration); }
public void StereoInTwoOutCanBeConfiguredToSwapLeftAndRight() { var input1 = new TestSampleProvider(32000, 2); float[] expected = new float[] { 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10 }; var mp = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 2); mp.ConnectInputToOutput(0, 1); mp.ConnectInputToOutput(1, 0); mp.AssertReadsExpected(expected); }
public void ConnectInputToOutputThrowsExceptionForInvalidOutput() { var input1 = new TestSampleProvider(32000, 2); var mp = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 1); Assert.Throws <ArgumentException>(() => mp.ConnectInputToOutput(1, 1)); }
public void HasConnectInputToOutputMethod() { var input1 = new TestSampleProvider(32000, 2); var mp = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 1); mp.ConnectInputToOutput(1, 0); }
public void TwoInOneOutShouldCanBeConfiguredToSelectRightChannel() { var input1 = new TestSampleProvider(32000, 2); float[] expected = new float[] { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19 }; var mp = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 1); mp.ConnectInputToOutput(1, 0); mp.AssertReadsExpected(expected); }
public AudioSampleBuffer Build() { BuildOutputMap(); multiplexer = new MultiplexingSampleProvider(inputs, outputMap.Length); for (int i = 0; i < outputMap.Length; i++) { var input = outputMap[i]; multiplexer.ConnectInputToOutput(input, i); AudioEngine.Log($" ch: {input} ==> {i}"); } return(new AudioSampleBuffer(multiplexer.WaveFormat) { Processor = this }); }
public static ISampleProvider AdjustChannelCount(ISampleProvider snd, UInt32 AudioChannelCount) { if (AudioChannelCount == 1) { if (snd.WaveFormat.Channels == 1) { return(snd); } return(new MultiChannelToMonoSampleProvider(snd)); } else if (AudioChannelCount == 2) { if (snd.WaveFormat.Channels == 2) { return(snd); } if (snd.WaveFormat.Channels == 1) { return(new MonoToStereoSampleProvider(snd)); } var sInput = new MultiplexingSampleProvider(new ISampleProvider[] { snd }, 2); if (snd.WaveFormat.Channels == 6) { // 5.1 sound sInput.ConnectInputToOutput(0, 0); // FRONT-LEFT -> LEFT sInput.ConnectInputToOutput(1, 1); // FRONT-RIGHT -> RIGHT sInput.ConnectInputToOutput(2, 0); // CENTRE -> LEFT sInput.ConnectInputToOutput(2, 1); // CENTRE -> RIGHT // sInput.ConnectInputToOutput(3, ?); // LFE -> ??? sInput.ConnectInputToOutput(3, 0); // LOW-FREQ -> LEFT sInput.ConnectInputToOutput(3, 1); // LOW-FREQ -> RIGHT sInput.ConnectInputToOutput(4, 0); // SURROUND-LEFT -> LEFT sInput.ConnectInputToOutput(5, 1); // SURROUND-RIGHT -> RIGHT } else if (snd.WaveFormat.Channels == 8) { // 7.1 sound (assuming standard order, but alternative still goes to same stereo channel) // L, R, C, LFE, RL, RR, SL, SR sInput.ConnectInputToOutput(0, 0); // LEFT sInput.ConnectInputToOutput(1, 1); // RIGHT sInput.ConnectInputToOutput(2, 0); // CENTRE sInput.ConnectInputToOutput(2, 1); sInput.ConnectInputToOutput(3, 0); // LOW-FREQ sInput.ConnectInputToOutput(3, 1); sInput.ConnectInputToOutput(4, 0); // REAR-LEFT sInput.ConnectInputToOutput(5, 1); // REAR-RIGHT sInput.ConnectInputToOutput(6, 0); // SIDE-LEFT sInput.ConnectInputToOutput(7, 1); // SIDE-RIGHT } else { throw new UnsupportedAudioException(I18NString.Lookup("Audio_ChannelConversionFailed")); } return(sInput); } else if (AudioChannelCount == 6) { if (snd.WaveFormat.Channels == 6) { return(snd); } if (snd.WaveFormat.Channels == 1) { return(new MonoToMultiChannelSampleProvider(snd, 6)); } var sInput = new MultiplexingSampleProvider(new ISampleProvider[] { snd }, 6); if (snd.WaveFormat.Channels == 8) { sInput.ConnectInputToOutput(0, 0); sInput.ConnectInputToOutput(1, 1); sInput.ConnectInputToOutput(2, 2); sInput.ConnectInputToOutput(3, 3); sInput.ConnectInputToOutput(4, 4); sInput.ConnectInputToOutput(5, 5); sInput.ConnectInputToOutput(6, 4); sInput.ConnectInputToOutput(7, 5); } else if (snd.WaveFormat.Channels == 2) { sInput.ConnectInputToOutput(0, 0); sInput.ConnectInputToOutput(1, 1); sInput.ConnectInputToOutput(0, 2); sInput.ConnectInputToOutput(1, 2); sInput.ConnectInputToOutput(0, 3); sInput.ConnectInputToOutput(1, 3); sInput.ConnectInputToOutput(0, 4); sInput.ConnectInputToOutput(1, 5); } else { throw new UnsupportedAudioException(I18NString.Lookup("Audio_ChannelConversionFailed")); } return(sInput); } else if (AudioChannelCount == 8) { if (snd.WaveFormat.Channels == 8) { return(snd); } if (snd.WaveFormat.Channels == 1) { return(new MonoToMultiChannelSampleProvider(snd, 8)); } var sInput = new MultiplexingSampleProvider(new ISampleProvider[] { snd }, 8); if (snd.WaveFormat.Channels == 6) { sInput.ConnectInputToOutput(0, 0); sInput.ConnectInputToOutput(1, 1); sInput.ConnectInputToOutput(2, 2); sInput.ConnectInputToOutput(3, 3); sInput.ConnectInputToOutput(4, 4); sInput.ConnectInputToOutput(5, 5); sInput.ConnectInputToOutput(4, 6); sInput.ConnectInputToOutput(5, 7); } else if (snd.WaveFormat.Channels == 2) { sInput.ConnectInputToOutput(0, 0); sInput.ConnectInputToOutput(1, 1); sInput.ConnectInputToOutput(0, 2); sInput.ConnectInputToOutput(1, 2); sInput.ConnectInputToOutput(0, 3); sInput.ConnectInputToOutput(1, 3); sInput.ConnectInputToOutput(0, 4); sInput.ConnectInputToOutput(1, 5); sInput.ConnectInputToOutput(0, 6); sInput.ConnectInputToOutput(0, 7); } else { throw new UnsupportedAudioException(I18NString.Lookup("Audio_ChannelConversionFailed")); } return(sInput); } else { throw new UnsupportedAudioException(I18NString.Lookup("Audio_ChannelConversionFailed")); } }