Reputation: 432
I have a .Net Winforms application where I am using NAudio for the playing and merging of audio files.
Traditionally this application has been run on PCs and audio playback is fine. Recently there have been some requests to be able to run the application remotely while logged into a terminal server. The application works but the audio playback is choppy and occasionally the audio will just quit playing part way through the file. If I play the same audio file with Windows Media Player, it is not choppy.
I created a simple test app (code snippet below) and experience the same issue playing audio back with it over the Terminal Server connection.
Is there a different way that I should be playing the audio when connected to a terminal server vs locally on a PC? or are there some settings that need tweaked?
WaveOutEvent wo = new WaveOutEvent();
var wavReader = new WaveFileReader(String.Format(@"{0}\{1}", AssemblyDirectory, "5_3712.wav"));
wo.DeviceNumber = comboSelectDevice.SelectedIndex;
wo.Init(wavReader);
wo.Play();
.Net Framework 3.5
Windows Server 2008 R2
Thank You
RESOLUTION
Based on Mark Heath's suggestion below, I increased the default buffer duration from 300ms to 500ms and that got rid of the choppy playback when playing from a terminal server connection
The DesiredLatency
property on WaveOutEvent
is where the buffer duration is changed.
From one of Mark's Blog Posts: Link
"You can also set DesiredLatency, which is measured in milliseconds. This figure actually sets the total duration of all the buffers. So in fact, you could argue that the real latency is shorter. In a future NAudio, I might reduce confusion by replacing this with a BufferDuration property. By default the DesiredLatency is 300ms, which should ensure a smooth playback experience on most computers. You can also set the NumberOfBuffers to something other than its default of 2 although 3 is the only other value that is really worth using."
Updated Code Sample:
WaveOutEvent wo = new WaveOutEvent();
var wavReader = new WaveFileReader(String.Format(@"{0}\{1}", AssemblyDirectory, "5_3712.wav"));
wo.DeviceNumber = comboSelectDevice.SelectedIndex;
wo.DesiredLatency = 500;
wo.Init(wavReader);
wo.Play();
Upvotes: 0
Views: 432
Reputation: 49482
You could try upping the default buffer size to see if that helps. Or you could try DirectSoundOut to see if that makes any difference. Is there anything going on in your application that might be causing .NET garbage collections to occur?
Upvotes: 1