mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
Re-implement collision sound pitch shifting
This commit is contained in:
parent
a421ba7649
commit
e2e4e7f423
1 changed files with 2 additions and 20 deletions
|
@ -427,28 +427,11 @@ AudioInjectorPointer AudioInjector::playSound(SharedSoundPointer sound, const fl
|
|||
options.stereo = sound->isStereo();
|
||||
options.position = position;
|
||||
options.volume = volume;
|
||||
options.pitch = 1.0f / stretchFactor;
|
||||
|
||||
QByteArray samples = sound->getByteArray();
|
||||
if (stretchFactor == 1.0f) {
|
||||
return playSoundAndDelete(samples, options);
|
||||
}
|
||||
|
||||
const int standardRate = AudioConstants::SAMPLE_RATE;
|
||||
const int resampledRate = standardRate * stretchFactor;
|
||||
const int channelCount = sound->isStereo() ? 2 : 1;
|
||||
|
||||
AudioSRC resampler(standardRate, resampledRate, channelCount);
|
||||
|
||||
const int nInputFrames = samples.size() / (channelCount * sizeof(int16_t));
|
||||
const int maxOutputFrames = resampler.getMaxOutput(nInputFrames);
|
||||
QByteArray resampled(maxOutputFrames * channelCount * sizeof(int16_t), '\0');
|
||||
|
||||
int nOutputFrames = resampler.render(reinterpret_cast<const int16_t*>(samples.data()),
|
||||
reinterpret_cast<int16_t*>(resampled.data()),
|
||||
nInputFrames);
|
||||
|
||||
Q_UNUSED(nOutputFrames);
|
||||
return playSoundAndDelete(resampled, options);
|
||||
return playSoundAndDelete(samples, options);
|
||||
}
|
||||
|
||||
AudioInjectorPointer AudioInjector::playSoundAndDelete(const QByteArray& buffer, const AudioInjectorOptions options) {
|
||||
|
@ -461,7 +444,6 @@ AudioInjectorPointer AudioInjector::playSoundAndDelete(const QByteArray& buffer,
|
|||
return sound;
|
||||
}
|
||||
|
||||
|
||||
AudioInjectorPointer AudioInjector::playSound(const QByteArray& buffer, const AudioInjectorOptions options) {
|
||||
|
||||
if (options.pitch == 1.0f) {
|
||||
|
|
Loading…
Reference in a new issue