.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Imran Ghani

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

To Achieve draw wave form from speaker outputs.

Posted By: athivarathan     Posted Date: January 24, 2017    Points:5   Category :C#
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. Be the first to respond this post
Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend