Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai, Am doing a project of Transferring data over udp, Now am facing a problem,

Am Getting stream of data from two events.

event1 give

C#
private void ondatareceived_one(byte[] values)
{
mixdata(1, values);
}


event2 give

C#
private void ondatareceived_two(byte[] values)
{
mixdata(2, values);
}}




i have to mix this two byte array values

this events triggers 10 times per second


the mixing method is

C#
Dictionary<int,byte[]> dict = new Dictionary<int,byte[]>(); 
private void mixdata(int index, byte[] values)
{
dict[index] = values;

if(dict.count==2)
{
list<byte[]> listdata= dict.values.Tolist();
dict.clear();

foreach (byte[] values in listdata)
{
// mixing datas from two byte[]

} 
}
}



This implementation is very slower, i need an alternate way which perfoms very faster..
Kindly help me...
Posted
Comments
Bernhard Hiller 18-Nov-13 3:17am    
I do not understand at all what you mean with "mixing data". Please try to explain that.
Also: why are there two events? Do they have special meaning?
sugin.se 18-Nov-13 5:42am    
Actually, its two stream of audio.. am mixing these two audio channel for audio conferencing.
Per Söderlund 18-Nov-13 7:27am    
Mixing how? put one on top of the other?
Which part of your code is slow, I fail to see what you are trying to do.
So far you save 2 bytearrays into a dictionary and take them out of the dictionary into a list of 2 byte arrays.
Bernhard Hiller 18-Nov-13 11:30am    
Be careful! Is it compressed audio or wave PCM? 8bit or 16bit samples? How do the audio data arrive in your computer - via a network - and are the channels in sync? Bad things are prone to happen!
BillWoodruff 18-Nov-13 7:35am    
Depending on your hardware you are probably dealing with audio latency problems and need to use very low-level audio routines written in "unsafe" code.

There are resources on audio processing, including mixing, here on CodeProject, like:

http://www.codeproject.com/Articles/35725/C-WAV-file-class-audio-mixing-and-some-light-audio

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900