summaryrefslogtreecommitdiff
path: root/src/audio/audio.cc
blob: 0eceed5f6055a32530ee249cfef7263b0520c647 (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
29
30
#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);
}