libctru  v1.6.0
mic.h
Go to the documentation of this file.
1 /**
2  * @file mic.h
3  * @brief MIC (Microphone) service.
4  */
5 #pragma once
6 
7 /// Microphone audio encodings.
8 typedef enum
9 {
10  MICU_ENCODING_PCM8 = 0, ///< Unsigned 8-bit PCM.
11  MICU_ENCODING_PCM16 = 1, ///< Unsigned 16-bit PCM.
12  MICU_ENCODING_PCM8_SIGNED = 2, ///< Signed 8-bit PCM.
13  MICU_ENCODING_PCM16_SIGNED = 3, ///< Signed 16-bit PCM.
15 
16 /// Microphone audio sampling rates.
17 typedef enum
18 {
19  MICU_SAMPLE_RATE_32730 = 0, ///< 32728.498 Hz
20  MICU_SAMPLE_RATE_16360 = 1, ///< 16364.479 Hz
21  MICU_SAMPLE_RATE_10910 = 2, ///< 10909.499 Hz
22  MICU_SAMPLE_RATE_8180 = 3, ///< 8182.1245 Hz
24 
25 /**
26  * @brief Initializes MIC.
27  * @param size Shared memory buffer to write audio data to. Must be aligned to 0x1000 bytes.
28  * @param handle Size of the shared memory buffer.
29  */
30 Result micInit(u8* buffer, u32 bufferSize);
31 
32 /// Exits MIC.
33 void micExit(void);
34 
35 /**
36  * @brief Gets the size of the sample data area within the shared memory buffer.
37  * @return The sample data's size.
38  */
40 
41 /**
42  * @brief Gets the offset within the shared memory buffer of the last sample written.
43  * @return The last sample's offset.
44  */
46 
47 /**
48  * @brief Maps MIC shared memory.
49  * @param size Size of the shared memory.
50  * @param handle Handle of the shared memory.
51  */
52 Result MICU_MapSharedMem(u32 size, Handle handle);
53 
54 /// Unmaps MIC shared memory.
56 
57 /**
58  * @brief Begins sampling microphone input.
59  * @param encoding Encoding of outputted audio.
60  * @param sampleRate Sample rate of outputted audio.
61  * @param sharedMemAudioOffset Offset to write audio data to in the shared memory buffer.
62  * @param sharedMemAudioSize Size of audio data to write to the shared memory buffer. This should be at most "bufferSize - 4".
63  * @param loop Whether to loop back to the beginning of the buffer when the end is reached.
64  */
65 Result MICU_StartSampling(MICU_Encoding encoding, MICU_SampleRate sampleRate, u32 offset, u32 size, bool loop);
66 
67 /**
68  * @brief Adjusts the configuration of the current sampling session.
69  * @param sampleRate Sample rate of outputted audio.
70  */
72 
73 /// Stops sampling microphone input.
75 
76 /**
77  * @brief Gets whether microphone input is currently being sampled.
78  * @param sampling Pointer to output the sampling state to.
79  */
80 Result MICU_IsSampling(bool* sampling);
81 
82 /**
83  * @brief Gets an event handle triggered when the shared memory buffer is full.
84  * @param handle Pointer to output the event handle to.
85  */
87 
88 /**
89  * @brief Sets the microphone's gain.
90  * @param gain Gain to set.
91  */
92 Result MICU_SetGain(u8 gain);
93 
94 /**
95  * @brief Gets the microphone's gain.
96  * @param gain Pointer to output the current gain to.
97  */
98 Result MICU_GetGain(u8* gain);
99 
100 /**
101  * @brief Sets whether the microphone is powered on.
102  * @param power Whether the microphone is powered on.
103  */
104 Result MICU_SetPower(bool power);
105 
106 /**
107  * @brief Gets whether the microphone is powered on.
108  * @param power Pointer to output the power state to.
109  */
110 Result MICU_GetPower(bool* power);
111 
112 /**
113  * @brief Sets whether to clamp microphone input.
114  * @param clamp Whether to clamp microphone input.
115  */
116 Result MICU_SetClamp(bool clamp);
117 
118 /**
119  * @brief Gets whether to clamp microphone input.
120  * @param clamp Pointer to output the clamp state to.
121  */
122 Result MICU_GetClamp(bool* clamp);
123 
124 /**
125  * @brief Sets whether to allow sampling when the shell is closed.
126  * @param allowShellClosed Whether to allow sampling when the shell is closed.
127  */
128 Result MICU_SetAllowShellClosed(bool allowShellClosed);
Result MICU_GetPower(bool *power)
Gets whether the microphone is powered on.
MICU_SampleRate
Microphone audio sampling rates.
Definition: mic.h:17
Result micInit(u8 *buffer, u32 bufferSize)
Initializes MIC.
s32 Result
Function result.
Definition: types.h:42
Result MICU_StartSampling(MICU_Encoding encoding, MICU_SampleRate sampleRate, u32 offset, u32 size, bool loop)
Begins sampling microphone input.
u32 micGetSampleDataSize(void)
Gets the size of the sample data area within the shared memory buffer.
32728.498 Hz
Definition: mic.h:19
Result MICU_AdjustSampling(MICU_SampleRate sampleRate)
Adjusts the configuration of the current sampling session.
8182.1245 Hz
Definition: mic.h:22
u32 Handle
Resource handle.
Definition: types.h:41
uint8_t u8
would be nice if newlib had this already
Definition: types.h:21
void micExit(void)
Exits MIC.
Result MICU_SetGain(u8 gain)
Sets the microphone's gain.
uint32_t u32
32-bit unsigned integer
Definition: types.h:23
Signed 16-bit PCM.
Definition: mic.h:13
Unsigned 16-bit PCM.
Definition: mic.h:11
Result MICU_UnmapSharedMem(void)
Unmaps MIC shared memory.
Result MICU_IsSampling(bool *sampling)
Gets whether microphone input is currently being sampled.
Result MICU_SetPower(bool power)
Sets whether the microphone is powered on.
16364.479 Hz
Definition: mic.h:20
Result MICU_GetClamp(bool *clamp)
Gets whether to clamp microphone input.
Signed 8-bit PCM.
Definition: mic.h:12
MICU_Encoding
Microphone audio encodings.
Definition: mic.h:8
Result MICU_GetEventHandle(Handle *handle)
Gets an event handle triggered when the shared memory buffer is full.
Result MICU_StopSampling(void)
Stops sampling microphone input.
Result MICU_SetClamp(bool clamp)
Sets whether to clamp microphone input.
Unsigned 8-bit PCM.
Definition: mic.h:10
10909.499 Hz
Definition: mic.h:21
u32 micGetLastSampleOffset(void)
Gets the offset within the shared memory buffer of the last sample written.
Result MICU_MapSharedMem(u32 size, Handle handle)
Maps MIC shared memory.
Result MICU_SetAllowShellClosed(bool allowShellClosed)
Sets whether to allow sampling when the shell is closed.
Result MICU_GetGain(u8 *gain)
Gets the microphone's gain.