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

WCF callback mixing sound transfer

Nov 20, 2014 at 6:37 PM
Hi,

I've got this:

In WCF service where I want mix sounds together:
var mixer = MixingSampleProvider(sound32.WaveFormat) { ReadFully = true };
and using callbacks to communicate with clients, like this:
client.Callback.SendAudio(???mixer???);
Here is the question... how can I send audio (stream, byte array, bytes, samples,...) to all clients? What I need to do with income data in client app? How to play this data?

Some ideas or examples?
Nov 23, 2014 at 4:51 PM
Ok... after some research, I found something like this:

While in local playing of mixed sounds I can use:
// something like this, I need on server side
var mixer = MixingSampleProvider(sound32.WaveFormat) { ReadFully = true };
mixer.AddMixerInput(someInput);
mixer.AddMixerInput(someOtherInput);

// this will be on client side
output.Init(mixer);
output.Play();

Client-server side should looks like this:
Server side:
var mixer = MixingSampleProvider(sound32.WaveFormat) { ReadFully = true };
mixer.AddMixerInput(someInput);
mixer.AddMixerInput(someOtherInput);

SampleToWaveProvider sampleToWave = new SampleToWaveProvider(_mixer);

byte[] bufferByteArray = new byte[1000];        // How can I know, that buffer size is correct?
int x = 0;

do {
    sampleToWave.Read(bufferByteArray, x * 10, 10);
} while (x < 100)

client.Callback.SendAudio(bufferByteArray);               // some buffer clearings? stockowerflow if mixing is ReadFully set to true?
Client side:
BufferedWaveProvider bufferedWave = new BufferedWaveProvider(sound32.WaveFormat);
output.Init(bufferedWave);
output.Play();

bufferedWave.AddSamples(byteArray, 0, byteArray.Length);

This is only my idea... can someone tell if it is good way to do this?
I created local app with something like this for test, but music is not correct! Something is wrong with this idea?
Coordinator
Jan 10, 2015 at 8:39 AM
sorry for late reply. Two pointers
  1. no need to read 10 bytes at a time. Read the whole of your buffer to send. I'd also recommend buffer sizes of around 100ms of audio.
  2. to test your mixing code, write the mixed audio to a WAV file on the server side. then you can be sure you are sending the right data, before you move on to debugging the client side