-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheight.cpp
More file actions
49 lines (37 loc) · 1.18 KB
/
Copy patheight.cpp
File metadata and controls
49 lines (37 loc) · 1.18 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "eight.hpp"
#include <cassert>
#include <vector>
#include "miniaudio/miniaudio.h"
namespace miniaudio
{
std::vector<float> decoder::read_pcm_frames(int frames_count)
{
ma_uint32 channels = m_decoder.outputChannels;
std::vector<float> pcm(frames_count * channels);
ma_uint64 frames_read;
auto r = ma_decoder_read_pcm_frames(&m_decoder, pcm.data(), frames_count, &frames_read);
assert(r == MA_SUCCESS);
if (frames_read <= 0)
{
std::exit(1);
}
return pcm;
}
void device::internal_data_callback(ma_device *dev, void *out, const void *in, ma_uint32 frame_count)
{
auto *mdev = reinterpret_cast<device *>(dev->pUserData);
mdev->m_data_callback(dev, out, in, frame_count);
}
device::device(data_callback_type data_callback)
{
m_data_callback = data_callback;
m_config = ma_device_config_init(ma_device_type_playback);
m_config.playback.format = ma_format_f32;
m_config.playback.channels = 2;
m_config.sampleRate = 48000;
m_config.dataCallback = internal_data_callback;
m_config.pUserData = this;
auto r = ma_device_init(nullptr, &m_config, &m_device);
assert(r == MA_SUCCESS);
}
} // namespace miniaudio