Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Audio/MiniAudio/MiniAudioDevice.cpp
1163 views
1
#define MINIAUDIO_IMPLEMENTATION
2
#include <miniaudio/miniaudio.h>
3
4
uint8 AudioDevice::contextInitialized;
5
ma_device AudioDevice::device;
6
7
bool32 AudioDevice::Init()
8
{
9
if (!contextInitialized) {
10
contextInitialized = true;
11
InitAudioChannels();
12
}
13
14
ma_device_config config = ma_device_config_init(ma_device_type_playback);
15
config.playback.format = ma_format_f32; // Set to ma_format_unknown to use the device's native format.
16
config.playback.channels = 2; // Set to 0 to use the device's native channel count.
17
config.periodSizeInFrames = MIX_BUFFER_SIZE;
18
config.sampleRate = AUDIO_FREQUENCY; // Set to 0 to use the device's native sample rate.
19
config.dataCallback = AudioCallback; // This function will be called when miniaudio needs more data.
20
21
ma_result result = ma_device_init(NULL, &config, &device);
22
if (result != MA_SUCCESS) {
23
PrintLog(PRINT_NORMAL, "[MA] Initializing device failed: %d", result);
24
return false;
25
}
26
27
result = ma_device_start(&device);
28
if (result != MA_SUCCESS) {
29
PrintLog(PRINT_NORMAL, "[MA] Starting device failed: %d", result);
30
return false;
31
}
32
33
return true;
34
}
35
36
void AudioDevice::Release()
37
{
38
ma_device_uninit(&device);
39
}
40
41
void AudioDevice::InitAudioChannels() { AudioDeviceBase::InitAudioChannels(); }
42
43
void RSDK::AudioDevice::AudioCallback(ma_device* device, void *output, const void *input, ma_uint32 frameCount)
44
{
45
(void)input;
46
(void)device;
47
48
AudioDevice::ProcessAudioMixing(output, frameCount * AUDIO_CHANNELS);
49
}
50
51