blob: f6531f5c60b104c69f77b55c218cf3409a2e0f12 (
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#include "aoblipplayer.h"
AOBlipPlayer::AOBlipPlayer(AOApplication *ao_app)
: ao_app(ao_app)
{}
AOBlipPlayer::~AOBlipPlayer()
{
ma_sound_uninit(&m_stream[0]);
}
void AOBlipPlayer::setVolume(int value)
{
m_volume = value / 100.0f;
updateInternalVolume();
}
void AOBlipPlayer::setMuted(bool enabled)
{
m_muted = enabled;
updateInternalVolume();
}
void AOBlipPlayer::setBlip(QString blip)
{
if (m_initialized)
{
ma_sound_uninit(&m_stream[0]);
m_initialized = false;
}
// ma_sound_init_copy?
QString path = ao_app->get_sfx_suffix(ao_app->get_sounds_path(blip));
ma_result r = ma_sound_init_from_file(&ao_app->audio_engine, qPrintable(path), MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_DECODE | MA_SOUND_FLAG_NO_SPATIALIZATION | MA_SOUND_FLAG_NO_PITCH, nullptr, nullptr, &m_stream[0]);
if (r == MA_SUCCESS)
{
m_initialized = true;
updateInternalVolume();
}
else
{
qWarning() << "Failed to init blip" << path << "error" << r;
}
}
void AOBlipPlayer::playBlip()
{
if (m_initialized)
{
ma_sound_start(&m_stream[0]);
}
}
void AOBlipPlayer::updateInternalVolume()
{
if (m_initialized)
{
ma_sound_set_volume(&m_stream[0], m_muted ? 0.0f : qBound(0.0f, m_volume, 1.0f));
}
}
|