libnx  v4.2.2
audout.h
Go to the documentation of this file.
1 /**
2  * @file audout.h
3  * @brief Audio output service.
4  * @author hexkyz
5  * @copyright libnx Authors
6  */
7 #pragma once
8 
9 #include "../types.h"
10 #include "../audio/audio.h"
11 #include "../sf/service.h"
12 
13 typedef enum {
14  AudioOutState_Started = 0,
15  AudioOutState_Stopped = 1,
16 } AudioOutState;
17 
18 /// Audio output buffer format
19 typedef struct AudioOutBuffer AudioOutBuffer;
20 
22 {
23  AudioOutBuffer* next; ///< Next buffer. (Unused)
24  void* buffer; ///< Sample buffer (aligned to 0x1000 bytes).
25  u64 buffer_size; ///< Sample buffer size (aligned to 0x1000 bytes).
26  u64 data_size; ///< Size of data inside the buffer.
27  u64 data_offset; ///< Offset of data inside the buffer. (Unused?)
28 };
29 
30 /// Initialize audout.
32 
33 /// Exit audout.
34 void audoutExit(void);
35 
36 /// Gets the Service object for the actual audout service session.
38 
39 /// Gets the Service object for IAudioOut.
41 
42 Result audoutListAudioOuts(char *DeviceNames, s32 count, u32 *DeviceNamesCount);
43 Result audoutOpenAudioOut(const char *DeviceNameIn, char *DeviceNameOut, u32 SampleRateIn, u32 ChannelCountIn, u32 *SampleRateOut, u32 *ChannelCountOut, PcmFormat *Format, AudioOutState *State);
44 Result audoutGetAudioOutState(AudioOutState *State);
45 Result audoutStartAudioOut(void);
46 Result audoutStopAudioOut(void);
47 
48 /// Submits an \ref AudioOutBuffer for playing.
50 
51 Result audoutGetReleasedAudioOutBuffer(AudioOutBuffer **Buffer, u32 *ReleasedBuffersCount);
52 Result audoutContainsAudioOutBuffer(AudioOutBuffer *Buffer, bool *ContainsBuffer);
53 
54 /// Only available with [4.0.0+].
56 /// Only available with [4.0.0+].
58 /// Only available with [4.0.0+].
59 Result audoutFlushAudioOutBuffers(bool *flushed);
60 /// Only available with [6.0.0+].
61 Result audoutSetAudioOutVolume(float volume);
62 /// Only available with [6.0.0+].
63 Result audoutGetAudioOutVolume(float *volume);
64 
65 /**
66  * @brief Submits an audio sample data buffer for playing and waits for it to finish playing.
67  * @brief Uses \ref audoutAppendAudioOutBuffer and \ref audoutWaitPlayFinish internally.
68  * @param source AudioOutBuffer containing the source sample data to be played.
69  * @param released AudioOutBuffer to receive the played buffer after being released.
70  */
72 
73 /**
74  * @brief Waits for audio playback to finish.
75  * @param released AudioOutBuffer to receive the first played buffer after being released.
76  * @param released_count Pointer to receive the number of played buffers.
77  * @param timeout Timeout value, use UINT64_MAX to wait until all finished.
78  */
79 Result audoutWaitPlayFinish(AudioOutBuffer **released, u32* released_count, u64 timeout);
80 
81 /// These return the state associated with the currently active audio output device.
82 u32 audoutGetSampleRate(void); ///< Supported sample rate (48000Hz).
83 u32 audoutGetChannelCount(void); ///< Supported channel count (2 channels).
84 PcmFormat audoutGetPcmFormat(void); ///< Supported PCM format (Int16).
85 AudioOutState audoutGetDeviceState(void); ///< Initial device state (stopped).
audoutGetAudioOutBufferCount
Result audoutGetAudioOutBufferCount(u32 *count)
Only available with [4.0.0+].
AudioOutBuffer::next
AudioOutBuffer * next
Next buffer. (Unused)
Definition: audout.h:23
audoutGetChannelCount
u32 audoutGetChannelCount(void)
Supported channel count (2 channels).
audoutInitialize
Result audoutInitialize(void)
Initialize audout.
audoutWaitPlayFinish
Result audoutWaitPlayFinish(AudioOutBuffer **released, u32 *released_count, u64 timeout)
Waits for audio playback to finish.
audoutGetAudioOutPlayedSampleCount
Result audoutGetAudioOutPlayedSampleCount(u64 *count)
Only available with [4.0.0+].
audoutSetAudioOutVolume
Result audoutSetAudioOutVolume(float volume)
Only available with [6.0.0+].
s32
int32_t s32
32-bit signed integer.
Definition: types.h:27
AudioOutBuffer::buffer_size
u64 buffer_size
Sample buffer size (aligned to 0x1000 bytes).
Definition: audout.h:25
u32
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21
AudioOutBuffer::data_offset
u64 data_offset
Offset of data inside the buffer. (Unused?)
Definition: audout.h:27
audoutGetPcmFormat
PcmFormat audoutGetPcmFormat(void)
Supported PCM format (Int16).
u64
uint64_t u64
64-bit unsigned integer.
Definition: types.h:22
audoutGetServiceSession_AudioOut
Service * audoutGetServiceSession_AudioOut(void)
Gets the Service object for IAudioOut.
audoutGetAudioOutVolume
Result audoutGetAudioOutVolume(float *volume)
Only available with [6.0.0+].
PcmFormat
PcmFormat
PcmFormat.
Definition: audio.h:12
Result
u32 Result
Function error code result type.
Definition: types.h:44
AudioOutBuffer::data_size
u64 data_size
Size of data inside the buffer.
Definition: audout.h:26
audoutPlayBuffer
Result audoutPlayBuffer(AudioOutBuffer *source, AudioOutBuffer **released)
Submits an audio sample data buffer for playing and waits for it to finish playing.
audoutAppendAudioOutBuffer
Result audoutAppendAudioOutBuffer(AudioOutBuffer *Buffer)
Submits an AudioOutBuffer for playing.
audoutFlushAudioOutBuffers
Result audoutFlushAudioOutBuffers(bool *flushed)
Only available with [4.0.0+].
AudioOutBuffer::buffer
void * buffer
Sample buffer (aligned to 0x1000 bytes).
Definition: audout.h:24
Service
Service object structure.
Definition: service.h:13
audoutGetDeviceState
AudioOutState audoutGetDeviceState(void)
Initial device state (stopped).
audoutGetServiceSession
Service * audoutGetServiceSession(void)
Gets the Service object for the actual audout service session.
audoutExit
void audoutExit(void)
Exit audout.
AudioOutBuffer
Audio output buffer format.
Definition: audout.h:21
audoutGetSampleRate
u32 audoutGetSampleRate(void)
These return the state associated with the currently active audio output device.