Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

XNA 4 includes the Microsoft.Xna.Framework.Audio.Microphone class which can seemingly read the raw sound data off the microphone via its API as documented:

GetData - Gets the latest recorded data from the microphone.

GetSampleDuration - Returns the duration of audio playback based on the size of the buffer.

GetSampleSizeInBytes - Returns the size of the byte array required to hold the specified duration of audio for this microphone object.

Can I read sound data using this class, record it in an array and then play it back? On the Xbox 360?

share|improve this question
add comment

2 Answers 2

up vote 7 down vote accepted

You could try submitting the data from the microphone to a Dynamic Sound Effect.

I just wrote some code to test this, it works.

DynamicSoundEffectInstance sound;

protected override void Initialize()
{
    sound = new DynamicSoundEffectInstance(Microphone.Default.SampleRate, AudioChannels.Mono);

    Microphone.Default.BufferReady += (a, b) =>
    {
        byte[] data = new byte[Microphone.Default.GetSampleSizeInBytes(Microphone.Default.BufferDuration)];
        Microphone.Default.GetData(data);

        sound.SubmitBuffer(data);
    };
    Microphone.Default.Start();

    base.Initialize();
}

protected override void Update(GameTime gameTime)
{
    if (gameTime.TotalGameTime.TotalSeconds > 5)
    {
        Microphone.Default.Stop();
        sound.Play();
    }

    base.Update(gameTime);
}
share|improve this answer
add comment

As a supplement to Martin's answer (can't comment yet, otherwise I would just do that):

http://create.msdn.com/en-US/education/catalog/article/dynamic_audio

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.