project rates vs actual sample rates under DirectSound

hello,

I’m using Windows 10 (with the latest updates), Audacity 2.1.3 which I obtained via the installer.

As far as i can tell, DirectSound supports only the following sample rates (based on mmeapi.h lines 280-305):
11025, 22050, 44100, 48000, 96000
(Please correct me if I’m wrong).

according to the inline documentation in your code (AudioIO.cpp line 1423) -
“pick a rate to do the audio I/O at, from those available. The project
rate is suggested, but we may get something else if it isn’t supported”

and in line 2873:
“… if we get here, there is a problem - the project rate isn’t supported
on our hardware, so we can’t us it. Need to come up with an alternative
rate to use.”

my question is: if i choose, say, 16000 as the project rate -
will i always get 22050 as the actual sample rate, assuming the device supports it, because DirectSound doesn’t?

thanks a lot,

Shalev.

I’m not on Windows so I can’t answer your question directly, but if you start playback, then look in the status bar (at the bottom of the main Audacity window) toward the right, Audacity reports what the actual sample rate is.

I don’t have an answer either…

The “difficulty” is, that the drivers will make any necessary conversions (without telling you) so it’s hard to know what the hardware is really doing. The same is true with video & graphics. You can display graphics/video with higher-resolution than your monitor supports, or higher than your monitor is set-for, or in a shrunk-Window, with no issues (except for lower resolution) because Windows and your drivers automatically take care of it.

my question is: if i choose, say, 16000 as the project rate -
will i always get 22050 as the actual sample rate, assuming the device supports it, because DirectSound doesn’t?

I assume you’re talking about recording? Try it! :wink: I’m betting you CAN record at 16KHz…

You certainly CAN export as a 16kHz WAV file, and Windows CAN play it.

I didn’t try recording, but I just opened a file, changed the project rate to 16KHz, exported to WAV, and played it in Windows Media Player. (This was on a “basic” computer with a motherboard sound-chip… No special hardware.)

I confirmed the sample rate by checking the file size - The playing time is 5:23 (323 seconds). There are 8-bits in a byte and I saved as 16-bits, so that’s two byes per sample, X2 for stereo… 320 x 2 x 2 x 16000 gives me about 20MB, and indeed Windows says the file is about 20MB.

First off - thanks for the quick responses.

i think i need to clarify my question.

indeed - i can look at the GUI during playback or check the file size and see that the sample rate was actually 16k.

but from DirectSound’s documentation:
https://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.reference.dsccaps(v=vs.85).aspx
(see under dwFormats)
https://msdn.microsoft.com/en-us/library/dd743839(v=vs.85).aspx

clearly - 16K sample rate is not supported, regardless of the device.
so my question becomes - what is Audacity doing to get a 16K sample rate nonetheless when working with DirectSound?

thanks again,

Shalev.

The sound system will (‘should’) provide audio data at an alternative (supported) sample rate, and Audacity will then resample the data on the fly.
So if you select 16000 Hz as the project rate, and Direct Sound as the host, Direct Sound will supply data at a supported rate (I guess 22050), Audacity will show that as the “actual” sample rate, and resample the data to 16000 Hz before writing the data to disk.

Fortunately Audacity is extremely good at resampling, thanks to the excellent “libsoxr” resampling library (Missing features - Audacity Support)

Thanks a lot!!

This helps me so much.

All the best,

Shalev.