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