-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy patha_lane.cpp
More file actions
90 lines (76 loc) · 2.41 KB
/
a_lane.cpp
File metadata and controls
90 lines (76 loc) · 2.41 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "a_filter.h"
#include "a_lane.h"
#include "u_assert.h"
namespace a {
///! LaneInstance
LaneInstance::LaneInstance(Lane *parent)
: m_parent(parent)
{
m_flags |= kProtected;
}
void LaneInstance::getAudio(float *buffer, size_t samples) {
int handle = m_parent->m_channelHandle;
if (handle == 0) {
// avoid reuse of scratch buffer if this lane hasn't played anything yet
for (size_t i = 0; i < samples * m_channels; i++)
m_scratch[i] = 0;
return;
}
Audio *owner = m_parent->m_owner;
if (owner->m_scratchNeeded != m_scratch.size())
m_scratch.resize(owner->m_scratchNeeded);
owner->mixLane(buffer, samples, &m_scratch[0], handle);
}
bool LaneInstance::hasEnded() const {
return false;
}
LaneInstance::~LaneInstance() {
Audio *owner = m_parent->m_owner;
for (size_t i = 0; i < owner->m_voices.size(); i++) {
if (owner->m_voices[i] && owner->m_voices[i]->m_laneHandle == m_parent->m_channelHandle)
owner->stopVoice(i);
}
}
///! Lane
Lane::Lane()
: m_channelHandle(0)
, m_instance(nullptr)
{
m_channels = 2;
}
LaneInstance *Lane::create() {
if (m_channelHandle) {
int voice = m_owner->getVoiceFromHandle(m_channelHandle);
U_ASSERT(voice != -1);
m_owner->stopVoice(voice);
m_channelHandle = 0;
m_instance = nullptr;
}
return m_instance = new LaneInstance(this);
}
int Lane::play(Source &sound, float volume, float pan, bool paused) {
if (!m_instance || !m_owner)
return 0;
if (m_channelHandle == 0) {
// find channel the lane is playing on
for (size_t i = 0; m_channelHandle == 0 && i < m_owner->m_voices.size(); i++)
if (m_owner->m_voices[i] == m_instance)
m_channelHandle = m_owner->getHandleFromVoice(i);
// could not find channel
if (m_channelHandle == 0)
return 0;
}
return m_owner->play(sound, volume, pan, paused, m_channelHandle);
}
void Lane::setFilter(int filterHandle, Filter *filter) {
if (filterHandle < 0 || filterHandle >= kMaxStreamFilters)
return;
m_filters[filterHandle] = filter;
if (m_instance) locked(m_owner->m_mutex) {
delete m_instance->m_filters[filterHandle];
m_instance->m_filters[filterHandle] = nullptr;
if (filter)
m_instance->m_filters[filterHandle] = m_filters[filterHandle]->create();
}
}
}