1
DotNet / Re: How to combine multiple sound buffer in real-time with C#?
« on: October 02, 2012, 02:59:27 pm »
Thank you everyone, following code nicely working -need little corrections-.
string soundLocation = AppDomain.CurrentDomain.BaseDirectory + "notes\\";
int totalAddedLen = 0;
Int16[] newBigMusic = new Int16[10000000];
public Form1()
{
InitializeComponent();
LoadAndPlay();
}
private void tryProductBuffer(Int16[] Buff)
{
Array.Copy(Buff, 0, newBigMusic, totalAddedLen, Buff.Length);
totalAddedLen = totalAddedLen + Buff.Length;
}
public void LoadAndPlay()
{
SoundBuffer do_a = new SoundBuffer(soundLocation + "do_a.wav");
SoundBuffer re = new SoundBuffer(soundLocation + "re.wav");
SoundBuffer mi = new SoundBuffer(soundLocation + "mi.wav");
SoundBuffer fa = new SoundBuffer(soundLocation + "fa.wav");
SoundBuffer sol = new SoundBuffer(soundLocation + "sol.wav");
SoundBuffer la = new SoundBuffer(soundLocation + "la.wav");
SoundBuffer si = new SoundBuffer(soundLocation + "si.wav");
SoundBuffer do_b = new SoundBuffer(soundLocation + "do_b.wav");
/*
User enter textbox -> do do re re do re mi
string[0]->
if(do_a)
{
tryProductBuffer(do_a.Samples);
}
if(re)
{
tryProductBuffer(re.Samples);
}
...
*/
Array.Resize(ref newBigMusic, totalAddedLen);
SoundBuffer AllBuf = new SoundBuffer(newBigMusic, 2, 44100);
AllBuf.SaveToFile("newBigMusic.wav");
Sound Q = new Sound(AllBuf);
// Q.Pitch = 3;
Q.Play();
}
int totalAddedLen = 0;
Int16[] newBigMusic = new Int16[10000000];
public Form1()
{
InitializeComponent();
LoadAndPlay();
}
private void tryProductBuffer(Int16[] Buff)
{
Array.Copy(Buff, 0, newBigMusic, totalAddedLen, Buff.Length);
totalAddedLen = totalAddedLen + Buff.Length;
}
public void LoadAndPlay()
{
SoundBuffer do_a = new SoundBuffer(soundLocation + "do_a.wav");
SoundBuffer re = new SoundBuffer(soundLocation + "re.wav");
SoundBuffer mi = new SoundBuffer(soundLocation + "mi.wav");
SoundBuffer fa = new SoundBuffer(soundLocation + "fa.wav");
SoundBuffer sol = new SoundBuffer(soundLocation + "sol.wav");
SoundBuffer la = new SoundBuffer(soundLocation + "la.wav");
SoundBuffer si = new SoundBuffer(soundLocation + "si.wav");
SoundBuffer do_b = new SoundBuffer(soundLocation + "do_b.wav");
/*
User enter textbox -> do do re re do re mi
string[0]->
if(do_a)
{
tryProductBuffer(do_a.Samples);
}
if(re)
{
tryProductBuffer(re.Samples);
}
...
*/
Array.Resize(ref newBigMusic, totalAddedLen);
SoundBuffer AllBuf = new SoundBuffer(newBigMusic, 2, 44100);
AllBuf.SaveToFile("newBigMusic.wav");
Sound Q = new Sound(AllBuf);
// Q.Pitch = 3;
Q.Play();
}