;compile with "sc alsa.pcm_min.sc alsa.pcm_min.c && gcc -lasound alsa.pcm_min.c" (includep "alsa/asoundlib.h") (includep "inttypes.h") (includep "stdio.h") (define device-name uint8-t* "default") (define output snd-output-t* 0) (define-macro buffer-size (* 16 1024)) (define buffer[buffer-size] uint8-t) (define channels uint32-t 1) (define sample-rate uint32-t 48000) (define latency uint32-t) (define (main) void ;initialisation, concerning hardware capabilities (define s int32-t out snd-pcm-t*) (set s (snd-pcm-open (address-of out) device-name SND_PCM_STREAM_PLAYBACK 0)) (if (< s 0) (begin (printf "Playback open error: %s\n" (snd_strerror s)) (exit EXIT_FAILURE))) (set s (snd-pcm-set-params out SND_PCM_FORMAT_U8 SND_PCM_ACCESS_RW_INTERLEAVED channels sample-rate 0 latency)) (if (< s 0) (begin (printf "Playback open error: %s\n" (snd-strerror s)) (exit EXIT_FAILURE))) ;sound data creation (define frames snd-pcm-sframes-t) (define index uint32-t 0) (while (< index buffer-size) (set (deref buffer index) (modulo index 5)) (set index (+ 1 index))) (set index 0) (while (< index 6) (set frames (snd-pcm-writei out buffer buffer-size)) (if (< frames 0) (set s (snd-pcm-recover out frames 0))) (if (< s 0) (printf "snd_pcm_writei failed: %s\n" (snd-strerror s))) (if (and (> frames 0) (< frames buffer-size)) (printf "short write (expected %li, wrote %li)\n" buffer-size frames)) (set index (+ 1 index))) ;deinitialisation (snd-pcm-close out))