mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 13:28:09 +02: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.stereo = sound->isStereo();
|
||||||
options.position = position;
|
options.position = position;
|
||||||
options.volume = volume;
|
options.volume = volume;
|
||||||
|
options.pitch = 1.0f / stretchFactor;
|
||||||
|
|
||||||
QByteArray samples = sound->getByteArray();
|
QByteArray samples = sound->getByteArray();
|
||||||
if (stretchFactor == 1.0f) {
|
|
||||||
return playSoundAndDelete(samples, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
const int standardRate = AudioConstants::SAMPLE_RATE;
|
return playSoundAndDelete(samples, options);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioInjectorPointer AudioInjector::playSoundAndDelete(const QByteArray& buffer, const AudioInjectorOptions options) {
|
AudioInjectorPointer AudioInjector::playSoundAndDelete(const QByteArray& buffer, const AudioInjectorOptions options) {
|
||||||
|
@ -461,7 +444,6 @@ AudioInjectorPointer AudioInjector::playSoundAndDelete(const QByteArray& buffer,
|
||||||
return sound;
|
return sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AudioInjectorPointer AudioInjector::playSound(const QByteArray& buffer, const AudioInjectorOptions options) {
|
AudioInjectorPointer AudioInjector::playSound(const QByteArray& buffer, const AudioInjectorOptions options) {
|
||||||
|
|
||||||
if (options.pitch == 1.0f) {
|
if (options.pitch == 1.0f) {
|
||||||
|
|
Loading…
Reference in a new issue