summaryrefslogtreecommitdiff
path: root/src/audio/audio.cpp
blob: 318ccb8944e6f30ff779fe2a1b35ee82647e0035 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"
#include "synth.h"
#include <math.h>

static ma_device device;

static void audio_callback(ma_device*, void* output, const void*, ma_uint32 frames) {
    synth_render((float*)output, frames);
}

void audio_init() {
    synth_init();
    ma_device_config cfg = ma_device_config_init(ma_device_type_playback);
    cfg.playback.format = ma_format_f32;
    cfg.playback.channels = 2;
    cfg.sampleRate = 32000;
    cfg.dataCallback = audio_callback;

    ma_device_init(nullptr, &cfg, &device);
    ma_device_start(&device);
}

void audio_update() {}
void audio_shutdown() {
    synth_shutdown();
    ma_device_uninit(&device);
}