muteki
Loading...
Searching...
No Matches
audio.h File Reference

Audio API. More...

#include <muteki/common.h>
#include <muteki/devio.h>
#include <muteki/threading.h>

Go to the source code of this file.

Data Structures

struct  pcm_config_s
 The PCM codec configuration. More...
 
struct  pcm_codec_context_s
 The PCM codec context. More...
 
struct  device_service_pcm_s
 
struct  pcm_state_s
 
struct  pcm_frame_s
 PCM frame data structure. Used internally. More...
 
struct  pcm_decoder_buffer_s
 Codec buffer descriptor. Used Internally. More...
 

Typedefs

typedef struct device_service_pcm_s device_service_pcm_t
 
typedef struct pcm_config_s pcm_config_t
 
typedef struct pcm_codec_context_s pcm_codec_context_t
 
typedef struct pcm_state_s pcm_state_t
 
typedef struct pcm_frame_s pcm_frame_t
 
typedef struct pcm_decoder_buffer_s pcm_decoder_buffer_t
 
typedef void(* pcm_codec_func_t) (device_service_pcm_t *pcm, pcm_decoder_buffer_t *src, pcm_decoder_buffer_t *dest)
 

Enumerations

enum  pcm_direction_e { DIRECTION_DEFAULT , DIRECTION_OUT , DIRECTION_IN }
 PCM codec direction/mode. More...
 
enum  pcm_format_e { FORMAT_AUTO = -1 , FORMAT_PCM_MONO = 1 , FORMAT_PCM_STEREO = 3 }
 Sample format. More...
 

Functions

pcm_codec_context_tOpenPCMCodec (int direction, int sample_rate, int format)
 Create PCM codec context.
 
void ClosePCMCodec (pcm_codec_context_t *ctx)
 Destroy a PCM codec context.
 

Variables

const int SAMPLE_RATE_AUTO = -1
 Use the default sample rate. Usually this is equivalent to 44100Hz.
 

Detailed Description

Audio API.

Enumeration Type Documentation

◆ pcm_direction_e

PCM codec direction/mode.

Enumerator
DIRECTION_DEFAULT 

Default direction. Usually DIRECTION_OUT.

DIRECTION_OUT 

Output/playback mode.

DIRECTION_IN 

Input/recording mode.

◆ pcm_format_e

Sample format.

Enumerator
FORMAT_AUTO 

Use the default format. Usually FORMAT_PCM_STEREO.

FORMAT_PCM_MONO 

PCM mono.

FORMAT_PCM_STEREO 

PCM stereo.

Function Documentation

◆ ClosePCMCodec()

void ClosePCMCodec ( pcm_codec_context_t ctx)
extern

Destroy a PCM codec context.

Syscall Number
0x10251
Parameters
ctxThe context.

◆ OpenPCMCodec()

pcm_codec_context_t * OpenPCMCodec ( int  direction,
int  sample_rate,
int  format 
)
extern

Create PCM codec context.

Use this to play/record audio in a streaming manner.

This changes the configuration of the \\?\PCM service. More details TBA.

The context object can be used directly, but it's recommended to open another descriptor using the CreateFile() syscall, and use ReadFile() / WriteFile() / DeviceIoControl() to access the device.

For example, below is a simple loop that uses both the PCM and the device IO syscalls together to play samples:

char sample[0x2000]; // Write audio data to this buffer periodically
size_t num_bytes, actual_bytes;
if (pcmdesc == NULL) {
// TODO fail
}
devio_descriptor_t *pcmdev = CreateFile("\\\\?\\PCM", 0, 0, NULL, 3, 0, NULL);
if (pcmdev == NULL || pcmdev == DEVIO_DESC_INVALID) {
ClosePCMCodec(pcmdesc);
// TODO fail
}
while (true) {
// TODO populate the samples and set num_bytes to how many bytes to play
WriteFile(pcmdev, sample, num_bytes, &actual_bytes, NULL);
if (num_bytes != actual_bytes) {
// TODO optionally report error
}
}
CloseHandle(pcmdev);
ClosePCMCodec(pcmdesc);
@ DIRECTION_OUT
Output/playback mode.
Definition audio.h:33
void ClosePCMCodec(pcm_codec_context_t *ctx)
Destroy a PCM codec context.
@ FORMAT_AUTO
Use the default format. Usually FORMAT_PCM_STEREO.
Definition audio.h:47
pcm_codec_context_t * OpenPCMCodec(int direction, int sample_rate, int format)
Create PCM codec context.
const int SAMPLE_RATE_AUTO
Use the default sample rate. Usually this is equivalent to 44100Hz.
Definition audio.h:61
devio_descriptor_t * CreateFile(const char *pathname, unsigned int access, unsigned int shmode, void *secattr, unsigned int on_noentry, unsigned int flags, void *template_file)
Open or create a file/device by its pathname.
bool WriteFile(devio_descriptor_t *devfd, const void *buf, size_t size, size_t *actual_size, void *overlapped)
Write/send data to a device IO descriptor.
bool CloseHandle(devio_descriptor_t *devfd)
Close a device IO descriptor.
#define DEVIO_DESC_INVALID
Invalid descriptor.
Definition devio.h:93
The device IO descriptor.
Definition devio.h:35
The PCM codec context.
Definition audio.h:129
Syscall Number
0x10250
Parameters
directionDirection. Can either be input (record) or output (playback).
sample_rateSample rate.
formatSample format.
Returns
The context.
See also
pcm_direction_e Predefined values for codec direction.
pcm_format_e Supported sample formats.