diff options
| author | Ray <raysan5@gmail.com> | 2019-02-23 17:58:21 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-23 17:58:21 +0100 |
| commit | 854e5d2f7efff4fbd661a47825b8d1e3d70b4fa3 (patch) | |
| tree | 67baf4494bc8a790a6fb721b2006d7213628b390 /src | |
| parent | 374811c440302701496bfb474ce5861c951c5884 (diff) | |
| parent | 8ad608888e9ea24d72802520282136cf5a7659e8 (diff) | |
| download | raylib-854e5d2f7efff4fbd661a47825b8d1e3d70b4fa3.tar.gz raylib-854e5d2f7efff4fbd661a47825b8d1e3d70b4fa3.zip | |
Merge pull request #762 from ftk/pitchfix
Fix audio pitch
Diffstat (limited to 'src')
| -rw-r--r-- | src/raudio.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/raudio.c b/src/raudio.c index 451d3bc3..5f42222e 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -712,11 +712,13 @@ void SetAudioBufferPitch(AudioBuffer *audioBuffer, float pitch) return; } - audioBuffer->pitch = pitch; + float pitchMul = pitch / audioBuffer->pitch; // Pitching is just an adjustment of the sample rate. Note that this changes the duration of the sound - higher pitches // will make the sound faster; lower pitches make it slower. - mal_uint32 newOutputSampleRate = (mal_uint32)((((float)audioBuffer->dsp.src.config.sampleRateOut / (float)audioBuffer->dsp.src.config.sampleRateIn) / pitch) * audioBuffer->dsp.src.config.sampleRateIn); + mal_uint32 newOutputSampleRate = (mal_uint32)((float)audioBuffer->dsp.src.config.sampleRateOut / pitchMul); + audioBuffer->pitch *= (float)audioBuffer->dsp.src.config.sampleRateOut / newOutputSampleRate; + mal_dsp_set_output_sample_rate(&audioBuffer->dsp, newOutputSampleRate); } |
