Skip to content

Commit

Permalink
Initial audio support (switchbrew#43)
Browse files Browse the repository at this point in the history
Initial audio support
  • Loading branch information
hexkyz authored and yellows8 committed Feb 17, 2018
1 parent c22655e commit 0e40828
Show file tree
Hide file tree
Showing 3 changed files with 507 additions and 0 deletions.
1 change: 1 addition & 0 deletions nx/include/switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern "C" {
#include "switch/services/acc.h"
#include "switch/services/apm.h"
#include "switch/services/applet.h"
#include "switch/services/audout.h"
#include "switch/services/bsd.h"
#include "switch/services/fatal.h"
#include "switch/services/usb.h"
Expand Down
61 changes: 61 additions & 0 deletions nx/include/switch/services/audout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @file audout.h
* @brief Audio output service.
* @author hexkyz
* @copyright libnx Authors
*/
#pragma once

#include "../types.h"

typedef enum {
PcmFormat_Invalid = 0,
PcmFormat_INT8 = 1,
PcmFormat_INT16 = 2,
PcmFormat_INT24 = 3,
PcmFormat_INT32 = 4,
PcmFormat_FLOAT = 5,
PcmFormat_ADPCM = 6,
} PcmFormat;

typedef enum {
AudioOutState_Started = 0,
AudioOutState_Stopped = 1,
} AudioOutState;

/// Audio output buffer format
typedef struct AudioOutBuffer AudioOutBuffer;

struct AudioOutBuffer
{
AudioOutBuffer* next; ///< Next buffer.
void* buffer; ///< Sample buffer.
u64 buffer_size; ///< Sample buffer size.
u64 data_size; ///< Size of data inside the buffer.
u64 data_offset; ///< Offset of data inside the buffer.
};

Result audoutInitialize(void);
void audoutExit(void);

Result audoutListAudioOuts(char *DeviceNames, u32 *DeviceNamesCount);
Result audoutOpenAudioOut(const char *DeviceNameIn, char *DeviceNameOut, u32 SampleRateIn, u32 ChannelCountIn, u32 *SampleRateOut, u32 *ChannelCountOut, PcmFormat *Format, AudioOutState *State);
Result audoutGetAudioOutState(AudioOutState *State);
Result audoutStartAudioOut(void);
Result audoutStopAudioOut(void);
Result audoutAppendAudioOutBuffer(AudioOutBuffer *Buffer);
Result audoutGetReleasedAudioOutBuffer(AudioOutBuffer *Buffer, u32 *ReleasedBuffersCount);
Result audoutContainsAudioOutBuffer(AudioOutBuffer *Buffer, bool *ContainsBuffer);

/**
* @brief Submits an audio sample data buffer for playing.
* @param source AudioOutBuffer containing the source sample data to be played.
* @param released AudioOutBuffer to receive the last played buffer.
*/
void audoutPlayBuffer(AudioOutBuffer *source, AudioOutBuffer *released);

/// These return the state associated with the currently active audio output device.
u32 audoutGetSampleRate(void); ///< Supported sample rate (48000Hz).
u32 audoutGetChannelCount(void); ///< Supported channel count (2 channels).
PcmFormat audoutGetPcmFormat(void); ///< Supported PCM format (INT16).
AudioOutState audoutGetDeviceState(void); ///< Initial device state (stopped).
Loading

0 comments on commit 0e40828

Please sign in to comment.