This project has moved. For the latest updates, please go here.

Cannot Hear Audio

Jun 4, 2014 at 9:46 PM
I am attempting to hear a mixed stream using WaveMixerStream32.
When the form loads it creates the mixer
        private void Messenger_Load(object sender, EventArgs e)
        {
            comboBoxCodecs.SelectedIndex = 2;
            comboBoxCodecs.Enabled = false;
            selectedCodec = ((CodecComboItem)comboBoxCodecs.SelectedItem).Codec;
            mixer = new WaveMixerStream32();
            mixer.AutoStop = false;
            waveOut = new WaveOut();
            waveOut.Init(mixer);
            waveOut.Play();
            ThreadPool.QueueUserWorkItem(StartRecieve, null);
        }
When Audio is received...
        if (msgReceived.messageContents != null)
        {
        byte[] decoded = new byte[1024];
        decoded = selectedCodec.Decode(msgReceived.messageContents, 0, msgReceived.messageContents.Length);
        Stream audioStream = new MemoryStream(decoded);
        RawSourceWaveStream rawStream = new RawSourceWaveStream(audioStream, selectedCodec.RecordFormat);
        WaveChannel32 rawStream32 = new WaveChannel32(rawStream);
        mixer.AddInputStream(rawStream32);
        }
What Am I doing wrong? All I hear is silence. I am positive sound is being received as I can play without using a mixer; and decoded contains pcm values.
Coordinator
Jun 17, 2014 at 8:42 AM
can you try with MixingSampleProvider instead. ( use rawStream.ToSampleProvider as the input)
WaveMixerStream32 is quite an old class and I'm not sure how well it works if you try to add inputs on the fly.
Jul 15, 2014 at 10:50 PM
Edited Jul 15, 2014 at 10:59 PM
byte[] decoded = new byte[4096];
decoded = selectedCodec.Decode(msgReceived.messageContents, 0, msgReceived.messageContents.Length);
Stream audioStream = new MemoryStream(decoded);
RawSourceWaveStream rawStream = new RawSourceWaveStream(audioStream, selectedCodec.RecordFormat);
rawStream.Position = 0;
MSMixer.AddMixerInput(rawStream.ToSampleProvider());
//WaveChannel32 rawStream32 = new WaveChannel32(rawStream);
//rawStream32.Position = 0;
//MSMixer.AddMixerInput(rawStream32);
Currently receiving an argument exception when using rawStream.ToSampleProvider()
"All mixer inputs must have the same WaveFormat"

Not positive what you want me to do here, I tried the code commented out, which worked, but the audio was incredibly choppy; After some time I received an error saying "to many mixer inputs".

Thoughts?
-Ryan
Coordinator
Jul 17, 2014 at 2:26 PM
if you are receiving small blocks of audio on the fly, then I would recommend using a BufferedWaveProvider rather than a RawSourceWaveStream.
The all mixer inputs must have the same waveformat means what it says. How did you set up your mixer in the first place?
Jul 22, 2014 at 12:46 AM
Okay I follow the waveformat issue. Here is how the mixer is setup.
MSMixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(selectedCodec.RecordFormat.SampleRate, 1));
MSMixer.ReadFully = true;
waveOut = new WaveOut();
waveOut.Init(MSMixer);
waveOut.Play();
I believe im missing one last thing; How to turn the mixed ieee float back to the recorded format? All Im hearing is blipping, which I assume, represents the time in between packets.

Here are the newest changes.
byte[] decoded = new byte[4096];
decoded = selectedCodec.Decode(msgReceived.messageContents, 0, msgReceived.messageContents.Length);
BufferedWaveProvider bufferedWave = new BufferedWaveProvider(WaveFormat.CreateIeeeFloatWaveFormat(selectedCodec.RecordFormat.SampleRate, 1));
bufferedWave.AddSamples(decoded, 0, decoded.Length);
MSMixer.AddMixerInput(bufferedWave);
I also tried ToSampleProvider as well however still heard only blipping.
MSMixer.AddMixerInput(bufferedWave.ToSampleProvider());
Thanks for your help by the way, everything here is really cool.
-Ryan
Coordinator
Jul 28, 2014 at 4:27 PM
Only add the buffered wave provider to your mixer once (assuming you have one continuous stream of incoming audio). Then decode all audio and write it into the same bufferedWaveProvider.
Also, I suspect your selectedCodec is not decoding to IEEE float. Set the BufferedWaveprovider up with the exact output format of the decoder, and then turn your buffered wave provider into a sampleProvider with ToSampleProvider before adding it as a mixer input.