Looping audio clips now functioning correctly in Siren.
KRAudioSource::IsPlaying() now returning false when a non-looping audio source ends.
This commit is contained in:
@@ -216,13 +216,10 @@ void KRAudioManager::renderReverb()
|
||||
KRAudioSource *source = *itr;
|
||||
float reverb_send_level = m_global_reverb_send_level * m_global_gain * source->getReverb();
|
||||
if(reverb_send_level > 0.0f) {
|
||||
KRAudioSample *sample = source->getAudioSample();
|
||||
if(sample) {
|
||||
sample->sample((int)((__int64_t)m_audio_frame - source->getStartAudioFrame()), KRENGINE_AUDIO_BLOCK_LENGTH, 0, reverb_data, reverb_send_level);
|
||||
source->sample(KRENGINE_AUDIO_BLOCK_LENGTH, 0, reverb_data, reverb_send_level);
|
||||
vDSP_vadd(reverb_accum, 1, reverb_data, 1, reverb_accum, 1, KRENGINE_AUDIO_BLOCK_LENGTH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Apply impulse response reverb
|
||||
// KRAudioSample *impulse_response = getContext().getAudioManager()->get("hrtf_kemar_H10e040a");
|
||||
@@ -1314,8 +1311,6 @@ void KRAudioManager::renderHRTF()
|
||||
|
||||
for(std::set<KRAudioSource *>::iterator itr=m_activeAudioSources.begin(); itr != m_activeAudioSources.end(); itr++) {
|
||||
KRAudioSource *source = *itr;
|
||||
KRAudioSample *source_sample = source->getAudioSample();
|
||||
if(source_sample) {
|
||||
KRVector3 source_world_position = source->getWorldTranslation();
|
||||
KRVector3 diff = source_world_position - m_listener_position;
|
||||
float distance = diff.magnitude();
|
||||
@@ -1362,7 +1357,7 @@ void KRAudioManager::renderHRTF()
|
||||
}
|
||||
}
|
||||
|
||||
source_sample->sample((int)((__int64_t)m_audio_frame - source->getStartAudioFrame()), KRENGINE_AUDIO_BLOCK_LENGTH, 0, hrtf_sample->realp, gain);
|
||||
source->sample(KRENGINE_AUDIO_BLOCK_LENGTH, 0, hrtf_sample->realp, gain);
|
||||
memset(hrtf_sample->realp + hrtf_frames, 0, sizeof(float) * hrtf_frames);
|
||||
memset(hrtf_sample->imagp, 0, sizeof(float) * fft_size);
|
||||
|
||||
@@ -1384,7 +1379,6 @@ void KRAudioManager::renderHRTF()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KRAudioManager::renderITD()
|
||||
|
||||
@@ -504,6 +504,38 @@ __int64_t KRAudioSource::getStartAudioFrame()
|
||||
return m_start_audio_frame;
|
||||
}
|
||||
|
||||
void KRAudioSource::sample(int frame_count, int channel, float *buffer, float gain)
|
||||
{
|
||||
KRAudioSample *source_sample = getAudioSample();
|
||||
if(source_sample && m_playing) {
|
||||
if(m_looping) {
|
||||
int buffer_offset = 0;
|
||||
int frames_left = frame_count;
|
||||
int sample_length = source_sample->getFrameCount();
|
||||
while(frames_left) {
|
||||
int next_frame = (int)((getContext().getAudioManager()->getAudioFrame() - getStartAudioFrame() + buffer_offset) % sample_length);
|
||||
if(next_frame + frames_left >= sample_length) {
|
||||
int frames_processed = sample_length - next_frame;
|
||||
source_sample->sample(next_frame, frames_processed, channel, buffer + buffer_offset, gain);
|
||||
frames_left -= frames_processed;
|
||||
buffer_offset += frames_processed;
|
||||
} else {
|
||||
source_sample->sample(next_frame, frames_left, channel, buffer + buffer_offset, gain);
|
||||
frames_left = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int next_frame = (int)(getContext().getAudioManager()->getAudioFrame() - getStartAudioFrame());
|
||||
source_sample->sample(next_frame, frame_count, channel, buffer, gain);
|
||||
if(next_frame > source_sample->getFrameCount()) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
memset(buffer, 0, sizeof(float) * frame_count);
|
||||
}
|
||||
}
|
||||
|
||||
OSStatus alcASASetSourceProc(const ALuint property, ALuint source, ALvoid *data, ALuint dataSize)
|
||||
{
|
||||
OSStatus err = noErr;
|
||||
|
||||
@@ -96,6 +96,7 @@ public:
|
||||
|
||||
|
||||
__int64_t getStartAudioFrame();
|
||||
void sample(int frame_count, int channel, float *buffer, float gain);
|
||||
|
||||
private:
|
||||
__int64_t m_start_audio_frame; // Global audio frame that matches the start of the audio sample playback
|
||||
|
||||
Reference in New Issue
Block a user