To Achieve draw wave form from speakers ouputs

Posted by Athivarathan under C# on 1/24/2017 | Points: 10 | Views : 223 | Status : [Member] | Replies : 0
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;
//}
}





Responses

(No response found.)

Login to post response