X-Git-Url: https://git.distorted.org.uk/~mdw/jog/blobdiff_plain/b1ffb19d137241e62b4eea0e6db834bd624bdda2..e9060e7e4c0de71ef6d4b7d7b05c3167790073e3:/rxglue.c diff --git a/rxglue.c b/rxglue.c index 9126ff4..d57d798 100644 --- a/rxglue.c +++ b/rxglue.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: rxglue.c,v 1.2 2002/01/30 09:22:48 mdw Exp $ + * $Id: rxglue.c,v 1.3 2002/02/02 19:17:41 mdw Exp $ * * REXX glue for C core functionality * @@ -29,6 +29,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: rxglue.c,v $ + * Revision 1.3 2002/02/02 19:17:41 mdw + * New audio subsystem. + * * Revision 1.2 2002/01/30 09:22:48 mdw * Use memory-allocation functions provided by the REXX interpreter. * Now that configuration can be applied after initialization, allow @@ -67,6 +70,8 @@ #include #include +#include "au.h" +#include "aunum.h" #include "err.h" #include "rxglue.h" #include "txport.h" @@ -488,6 +493,88 @@ static APIRET APIENTRY rxfn_txready(const char *fn, ULONG ac, RXSTRING *av, return (0); } +/* --- @AUPLAY(TAG, [FLAG])@ --- * + * + * Arguments: @TAG@ = audio sample tag to play + * @FLAG@ = a string to explain what to do more clearly. + * + * Returns: True if it succeeded. + * + * Use: Plays a sample. If @FLAG@ begins with `t', don't report + * errors if the sample can't be found. + */ + +static APIRET APIENTRY rxfn_auplay(const char *fn, ULONG ac, RXSTRING *av, + const char *sn, RXSTRING *r) +{ + dstr d = DSTR_INIT; + int rc = 1; + + if (ac < 1 || !av[0].strlength || ac > 2) + return (-1); + rxs_get(&av[0], &d); + if (ac > 1 && av[1].strlength >= 1 && + (av[1].strptr[0] == 't' || av[1].strptr[0] == 'T')) + rc = au_tryplay(d.buf); + else + au_play(d.buf); + dstr_destroy(&d); + rxs_putf(r, "%d", rc); + return (0); +} + +/* --- @AUFETCH(TAG)@ --- * + * + * Arguments: @TAG@ = audio sample tag to play + * + * Returns: True if it succeeded. + * + * Use: Prefetches a sample into the cache. + */ + +static APIRET APIENTRY rxfn_aufetch(const char *fn, ULONG ac, RXSTRING *av, + const char *sn, RXSTRING *r) +{ + dstr d = DSTR_INIT; + int rc = 0; + au_sample *s; + au_data *a; + + if (ac < 1 || !av[0].strlength || ac > 1) + return (-1); + rxs_get(&av[0], &d); + if ((s = au_find(d.buf)) != 0 && + (a = au_fetch(s)) != 0) { + au_free(a); + rc = 1; + } + dstr_destroy(&d); + rxs_putf(r, "%d", rc); + return (0); +} + +/* --- @AUNUM(TAG)@ --- * + * + * Arguments: @NUM@ = a number to be read + * + * Returns: --- + * + * Use: Reads a number aloud to the audio device. + */ + +static APIRET APIENTRY rxfn_aunum(const char *fn, ULONG ac, RXSTRING *av, + const char *sn, RXSTRING *r) +{ + dstr d = DSTR_INIT; + + if (ac < 1 || !av[0].strlength || ac > 1) + return (-1); + rxs_get(&av[0], &d); + aunum(d.buf); + dstr_destroy(&d); + return (0); +} + /* --- @MILLIWAIT(MILLIS)@ --- * * * Arguments: @MILLIS@ = how long (in milliseconds) to wait @@ -527,6 +614,9 @@ static const struct rxfntab rxfntab[] = { { "txrecv", rxfn_txrecv }, { "txeof", rxfn_txeof }, { "txready", rxfn_txready }, + { "auplay", rxfn_auplay }, + { "aufetch", rxfn_aufetch }, + { "aunum", rxfn_aunum }, { "milliwait", rxfn_milliwait }, { 0, 0 } };