Click here to Skip to main content
15,885,944 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hye,

I m working on WP7,
and i have created a audio recording app.

when i click on record button,
the code executed is -

microphone.BufferDuration = TimeSpan.FromMilliseconds(1000);
buffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];

microphone.BufferReady += new EventHandler<eventargs>(microphone_BufferReady);

microphone.Start();</eventargs>


(where buffer is byte[], microphone is Microsoft.Xna.Framework.Audio.Microphone object)

now when i overwrite this recording, i clear the byte[] buffer as

for(int i= 0;i< buffer.Length; i++)
{
    buffer[i] =0;
}


and then again this code is executed -

microphone.BufferDuration = TimeSpan.FromMilliseconds(1000);
buffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];

microphone.BufferReady += new EventHandler<eventargs>(microphone_BufferReady);

microphone.Start();</eventargs>


but buffer gets initialized by some bytes, before any recording gets started.

why is it happening.?
due to this, the new recording gets append to the previous one, n it echo while playing (repeat some parts).

thanks in advance.
Posted

Hye,

record append problem is solved by clearing the MemoryStream object- stream before overwriting the previous record.

stream.flush;
and 
stream.SetLength(0);


but the echo problem is still there.
its like when my applications starts and i record for the first time say-
"one two three four" and play the recording,
it sounds correct as- "one two three four".

now when i overwrite it by -"five six seven eight"
and play it, some of the parts of the recording gets repeated like-
"five six.. five six seven eight.. seven eight"

why this happens..??
is it because the SoundEffect object or the Microphone.?

also, there is something strange happening.

if i starts my app and record for the first time,
it records well. (echo problem is still there if u overwrite).

now i save the recording and navigate to some other page and perform some other stuffs..,

and then if i navigate to the page for recording
and starts recording, it records something, as the byte[] have some values.

but when i play it using the SoundEffect object,
there is nothing i can hear.

there is no error or exception.

why this happens?

is there something i m missing, or is it something with the microphone.???


thanks in advance.
 
Share this answer
 
Hye everyone,

i came to know that the reason of sound echo in recording is
when i tap on record button in my Application and call the function to record which is -

private void record()
        {
            counter = 1;
            Microphone microphone = Microphone.Default;

            TimeSpan tt = new TimeSpan();
            tt = TimeSpan.FromMilliseconds(1000);
            microphone.BufferDuration = new TimeSpan(0, 0, 1);
            microphone.BufferDuration = tt;

            buffer = null;
            buffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];
            stream.SetLength(0);
            
            microphone.BufferReady += new EventHandler<EventArgs>(microphone_BufferReady);
            microphone.Start();
        }



        void microphone_BufferReady(object sender, EventArgs e)
        {
            microphone.GetData(buffer);
            stream.Write(buffer, 0, buffer.Length);
        }


Now when i tap on the record button the method
VB
record()
is called and
microphone_BufferReady is called in every 1 second.

Now, if i again tap on record button and overwrite my previous recording (i m on the same page)
the microphone_BufferReady is called in every 2 second.

if i tap third time it will be 3 sec and so on.

it can be easily noticed by increamenting a counter in microphone_BufferReady and display it in a textblock.

i m not getting why this is happening.?


thanks in advance.
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900