Separating audio left and right

Alper Can Kat 20 Reputation points
2023-11-14T20:07:20.83+00:00

Hello,

I have two wav audio files.

I want to hear these two files separately from the left and right outputs of my headphone.

I have an attempt below but;

When the script runs, the sound of two files comes from the left and right channels, and the sound of one file is quieter but audible.

I want to completely separate the two audio files. For example, my test1.wav file should only play on the left headphone output.

I'm waiting for your help.

var input1 = new WaveFileReader("c:\deneme\test1.wav");

var input2 = new WaveFileReader("c:\deneme\test2.wav");

MultiplexingWaveProvider waveProvider = new MultiplexingWaveProvider(new IWaveProvider[] { input1, input2 }, 2);

waveProvider.ConnectInputToOutput(1,1);

WaveOut wave = new WaveOut();

wave.Init(waveProvider);

wave.Play();

My respects

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,853 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,925 questions
0 comments No comments
{count} votes

Accepted answer
  1. gekka 9,181 Reputation points MVP
    2023-11-14T22:53:21.0066667+00:00
    //using NAudio.Wave;
    
    var input1 = new WaveFileReader(path1);
    var input2 = new WaveFileReader(path2);
    
    var mono1 = new StereoToMonoProvider16(input1);
    var mono2 = new StereoToMonoProvider16(input2);
                
    var stereo1 = new MonoToStereoProvider16(mono1);
    stereo1.LeftVolume = 1;
    stereo1.RightVolume = 0;
    
    var stereo2 = new MonoToStereoProvider16(mono2);
    stereo2.LeftVolume = 0;
    stereo2.RightVolume = 1;
                
    
    var f1 = new Wave16ToFloatProvider(stereo1);
    var f2 = new Wave16ToFloatProvider(stereo2);
    
    var mix = new NAudio.Wave.MixingWaveProvider32(new IWaveProvider[] { f1, f2 });
                
    WaveOut wave = new WaveOut();
    wave.Init(mix);
    wave.Play();
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.