libctru v2.5.0
Loading...
Searching...
No Matches
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.
8typedef 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.
17typedef 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 */
30Result micInit(u8* buffer, u32 bufferSize);
31
32/// Exits MIC.
33void 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 */
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 */
65Result 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 */
80Result 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 */
93
94/**
95 * @brief Gets the microphone's gain.
96 * @param gain Pointer to output the current gain to.
97 */
99
100/**
101 * @brief Sets whether the microphone is powered on.
102 * @param power Whether the microphone is powered on.
103 */
105
106/**
107 * @brief Gets whether the microphone is powered on.
108 * @param power Pointer to output the power state to.
109 */
111
112/**
113 * @brief Sets whether to clamp microphone input.
114 * @param clamp Whether to clamp microphone input.
115 */
117
118/**
119 * @brief Gets whether to clamp microphone input.
120 * @param clamp Pointer to output the clamp state to.
121 */
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 */
128Result MICU_SetAllowShellClosed(bool allowShellClosed);
Result micInit(u8 *buffer, u32 bufferSize)
Initializes MIC.
u32 micGetSampleDataSize(void)
Gets the size of the sample data area within the shared memory buffer.
Result MICU_SetClamp(bool clamp)
Sets whether to clamp microphone input.
Result MICU_SetGain(u8 gain)
Sets the microphone's gain.
Result MICU_GetPower(bool *power)
Gets whether the microphone is powered on.
Result MICU_SetPower(bool power)
Sets whether the microphone is powered on.
Result MICU_MapSharedMem(u32 size, Handle handle)
Maps MIC shared memory.
MICU_Encoding
Microphone audio encodings.
Definition mic.h:9
@ MICU_ENCODING_PCM16
Unsigned 16-bit PCM.
Definition mic.h:11
@ MICU_ENCODING_PCM8
Unsigned 8-bit PCM.
Definition mic.h:10
@ MICU_ENCODING_PCM8_SIGNED
Signed 8-bit PCM.
Definition mic.h:12
@ MICU_ENCODING_PCM16_SIGNED
Signed 16-bit PCM.
Definition mic.h:13
Result MICU_IsSampling(bool *sampling)
Gets whether microphone input is currently being sampled.
void micExit(void)
Exits MIC.
Result MICU_StartSampling(MICU_Encoding encoding, MICU_SampleRate sampleRate, u32 offset, u32 size, bool loop)
Begins sampling microphone input.
Result MICU_StopSampling(void)
Stops sampling microphone input.
Result MICU_GetEventHandle(Handle *handle)
Gets an event handle triggered when the shared memory buffer is full.
Result MICU_SetAllowShellClosed(bool allowShellClosed)
Sets whether to allow sampling when the shell is closed.
u32 micGetLastSampleOffset(void)
Gets the offset within the shared memory buffer of the last sample written.
Result MICU_UnmapSharedMem(void)
Unmaps MIC shared memory.
Result MICU_GetGain(u8 *gain)
Gets the microphone's gain.
MICU_SampleRate
Microphone audio sampling rates.
Definition mic.h:18
@ MICU_SAMPLE_RATE_16360
16364.479 Hz
Definition mic.h:20
@ MICU_SAMPLE_RATE_8180
8182.1245 Hz
Definition mic.h:22
@ MICU_SAMPLE_RATE_32730
32728.498 Hz
Definition mic.h:19
@ MICU_SAMPLE_RATE_10910
10909.499 Hz
Definition mic.h:21
Result MICU_GetClamp(bool *clamp)
Gets whether to clamp microphone input.
Result MICU_AdjustSampling(MICU_SampleRate sampleRate)
Adjusts the configuration of the current sampling session.
uint8_t u8
would be nice if newlib had this already
Definition types.h:21
u32 Handle
Resource handle.
Definition types.h:41
s32 Result
Function result.
Definition types.h:42
uint32_t u32
32-bit unsigned integer
Definition types.h:23