Skip to content
This repository was archived by the owner on Jun 9, 2022. It is now read-only.

Commit 5cc55c4

Browse files
author
nshmyrev
committed
Use openal backend.
Patch by Zhi-Qiang Lei. See also http://sourceforge.net/p/cmusphinx/bugs/389/ git-svn-id: svn+ssh://svn.code.sf.net/p/cmusphinx/code/trunk/sphinxbase@12610 94700074-3cef-4d97-a70e-9c8c206c02f5
1 parent 961e928 commit 5cc55c4

File tree

8 files changed

+116
-576
lines changed

8 files changed

+116
-576
lines changed

configure.in

+15-21
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,10 @@ AC_CONFIG_MACRO_DIR([m4])
99
CFLAGS=${CFLAGS:--g -O2 -Wall}
1010

1111
AC_CANONICAL_HOST
12-
13-
dnl
14-
dnl Set proper compiler flags and such for some platforms
15-
dnl
16-
case $host in
17-
arm-wince-pe*)
18-
CFLAGS=${CFLAGS:--march=armv4 -mapcs-32 -malignment-traps}
19-
LIBS='-lc -lgcc -lwinsock -lcoredll'
20-
CFLAGS="$CFLAGS -DNEWLIB -DSARM -DWIN32 -DGNUWINCE"
21-
;;
22-
*uclinux*)
23-
# uClinux needs special "flat" binaries
24-
LDFLAGS="$LDFLAGS -Wl,-elf2flt"
25-
;;
26-
*)
27-
;;
28-
esac
29-
3012
AC_ISC_POSIX
3113
AC_PROG_CC
3214
AC_PROG_CC_STDC
15+
AC_PROG_LIBTOOL
3316

3417
# We don't bother ourselves with flex checks until the rest of the world has an up-to-date Flex
3518
# We need specific bison extensions, so check for bison
@@ -186,11 +169,23 @@ case $host in
186169
])
187170
;;
188171
*-*-*cygwin*|*-*-*mingw*)
189-
ad_files="play_win32.lo rec_win32.lo"
172+
ad_files="ad_win32.lo"
190173
ad_libs="-lwinmm"
191174
ad_backend="AD_BACKEND_WIN32"
192175
AC_DEFINE(AD_BACKEND_WIN32, [], [Use WinMM interface for sound I/O])
193176
;;
177+
*-apple-*darwin*)
178+
sdkpath=`xcodebuild -version -sdk | grep MacOSX | grep "^Path:" | cut -d" " -f2`
179+
ad_cppflags="-I$sdkpath/System/Library/Frameworks/OpenAL.framework/Versions/A/Headers/"
180+
backup_CPPFLAGS="$CPPFLAGS"
181+
CPPFLAGS="$CPPFLAGS $ad_cppflags"
182+
AC_CHECK_HEADER("alc.h", [], AC_MSG_ERROR([OpenAL not found]))
183+
CPPFLAGS="$backup_CPPFLAGS"
184+
ad_files="ad_openal.lo"
185+
ad_libs="-framework OpenAL"
186+
ad_backend="AD_BACKEND_OPENAL"
187+
AC_DEFINE(AD_BACKEND_OPENAL, [], [Use OpenAL for sound I/O])
188+
;;
194189
*)
195190
ad_files="ad_base.lo"
196191
ad_backend="AD_BACKEND_NONE"
@@ -199,12 +194,11 @@ case $host in
199194
;;
200195
esac
201196

197+
AC_SUBST(ad_cppflags)
202198
AC_SUBST(ad_files)
203199
AC_SUBST(ad_libs)
204200
AC_SUBST(ad_backend)
205201

206-
AM_PROG_LIBTOOL
207-
208202
dnl
209203
dnl Check for Doxygen, and build dox if present
210204
dnl

include/sphinxbase/ad.h

+10-128
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
22
/* ====================================================================
3-
* Copyright (c) 1999-2004 Carnegie Mellon University. All rights
3+
* Copyright (c) 1999-2014 Carnegie Mellon University. All rights
44
* reserved.
55
*
66
* Redistribution and use in source and binary forms, with or without
@@ -34,68 +34,6 @@
3434
* ====================================================================
3535
*
3636
*/
37-
/*
38-
* ad.h -- generic live audio interface for recording and playback
39-
*
40-
* **********************************************
41-
* CMU ARPA Speech Project
42-
*
43-
* Copyright (c) 1996 Carnegie Mellon University.
44-
* ALL RIGHTS RESERVED.
45-
* **********************************************
46-
*
47-
* HISTORY
48-
*
49-
* $Log: ad.h,v $
50-
* Revision 1.8 2005/06/22 08:00:06 arthchan2003
51-
* Completed all doxygen documentation on file description for libs3decoder/libutil/libs3audio and programs.
52-
*
53-
* Revision 1.7 2004/12/14 00:39:49 arthchan2003
54-
* add <s3types.h> to the code, change some comments to doxygen style
55-
*
56-
* Revision 1.6 2004/12/06 11:17:55 arthchan2003
57-
* Update the copyright information of ad.h, *sigh* start to feel tired of updating documentation system. Anyone who has time, please take up libs3audio. That is the last place which is undocumented
58-
*
59-
* Revision 1.5 2004/07/23 23:44:46 egouvea
60-
* Changed the cygwin code to use the same audio files as the MS Visual code, removed unused variables from fe_interface.c
61-
*
62-
* Revision 1.4 2004/02/29 23:48:31 egouvea
63-
* Updated configure.in to the recent automake/autoconf, fixed win32
64-
* references in audio files.
65-
*
66-
* Revision 1.3 2002/11/10 19:27:38 egouvea
67-
* Fixed references to sun's implementation of audio interface,
68-
* referring to the correct .h file, and replacing sun4 with sunos.
69-
*
70-
* Revision 1.2 2001/12/11 04:40:55 lenzo
71-
* License cleanup.
72-
*
73-
* Revision 1.1.1.1 2001/12/03 16:01:45 egouvea
74-
* Initial import of sphinx3
75-
*
76-
* Revision 1.1.1.1 2001/01/17 05:17:14 ricky
77-
* Initial Import of the s3.3 decoder, has working decodeaudiofile, s3.3_live
78-
*
79-
*
80-
* 19-Jan-1999 M K Ravishankar ([email protected]) at Carnegie Mellon University
81-
* Added AD_ return codes. Added ad_open_sps_bufsize(), and
82-
* ad_rec_t.n_buf.
83-
*
84-
* 17-Apr-98 M K Ravishankar ([email protected]) at Carnegie Mellon University
85-
* Added ad_open_play_sps().
86-
*
87-
* 07-Mar-98 M K Ravishankar ([email protected]) at Carnegie Mellon University
88-
* Added ad_open_sps().
89-
*
90-
* 10-Jun-96 M K Ravishankar ([email protected]) at Carnegie Mellon University
91-
* Added ad_wbuf_t, ad_rec_t, and ad_play_t types, and augmented all
92-
* recording functions with ad_rec_t, and playback functions with
93-
* ad_play_t.
94-
*
95-
* 06-Jun-96 M K Ravishankar ([email protected]) at Carnegie Mellon University
96-
* Created.
97-
*/
98-
9937
/** \file ad.h
10038
* \brief generic live audio interface for recording and playback
10139
*/
@@ -122,6 +60,9 @@
12260
#include <pulse/simple.h>
12361
#elif defined(AD_BACKEND_ALSA)
12462
#include <alsa/asoundlib.h>
63+
#elif defined(AD_BACKEND_OPENAL)
64+
#include <al.h>
65+
#include <alc.h>
12566
#endif
12667

12768
/* Win32/WinCE DLL gunk */
@@ -249,6 +190,12 @@ typedef struct ad_rec_s {
249190
SPHINXBASE_EXPORT
250191
ad_rec_t *ad_open_sps_bufsize (int32 samples_per_sec, int32 bufsize_msec);
251192

193+
#elif defined(AD_BACKEND_OPENAL)
194+
195+
typedef struct {
196+
ALCdevice * device;
197+
} ad_rec_t;
198+
252199
#else
253200

254201
#define DEFAULT_DEVICE NULL
@@ -316,7 +263,6 @@ int32 ad_stop_rec (ad_rec_t *);
316263
SPHINXBASE_EXPORT
317264
int32 ad_close (ad_rec_t *);
318265

319-
320266
/*
321267
* Read next block of audio samples while recording; read upto max samples into buf.
322268
* Return value: # samples actually read (could be 0 since non-blocking); -1 if not
@@ -326,72 +272,8 @@ SPHINXBASE_EXPORT
326272
int32 ad_read (ad_rec_t *, int16 *buf, int32 max);
327273

328274

329-
/* ------ PLAYBACK; SIMILAR TO RECORDING ------- */
330-
331-
#if defined(_WIN32) && !defined(GNUWINCE)
332-
333-
typedef struct {
334-
HWAVEOUT h_waveout; /* "HANDLE" to the audio output device */
335-
ad_wbuf_t *wo_buf; /* Playback buffers given to the system */
336-
int32 opened; /* Flag; A/D opened for playback */
337-
int32 playing;
338-
char *busy; /* flags [N_WO_BUF] indicating whether given to system */
339-
int32 nxtbuf; /* Next buffer [0..N_WO_BUF-1] to be used for playback data */
340-
int32 sps; /* Samples/sec */
341-
int32 bps; /* Bytes/sample */
342-
} ad_play_t;
343-
344-
#else
345-
346-
typedef struct {
347-
int32 sps; /* Samples/sec */
348-
int32 bps; /* Bytes/sample */
349-
} ad_play_t; /* Dummy definition for systems without A/D stuff */
350-
351-
#endif
352-
353-
354-
SPHINXBASE_EXPORT
355-
ad_play_t *ad_open_play_sps (int32 samples_per_sec);
356-
357-
SPHINXBASE_EXPORT
358-
ad_play_t *ad_open_play ( void );
359-
360-
SPHINXBASE_EXPORT
361-
int32 ad_start_play (ad_play_t *);
362-
363-
SPHINXBASE_EXPORT
364-
int32 ad_stop_play (ad_play_t *);
365-
366-
SPHINXBASE_EXPORT
367-
int32 ad_close_play (ad_play_t *);
368-
369-
370-
/**
371-
* Queue a block of audio samples for playback.
372-
*
373-
* Write the next block of [len] samples from rawbuf to the A/D device for playback.
374-
* The device may queue less than len samples, possibly 0, since it is non-blocking.
375-
* The application should resubmit the remaining data to be played.
376-
* Return value: # samples accepted for playback; -1 if error.
377-
*/
378-
SPHINXBASE_EXPORT
379-
int32 ad_write (ad_play_t *, int16 *buf, int32 len);
380-
381-
382-
/* ------ MISCELLANEOUS ------- */
383-
384-
/**
385-
* Convert mu-law data to int16 linear PCM format.
386-
*/
387-
SPHINXBASE_EXPORT
388-
void ad_mu2li (int16 *outbuf, /* Out: PCM data placed here (allocated by user) */
389-
unsigned char *inbuf, /* In: Input buffer with mulaw data */
390-
int32 n_samp); /* In: #Samples in inbuf */
391-
392275
#ifdef __cplusplus
393276
}
394277
#endif
395278

396-
397279
#endif

src/libsphinxad/Makefile.am

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ EXTRA_libsphinxad_la_SOURCES = ad_base.c \
1616
ad_pulse.c \
1717
ad_jack.c
1818

19-
EXTRA_DIST = ad_s60.cpp \
20-
play_win32.c \
21-
rec_win32.c
19+
EXTRA_DIST = \
20+
ad_s60.cpp \
21+
ad_win32.c
2222

2323
libsphinxad_la_DEPENDENCIES = @ad_files@
2424

@@ -29,7 +29,7 @@ libsphinxad_la_LIBADD = \
2929
$(top_builddir)/src/libsphinxbase/libsphinxbase.la
3030

3131
INCLUDES = \
32-
@SAMPLERATE_CFLAGS@ \
32+
@ad_cppflags@ \
3333
-I$(top_srcdir)/include/sphinxbase \
3434
-I$(top_srcdir)/include \
3535
-I$(top_builddir)/include

src/libsphinxad/ad_openal.c

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include <config.h>
2+
#include <stdlib.h>
3+
#include <stdio.h>
4+
5+
#include "ad.h"
6+
7+
ad_rec_t *
8+
ad_open_dev(const char * dev, int32 samples_per_sec)
9+
{
10+
ad_rec_t * handle = malloc(sizeof(ad_rec_t));
11+
12+
if (handle == NULL) {
13+
fprintf(stderr, "%s\n", "failed to allocate memory");
14+
abort();
15+
}
16+
17+
handle -> device = alcCaptureOpenDevice(dev, samples_per_sec, AL_FORMAT_MONO16, samples_per_sec * 10);
18+
19+
if (handle -> device == NULL) {
20+
free(handle);
21+
fprintf(stderr, "%s\n", "failed to open capture device");
22+
abort();
23+
}
24+
25+
return handle;
26+
}
27+
28+
29+
ad_rec_t *
30+
ad_open_sps(int32 samples_per_sec)
31+
{
32+
return ad_open_dev(NULL, samples_per_sec);
33+
}
34+
35+
ad_rec_t *
36+
ad_open(void)
37+
{
38+
return ad_open_sps(DEFAULT_SAMPLES_PER_SEC);
39+
}
40+
41+
42+
int32
43+
ad_start_rec(ad_rec_t * r)
44+
{
45+
alcCaptureStart(r -> device);
46+
return 0;
47+
}
48+
49+
50+
int32
51+
ad_stop_rec(ad_rec_t * r)
52+
{
53+
alcCaptureStop(r -> device);
54+
return 0;
55+
}
56+
57+
58+
int32
59+
ad_read(ad_rec_t * r, int16 * buf, int32 max)
60+
{
61+
ALCint number;
62+
63+
alcGetIntegerv(r -> device, ALC_CAPTURE_SAMPLES, sizeof(number), &number);
64+
if (number >= 0) {
65+
number = (number < max ? number : max);
66+
alcCaptureSamples(r -> device, buf, number);
67+
}
68+
69+
return number;
70+
}
71+
72+
73+
int32
74+
ad_close(ad_rec_t * r)
75+
{
76+
ALCboolean isClosed;
77+
78+
isClosed = alcCaptureCloseDevice(r -> device);
79+
80+
if (isClosed) {
81+
return 0;
82+
} else {
83+
return -1;
84+
}
85+
}
File renamed without changes.

0 commit comments

Comments
 (0)