XNA Creators Club Online
Page 1 of 1 (2 items)
Sort Posts: Previous Next

DirectSound from Memory in C#

Last post 28/07/2009 12:56 by darkin8. 1 replies.
  • 03/07/2009 11:41

    DirectSound from Memory in C#

    I have written a C# program that takes raw PCM audio from a USB port and
    plays it with DirectSound.  The audio originates from a microphone in a
    wireless remote control and is sent to a USB receiver.   I read the audio
    with the SerialPort in System.IO.Ports and put it in the SecondaryBuffer.
    While the audio is understandable, it's not good quality... sort of an echo
    and clipped at the end of each packet.

    I'm obviously new at C# and DirectSound and here's the code I'm using.  I'm
    just taking the sound packets as they arrive and stuffing them in the
    SecondaryBuffer.  I'm guessing there is a better way to do that.  Does
    anyone have any suggestions as to how to clear up the audio?

    Thanks,

    Steve

            remoteFormat = new WaveFormat {
                AverageBytesPerSecond = 8000,
                BitsPerSample = 8,
                Channels = 1,
                SamplesPerSecond = 8000,
                BlockAlign = 1,
                FormatTag = WaveFormatTag.Pcm };
            sounddevice = new DS.Device();
            sounddevice.SetCooperativeLevel(this, CooperativeLevel.Priority);

            buffDescription = new BufferDescription
            {
                BufferBytes = 60,
                Format = remoteFormat,
                DeferLocation = true,
                GlobalFocus = true
            };
            buffDescription.ControlEffects = false;
        }

                            //soundBuffer contains the raw audio

                            audioBuffer = new SecondaryBuffer(buffDescription,
    sounddevice);
                            audioBuffer.Write(0, soundBuffer,
    LockFlag.EntireBuffer);
                            audioBuffer.SetCurrentPosition(0);
                            audioBuffer.Play(0, BufferPlayFlags.Default);

     
  • 28/07/2009 12:56 In reply to

    Re: DirectSound from Memory in C#

    Hello. Did you find solution for your problem? I have the same noise in my sound.
Page 1 of 1 (2 items) Previous Next