9
\$\begingroup\$

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?

\$\endgroup\$
7
\$\begingroup\$

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);
}
\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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