This project has moved and is read-only. For the latest updates, please go here.

Mixing an input signal and mp3 file

Jan 12, 2016 at 7:40 PM
Edited Jan 12, 2016 at 7:42 PM
Hi. I'm trying to mixing an input guitar signal and mp3 file. I'm using AsioOut class. Guitar signal should being played at one channel, audio file should being played in both channels.

I have not working code.
        private static AsioOut asioout;
        private static AudioFileReader reader;
        private static BufferedWaveProvider bufferedWaveProvider;
        private static MixingSampleProvider mixer;

        static void Main(string[] args)
            asioout = new AsioOut(1);
            reader = new AudioFileReader(/*SomeMp3File*/);
            bufferedWaveProvider = new BufferedWaveProvider(WaveFormat.CreateIeeeFloatWaveFormat(44100, 2));
            mixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(44100, 2));
            asioout.AudioAvailable += AsioOutFtAudioAvailable;
            asioout.InitRecordAndPlayback(new SampleToWaveProvider(mixer), 2, 0);
            while (true)

        private static void AsioOutFtAudioAvailable(object sender, AsioAudioAvailableEventArgs e)
            byte[] bytes = new byte[e.SamplesPerBuffer * 4];
            Marshal.Copy(e.InputBuffers[1], bytes, 0, e.SamplesPerBuffer * 4);
            Marshal.Copy(bytes, 0, e.OutputBuffers[1], e.SamplesPerBuffer * 4);
            e.WrittenToOutputBuffers = true;
When e.WrittenToOutputBuffers is true I hear the guitar signal, but audio file is not being played. When e.WrittenToOutputBuffers is false the only audio file is played.

How does make it work?