Reputation: 589
I want to get the real time amplitude of the microphone input in windows phone. What is the simplest and efficient way to achieve this ?
Upvotes: 0
Views: 257
Reputation: 2067
To get the amplitude, you will have to handle the BufferReady event of the Microphone class:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/gg442302(v=vs.105).aspx
Setup code
Microphone microphone = Microphone.Default;
microphone.BufferReady += new EventHandler<EventArgs>(microphone_BufferReady);
microphone.BufferDuration = TimeSpan.FromMilliseconds(1000);
byte[] buffer;
buffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];
microphone.Start();
Event handler block
void microphone_BufferReady(object sender, EventArgs e)
{
microphone.GetData(buffer);
for(int i = 0; i< buffer.Length; i+=2)
{
//The value of sample is the amplitude of the signal
short sample = BitConverter.ToInt16(new byte[2] { buffer[i], buffer[i + 1] }, 0);
}
}
Upvotes: 1