SphinxBase  5prealpha
ad.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3  * Copyright (c) 1999-2014 Carnegie Mellon University. All rights
4  * reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * This work was supported in part by funding from the Defense Advanced
19  * Research Projects Agency and the National Science Foundation of the
20  * United States of America, and the CMU Sphinx Speech Consortium.
21  *
22  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
23  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
26  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * ====================================================================
35  *
36  */
41 #ifndef _AD_H_
42 #define _AD_H_
43 
44 #include <sphinx_config.h>
45 
46 #include <sphinxbase/sphinxbase_export.h>
47 #include <sphinxbase/prim_type.h>
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 #if 0
53 /* Fool Emacs. */
54 }
55 #endif
56 
57 #define DEFAULT_SAMPLES_PER_SEC 16000
58 
59 /* Return codes */
60 #define AD_OK 0
61 #define AD_EOF -1
62 #define AD_ERR_GEN -1
63 #define AD_ERR_NOT_OPEN -2
64 #define AD_ERR_WAVE -3
65 
66 typedef struct ad_rec_s ad_rec_t;
67 
77 SPHINXBASE_EXPORT
79  const char *dev,
80  int32 samples_per_sec
81  );
82 
86 SPHINXBASE_EXPORT
88  int32 samples_per_sec
89  );
90 
91 
95 SPHINXBASE_EXPORT
96 ad_rec_t *ad_open ( void );
97 
98 
99 /* Start audio recording. Return value: 0 if successful, <0 otherwise */
100 SPHINXBASE_EXPORT
101 int32 ad_start_rec (ad_rec_t *);
102 
103 
104 /* Stop audio recording. Return value: 0 if successful, <0 otherwise */
105 SPHINXBASE_EXPORT
106 int32 ad_stop_rec (ad_rec_t *);
107 
108 
109 /* Close the recording device. Return value: 0 if successful, <0 otherwise */
110 SPHINXBASE_EXPORT
111 int32 ad_close (ad_rec_t *);
112 
113 /*
114  * Read next block of audio samples while recording; read upto max samples into buf.
115  * Return value: # samples actually read (could be 0 since non-blocking); -1 if not
116  * recording and no more samples remaining to be read from most recent recording.
117  */
118 SPHINXBASE_EXPORT
119 int32 ad_read (ad_rec_t *, int16 *buf, int32 max);
120 
121 
122 #ifdef __cplusplus
123 }
124 #endif
125 
126 #endif
Audio recording structure.
Basic type definitions used in Sphinx.
SPHINXBASE_EXPORT ad_rec_t * ad_open(void)
Open the default audio device.
Definition: ad_alsa.c:228
SPHINXBASE_EXPORT ad_rec_t * ad_open_dev(const char *dev, int32 samples_per_sec)
Open a specific audio device for recording.
Definition: ad_alsa.c:187
SPHINXBASE_EXPORT ad_rec_t * ad_open_sps(int32 samples_per_sec)
Open the default audio device with a given sampling rate.
Definition: ad_alsa.c:222
Audio recording structure.
Definition: ad_alsa.c:90