Hi,
i have develop winfrom application using media file, recording and editing with wave form.
receiving input through microphone is possible draw wave form the same not possible when tried to record output of a system (Speakers) find the below code and suggest better way to achieve the same.
Mic codes used:
private void RecorderOnDataAvailable(object sender, WaveInEventArgs waveInEventArgs)
{
try
{
bufferedWaveProvider.AddSamples(waveInEventArgs.Buffer, 0, waveInEventArgs.BytesRecorded);
byte[] waveData = new byte[100 * Bytes_Per_Sample1];
short low = 0;
short high = 0;
for (int n = 0; n < waveInEventArgs.BytesRecorded; n += 2)
{
short sample = BitConverter.ToInt16(waveInEventArgs.Buffer, n);
if (sample < low)
low = sample;
if (sample > high)
high = sample;
}
float lowPercent = ((((float)low) - short.MinValue) / ushort.MaxValue);
float highPercent = ((((float)high) - short.MinValue) / ushort.MaxValue);
g.DrawLine(Draw_lIne, d, Wave_Control_Main_Player.Height * lowPercent, d, Wave_Control_Main_Player.Height * highPercent);
d++;
if (d == Wave_Control_Main_Player.Width)
{
Wave_Control_Main_Player.Invalidate();
d = 0;
}
}
Used for capturing:
WasapiLoopbackCapture class used to get the output sounds.
public void OnDataAvailable(object sender, WaveInEventArgs e)
{
_writer.Write(e.Buffer, 0, e.BytesRecorded);
//byte[] waveData = new byte[100 * Bytes_Per_Sample1];
//short low = 0;
//short high = 0;
//stream.Read(waveData, 0, waveData.Length);
//for (int n = 0; n < waveData.Length; n += 8)
//{
// short sample = BitConverter.ToInt16(waveData, n);
// if (sample < low) low = sample;
// if (sample > high)
// high = sample;
//}
//float lowPercent = ((((float)low) - short.MinValue) / ushort.MaxValue);
//float highPercent = ((((float)high) - short.MinValue) / ushort.MaxValue);
//g.DrawLine(Draw_lIne, d, Wave_Control_Main_Player.Height * lowPercent, d, Wave_Control_Main_Player.Height * highPercent);
//d++;
//if (d == Wave_Control_Main_Player.Width)
//{
// Wave_Control_Main_Player.Invalidate();
// d = 0;
//}
}
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Bikesh SrivastavaPosted Jan 26, 2017, 1:32 PM