/* * Now, a month ago I was meant to write th a simple UDP mixer. * I'll get to that this week..... for now, let's just get C to * vomit sound into openbsd aucat (sndio device base) * (or for the non-openbsd-er, mpv will do...) * Imagine something like this: * cc -o test rawcat.c -lm * ./test | aucat -h raw -e s16le -r 44100 -i - * or similarly (now, who did I use the defaults of) * ./test | mpv --demuxer=rawaudio - */ #include #include #include #include #define BUF_LEN 88200 #define SF 44100 #define CH 2 int main(void) { int16_t buffer[BUF_LEN]; int s; double frequency, time_coef, k; k = 1.0 * (1 << 14); // Note that if you turn frequency up to 440 // You might like to bitshift left only 10 // Because of how wave energy ~ k^2 . f^2 frequency = 80 * CH; // 'Cause buffer will be distributed // between CH channels we speed it up // by CH times in this example. #klooge time_coef = M_PI * 2.0 / SF; // imagine k * sin( freq * s * 2 pi / SF ); for (s=0; s