43 using namespace Nsound;
66 if(beats_per_minute < 0.0)
68 beats_per_minute = 0.0;
72 first_beat_time, beats_per_minute, audio_stream);
129 if(start_time >= end_time)
return AudioStream(1,1);
131 MixerSet::const_iterator node =
mixer_set_.begin();
134 float64 sample_rate = node->audio_stream_->getSampleRate();
145 for(
uint32 i = 0; i < n_samples; ++i)
162 float64 beat_time = 60.0 / node->bpm_;
165 static_cast<float64>(node->audio_stream_->getLength())
166 / static_cast<float64>(sample_rate);
169 float64 next_beat_time = node->first_beat_time_;
170 float64 next_end_time = next_beat_time + beat_length;
173 uint32 new_stream_offset_index = 0;
179 while(next_end_time < mixer_time)
181 next_beat_time += beat_time;
182 next_end_time = next_beat_time + beat_length;
193 if(mixer_time < next_beat_time)
195 mixer_time = next_beat_time;
203 else if(next_beat_time < mixer_time)
207 uint32 node_index =
static_cast<uint32>((next_end_time - mixer_time) * sample_rate);
209 new_stream_offset_index =
static_cast<uint32>(
214 new_stream.
add(temp, new_stream_offset_index);
216 next_beat_time += beat_time;
217 next_end_time = next_beat_time + beat_length;
218 mixer_time = next_beat_time;
219 new_stream_time = next_beat_time -
start_time;
222 while(new_stream_time < new_stream_end_time)
224 new_stream_offset_index =
static_cast<uint32>
225 (new_stream_time * sample_rate);
228 uint32 add_n_samples = node_max_index;
230 if(next_end_time > end_time)
232 add_n_samples -=
static_cast<uint32>((next_end_time - end_time)
233 * static_cast<float64>(sample_rate));
237 *node->audio_stream_,
238 new_stream_offset_index,
241 next_beat_time += beat_time;
242 next_end_time = next_beat_time + beat_length;
243 mixer_time = next_beat_time;
244 new_stream_time += beat_time;
#define M_ASSERT_VALUE(a, op, value)
void add(float64 first_beat_time, float64 beats_per_minute, const AudioStream &audio_stream)
This method inserts the AudioStream to the Mixer's LinkList.
Nsound::uint32 max_channels_
Stores the maximum number of channels.
uint32 getLength() const
Returns the number of samples of audio data in the stream.
AudioStream substream(uint32 start_index, uint32 n_samples=0) const
Nsound::MixerSet mixer_set_
This stores all the MixerNodes.
uint32 getNChannels(void) const
Returns the number of audio channels in the stream.
AudioStream getStream(float64 end_time)
This method returns one AudioStream composed of all AudioStreams stored in the Mixer's LinkList...
This class holds the nodes for use with the Mixer class.
void clear()
This method removes all streams from the mixer.
void add(const AudioStream &as, uint32 offset, uint32 n_samples=0)
This method adds the passed AudioStream to this AudioStream.