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);