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