~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to intern/audaspace/intern/AUD_SoftwareDevice.cpp

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "AUD_IFactory.h"
34
34
#include "AUD_JOSResampleReader.h"
35
35
#include "AUD_LinearResampleReader.h"
 
36
#include "AUD_MutexLock.h"
36
37
 
37
38
#include <cstring>
38
39
#include <cmath>
56
57
/********************** AUD_SoftwareHandle Handle Code ************************/
57
58
/******************************************************************************/
58
59
 
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),
226
227
{
227
228
        if(m_status)
228
229
        {
229
 
                m_device->lock();
 
230
                AUD_MutexLock lock(*m_device);
230
231
 
231
232
                if(m_status == AUD_STATUS_PLAYING)
232
233
                {
233
 
                        m_device->m_playingSounds.remove(this);
234
 
                        m_device->m_pausedSounds.push_back(this);
235
 
 
236
 
                        if(m_device->m_playingSounds.empty())
237
 
                                m_device->playing(m_device->m_playback = false);
238
 
                        m_status = AUD_STATUS_PAUSED;
239
 
                        m_device->unlock();
240
 
 
241
 
                        return true;
 
234
                        for(AUD_HandleIterator it = m_device->m_playingSounds.begin(); it != m_device->m_playingSounds.end(); it++)
 
235
                        {
 
236
                                if(it->get() == this)
 
237
                                {
 
238
                                        boost::shared_ptr<AUD_SoftwareHandle> This = *it;
 
239
 
 
240
                                        m_device->m_playingSounds.erase(it);
 
241
                                        m_device->m_pausedSounds.push_back(This);
 
242
 
 
243
                                        if(m_device->m_playingSounds.empty())
 
244
                                                m_device->playing(m_device->m_playback = false);
 
245
 
 
246
                                        m_status = AUD_STATUS_PAUSED;
 
247
 
 
248
                                        return true;
 
249
                                }
 
250
                        }
242
251
                }
243
 
 
244
 
                m_device->unlock();
245
252
        }
246
253
 
247
254
        return false;
251
258
{
252
259
        if(m_status)
253
260
        {
254
 
                m_device->lock();
 
261
                AUD_MutexLock lock(*m_device);
255
262
 
256
263
                if(m_status == AUD_STATUS_PAUSED)
257
264
                {
258
 
                        m_device->m_pausedSounds.remove(this);
259
 
                        m_device->m_playingSounds.push_back(this);
260
 
 
261
 
                        if(!m_device->m_playback)
262
 
                                m_device->playing(m_device->m_playback = true);
263
 
                        m_status = AUD_STATUS_PLAYING;
264
 
                        m_device->unlock();
265
 
                        return true;
 
265
                        for(AUD_HandleIterator it = m_device->m_pausedSounds.begin(); it != m_device->m_pausedSounds.end(); it++)
 
266
                        {
 
267
                                if(it->get() == this)
 
268
                                {
 
269
                                        boost::shared_ptr<AUD_SoftwareHandle> This = *it;
 
270
 
 
271
                                        m_device->m_pausedSounds.erase(it);
 
272
 
 
273
                                        m_device->m_playingSounds.push_back(This);
 
274
 
 
275
                                        if(!m_device->m_playback)
 
276
                                                m_device->playing(m_device->m_playback = true);
 
277
                                        m_status = AUD_STATUS_PLAYING;
 
278
 
 
279
                                        return true;
 
280
                                }
 
281
                        }
266
282
                }
267
283
 
268
 
                m_device->unlock();
269
284
        }
270
285
 
271
286
        return false;
276
291
        if(!m_status)
277
292
                return false;
278
293
 
279
 
        m_device->lock();
280
 
 
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;
284
 
 
285
 
        if(m_status == AUD_STATUS_PLAYING)
286
 
        {
287
 
                m_device->m_playingSounds.remove(This);
288
 
 
289
 
                if(m_device->m_playingSounds.empty())
290
 
                        m_device->playing(m_device->m_playback = false);
291
 
        }
292
 
        else
293
 
                m_device->m_pausedSounds.remove(This);
294
 
 
295
 
        m_device->unlock();
 
294
        AUD_MutexLock lock(*m_device);
 
295
 
 
296
        if(!m_status)
 
297
                return false;
 
298
 
296
299
        m_status = AUD_STATUS_INVALID;
297
 
        return true;
 
300
 
 
301
        for(AUD_HandleIterator it = m_device->m_playingSounds.begin(); it != m_device->m_playingSounds.end(); it++)
 
302
        {
 
303
                if(it->get() == this)
 
304
                {
 
305
                        boost::shared_ptr<AUD_SoftwareHandle> This = *it;
 
306
 
 
307
                        m_device->m_playingSounds.erase(it);
 
308
 
 
309
                        if(m_device->m_playingSounds.empty())
 
310
                                m_device->playing(m_device->m_playback = false);
 
311
 
 
312
                        return true;
 
313
                }
 
314
        }
 
315
 
 
316
        for(AUD_HandleIterator it = m_device->m_pausedSounds.begin(); it != m_device->m_pausedSounds.end(); it++)
 
317
        {
 
318
                if(it->get() == this)
 
319
                {
 
320
                        m_device->m_pausedSounds.erase(it);
 
321
                        return true;
 
322
                }
 
323
        }
 
324
 
 
325
        return false;
298
326
}
299
327
 
300
328
bool AUD_SoftwareDevice::AUD_SoftwareHandle::getKeep()
310
338
        if(!m_status)
311
339
                return false;
312
340
 
313
 
        m_device->lock();
 
341
        AUD_MutexLock lock(*m_device);
 
342
 
 
343
        if(!m_status)
 
344
                return false;
314
345
 
315
346
        m_keep = keep;
316
347
 
317
 
        m_device->unlock();
318
 
 
319
348
        return true;
320
349
}
321
350
 
324
353
        if(!m_status)
325
354
                return false;
326
355
 
327
 
        m_device->lock();
 
356
        AUD_MutexLock lock(*m_device);
 
357
 
 
358
        if(!m_status)
 
359
                return false;
328
360
 
329
361
        m_reader->seek((int)(position * m_reader->getSpecs().rate));
330
362
 
331
 
        m_device->unlock();
332
 
 
333
363
        return true;
334
364
}
335
365
 
336
366
float AUD_SoftwareDevice::AUD_SoftwareHandle::getPosition()
337
367
{
338
368
        if(!m_status)
 
369
                return false;
 
370
 
 
371
        AUD_MutexLock lock(*m_device);
 
372
 
 
373
        if(!m_status)
339
374
                return 0.0f;
340
375
 
341
 
        m_device->lock();
342
 
 
343
376
        float position = m_reader->getPosition() / (float)m_device->m_specs.rate;
344
377
 
345
 
        m_device->unlock();
346
 
 
347
378
        return position;
348
379
}
349
380
 
407
438
        if(!m_status)
408
439
                return false;
409
440
 
410
 
        m_device->lock();
 
441
        AUD_MutexLock lock(*m_device);
 
442
 
 
443
        if(!m_status)
 
444
                return false;
411
445
 
412
446
        m_stop = callback;
413
447
        m_stop_data = data;
414
448
 
415
 
        m_device->unlock();
416
 
 
417
449
        return true;
418
450
}
419
451
 
657
689
{
658
690
        m_playback = false;
659
691
        m_volume = 1.0f;
660
 
        m_mixer = new AUD_Mixer(m_specs);
 
692
        m_mixer = boost::shared_ptr<AUD_Mixer>(new AUD_Mixer(m_specs));
661
693
        m_speed_of_sound = 343.0f;
662
694
        m_doppler_factor = 1.0f;
663
695
        m_distance_model = AUD_DISTANCE_MODEL_INVERSE_CLAMPED;
691
723
{
692
724
        m_buffer.assureSize(length * AUD_SAMPLE_SIZE(m_specs));
693
725
 
694
 
        lock();
 
726
        AUD_MutexLock lock(*this);
695
727
 
696
728
        {
697
 
                AUD_Reference<AUD_SoftwareDevice::AUD_SoftwareHandle> sound;
 
729
                boost::shared_ptr<AUD_SoftwareDevice::AUD_SoftwareHandle> sound;
698
730
                int len;
699
731
                int pos;
700
732
                bool eos;
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();
704
736
 
705
737
                m_mixer->clear(length);
775
807
                        sound->pause();
776
808
                }
777
809
        }
778
 
 
779
 
        unlock();
780
810
}
781
811
 
782
812
void AUD_SoftwareDevice::setPanning(AUD_IHandle* handle, float pan)
806
836
        return m_specs;
807
837
}
808
838
 
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)
810
840
{
811
841
        // prepare the reader
812
842
        // pitch
813
843
 
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);
816
846
 
817
 
        AUD_Reference<AUD_ResampleReader> resampler;
 
847
        boost::shared_ptr<AUD_ResampleReader> resampler;
818
848
 
819
849
        // resample
820
850
        if(m_quality)
821
 
                resampler = new AUD_JOSResampleReader(reader, m_specs.specs);
 
851
                resampler = boost::shared_ptr<AUD_ResampleReader>(new AUD_JOSResampleReader(reader, m_specs.specs));
822
852
        else
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);
825
855
 
826
856
        // rechannel
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);
829
859
 
830
 
        if(reader.isNull())
831
 
                return AUD_Reference<AUD_IHandle>();
 
860
        if(!reader.get())
 
861
                return boost::shared_ptr<AUD_IHandle>();
832
862
 
833
863
        // play sound
834
 
        AUD_Reference<AUD_SoftwareDevice::AUD_SoftwareHandle> sound = new AUD_SoftwareDevice::AUD_SoftwareHandle(this, reader, pitch, resampler, mapper, keep);
835
 
 
836
 
        lock();
 
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));
 
865
 
 
866
        AUD_MutexLock lock(*this);
 
867
 
837
868
        m_playingSounds.push_back(sound);
838
869
 
839
870
        if(!m_playback)
840
871
                playing(m_playback = true);
841
 
        unlock();
842
872
 
843
 
        return AUD_Reference<AUD_IHandle>(sound);
 
873
        return boost::shared_ptr<AUD_IHandle>(sound);
844
874
}
845
875
 
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)
847
877
{
848
878
        return play(factory->createReader(), keep);
849
879
}
850
880
 
851
881
void AUD_SoftwareDevice::stopAll()
852
882
{
853
 
        lock();
 
883
        AUD_MutexLock lock(*this);
854
884
 
855
885
        while(!m_playingSounds.empty())
856
886
                m_playingSounds.front()->stop();
857
887
 
858
888
        while(!m_pausedSounds.empty())
859
889
                m_pausedSounds.front()->stop();
860
 
 
861
 
        unlock();
862
890
}
863
891
 
864
892
void AUD_SoftwareDevice::lock()