1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
#include <useconfig.h>
#include <sys/time.h>
#include <sys/stat.h>
#ifdef __GNUC__
#define NeedFunctionPrototypes 1
#define NeedNestedPrototypes 1
#endif
#include <audio/audiolib.h>
#include <audio/soundlib.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <ctype.h>
#include "proto.h"
#include "getargs.h"
#include "hplay.h"
long samp_rate = 8000;
static int volume = 100;
static char *audioserver = NULL;
static AuServer *aud;
static void done PROTO((AuServer * aud, AuEventHandlerRec * handler, AuEvent * ev, AuPointer data));
static void
done(aud, handler, ev, data)
AuServer *aud;
AuEventHandlerRec *handler;
AuEvent *ev;
AuPointer data;
{
switch (ev->auany.type)
{
case AuEventTypeElementNotify:
{
int *d = (int *) data;
*d = (ev->auelementnotify.cur_state == AuStateStop);
if (!*d || ev->auelementnotify.reason != AuReasonEOF)
{
fprintf(stderr, "curr_state=%d reason=%d\n",
ev->auelementnotify.cur_state,
ev->auelementnotify.reason);
}
}
break;
case AuEventTypeMonitorNotify:
break;
default:
fprintf(stderr, "type=%d serial=%ld time=%ld id=%ld\n",
ev->auany.type, ev->auany.serial, ev->auany.time, ev->auany.id);
break;
}
}
void
audio_play(n,data)
int n;
short *data;
{
int endian = 1;
#define little_endian ((*((char *)&endian) == 1))
int priv = 0;
AuEvent ev;
Sound s = SoundCreate(SoundFileFormatNone, little_endian ?
AuFormatLinearSigned16LSB : AuFormatLinearSigned16MSB,
1, samp_rate, n, "Chit chat");
if (aud)
{
#ifdef USE_ALL_ARGS
AuStatus ret_status;
AuFlowID flow = 0;
int monitor = 0;
int multiplier = 0;
if (!AuSoundPlayFromData(aud, s, data, AuNone,
AuFixedPointFromFraction(volume, 100),
done, &priv,
&flow, &multiplier,
&monitor, &ret_status))
#else
if (!AuSoundPlayFromData(aud, s, data, AuNone,
AuFixedPointFromFraction(volume, 100),
done, &priv,
NULL, NULL, NULL, NULL))
#endif
perror("problems playing data");
else
{
while (1)
{
AuNextEvent(aud, AuTrue, &ev);
AuDispatchEvent(aud, &ev);
if (priv)
break;
}
}
}
SoundDestroy(s);
}
void
audio_term()
{
if (aud)
{
AuFlush(aud);
AuCloseServer(aud);
}
}
int
audio_init(argc,argv)
int argc;
char *argv[];
{
int rate_set = samp_rate;
int vol = 0;
argc = getargs("Nas",argc, argv,
"r", "%d", &rate_set, "Sample rate Hz",
"V", "%d", &vol, "Volume 0 .. 1.0",
"a", "", &audioserver,"Name of server",
NULL);
if (help_only)
return argc;
if ((aud = AuOpenServer(audioserver, 0, NULL, 0, NULL, NULL)) == (AuServer *) 0)
perror(audioserver);
if (rate_set && rate_set != samp_rate)
samp_rate = rate_set;
if (vol)
volume = vol;
return argc;
}
|