My understanding is that the input to /dev/dsp should be an 8-bit unsigned PCM signal/character stream.


$ cat a.c
#include <stdio.h>
#include <math.h>
    uint32_t t;
    uint8_t out;
    return 0;

$ gcc a.c;./a >/dev/dsp

outputs for 1 second a sound that has a frequency modulation like 420242024 (i.e. 'high->low->high->low->high' frequency). The output I was expecting was a single cycle 1Hz frequency that I would not be able to hear with my ears. That I can hear anything at all is surprising.

The only thing I can think of that explains what I am hearing is if the /dev/dsp special file is outputting to the speakers with a pulse-density modulation.

pulse-density modulation.

Since the clicking sounds (which at high frequency sound like a square wave) from the pulses have higher frequency when the derivative of my signal is highest or lowest, and have the lowest frequency at the peaks and troughs of my signal.

If your in the mood for some hard core punk-rock/techno(whatever) use out=t*((t>>9|t>>13)&25&t>>6); and remove the t<8000. That apparently does give the correct output to my speakers, but that is just a coincidence of the mostly square waves sounding mostly the same after modulation (I assume.).

Yet when I output 0xff or 0x80 or any constant I get silence as expected (and depending on the distance from 0x80 I get that loud a click at the end, and no click if I use 0x80)... so pulse-density modulation can not be the answer.

So what is going on? Could this be a sign of faulty speakers not being able to handle the low frequency(normal frequencies sound fine (e.g. youtube))? How do I output a single cycle 1Hz signal to /dev/dsp?


1 Answer 1


Waited a long while and looked at it again, everything is working exactly as it should. I replaced the out variable with out=0x80+t%2; to see if I could hear a single bit transition, and it has the exact same volume as the original, but at a higher frequency. So I am literally hearing the transitions in the audio levels as clicks because it only has 8 bits of precision.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.