Edinburgh Speech Tools  2.1-release
irixaudio.cc
Go to the documentation of this file.
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 using namespace std;
21 
22 #if defined (SUPPORT_IRIX) || defined (SUPPORT_IRIX53)
23 #include <audio.h>
24 #include <unistd.h>
25 
26 int irix_supported = TRUE;
27 
28 int play_irix_wave(EST_Wave &inwave, EST_Option &al)
29 {
30  int sample_rate;
31  short *waveform;
32  int num_samples;
33  ALconfig config;
34  ALport port;
35  int r;
36  (void)al;
37 
38  waveform = inwave.values().memory();
39  num_samples = inwave.num_samples();
40  sample_rate = inwave.sample_rate();
41 
42  config = ALnewconfig();
43  ALsetsampfmt(config, AL_SAMPFMT_TWOSCOMP);
44  ALsetwidth(config, AL_SAMPLE_16);
45  ALsetchannels(config, AL_MONO);
46 
47  long pvbuf[2];
48  pvbuf[0] = AL_OUTPUT_RATE;
49  pvbuf[1] = sample_rate;
50  ALsetparams(AL_DEFAULT_DEVICE, pvbuf, 2);
51 
52 /*
53  ALgetparams(AL_DEFAULT_DEVICE, pvbuf, 2);
54  if (pvbuf[1] != sample_rate)
55  {
56  cerr << "IRIX: sample rate " << sample_rate <<
57  " not supported; using " << pvbuf[1] << endl;
58  }
59 */
60 
61  port = ALopenport("speech-tools", "w", config);
62  if (!port)
63  {
64  cerr << "IRIX: can't open audio port" << endl;
65  ALfreeconfig(config);
66  return -1;
67  }
68 
69  r = ALwritesamps(port, waveform, num_samples);
70  if (r != 0)
71  cerr << "IRIX: failed to write to buffer" << endl;
72 
73  // Wait until all samples are played.
74  // IRIX 5.3 doesn't have usleep
75 #ifdef SUPPORT_IRIX53
76  while (ALgetfilled(port)) sginap(1);
77 #elseif
78  while (ALgetfilled(port)) usleep(10000);
79 #endif
80 
81  ALcloseport(port);
82  ALfreeconfig(config);
83 
84  return 1;
85 }
86 
87 #else
89 
91 {
92  (void)inwave;
93  (void)al;
94  cerr << "IRIX 16bit linear not supported" << endl;
95  return -1;
96 }
97 
98 #endif
A class for storing digital waveforms. The waveform is stored as an array of 16 bit shorts...
Definition: EST_Wave.h:64
Utility IO Function header file.
ssize_t num_samples() const
return the number of samples in the waveform
Definition: EST_Wave.h:143
int irix_supported
Definition: irixaudio.cc:88
const EST_SMatrix & values() const
Definition: EST_Wave.h:177
int play_irix_wave(EST_Wave &inwave, EST_Option &al)
Definition: irixaudio.cc:90
#define FALSE
Definition: EST_bool.h:119
int sample_rate() const
return the sampling rate (frequency)
Definition: EST_Wave.h:147
const T * memory() const
Definition: EST_TVector.h:238
#define TRUE
Definition: EST_bool.h:118