File: irixaudio.cc

package info (click to toggle)
speech-tools 1%3A2.5.0-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 9,848 kB
  • sloc: cpp: 67,350; ansic: 12,175; sh: 4,047; java: 3,748; makefile: 1,109; lisp: 711; perl: 501; awk: 85; xml: 9
file content (96 lines) | stat: -rw-r--r-- 2,423 bytes parent folder | download | duplicates (8)
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
/*************************************************************************/
/*                Author :  Theo Veenker (Utrecht University)            */
/*                Date   :  September 1997                               */
/*-----------------------------------------------------------------------*/
/*  Optional 16bit linear support for audio on IRIS 4D workstations      */
/*                                                                       */
/*=======================================================================*/

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include "EST_unix.h"
#include "EST_cutils.h"
#include "EST_Wave.h"
#include "EST_Option.h"
#include "audioP.h"
#include "EST_io_aux.h"

#if defined (SUPPORT_IRIX) || defined (SUPPORT_IRIX53)
#include <audio.h>
#include <unistd.h>

int irix_supported = TRUE;

int play_irix_wave(EST_Wave &inwave, EST_Option &al)
{
    int sample_rate;
    short *waveform;
    int num_samples;
    ALconfig config;
    ALport port;
    int r;
    (void)al;
    
    waveform = inwave.values().memory();
    num_samples = inwave.num_samples();
    sample_rate = inwave.sample_rate();
    
    config = ALnewconfig();
    ALsetsampfmt(config, AL_SAMPFMT_TWOSCOMP);
    ALsetwidth(config, AL_SAMPLE_16);
    ALsetchannels(config, AL_MONO);

    long pvbuf[2];
    pvbuf[0] = AL_OUTPUT_RATE;
    pvbuf[1] = sample_rate;
    ALsetparams(AL_DEFAULT_DEVICE, pvbuf, 2);

/*
    ALgetparams(AL_DEFAULT_DEVICE, pvbuf, 2);
    if (pvbuf[1] != sample_rate) 
    {
	cerr << "IRIX: sample rate " << sample_rate << 
	    " not supported; using " << pvbuf[1] << endl;
    }
*/
    
    port = ALopenport("speech-tools", "w", config);
    if (!port)
    {
	cerr << "IRIX: can't open audio port" << endl;
	ALfreeconfig(config);
	return -1;
    }

    r = ALwritesamps(port, waveform, num_samples);
    if (r != 0)
	cerr << "IRIX: failed to write to buffer" << endl;
    
    // Wait until all samples are played.
    // IRIX 5.3 doesn't have usleep
#ifdef SUPPORT_IRIX53
    while (ALgetfilled(port)) sginap(1);
#elseif
    while (ALgetfilled(port)) usleep(10000);
#endif
    
    ALcloseport(port);
    ALfreeconfig(config);
    
    return 1;
}

#else
int irix_supported = FALSE;

int play_irix_wave(EST_Wave &inwave, EST_Option &al)
{
    (void)inwave;
    (void)al;
    cerr << "IRIX 16bit linear not supported" << endl;
    return -1;
}

#endif