# A very basic question about DAC conversion in a sound card

This is a conceptual question about how a sound card converts digital data to analog.

To illustrate this let's say we have constructed a discrete data which represents a sinusoid with particular number of points per period.

For example, below discrete sinusoid stem plot is composed of 48 points per period of a sine: Imagine now this digital data is fed to a sound card which has 48kHz sample rate.

Would we hear f = 1/[48 * 1/(48000)] = 1kHz vibration?

Actually I wanted to be sure about this. I want to try this by using a program like Python or MATLAB ect. Do you know how to send such digital data to sound card? Secondly the sine in my question has range -1 to +1. What is the relation between the volume and this amplitude for a 24 bit soundcard?

• Yes. Perhaps you wanted to ask something else? – Eugene Sh. Mar 12 '18 at 17:54
• The common human hearing range is from 20Hz to 20kHz. But obviously as you hit your mid-20s, that range can go down to around 15kHz. – KingDuken Mar 12 '18 at 17:56
• If the sample rate is 48KHz and that represents the samples, yes, the analog frequency must be 1Khz. – lakeweb Mar 12 '18 at 17:57
• I wanted to be sure and I updated the question. Please see the last paragraph. – user16307 Mar 12 '18 at 17:59
• @KingDuken Assume 23 kHz at newborn and -100 Hz/year. Coincidentally you start with about 230 bpm max heart rate too and loose 1 bpm/year. – winny Mar 12 '18 at 19:09

## 1 Answer

For example, below discrete sinusoid stem plot is composed of 48 points per period of a sine:

No, it's not!

Would we hear f = 1/[48 * 1/(48000)] = 1kHz vibration?

For the particular waveform you've plotted, you would hear f = 1/[47 * 1/(48000)] = 1021Hz vibration.

If you were intending to represent a 1kHz waveform, you've made the classic off by one fencepost error mistake of thinking the number of points was equal to the number of intervals. You need 48 intervals in the waveform, which means as the curve starts and finishes at zero, you need one extra point, for 49 points to make 48 intervals.

With Python, include the PyAudio library, which is a python binding for PortAudio v19, which will drive most cards on most operating systems. Generate the waveform as a Numpy array, and follow the documentation with the library. IIRC, if you use floats, then +/- 1 corresponds to full scale on the DAC, but if you use integers, then +127/-128 or +32767/-32768 correspond to full scale depending on the 8/16 bit mode. RTFM and all will be revealed.

You might prefer to use Audacity to build, play and store waveforms. Obviously not a programmable solution, but has a nice GUI and gets you experimenting faster.

• Please see my last paragraph thanks. Maybe you add something more. There are 48 samples. Index starts from 0. – user16307 Mar 12 '18 at 18:04
• Oh the number of gaps matter?? Is that because you said 47?? – user16307 Mar 12 '18 at 18:05
• Nice catch! But now I think the question is specifically about the nature of a soundcard. – lakeweb Mar 12 '18 at 18:05
• Yes, there are 48 samples, but the the first and last are the same zero sample, so there are only 47 repeated in the waveform. Please do lookup and understand the 'off by one' link I posted. Why do you think I bothered to count the samples carefully? It's what people always get wrong! – Neil_UK Mar 12 '18 at 18:07
• Actually, if you sent that set of 48 samples to a sound card in a loop at 48 ksps, you'd get a 1000.0 Hz tone. However, it would not be a pure sine wave -- it would be distorted because of the repeated zero at the looping point. – Dave Tweed Mar 12 '18 at 19:08