annotate examples/sound/sampled/audioio.scm @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents b67a33c44de7
children
rev   line source
samer@0 1 ;;; Simple program that streams audio input to audio output
samer@0 2 ;;; and a WAV file called out.wav.
samer@0 3 ;;; Uses raw LineSource and LineSink, not LineIn and LineOut objects
samer@0 4 ;;; (see lineio.scm)
samer@0 5
samer@0 6 (load "audio.scm")
samer@0 7
samer@0 8 (tasks)
samer@0 9 (define fmt (mono 44100)) ; see audio.scm for other options
samer@0 10
samer@5 11 (define in (linesrc fmt))
samer@5 12 (define out (linesnk fmt))
samer@0 13 (define wav (filesnk "out.wav" fmt))
samer@0 14
samer@0 15 (define N 1024) ; frame size for audio transfers
samer@0 16 (define x (VVector. "x" N)) ; frame of audio data
samer@0 17
samer@0 18 ; this sets up the tasks to run in the main loop, but
samer@0 19 ; nothing happens until the loop is started
samer@0 20 (addtasks
samer@0 21 (.reader in (.array x) 0 N) ; read N samples into x
samer@0 22 (Ops.update x) ; to update GUI
samer@0 23 ; the switches mean that the tasks can be switched in
samer@0 24 ; and out of the main loop on the fly through the GUI
samer@0 25 (node "writer" (switch (.writer wav (.array x) 0 N)))
samer@0 26 (node "lineout" (switch (.writer out (.array x) 0 N)))
samer@0 27 )
samer@0 28
samer@0 29 (expose) ; show GUI
samer@0 30 (expose (.getScale out)) ; show GUI for lineout scaling
samer@0 31 (expose (.getScale wav)) ; ditto for file out scaling
samer@0 32
samer@0 33 (display "Type (start) or press start button to start main loop.\n")