Update of /cvsroot/q-lang/q-audio/src
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16447
Modified Files:
audio.q audio_player.q
Log Message:
add audio_in/audio_out convenience functions
Index: audio.q
===================================================================
RCS file: /cvsroot/q-lang/q-audio/src/audio.q,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** audio.q 19 Sep 2004 23:47:29 -0000 1.5
--- audio.q 31 Jan 2008 07:00:16 -0000 1.6
***************
*** 87,90 ****
--- 87,105 ----
audio_active = islist audio_devices;
+ /* Convenience functions to determine alternate input/output devices. These
+ first inspect the Q_AUDIO_IN and Q_AUDIO_OUT environment variables. If
+ these are set to integers, the corresponding entries in the audio_devices
+ list will be used. Alternatively, you can also specify a shell glob pattern
+ matching the device name instead; thus, e.g., "SBLive*" will match the ALSA
+ device for a SoundBlaster Live. If no device can be found that way, we look
+ for JACK and use its default input/output ports if we can. Failing that, we
+ just pick the first devices with a nonzero number of input/output ports. If
+ this also fails, the PortAudio defaults (AUDIO_IN, AUDIO_OUT) are used. You
+ can employ these functions to provide reasonable defaults for the input/
+ output devices in your program as follows:
+ def (AUDIO_IN,AUDIO_OUT) = (audio_in,audio_out); */
+
+ public audio_in, audio_out;
+
/* Audio stream objects. These are returned by the open_audio_stream function
and used by the other functions. */
***************
*** 154,155 ****
--- 169,229 ----
public extern audio_stream_readable AS;
public extern audio_stream_writeable AS;
+
+ /* Implementation of audio_in/audio_out functions. */
+
+ from system import getenv;
+
+ private default_in, default_out, jack_devs, in_dev_ok, out_dev_ok, find P Xs;
+
+ audio_in
+ where S:String = getenv "Q_AUDIO_IN", DEVS = audio_devices:
+ = ID where VAL:Int = val S, ID:Int = (DEVS!VAL)!1;
+ = (DEVS!ID)!1 if ID>=0
+ where ID = find (fnmatch S.(!0)) DEVS;
+ otherwise: = default_in;
+
+ audio_out
+ where S:String = getenv "Q_AUDIO_OUT", DEVS = audio_devices:
+ = ID where VAL:Int = val S, ID:Int = (DEVS!VAL)!1;
+ = (DEVS!ID)!1 if ID>=0
+ where ID = find (fnmatch S.(!0)) DEVS;
+ otherwise: = default_out;
+
+ default_in = DEVS!ID if ID>=0
+ where DEVS = jack_devs, ID = find in_dev_ok DEVS;
+ = DEVS!ID if ID>=0
+ where DEVS = [0..#audio_devices-1],
+ ID = find in_dev_ok DEVS;
+ = AUDIO_IN otherwise;
+
+ default_out = DEVS!ID if ID>=0
+ where DEVS = jack_devs, ID = find out_dev_ok DEVS;
+ = DEVS!ID if ID>=0
+ where DEVS = [0..#audio_devices-1],
+ ID = find out_dev_ok DEVS;
+ = AUDIO_OUT otherwise;
+
+ jack_devs = cat (map (!2) DRVS)
+ where DRVS = filter ((=12).(!1)) audio_drivers;
+
+ in_dev_ok (_,_,N,_,_)
+ = N>0;
+ in_dev_ok ID:Int
+ = in_dev_ok (audio_devices!ID);
+ in_dev_ok _ = false otherwise;
+
+ out_dev_ok (_,_,_,M,_)
+ = M>0;
+ out_dev_ok ID:Int
+ = out_dev_ok (audio_devices!ID);
+ out_dev_ok _ = false otherwise;
+
+ private find_loop N P Xs;
+
+ find P Xs = find_loop 0 P Xs;
+
+ find_loop N P []
+ = -1;
+ find_loop N P [X|Xs]
+ = N if P X;
+ = find_loop (N+1) P Xs otherwise;
Index: audio_player.q
===================================================================
RCS file: /cvsroot/q-lang/q-audio/src/audio_player.q,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** audio_player.q 27 Jan 2008 10:17:34 -0000 1.13
--- audio_player.q 31 Jan 2008 07:00:16 -0000 1.14
***************
*** 30,33 ****
--- 30,37 ----
import audio, sndfile, wave, tk, ggi;
+ /* Provide a reasonable default for AUDIO_OUT. */
+
+ def AUDIO_OUT = audio_out;
+
/* The main entry point. NAME is the name of the sound file to be played. */
|