annotate examples/sound/sampled/audioio.scm @ 2:74cc9e431818

Revert change to MidiSynth
author samer
date Fri, 05 Apr 2019 16:43:56 +0100
parents bf79fb79ee13
children b67a33c44de7
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
samer@0 9 (tasks)
samer@0 10 (define fmt (mono 44100)) ; see audio.scm for other options
samer@0 11
samer@0 12 ; this is set up to read audio from one mixer and write out to
samer@0 13 ; another. This is because my main mixer, though it does full
samer@0 14 ; duplex, ends up feeding back because tritonus alsa mixer is
samer@0 15 ; mixing all the input channels on the sound card, rather than
samer@0 16 ; letting me choose just the line input.
samer@0 17 (define in (linesrc (mixer-n 1) fmt))
samer@0 18 (define out (linesnk (mixer-n 2) fmt))
samer@0 19 (define wav (filesnk "out.wav" fmt))
samer@0 20
samer@0 21
samer@0 22 (define N 1024) ; frame size for audio transfers
samer@0 23 (define x (VVector. "x" N)) ; frame of audio data
samer@0 24
samer@0 25 ; this sets up the tasks to run in the main loop, but
samer@0 26 ; nothing happens until the loop is started
samer@0 27 (addtasks
samer@0 28 (.reader in (.array x) 0 N) ; read N samples into x
samer@0 29 (Ops.update x) ; to update GUI
samer@0 30 ; the switches mean that the tasks can be switched in
samer@0 31 ; and out of the main loop on the fly through the GUI
samer@0 32 (node "writer" (switch (.writer wav (.array x) 0 N)))
samer@0 33 (node "lineout" (switch (.writer out (.array x) 0 N)))
samer@0 34 )
samer@0 35
samer@0 36 (expose) ; show GUI
samer@0 37 (expose (.getScale out)) ; show GUI for lineout scaling
samer@0 38 (expose (.getScale wav)) ; ditto for file out scaling
samer@0 39
samer@0 40 (display "Type (start) or press start button to start main loop.\n")
samer@0 41