-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoundloader.cpp
More file actions
57 lines (49 loc) · 1.47 KB
/
soundloader.cpp
File metadata and controls
57 lines (49 loc) · 1.47 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
50
51
52
53
54
55
56
57
#include "soundloader.h"
#include "sound_shared.h"
#include "sounddevice.h"
#include "sound.h"
#include "soundinstance.h"
#include "qtsense.h"
#include "soundfademanager.h"
#include "soundchannelmanager.h"
#include <iostream>
bool InitializeVariantSound(GameLineInfo const& gli, SoundVariant& sv)
{
#ifdef PRINT_LOADED_SOUNDS
std::cout << "Attempting to load: " << sv.m_filename.toStdString() << std::endl;
#endif
QAudioFormat format;
format.setCodec("audio/pcm");
format.setChannelCount( SoundChannelManager::IsStereoChannel(gli.m_channel) ? 2 : 1 );
format.setByteOrder(g_sys_endian);
format.setSampleType(QAudioFormat::SignedInt);
format.setSampleRate(48000);
format.setSampleSize(16);
QAudioDecoder* decoder = new QAudioDecoder(g_soundDevice);
decoder->setSourceFilename(sv.m_filename);
decoder->setAudioFormat(format);
Sound* snd = new Sound(g_soundDevice, decoder);
if(!snd->valid())
{
delete snd;
return false;
}
decoder->start();
sv.m_sound.reset(snd);
return true;
}
SoundInstance* InitializeVariantSoundInst(GameLineInfo const& gli, SoundVariant& sv)
{
#ifdef PRINT_LOADED_SOUNDS
std::cout << "Now playing: " << sv.m_filename.toStdString() << std::endl;
#endif
SoundInstance* ninst = sv.m_sound->newInstance();
ninst->setLooping(gli.m_loop);
ninst->setGain(sv.m_volume);
float balance = sv.m_rngBalance ? sv.m_rngBalance->draw() : sv.m_balance;
ninst->setPosition(balance, 0.f, 0.f);
if(ninst->valid())
return ninst;
delete ninst;
return nullptr;
}