Reviewed SetAudioBufferPitch() #1450
This commit is contained in:
parent
039503e7c2
commit
459c4754dc
@ -52,6 +52,7 @@ int main(void)
|
|||||||
|
|
||||||
Music music = LoadMusicStream("resources/mini1111.xm");
|
Music music = LoadMusicStream("resources/mini1111.xm");
|
||||||
music.looping = false;
|
music.looping = false;
|
||||||
|
float pitch = 1.0f;
|
||||||
|
|
||||||
PlayMusicStream(music);
|
PlayMusicStream(music);
|
||||||
|
|
||||||
@ -84,6 +85,11 @@ int main(void)
|
|||||||
else ResumeMusicStream(music);
|
else ResumeMusicStream(music);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (IsKeyDown(KEY_DOWN)) pitch -= 0.01f;
|
||||||
|
else if (IsKeyDown(KEY_UP)) pitch += 0.01f;
|
||||||
|
|
||||||
|
SetMusicPitch(music, pitch);
|
||||||
|
|
||||||
// Get timePlayed scaled to bar dimensions
|
// Get timePlayed scaled to bar dimensions
|
||||||
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*(screenWidth - 40);
|
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*(screenWidth - 40);
|
||||||
|
|
||||||
|
10
src/raudio.c
10
src/raudio.c
@ -634,16 +634,14 @@ void SetAudioBufferPitch(AudioBuffer *buffer, float pitch)
|
|||||||
{
|
{
|
||||||
if (buffer != NULL)
|
if (buffer != NULL)
|
||||||
{
|
{
|
||||||
float pitchMul = pitch/buffer->pitch;
|
|
||||||
|
|
||||||
// Pitching is just an adjustment of the sample rate.
|
// Pitching is just an adjustment of the sample rate.
|
||||||
// Note that this changes the duration of the sound:
|
// Note that this changes the duration of the sound:
|
||||||
// - higher pitches will make the sound faster
|
// - higher pitches will make the sound faster
|
||||||
// - lower pitches make it slower
|
// - lower pitches make it slower
|
||||||
ma_uint32 newOutputSampleRate = (ma_uint32)((float)buffer->converter.config.sampleRateOut/pitchMul);
|
ma_uint32 outputSampleRate = (ma_uint32)((float)buffer->converter.config.sampleRateOut/pitch);
|
||||||
buffer->pitch *= (float)buffer->converter.config.sampleRateOut/newOutputSampleRate;
|
ma_data_converter_set_rate(&buffer->converter, buffer->converter.config.sampleRateIn, outputSampleRate);
|
||||||
|
|
||||||
ma_data_converter_set_rate(&buffer->converter, buffer->converter.config.sampleRateIn, newOutputSampleRate);
|
buffer->pitch = pitch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1477,7 +1475,7 @@ void SetMusicVolume(Music music, float volume)
|
|||||||
// Set pitch for music
|
// Set pitch for music
|
||||||
void SetMusicPitch(Music music, float pitch)
|
void SetMusicPitch(Music music, float pitch)
|
||||||
{
|
{
|
||||||
SetAudioStreamPitch(music.stream, pitch);
|
SetAudioBufferPitch(music.stream.buffer, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get music time length (in seconds)
|
// Get music time length (in seconds)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user