/* Chirp repeatedly from 6kHz to 10kHz at 2kHz/s at 48ksps (16-bit * little-endian 2-channel signed, like DAT). * make -k chirp LDFLAGS=-lm && ./chirp | play -t raw -r 48000 -s -b 16 -L -c 2 - */ #include #include int main() { int sampling_rate = 48000; double hz , hz_per_sec = 2000 , min_freq = 6000 , max_freq = 10000 , theta = 0 , hz_per_sample = hz_per_sec / sampling_rate , amplitude = 32767 ; hz = min_freq; for (;;) { short sample = amplitude * sin(theta) + 0.5; char low_byte = sample & 0xff, high_byte = sample >> 8; putchar(low_byte); putchar(high_byte); putchar(low_byte); putchar(high_byte); theta += 2 * M_PI * hz / sampling_rate; hz += hz_per_sample; if (hz > max_freq) hz = min_freq; } }