KallistiOS  2.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
sip.h
Go to the documentation of this file.
1 /* KallistiOS 2.0.0
2 
3  dc/maple/sip.h
4  Copyright (C) 2005, 2008, 2010 Lawrence Sebald
5 
6 */
7 
8 /** \file dc/maple/sip.h
9  \brief Definitions for using the Sound Input Peripheral.
10 
11  This file contains the definitions needed to access the Maple microphone
12  type device (the Seaman mic). Many thanks go out to ZeZu who pointed me
13  toward what some of the commands actually do in the original version of this
14  driver.
15 
16  As a note, the device itself is actually referred to by the system as the
17  Sound Input Peripheral, so hence why this driver is named as it is.
18 
19  \author Lawrence Sebald
20 */
21 
22 #ifndef __DC_MAPLE_SIP_H
23 #define __DC_MAPLE_SIP_H
24 
25 #include <sys/cdefs.h>
26 __BEGIN_DECLS
27 
28 #include <sys/types.h>
29 #include <dc/maple.h>
30 
31 /** \brief SIP status structure.
32 
33  This structure contains information about the status of the microphone
34  device and can be fetched with maple_dev_status(). You should not modify
35  any of the values in here, it is all "read-only" to your programs. Modifying
36  any of this, especially while the microphone is sampling could really screw
37  things up.
38 
39  \headerfile dc/maple/sip.h
40 */
41 typedef struct sip_state {
42  /** \brief The gain value for the microphone amp. */
43  int amp_gain;
44 
45  /** \brief The type of samples that are being recorded. */
47 
48  /** \brief What frequency are we sampling at? */
49  int frequency;
50 
51  /** \brief Is the mic currently sampling? */
53 
54  /** \brief How long is the samples buffer? */
55  size_t buf_len;
56 
57  /** \brief What is the last place written to in the buffer? */
58  off_t buf_pos;
59 
60  /** \brief Buffer for storing samples in (automatically allocated). */
62 } sip_state_t;
63 
64 /** \brief Get recorded samples from the microphone device.
65 
66  This subcommand is used with the MAPLE_COMMAND_MICCONTROL command to fetch
67  samples from the microphone.
68 */
69 #define SIP_SUBCOMMAND_GET_SAMPLES 0x01
70 
71 /** \brief Start and stop sampling.
72 
73  This subcommand is used with the MAPLE_COMMAND_MICCONTROL command to start
74  and stop sampling on the microphone.
75 */
76 #define SIP_SUBCOMMAND_BASIC_CTRL 0x02
77 
78 /** \brief Minimum microphone gain. */
79 #define SIP_MIN_GAIN 0x00
80 
81 /** \brief Default microphone gain. */
82 #define SIP_DEFAULT_GAIN 0x0F
83 
84 /** \brief Maximum microphone gain. */
85 #define SIP_MAX_GAIN 0x1F
86 
87 /** \brief Set the microphone's gain value.
88 
89  This function sets the gain value of the specified microphone device to
90  the value given. This should only be called prior to sampling so as to keep
91  the amplification constant throughout the sampling process, but can be
92  changed on the fly if you really want to.
93 
94  \param dev The microphone device to set gain on.
95  \param g The value to set as the gain.
96  \retval MAPLE_EOK On success.
97  \retval MAPLE_EINVALID If g is out of range.
98  \see SIP_MIN_GAIN
99  \see SIP_DEFAULT_GAIN
100  \see SIP_MAX_GAIN
101 */
102 int sip_set_gain(maple_device_t *dev, unsigned int g);
103 
104 /* Sample types. These two values are the only defined types of samples that
105  the SIP can output. 16-bit signed is your standard 16-bit signed samples,
106  where 8-bit ulaw is obvously encoded as ulaw. */
107 
108 /** \brief Record 16-bit signed integer samples. */
109 #define SIP_SAMPLE_16BIT_SIGNED 0x00
110 
111 /** \brief Record 8-bit ulaw samples. */
112 #define SIP_SAMPLE_8BIT_ULAW 0x01
113 
114 /** \brief Set the sample type to be recorded by the microphone.
115 
116  This function sets the sample type that the microphone will return. The
117  default value for this is 16-bit signed integer samples. You must call this
118  prior to sip_start_sampling() if you wish to change it from the default.
119 
120  \param dev The microphone device to set sample type on.
121  \param type The type of samples requested.
122  \retval MAPLE_EOK On success.
123  \retval MAPLE_EINVALID If type is invalid.
124  \retval MAPLE_EFAIL If the microphone is sampling.
125  \see SIP_SAMPLE_16BIT_SIGNED
126  \see SIP_SAMPLE_8BIT_ULAW
127 */
128 int sip_set_sample_type(maple_device_t *dev, unsigned int type);
129 
130 /* Sampling frequencies. The SIP supports sampling at either 8kHz or 11.025 kHz.
131  One of these values should be passed to the sip_set_frequency function. */
132 /** \brief Record samples at 11.025kHz. */
133 #define SIP_SAMPLE_11KHZ 0x00
134 
135 /** \brief Record samples at 8kHz. */
136 #define SIP_SAMPLE_8KHZ 0x01
137 
138 /** \brief Set the sample frequency to be recorded by the microphone.
139 
140  This function sets the sample frequency that the microphone will record. The
141  default value for this is about 11.025kHz samples. You must call this prior
142  to sip_start_sampling() if you wish to change it from the default.
143 
144  \param dev The microphone device to set sample type on.
145  \param freq The type of samples requested.
146  \retval MAPLE_EOK On success.
147  \retval MAPLE_EINVALID If freq is invalid.
148  \retval MAPLE_EFAIL If the microphone is sampling.
149  \see SIP_SAMPLE_11KHZ
150  \see SIP_SAMPLE_8KHZ
151 */
152 int sip_set_frequency(maple_device_t *dev, unsigned int freq);
153 
154 /** \brief Start sampling on a microphone.
155 
156  This function informs a microphone it should start recording samples.
157 
158  \param dev The device to start sampling on.
159  \param block Set to 1 to wait for the SIP to start sampling.
160  Otherwise check the is_sampling member of the status
161  for dev to know when it has started.
162  \retval MAPLE_EOK On success.
163  \retval MAPLE_EAGAIN If the command couldn't be sent, try again later.
164  \retval MAPLE_EFAIL If the microphone is already sampling.
165  \retval MAPLE_ETIMEOUT If the command timed out while blocking.
166 */
167 int sip_start_sampling(maple_device_t *dev, int block);
168 
169 /** \brief Stop sampling on a microphone.
170 
171  This function informs a microphone it should stop recording samples.
172 
173  \param dev The device to stop sampling on.
174  \param block Set to 1 to wait for the SIP to stop sampling.
175  Otherwise check the is_sampling member of the status
176  for dev to know when it has finished.
177  \retval MAPLE_EOK On success.
178  \retval MAPLE_EAGAIN If the command couldn't be sent, try again later.
179  \retval MAPLE_EFAIL If the microphone is not sampling.
180  \retval MAPLE_ETIMEOUT If the command timed out while blocking.
181 */
182 int sip_stop_sampling(maple_device_t *dev, int block);
183 
184 /** \brief Retrieve the sample buffer from the microphone.
185 
186  This function retrieves the sample buffer from the microphone and allocates
187  a new buffer for the microphone to record into. This function cannot be
188  called while the microphone is sampling. The caller is responsible for the
189  buffer returned, and must free the buffer when it is done with it.
190 
191  \param dev The device to fetch samples for.
192  \param sz On return, the size of the sample buffer in bytes.
193  This must not be NULL.
194  \return The sample buffer on success, NULL on failure.
195 */
196 uint8 *sip_get_samples(maple_device_t *dev, size_t *sz);
197 
198 /** \brief Clear the sample buffer of a microphone.
199 
200  This function clears out any old samples on the microphone buffer so that
201  recording will start from the beginning of the buffer again. This does not
202  resize the buffer in any way. This function will not work if called while
203  the microphone is sampling.
204 
205  \param dev The device to clear the buffer on.
206  \retval MAPLE_EOK On success.
207  \retval MAPLE_EFAIL If the device is currently sampling.
208 */
210 
211 /* \cond */
212 /* Init / Shutdown */
213 int sip_init();
214 void sip_shutdown();
215 /* \endcond */
216 
217 __END_DECLS
218 
219 #endif /* __DC_MAPLE_SIP_H */