56
57
/********************** AUD_SoftwareHandle Handle Code ************************/
57
58
/******************************************************************************/
59
AUD_SoftwareDevice::AUD_SoftwareHandle::AUD_SoftwareHandle(AUD_SoftwareDevice* device, AUD_Reference<AUD_IReader> reader, AUD_Reference<AUD_PitchReader> pitch, AUD_Reference<AUD_ResampleReader> resampler, AUD_Reference<AUD_ChannelMapperReader> mapper, bool keep) :
60
AUD_SoftwareDevice::AUD_SoftwareHandle::AUD_SoftwareHandle(AUD_SoftwareDevice* device, boost::shared_ptr<AUD_IReader> reader, boost::shared_ptr<AUD_PitchReader> pitch, boost::shared_ptr<AUD_ResampleReader> resampler, boost::shared_ptr<AUD_ChannelMapperReader> mapper, bool keep) :
60
61
m_reader(reader), m_pitch(pitch), m_resampler(resampler), m_mapper(mapper), m_keep(keep), m_user_pitch(1.0f), m_user_volume(1.0f), m_user_pan(0.0f), m_volume(1.0f), m_loopcount(0),
61
62
m_relative(true), m_volume_max(1.0f), m_volume_min(0), m_distance_max(std::numeric_limits<float>::max()),
62
63
m_distance_reference(1.0f), m_attenuation(1.0f), m_cone_angle_outer(M_PI), m_cone_angle_inner(M_PI), m_cone_volume_outer(0),
230
AUD_MutexLock lock(*m_device);
231
232
if(m_status == AUD_STATUS_PLAYING)
233
m_device->m_playingSounds.remove(this);
234
m_device->m_pausedSounds.push_back(this);
236
if(m_device->m_playingSounds.empty())
237
m_device->playing(m_device->m_playback = false);
238
m_status = AUD_STATUS_PAUSED;
234
for(AUD_HandleIterator it = m_device->m_playingSounds.begin(); it != m_device->m_playingSounds.end(); it++)
236
if(it->get() == this)
238
boost::shared_ptr<AUD_SoftwareHandle> This = *it;
240
m_device->m_playingSounds.erase(it);
241
m_device->m_pausedSounds.push_back(This);
243
if(m_device->m_playingSounds.empty())
244
m_device->playing(m_device->m_playback = false);
246
m_status = AUD_STATUS_PAUSED;
261
AUD_MutexLock lock(*m_device);
256
263
if(m_status == AUD_STATUS_PAUSED)
258
m_device->m_pausedSounds.remove(this);
259
m_device->m_playingSounds.push_back(this);
261
if(!m_device->m_playback)
262
m_device->playing(m_device->m_playback = true);
263
m_status = AUD_STATUS_PLAYING;
265
for(AUD_HandleIterator it = m_device->m_pausedSounds.begin(); it != m_device->m_pausedSounds.end(); it++)
267
if(it->get() == this)
269
boost::shared_ptr<AUD_SoftwareHandle> This = *it;
271
m_device->m_pausedSounds.erase(it);
273
m_device->m_playingSounds.push_back(This);
275
if(!m_device->m_playback)
276
m_device->playing(m_device->m_playback = true);
277
m_status = AUD_STATUS_PLAYING;
281
// AUD_XXX Create a reference of our own object so that it doesn't get
282
// deleted before the end of this function
283
AUD_Reference<AUD_SoftwareHandle> This = this;
285
if(m_status == AUD_STATUS_PLAYING)
287
m_device->m_playingSounds.remove(This);
289
if(m_device->m_playingSounds.empty())
290
m_device->playing(m_device->m_playback = false);
293
m_device->m_pausedSounds.remove(This);
294
AUD_MutexLock lock(*m_device);
296
299
m_status = AUD_STATUS_INVALID;
301
for(AUD_HandleIterator it = m_device->m_playingSounds.begin(); it != m_device->m_playingSounds.end(); it++)
303
if(it->get() == this)
305
boost::shared_ptr<AUD_SoftwareHandle> This = *it;
307
m_device->m_playingSounds.erase(it);
309
if(m_device->m_playingSounds.empty())
310
m_device->playing(m_device->m_playback = false);
316
for(AUD_HandleIterator it = m_device->m_pausedSounds.begin(); it != m_device->m_pausedSounds.end(); it++)
318
if(it->get() == this)
320
m_device->m_pausedSounds.erase(it);
300
328
bool AUD_SoftwareDevice::AUD_SoftwareHandle::getKeep()
692
724
m_buffer.assureSize(length * AUD_SAMPLE_SIZE(m_specs));
726
AUD_MutexLock lock(*this);
697
AUD_Reference<AUD_SoftwareDevice::AUD_SoftwareHandle> sound;
729
boost::shared_ptr<AUD_SoftwareDevice::AUD_SoftwareHandle> sound;
701
std::list<AUD_Reference<AUD_SoftwareDevice::AUD_SoftwareHandle> > stopSounds;
702
std::list<AUD_Reference<AUD_SoftwareDevice::AUD_SoftwareHandle> > pauseSounds;
733
std::list<boost::shared_ptr<AUD_SoftwareDevice::AUD_SoftwareHandle> > stopSounds;
734
std::list<boost::shared_ptr<AUD_SoftwareDevice::AUD_SoftwareHandle> > pauseSounds;
703
735
sample_t* buf = m_buffer.getBuffer();
705
737
m_mixer->clear(length);
809
AUD_Reference<AUD_IHandle> AUD_SoftwareDevice::play(AUD_Reference<AUD_IReader> reader, bool keep)
839
boost::shared_ptr<AUD_IHandle> AUD_SoftwareDevice::play(boost::shared_ptr<AUD_IReader> reader, bool keep)
811
841
// prepare the reader
814
AUD_Reference<AUD_PitchReader> pitch = new AUD_PitchReader(reader, 1);
815
reader = AUD_Reference<AUD_IReader>(pitch);
844
boost::shared_ptr<AUD_PitchReader> pitch = boost::shared_ptr<AUD_PitchReader>(new AUD_PitchReader(reader, 1));
845
reader = boost::shared_ptr<AUD_IReader>(pitch);
817
AUD_Reference<AUD_ResampleReader> resampler;
847
boost::shared_ptr<AUD_ResampleReader> resampler;
821
resampler = new AUD_JOSResampleReader(reader, m_specs.specs);
851
resampler = boost::shared_ptr<AUD_ResampleReader>(new AUD_JOSResampleReader(reader, m_specs.specs));
823
resampler = new AUD_LinearResampleReader(reader, m_specs.specs);
824
reader = AUD_Reference<AUD_IReader>(resampler);
853
resampler = boost::shared_ptr<AUD_ResampleReader>(new AUD_LinearResampleReader(reader, m_specs.specs));
854
reader = boost::shared_ptr<AUD_IReader>(resampler);
827
AUD_Reference<AUD_ChannelMapperReader> mapper = new AUD_ChannelMapperReader(reader, m_specs.channels);
828
reader = AUD_Reference<AUD_IReader>(mapper);
857
boost::shared_ptr<AUD_ChannelMapperReader> mapper = boost::shared_ptr<AUD_ChannelMapperReader>(new AUD_ChannelMapperReader(reader, m_specs.channels));
858
reader = boost::shared_ptr<AUD_IReader>(mapper);
831
return AUD_Reference<AUD_IHandle>();
861
return boost::shared_ptr<AUD_IHandle>();
834
AUD_Reference<AUD_SoftwareDevice::AUD_SoftwareHandle> sound = new AUD_SoftwareDevice::AUD_SoftwareHandle(this, reader, pitch, resampler, mapper, keep);
864
boost::shared_ptr<AUD_SoftwareDevice::AUD_SoftwareHandle> sound = boost::shared_ptr<AUD_SoftwareDevice::AUD_SoftwareHandle>(new AUD_SoftwareDevice::AUD_SoftwareHandle(this, reader, pitch, resampler, mapper, keep));
866
AUD_MutexLock lock(*this);
837
868
m_playingSounds.push_back(sound);
840
871
playing(m_playback = true);
843
return AUD_Reference<AUD_IHandle>(sound);
873
return boost::shared_ptr<AUD_IHandle>(sound);
846
AUD_Reference<AUD_IHandle> AUD_SoftwareDevice::play(AUD_Reference<AUD_IFactory> factory, bool keep)
876
boost::shared_ptr<AUD_IHandle> AUD_SoftwareDevice::play(boost::shared_ptr<AUD_IFactory> factory, bool keep)
848
878
return play(factory->createReader(), keep);
851
881
void AUD_SoftwareDevice::stopAll()
883
AUD_MutexLock lock(*this);
855
885
while(!m_playingSounds.empty())
856
886
m_playingSounds.front()->stop();
858
888
while(!m_pausedSounds.empty())
859
889
m_pausedSounds.front()->stop();
864
892
void AUD_SoftwareDevice::lock()