Edinburgh Speech Tools 2.4-release
irixaudio.cc
1/*************************************************************************/
2/* Author : Theo Veenker (Utrecht University) */
3/* Date : September 1997 */
4/*-----------------------------------------------------------------------*/
5/* Optional 16bit linear support for audio on IRIS 4D workstations */
6/* */
7/*=======================================================================*/
8
9#include <cstdio>
10#include <cstring>
11#include <cstdlib>
12#include <cctype>
13#include "EST_unix.h"
14#include "EST_cutils.h"
15#include "EST_Wave.h"
16#include "EST_Option.h"
17#include "audioP.h"
18#include "EST_io_aux.h"
19
20#if defined (SUPPORT_IRIX) || defined (SUPPORT_IRIX53)
21#include <audio.h>
22#include <unistd.h>
23
24int irix_supported = TRUE;
25
26int play_irix_wave(EST_Wave &inwave, EST_Option &al)
27{
28 int sample_rate;
29 short *waveform;
30 int num_samples;
31 ALconfig config;
32 ALport port;
33 int r;
34 (void)al;
35
36 waveform = inwave.values().memory();
37 num_samples = inwave.num_samples();
38 sample_rate = inwave.sample_rate();
39
40 config = ALnewconfig();
41 ALsetsampfmt(config, AL_SAMPFMT_TWOSCOMP);
42 ALsetwidth(config, AL_SAMPLE_16);
43 ALsetchannels(config, AL_MONO);
44
45 long pvbuf[2];
46 pvbuf[0] = AL_OUTPUT_RATE;
47 pvbuf[1] = sample_rate;
48 ALsetparams(AL_DEFAULT_DEVICE, pvbuf, 2);
49
50/*
51 ALgetparams(AL_DEFAULT_DEVICE, pvbuf, 2);
52 if (pvbuf[1] != sample_rate)
53 {
54 cerr << "IRIX: sample rate " << sample_rate <<
55 " not supported; using " << pvbuf[1] << endl;
56 }
57*/
58
59 port = ALopenport("speech-tools", "w", config);
60 if (!port)
61 {
62 cerr << "IRIX: can't open audio port" << endl;
63 ALfreeconfig(config);
64 return -1;
65 }
66
67 r = ALwritesamps(port, waveform, num_samples);
68 if (r != 0)
69 cerr << "IRIX: failed to write to buffer" << endl;
70
71 // Wait until all samples are played.
72 // IRIX 5.3 doesn't have usleep
73#ifdef SUPPORT_IRIX53
74 while (ALgetfilled(port)) sginap(1);
75#elseif
76 while (ALgetfilled(port)) usleep(10000);
77#endif
78
79 ALcloseport(port);
80 ALfreeconfig(config);
81
82 return 1;
83}
84
85#else
86int irix_supported = FALSE;
87
88int play_irix_wave(EST_Wave &inwave, EST_Option &al)
89{
90 (void)inwave;
91 (void)al;
92 cerr << "IRIX 16bit linear not supported" << endl;
93 return -1;
94}
95
96#endif
const T * memory() const
Definition: EST_TVector.h:241
int sample_rate() const
return the sampling rate (frequency)
Definition: EST_Wave.h:147
int num_samples() const
return the number of samples in the waveform
Definition: EST_Wave.h:143