mic.h
Go to the documentation of this file.
/**
* @file mic.h
* @brief MIC (Microphone) service.
*/
#pragma once
/// Microphone audio encodings.
typedef enum
{
MICU_ENCODING_PCM8 = 0, ///< Unsigned 8-bit PCM.
MICU_ENCODING_PCM16 = 1, ///< Unsigned 16-bit PCM.
MICU_ENCODING_PCM8_SIGNED = 2, ///< Signed 8-bit PCM.
MICU_ENCODING_PCM16_SIGNED = 3, ///< Signed 16-bit PCM.
} MICU_Encoding;
/// Microphone audio sampling rates.
typedef enum
{
MICU_SAMPLE_RATE_32730 = 0, ///< 32728.498 Hz
MICU_SAMPLE_RATE_16360 = 1, ///< 16364.479 Hz
MICU_SAMPLE_RATE_10910 = 2, ///< 10909.499 Hz
MICU_SAMPLE_RATE_8180 = 3, ///< 8182.1245 Hz
} MICU_SampleRate;
/**
* @brief Initializes MIC.
* @param size Shared memory buffer to write audio data to. Must be aligned to 0x1000 bytes.
* @param handle Size of the shared memory buffer.
*/
Result micInit(u8* buffer, u32 bufferSize);
/// Exits MIC.
void micExit(void);
/**
* @brief Gets the size of the sample data area within the shared memory buffer.
* @return The sample data's size.
*/
u32 micGetSampleDataSize(void);
/**
* @brief Gets the offset within the shared memory buffer of the last sample written.
* @return The last sample's offset.
*/
u32 micGetLastSampleOffset(void);
/**
* @brief Maps MIC shared memory.
* @param size Size of the shared memory.
* @param handle Handle of the shared memory.
*/
Result MICU_MapSharedMem(u32 size, Handle handle);
/// Unmaps MIC shared memory.
Result MICU_UnmapSharedMem(void);
/**
* @brief Begins sampling microphone input.
* @param encoding Encoding of outputted audio.
* @param sampleRate Sample rate of outputted audio.
* @param sharedMemAudioOffset Offset to write audio data to in the shared memory buffer.
* @param sharedMemAudioSize Size of audio data to write to the shared memory buffer. This should be at most "bufferSize - 4".
* @param loop Whether to loop back to the beginning of the buffer when the end is reached.
*/
Result MICU_StartSampling(MICU_Encoding encoding, MICU_SampleRate sampleRate, u32 offset, u32 size, bool loop);
/**
* @brief Adjusts the configuration of the current sampling session.
* @param sampleRate Sample rate of outputted audio.
*/
Result MICU_AdjustSampling(MICU_SampleRate sampleRate);
/// Stops sampling microphone input.
Result MICU_StopSampling(void);
/**
* @brief Gets whether microphone input is currently being sampled.
* @param sampling Pointer to output the sampling state to.
*/
Result MICU_IsSampling(bool* sampling);
/**
* @brief Gets an event handle triggered when the shared memory buffer is full.
* @param handle Pointer to output the event handle to.
*/
Result MICU_GetEventHandle(Handle* handle);
/**
* @brief Sets the microphone's gain.
* @param gain Gain to set.
*/
Result MICU_SetGain(u8 gain);
/**
* @brief Gets the microphone's gain.
* @param gain Pointer to output the current gain to.
*/
Result MICU_GetGain(u8* gain);
/**
* @brief Sets whether the microphone is powered on.
* @param power Whether the microphone is powered on.
*/
Result MICU_SetPower(bool power);
/**
* @brief Gets whether the microphone is powered on.
* @param power Pointer to output the power state to.
*/
Result MICU_GetPower(bool* power);
/**
* @brief Sets whether to clamp microphone input.
* @param clamp Whether to clamp microphone input.
*/
Result MICU_SetClamp(bool clamp);
/**
* @brief Gets whether to clamp microphone input.
* @param clamp Pointer to output the clamp state to.
*/
Result MICU_GetClamp(bool* clamp);
/**
* @brief Sets whether to allow sampling when the shell is closed.
* @param allowShellClosed Whether to allow sampling when the shell is closed.
*/
Result MICU_SetAllowShellClosed(bool allowShellClosed);
micInit
Result micInit(u8 *buffer, u32 bufferSize)
Initializes MIC.
micGetSampleDataSize
u32 micGetSampleDataSize(void)
Gets the size of the sample data area within the shared memory buffer.
MICU_SetClamp
Result MICU_SetClamp(bool clamp)
Sets whether to clamp microphone input.
MICU_SetGain
Result MICU_SetGain(u8 gain)
Sets the microphone's gain.
MICU_GetPower
Result MICU_GetPower(bool *power)
Gets whether the microphone is powered on.
MICU_SetPower
Result MICU_SetPower(bool power)
Sets whether the microphone is powered on.
MICU_MapSharedMem
Result MICU_MapSharedMem(u32 size, Handle handle)
Maps MIC shared memory.
MICU_Encoding
MICU_Encoding
Microphone audio encodings.
Definition: mic.h:9
MICU_ENCODING_PCM16
@ MICU_ENCODING_PCM16
Unsigned 16-bit PCM.
Definition: mic.h:11
MICU_ENCODING_PCM8
@ MICU_ENCODING_PCM8
Unsigned 8-bit PCM.
Definition: mic.h:10
MICU_ENCODING_PCM8_SIGNED
@ MICU_ENCODING_PCM8_SIGNED
Signed 8-bit PCM.
Definition: mic.h:12
MICU_ENCODING_PCM16_SIGNED
@ MICU_ENCODING_PCM16_SIGNED
Signed 16-bit PCM.
Definition: mic.h:13
MICU_IsSampling
Result MICU_IsSampling(bool *sampling)
Gets whether microphone input is currently being sampled.
micExit
void micExit(void)
Exits MIC.
MICU_StartSampling
Result MICU_StartSampling(MICU_Encoding encoding, MICU_SampleRate sampleRate, u32 offset, u32 size, bool loop)
Begins sampling microphone input.
MICU_StopSampling
Result MICU_StopSampling(void)
Stops sampling microphone input.
MICU_GetEventHandle
Result MICU_GetEventHandle(Handle *handle)
Gets an event handle triggered when the shared memory buffer is full.
MICU_SetAllowShellClosed
Result MICU_SetAllowShellClosed(bool allowShellClosed)
Sets whether to allow sampling when the shell is closed.
micGetLastSampleOffset
u32 micGetLastSampleOffset(void)
Gets the offset within the shared memory buffer of the last sample written.
MICU_UnmapSharedMem
Result MICU_UnmapSharedMem(void)
Unmaps MIC shared memory.
MICU_GetGain
Result MICU_GetGain(u8 *gain)
Gets the microphone's gain.
MICU_SampleRate
MICU_SampleRate
Microphone audio sampling rates.
Definition: mic.h:18
MICU_SAMPLE_RATE_16360
@ MICU_SAMPLE_RATE_16360
16364.479 Hz
Definition: mic.h:20
MICU_SAMPLE_RATE_8180
@ MICU_SAMPLE_RATE_8180
8182.1245 Hz
Definition: mic.h:22
MICU_SAMPLE_RATE_32730
@ MICU_SAMPLE_RATE_32730
32728.498 Hz
Definition: mic.h:19
MICU_SAMPLE_RATE_10910
@ MICU_SAMPLE_RATE_10910
10909.499 Hz
Definition: mic.h:21
MICU_GetClamp
Result MICU_GetClamp(bool *clamp)
Gets whether to clamp microphone input.
MICU_AdjustSampling
Result MICU_AdjustSampling(MICU_SampleRate sampleRate)
Adjusts the configuration of the current sampling session.
u8
uint8_t u8
would be nice if newlib had this already
Definition: types.h:21
Handle
u32 Handle
Resource handle.
Definition: types.h:41
Result
s32 Result
Function result.
Definition: types.h:42
u32
uint32_t u32
32-bit unsigned integer
Definition: types.h:23