Edinburgh Speech Tools 2.4-release
 
Loading...
Searching...
No Matches
win32audio.cc
1/*************************************************************************/
2/* */
3/* Centre for Speech Technology Research */
4/* University of Edinburgh, UK */
5/* Copyright (c) 1995,1996 */
6/* All Rights Reserved. */
7/* */
8/* Permission is hereby granted, free of charge, to use and distribute */
9/* this software and its documentation without restriction, including */
10/* without limitation the rights to use, copy, modify, merge, publish, */
11/* distribute, sublicense, and/or sell copies of this work, and to */
12/* permit persons to whom this work is furnished to do so, subject to */
13/* the following conditions: */
14/* 1. The code must retain the above copyright notice, this list of */
15/* conditions and the following disclaimer. */
16/* 2. Any modifications must be clearly marked as such. */
17/* 3. Original authors' names are not deleted. */
18/* 4. The authors' names are not used to endorse or promote products */
19/* derived from this software without specific prior written */
20/* permission. */
21/* */
22/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30/* THIS SOFTWARE. */
31/* */
32/*************************************************************************/
33/* Author : Richard Caley */
34/* Date : August 1997 */
35/*-----------------------------------------------------------------------*/
36/* Optional 16bit linear support for Windows NT/95 */
37/* */
38/*=======================================================================*/
39
40#include <cstdio>
41#include "EST_cutils.h"
42#include "EST_Wave.h"
43#include "EST_Option.h"
44#include "EST_io_aux.h"
45#include "EST_Pathname.h"
46
47#ifdef SUPPORT_WIN32AUDIO
48
49#include <EST_system.h>
50
51#ifdef SYSTEM_IS_UNIX
52
53// Even if we think we are unix, this must be Win32 if we are asked
54// to support win32 audio, presumably under cygnus gunwin32 These definitions
55// aren't in the gnuwin32 headers
56
57#undef TRUE
58#undef FALSE
59/* Changed for cygwin 1
60 #include <Windows32/BASE.h>
61 #define SND_MEMORY 0x0004
62 #define WAVE_FORMAT_PCM 1
63*/
64#include <windows.h>
65
66/* This is no longer required
67extern "C" {
68WINBOOL STDCALL PlaySoundA(LPCSTR pszSound, HMODULE hmod, DWORD fdwSound);
69};
70
71#define PlaySound PlaySoundA
72*/
73
74#endif
75
76int win32audio_supported = TRUE;
77
78struct riff_header {
79 char riff[4];
80 int file_size;
81 char wave[4];
82 char fmt[4];
83 int header_size;
84 short sample_format;
85 short n_channels;
86 int sample_rate;
87 int bytes_per_second;
88 short block_align;
89 short bits_per_sample;
90 char data[4];
91 int data_size;
92};
93
94int play_win32audio_wave(EST_Wave &inwave, EST_Option &al)
95{
96 char *buffer = new char[sizeof(riff_header) + inwave.length()*inwave.num_channels() * sizeof(short)];
97
98 struct riff_header *hdr = (struct riff_header *)buffer;
99 char *data = buffer + sizeof(struct riff_header);
100
101 strncpy(hdr->riff, "RIFF", 4);
102 hdr->file_size = sizeof(riff_header) + inwave.length()*sizeof(short);
103 strncpy(hdr->wave, "WAVE", 4);
104 strncpy(hdr->fmt, "fmt ", 4);
105 hdr->header_size = 16;
106 hdr->sample_format = WAVE_FORMAT_PCM;
107 hdr->n_channels = inwave.num_channels();
108 hdr->sample_rate = inwave.sample_rate();
109 hdr->bytes_per_second = hdr->sample_rate * hdr->n_channels * 2;
110 hdr->block_align = hdr->n_channels * 2;
111 hdr->bits_per_sample = 16;
112 strncpy(hdr->data, "data", 4);
113 hdr->data_size = hdr->n_channels * 2 * inwave.num_samples();
114
115 memcpy(data, inwave.values().memory(), hdr->n_channels * 2 * inwave.num_samples());
116 PlaySound( buffer,
117 NULL,
118 SND_MEMORY);
119 delete [] buffer;
120 return 1;
121}
122
123#else
124int win32audio_supported = FALSE;
125
126int play_win32audio_wave(EST_Wave &inwave, EST_Option &al)
127{
128 (void)inwave;
129 (void)al;
130 cerr << "Windows win32 audio not supported" << endl;
131 return -1;
132}
133
134#endif
const T * memory() const
int num_channels() const
return the number of channels in the waveform
Definition EST_Wave.h:145
int length() const
return the size of the waveform, i.e. the number of samples.
Definition EST_Wave.h:151
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