mirror of https://github.com/libsdl-org/SDL.git
examples: use doubles to generate sine waves and avoid distortion
This commit is contained in:
parent
307e6f2ca6
commit
03a3c19c27
|
|
@ -76,9 +76,9 @@ SDL_AppResult SDL_AppIterate(void *appstate)
|
||||||
for (i = 0; i < SDL_arraysize(samples); i++) {
|
for (i = 0; i < SDL_arraysize(samples); i++) {
|
||||||
/* You don't have to care about this math; we're just generating a simple sine wave as we go.
|
/* You don't have to care about this math; we're just generating a simple sine wave as we go.
|
||||||
https://en.wikipedia.org/wiki/Sine_wave */
|
https://en.wikipedia.org/wiki/Sine_wave */
|
||||||
const float time = total_samples_generated / 8000.0f;
|
const double time = total_samples_generated / 8000.0;
|
||||||
const int sine_freq = 500; /* run the wave at 500Hz */
|
const int sine_freq = 500; /* run the wave at 500Hz */
|
||||||
samples[i] = SDL_sinf(6.283185f * sine_freq * time);
|
samples[i] = (float)SDL_sin(6.283185 * sine_freq * time);
|
||||||
total_samples_generated++;
|
total_samples_generated++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,9 @@ static void SDLCALL FeedTheAudioStreamMore(void *userdata, SDL_AudioStream *astr
|
||||||
for (i = 0; i < total; i++) {
|
for (i = 0; i < total; i++) {
|
||||||
/* You don't have to care about this math; we're just generating a simple sine wave as we go.
|
/* You don't have to care about this math; we're just generating a simple sine wave as we go.
|
||||||
https://en.wikipedia.org/wiki/Sine_wave */
|
https://en.wikipedia.org/wiki/Sine_wave */
|
||||||
const float time = total_samples_generated / 8000.0f;
|
const double time = total_samples_generated / 8000.0;
|
||||||
const int sine_freq = 500; /* run the wave at 500Hz */
|
const int sine_freq = 500; /* run the wave at 500Hz */
|
||||||
samples[i] = SDL_sinf(6.283185f * sine_freq * time);
|
samples[i] = (float)SDL_sin(6.283185 * sine_freq * time);
|
||||||
total_samples_generated++;
|
total_samples_generated++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue