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

« back to all changes in this revision

Viewing changes to intern/audaspace/intern/AUD_SequencerReader.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:
28
28
 
29
29
 
30
30
#include "AUD_SequencerReader.h"
31
 
 
32
 
typedef std::list<AUD_Reference<AUD_SequencerHandle> >::iterator AUD_HandleIterator;
33
 
typedef std::list<AUD_Reference<AUD_SequencerEntry> >::iterator AUD_EntryIterator;
34
 
 
35
 
AUD_SequencerReader::AUD_SequencerReader(AUD_Reference<AUD_SequencerFactory> factory, bool quality) :
36
 
        m_position(0), m_device(factory->m_specs), m_factory(factory), m_status(0), m_entry_status(0)
 
31
#include "AUD_MutexLock.h"
 
32
 
 
33
typedef std::list<boost::shared_ptr<AUD_SequencerHandle> >::iterator AUD_HandleIterator;
 
34
typedef std::list<boost::shared_ptr<AUD_SequencerEntry> >::iterator AUD_EntryIterator;
 
35
 
 
36
AUD_SequencerReader::AUD_SequencerReader(boost::shared_ptr<AUD_Sequencer> sequence, bool quality) :
 
37
        m_position(0), m_device(sequence->m_specs), m_sequence(sequence), m_status(0), m_entry_status(0)
37
38
{
38
39
        m_device.setQuality(quality);
39
40
}
56
57
 
57
58
        for(AUD_HandleIterator it = m_handles.begin(); it != m_handles.end(); it++)
58
59
        {
59
 
                (*it)->seek(position / m_factory->m_specs.rate);
 
60
                (*it)->seek(position / m_sequence->m_specs.rate);
60
61
        }
61
62
}
62
63
 
72
73
 
73
74
AUD_Specs AUD_SequencerReader::getSpecs() const
74
75
{
75
 
        return m_factory->m_specs;
 
76
        return m_sequence->m_specs;
76
77
}
77
78
 
78
79
void AUD_SequencerReader::read(int& length, bool& eos, sample_t* buffer)
79
80
{
80
 
        m_factory->lock();
 
81
        AUD_MutexLock lock(*m_sequence);
81
82
 
82
 
        if(m_factory->m_status != m_status)
 
83
        if(m_sequence->m_status != m_status)
83
84
        {
84
 
                m_device.changeSpecs(m_factory->m_specs);
85
 
                m_device.setSpeedOfSound(m_factory->m_speed_of_sound);
86
 
                m_device.setDistanceModel(m_factory->m_distance_model);
87
 
                m_device.setDopplerFactor(m_factory->m_doppler_factor);
 
85
                m_device.changeSpecs(m_sequence->m_specs);
 
86
                m_device.setSpeedOfSound(m_sequence->m_speed_of_sound);
 
87
                m_device.setDistanceModel(m_sequence->m_distance_model);
 
88
                m_device.setDopplerFactor(m_sequence->m_doppler_factor);
88
89
 
89
 
                m_status = m_factory->m_status;
 
90
                m_status = m_sequence->m_status;
90
91
        }
91
92
 
92
 
        if(m_factory->m_entry_status != m_entry_status)
 
93
        if(m_sequence->m_entry_status != m_entry_status)
93
94
        {
94
 
                std::list<AUD_Reference<AUD_SequencerHandle> > handles;
 
95
                std::list<boost::shared_ptr<AUD_SequencerHandle> > handles;
95
96
 
96
97
                AUD_HandleIterator hit = m_handles.begin();
97
 
                AUD_EntryIterator  eit = m_factory->m_entries.begin();
 
98
                AUD_EntryIterator  eit = m_sequence->m_entries.begin();
98
99
 
99
100
                int result;
100
 
                AUD_Reference<AUD_SequencerHandle> handle;
 
101
                boost::shared_ptr<AUD_SequencerHandle> handle;
101
102
 
102
 
                while(hit != m_handles.end() && eit != m_factory->m_entries.end())
 
103
                while(hit != m_handles.end() && eit != m_sequence->m_entries.end())
103
104
                {
104
105
                        handle = *hit;
105
 
                        AUD_Reference<AUD_SequencerEntry> entry = *eit;
 
106
                        boost::shared_ptr<AUD_SequencerEntry> entry = *eit;
106
107
 
107
108
                        result = handle->compare(entry);
108
109
 
110
111
                        {
111
112
                                try
112
113
                                {
113
 
                                        handle = new AUD_SequencerHandle(entry, m_device);
 
114
                                        handle = boost::shared_ptr<AUD_SequencerHandle>(new AUD_SequencerHandle(entry, m_device));
114
115
                                        handles.push_front(handle);
115
116
                                }
116
117
                                catch(AUD_Exception&)
137
138
                        hit++;
138
139
                }
139
140
 
140
 
                while(eit != m_factory->m_entries.end())
 
141
                while(eit != m_sequence->m_entries.end())
141
142
                {
142
143
                        try
143
144
                        {
144
 
                                handle = new AUD_SequencerHandle(*eit, m_device);
 
145
                                handle = boost::shared_ptr<AUD_SequencerHandle>(new AUD_SequencerHandle(*eit, m_device));
145
146
                                handles.push_front(handle);
146
147
                        }
147
148
                        catch(AUD_Exception&)
152
153
 
153
154
                m_handles = handles;
154
155
 
155
 
                m_entry_status = m_factory->m_entry_status;
 
156
                m_entry_status = m_sequence->m_entry_status;
156
157
        }
157
158
 
158
 
        AUD_Specs specs = m_factory->m_specs;
 
159
        AUD_Specs specs = m_sequence->m_specs;
159
160
        int pos = 0;
160
161
        float time = float(m_position) / float(specs.rate);
161
162
        float volume, frame;
166
167
 
167
168
        while(pos < length)
168
169
        {
169
 
                frame = time * m_factory->m_fps;
 
170
                frame = time * m_sequence->m_fps;
170
171
                cfra = int(floor(frame));
171
172
 
172
 
                len = int(ceil((cfra + 1) / m_factory->m_fps * specs.rate)) - m_position;
 
173
                len = int(ceil((cfra + 1) / m_sequence->m_fps * specs.rate)) - m_position;
173
174
                len = AUD_MIN(length - pos, len);
174
175
                len = AUD_MAX(len, 1);
175
176
 
176
177
                for(AUD_HandleIterator it = m_handles.begin(); it != m_handles.end(); it++)
177
178
                {
178
 
                        (*it)->update(time, frame, m_factory->m_fps);
 
179
                        (*it)->update(time, frame, m_sequence->m_fps);
179
180
                }
180
181
 
181
 
                m_factory->m_volume.read(frame, &volume);
182
 
                if(m_factory->m_muted)
 
182
                m_sequence->m_volume.read(frame, &volume);
 
183
                if(m_sequence->m_muted)
183
184
                        volume = 0.0f;
184
185
                m_device.setVolume(volume);
185
186
 
186
 
                m_factory->m_orientation.read(frame, q.get());
 
187
                m_sequence->m_orientation.read(frame, q.get());
187
188
                m_device.setListenerOrientation(q);
188
 
                m_factory->m_location.read(frame, v.get());
 
189
                m_sequence->m_location.read(frame, v.get());
189
190
                m_device.setListenerLocation(v);
190
 
                m_factory->m_location.read(frame + 1, v2.get());
 
191
                m_sequence->m_location.read(frame + 1, v2.get());
191
192
                v2 -= v;
192
 
                m_device.setListenerVelocity(v2 * m_factory->m_fps);
 
193
                m_device.setListenerVelocity(v2 * m_sequence->m_fps);
193
194
 
194
195
                m_device.read(reinterpret_cast<data_t*>(buffer + specs.channels * pos), len);
195
196
 
197
198
                time += float(len) / float(specs.rate);
198
199
        }
199
200
 
200
 
        m_factory->unlock();
201
 
 
202
201
        m_position += length;
203
202
 
204
203
        eos = false;