• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

include/ad.h

Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
00002 /* ====================================================================
00003  * Copyright (c) 1999-2004 Carnegie Mellon University.  All rights
00004  * reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer. 
00012  *
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in
00015  *    the documentation and/or other materials provided with the
00016  *    distribution.
00017  *
00018  * This work was supported in part by funding from the Defense Advanced 
00019  * Research Projects Agency and the National Science Foundation of the 
00020  * United States of America, and the CMU Sphinx Speech Consortium.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 
00023  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
00024  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00025  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
00026  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00027  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00028  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
00029  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
00030  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00031  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00032  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * ====================================================================
00035  *
00036  */
00037 /*
00038  * ad.h -- generic live audio interface for recording and playback
00039  * 
00040  * **********************************************
00041  * CMU ARPA Speech Project
00042  *
00043  * Copyright (c) 1996 Carnegie Mellon University.
00044  * ALL RIGHTS RESERVED.
00045  * **********************************************
00046  * 
00047  * HISTORY
00048  * 
00049  * $Log: ad.h,v $
00050  * Revision 1.8  2005/06/22 08:00:06  arthchan2003
00051  * Completed all doxygen documentation on file description for libs3decoder/libutil/libs3audio and programs.
00052  *
00053  * Revision 1.7  2004/12/14 00:39:49  arthchan2003
00054  * add <s3types.h> to the code, change some comments to doxygen style
00055  *
00056  * Revision 1.6  2004/12/06 11:17:55  arthchan2003
00057  * 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
00058  *
00059  * Revision 1.5  2004/07/23 23:44:46  egouvea
00060  * Changed the cygwin code to use the same audio files as the MS Visual code, removed unused variables from fe_interface.c
00061  *
00062  * Revision 1.4  2004/02/29 23:48:31  egouvea
00063  * Updated configure.in to the recent automake/autoconf, fixed win32
00064  * references in audio files.
00065  *
00066  * Revision 1.3  2002/11/10 19:27:38  egouvea
00067  * Fixed references to sun's implementation of audio interface,
00068  * referring to the correct .h file, and replacing sun4 with sunos.
00069  *
00070  * Revision 1.2  2001/12/11 04:40:55  lenzo
00071  * License cleanup.
00072  *
00073  * Revision 1.1.1.1  2001/12/03 16:01:45  egouvea
00074  * Initial import of sphinx3
00075  *
00076  * Revision 1.1.1.1  2001/01/17 05:17:14  ricky
00077  * Initial Import of the s3.3 decoder, has working decodeaudiofile, s3.3_live
00078  *
00079  * 
00080  * 19-Jan-1999  M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
00081  *              Added AD_ return codes.  Added ad_open_sps_bufsize(), and
00082  *              ad_rec_t.n_buf.
00083  * 
00084  * 17-Apr-98    M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
00085  *              Added ad_open_play_sps().
00086  * 
00087  * 07-Mar-98    M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
00088  *              Added ad_open_sps().
00089  * 
00090  * 10-Jun-96    M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
00091  *              Added ad_wbuf_t, ad_rec_t, and ad_play_t types, and augmented all
00092  *              recording functions with ad_rec_t, and playback functions with
00093  *              ad_play_t.
00094  * 
00095  * 06-Jun-96    M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
00096  *              Created.
00097  */
00098 
00103 #ifndef _AD_H_
00104 #define _AD_H_
00105 
00106 #include <sphinx_config.h>
00107 
00108 #if defined (__CYGWIN__)
00109 
00110 #include <w32api/windows.h>
00111 #include <w32api/mmsystem.h>
00112 
00113 #elif (defined(WIN32) && !defined(GNUWINCE)) || defined(_WIN32_WCE)
00114 
00115 #include <windows.h>
00116 #include <mmsystem.h>
00117 
00118 #elif defined(AD_BACKEND_OSF) /* Not implemented, it seems */
00119 
00120 #include <AF/AFlib.h>
00121 
00122 #elif defined(AD_BACKEND_HPUX) /* Not implemented, it seems */
00123 
00124 #include <audio/Alib.h>
00125 
00126 #elif defined(AD_BACKEND_ALSA)
00127 
00128 #include <alsa/asoundlib.h>
00129 
00130 #elif defined(AD_BACKEND_IRIX)
00131 
00132 #include <dmedia/audio.h>
00133 
00134 #elif defined(AD_BACKEND_PORTAUDIO)
00135 
00136 #include "portaudio.h"
00137 #include "pablio.h"
00138 
00139 #endif
00140 
00141 /* Win32/WinCE DLL gunk */
00142 #include <sphinxbase_export.h>
00143 
00144 #include <prim_type.h>
00145 
00146 
00147 #ifdef __cplusplus
00148 extern "C" {
00149 #endif
00150 #if 0
00151 /* Fool Emacs. */
00152 }
00153 #endif
00154 
00155 #define AD_SAMPLE_SIZE          (sizeof(int16))
00156 #define DEFAULT_SAMPLES_PER_SEC 16000
00157 
00158 /* Return codes */
00159 #define AD_OK           0
00160 #define AD_EOF          -1
00161 #define AD_ERR_GEN      -1
00162 #define AD_ERR_NOT_OPEN -2
00163 #define AD_ERR_WAVE     -3
00164 
00165 
00166 #if  (defined(WIN32) || defined(AD_BACKEND_WIN32)) && !defined(GNUWINCE)
00167 typedef struct {
00168     HGLOBAL h_whdr;
00169     LPWAVEHDR p_whdr;
00170     HGLOBAL h_buf;
00171     LPSTR p_buf;
00172 } ad_wbuf_t;
00173 #endif
00174 
00175 
00176 /* ------------ RECORDING -------------- */
00177 
00178 /*
00179  * NOTE: ad_rec_t and ad_play_t are READ-ONLY structures for the user.
00180  */
00181 
00182 #if (defined(WIN32) || defined(AD_BACKEND_WIN32)) && !defined(GNUWINCE)
00183 
00184 #define DEFAULT_DEVICE (char*)DEV_MAPPER
00185 
00189 typedef struct ad_rec_s {
00190     HWAVEIN h_wavein;   /* "HANDLE" to the audio input device */
00191     ad_wbuf_t *wi_buf;  /* Recording buffers provided to system */
00192     int32 n_buf;        /* #Recording buffers provided to system */
00193     int32 opened;       /* Flag; A/D opened for recording */
00194     int32 recording;
00195     int32 curbuf;       /* Current buffer with data for application */
00196     int32 curoff;       /* Start of data for application in curbuf */
00197     int32 curlen;       /* #samples of data from curoff in curbuf */
00198     int32 lastbuf;      /* Last buffer containing data after recording stopped */
00199     int32 sps;          /* Samples/sec */
00200     int32 bps;          /* Bytes/sample */
00201 } ad_rec_t;
00202 
00203 #elif defined(AD_BACKEND_OSF)
00204 
00205 #define DEFAULT_DEVICE NULL
00206 
00207 typedef struct {
00208     AFAudioConn *aud;
00209     AC ac;
00210     int32 recording;            /* flag; TRUE iff currently recording */
00211     ATime last_rec_time;        /* timestamp of last sample recorded in buffer */
00212     ATime end_rec_time;         /* time at which recording stopped */
00213     int32 sps;          /* Samples/sec */
00214     int32 bps;          /* Bytes/sample */
00215 } ad_rec_t;
00216 
00217 #elif defined(AD_BACKEND_SUNOS)
00218 
00219 #define DEFAULT_DEVICE "/dev/audio"
00220 
00221 typedef struct {
00222     int32 audio_fd;
00223     int32 recording;
00224     int32 sps;          /* Samples/sec */
00225     int32 bps;          /* Bytes/sample */
00226 } ad_rec_t;
00227 
00228 #elif defined(AD_BACKEND_OSS) || defined(AD_BACKEND_OSS_BSD)
00229 
00230 #define DEFAULT_DEVICE "/dev/dsp"
00231 
00236 /* Added by jd5q+@andrew.cmu.edu, 10/3/1997: */
00237 typedef struct {
00238     int32 dspFD;        /* Audio device descriptor */
00239     int32 recording;
00240     int32 sps;          /* Samples/sec */
00241     int32 bps;          /* Bytes/sample */
00242 } ad_rec_t;
00243 
00244 #elif defined(AD_BACKEND_ESD)
00245 
00246 #define DEFAULT_DEVICE NULL
00247 typedef struct {
00248     int32 fd;
00249     int32 recording;
00250     int32 sps;
00251     int32 bps;
00252 } ad_rec_t;
00253 
00254 #elif defined(AD_BACKEND_ALSA)
00255 
00256 #define DEFAULT_DEVICE "default"
00257 typedef struct {
00258     snd_pcm_t *dspH;
00259     int32 recording;
00260     int32 sps;
00261     int32 bps;
00262 } ad_rec_t;
00263 
00264 #elif defined(AD_BACKEND_HPUX)
00265 
00266 #define DEFAULT_DEVICE NULL
00267 typedef struct {
00268     Audio *audio;       /* The main audio handle */
00269     ATransID xid;       /* The current transaction ID */
00270     int32 streamSocket; /* Connection socket */
00271     int32 recording;    /* TRUE iff currently recording */
00272     int32 sps;          /* Samples/sec */
00273     int32 bps;          /* Bytes/sample */
00274 } ad_rec_t;
00275 
00276 #elif defined(AD_BACKEND_IRIX)
00277 #define DEFAULT_DEVICE NULL
00278 typedef struct {
00279     ALport audio;       /* The main audio handle */
00280     int32 recording;    /* TRUE iff currently recording */
00281     int32 sps;          /* Samples/sec */
00282     int32 bps;          /* Bytes/sample */
00283 } ad_rec_t;
00284 
00285 #elif defined(AD_BACKEND_PORTAUDIO)
00286 #define DEFAULT_DEVICE NULL /* FIXME */
00287 typedef struct {
00288   PABLIO_Stream *astream;
00289   int32 sps;
00290   int32 bps;
00291   int32 recording;
00292 } ad_rec_t;
00293 
00294 #elif defined(AD_BACKEND_S60)
00295 
00296 typedef struct ad_rec_s {
00297     void* recorder;
00298     int32 recording;
00299     int32 sps;
00300     int32 bps;
00301 } ad_rec_t;
00302 
00303 SPHINXBASE_EXPORT
00304 ad_rec_t *ad_open_sps_bufsize (int32 samples_per_sec, int32 bufsize_msec);
00305 
00306 #else
00307 
00308 #define DEFAULT_DEVICE NULL
00309 typedef struct {
00310     int32 sps;          
00311     int32 bps;          
00312 } ad_rec_t;     
00313 
00314 
00315 #endif
00316 
00317 
00327 SPHINXBASE_EXPORT
00328 ad_rec_t *ad_open_dev (
00329         const char *dev, 
00330         int32 samples_per_sec 
00331         );
00332 
00336 SPHINXBASE_EXPORT
00337 ad_rec_t *ad_open_sps (
00338                        int32 samples_per_sec 
00339                        );
00340 
00341 
00345 SPHINXBASE_EXPORT
00346 ad_rec_t *ad_open ( void );
00347 
00348 
00349 #if defined(WIN32) && !defined(GNUWINCE)
00350 /*
00351  * Like ad_open_sps but specifies buffering required within driver.  This function is
00352  * useful if the default (5000 msec worth) is too small and results in loss of data.
00353  */
00354 SPHINXBASE_EXPORT
00355 ad_rec_t *ad_open_sps_bufsize (int32 samples_per_sec, int32 bufsize_msec);
00356 #endif
00357 
00358 
00359 /* Start audio recording.  Return value: 0 if successful, <0 otherwise */
00360 SPHINXBASE_EXPORT
00361 int32 ad_start_rec (ad_rec_t *);
00362 
00363 
00364 /* Stop audio recording.  Return value: 0 if successful, <0 otherwise */
00365 SPHINXBASE_EXPORT
00366 int32 ad_stop_rec (ad_rec_t *);
00367 
00368 
00369 /* Close the recording device.  Return value: 0 if successful, <0 otherwise */
00370 SPHINXBASE_EXPORT
00371 int32 ad_close (ad_rec_t *);
00372 
00373 
00374 /*
00375  * Read next block of audio samples while recording; read upto max samples into buf.
00376  * Return value: # samples actually read (could be 0 since non-blocking); -1 if not
00377  * recording and no more samples remaining to be read from most recent recording.
00378  */
00379 SPHINXBASE_EXPORT
00380 int32 ad_read (ad_rec_t *, int16 *buf, int32 max);
00381 
00382 
00383 /* ------ PLAYBACK; SIMILAR TO RECORDING ------- */
00384 
00385 #if defined(WIN32) && !defined(GNUWINCE)
00386 
00387 typedef struct {
00388     HWAVEOUT h_waveout; /* "HANDLE" to the audio output device */
00389     ad_wbuf_t *wo_buf;  /* Playback buffers given to the system */
00390     int32 opened;       /* Flag; A/D opened for playback */
00391     int32 playing;
00392     char *busy;         /* flags [N_WO_BUF] indicating whether given to system */
00393     int32 nxtbuf;       /* Next buffer [0..N_WO_BUF-1] to be used for playback data */
00394     int32 sps;          /* Samples/sec */
00395     int32 bps;          /* Bytes/sample */
00396 } ad_play_t;
00397 
00398 #else
00399 
00400 typedef struct {
00401     int32 sps;          /* Samples/sec */
00402     int32 bps;          /* Bytes/sample */
00403 } ad_play_t;    /* Dummy definition for systems without A/D stuff */
00404 
00405 #endif
00406 
00407 
00408 SPHINXBASE_EXPORT
00409 ad_play_t *ad_open_play_sps (int32 samples_per_sec);
00410 
00411 SPHINXBASE_EXPORT
00412 ad_play_t *ad_open_play ( void );
00413 
00414 SPHINXBASE_EXPORT
00415 int32 ad_start_play (ad_play_t *);
00416 
00417 SPHINXBASE_EXPORT
00418 int32 ad_stop_play (ad_play_t *);
00419 
00420 SPHINXBASE_EXPORT
00421 int32 ad_close_play (ad_play_t *);
00422 
00423 
00432 SPHINXBASE_EXPORT
00433 int32 ad_write (ad_play_t *, int16 *buf, int32 len);
00434 
00435 
00436 /* ------ MISCELLANEOUS ------- */
00437 
00441 SPHINXBASE_EXPORT
00442 void ad_mu2li (int16 *outbuf,           /* Out: PCM data placed here (allocated by user) */
00443                unsigned char *inbuf,    /* In: Input buffer with mulaw data */
00444                int32 n_samp);           /* In: #Samples in inbuf */
00445 
00446 #ifdef __cplusplus
00447 }
00448 #endif
00449 
00450 
00451 #endif

Generated on Mon Aug 29 2011 for SphinxBase by  doxygen 1.7.1