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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
/*
* Copyright 2009-2011 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* Audaspace is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* AudaSpace is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Audaspace; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/** \file audaspace/intern/AUD_SequencerReader.cpp
* \ingroup audaspaceintern
*/
#include "AUD_SequencerReader.h"
#include "AUD_MutexLock.h"
typedef std::list<boost::shared_ptr<AUD_SequencerHandle> >::iterator AUD_HandleIterator;
typedef std::list<boost::shared_ptr<AUD_SequencerEntry> >::iterator AUD_EntryIterator;
AUD_SequencerReader::AUD_SequencerReader(boost::shared_ptr<AUD_Sequencer> sequence, bool quality) :
m_position(0), m_device(sequence->m_specs), m_sequence(sequence), m_status(0), m_entry_status(0)
{
m_device.setQuality(quality);
}
AUD_SequencerReader::~AUD_SequencerReader()
{
}
bool AUD_SequencerReader::isSeekable() const
{
return true;
}
void AUD_SequencerReader::seek(int position)
{
if(position < 0)
return;
m_position = position;
for(AUD_HandleIterator it = m_handles.begin(); it != m_handles.end(); it++)
{
(*it)->seek(position / m_sequence->m_specs.rate);
}
}
int AUD_SequencerReader::getLength() const
{
return -1;
}
int AUD_SequencerReader::getPosition() const
{
return m_position;
}
AUD_Specs AUD_SequencerReader::getSpecs() const
{
return m_sequence->m_specs;
}
void AUD_SequencerReader::read(int& length, bool& eos, sample_t* buffer)
{
AUD_MutexLock lock(*m_sequence);
if(m_sequence->m_status != m_status)
{
m_device.changeSpecs(m_sequence->m_specs);
m_device.setSpeedOfSound(m_sequence->m_speed_of_sound);
m_device.setDistanceModel(m_sequence->m_distance_model);
m_device.setDopplerFactor(m_sequence->m_doppler_factor);
m_status = m_sequence->m_status;
}
if(m_sequence->m_entry_status != m_entry_status)
{
std::list<boost::shared_ptr<AUD_SequencerHandle> > handles;
AUD_HandleIterator hit = m_handles.begin();
AUD_EntryIterator eit = m_sequence->m_entries.begin();
int result;
boost::shared_ptr<AUD_SequencerHandle> handle;
while(hit != m_handles.end() && eit != m_sequence->m_entries.end())
{
handle = *hit;
boost::shared_ptr<AUD_SequencerEntry> entry = *eit;
result = handle->compare(entry);
if(result < 0)
{
try
{
handle = boost::shared_ptr<AUD_SequencerHandle>(new AUD_SequencerHandle(entry, m_device));
handles.push_back(handle);
}
catch(AUD_Exception&)
{
}
eit++;
}
else if(result == 0)
{
handles.push_back(handle);
hit++;
eit++;
}
else
{
handle->stop();
hit++;
}
}
while(hit != m_handles.end())
{
(*hit)->stop();
hit++;
}
while(eit != m_sequence->m_entries.end())
{
try
{
handle = boost::shared_ptr<AUD_SequencerHandle>(new AUD_SequencerHandle(*eit, m_device));
handles.push_back(handle);
}
catch(AUD_Exception&)
{
}
eit++;
}
m_handles = handles;
m_entry_status = m_sequence->m_entry_status;
}
AUD_Specs specs = m_sequence->m_specs;
int pos = 0;
float time = float(m_position) / float(specs.rate);
float volume, frame;
int len, cfra;
AUD_Vector3 v, v2;
AUD_Quaternion q;
while(pos < length)
{
frame = time * m_sequence->m_fps;
cfra = int(floor(frame));
len = int(ceil((cfra + 1) / m_sequence->m_fps * specs.rate)) - m_position;
len = AUD_MIN(length - pos, len);
len = AUD_MAX(len, 1);
for(AUD_HandleIterator it = m_handles.begin(); it != m_handles.end(); it++)
{
(*it)->update(time, frame, m_sequence->m_fps);
}
m_sequence->m_volume.read(frame, &volume);
if(m_sequence->m_muted)
volume = 0.0f;
m_device.setVolume(volume);
m_sequence->m_orientation.read(frame, q.get());
m_device.setListenerOrientation(q);
m_sequence->m_location.read(frame, v.get());
m_device.setListenerLocation(v);
m_sequence->m_location.read(frame + 1, v2.get());
v2 -= v;
m_device.setListenerVelocity(v2 * m_sequence->m_fps);
m_device.read(reinterpret_cast<data_t*>(buffer + specs.channels * pos), len);
pos += len;
time += float(len) / float(specs.rate);
}
m_position += length;
eos = false;
}
|