mirror of
https://github.com/love2d/megasource.git
synced 2026-08-19 04:05:09 +02:00
update SDL3 to 3.2.0
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
static SDL_Window *window = NULL;
|
||||
static SDL_Renderer *renderer = NULL;
|
||||
static SDL_AudioStream *stream = NULL;
|
||||
static int total_samples_generated = 0;
|
||||
static int current_sine_sample = 0;
|
||||
|
||||
/* This function runs once at startup. */
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
@@ -73,15 +73,17 @@ SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
static float samples[512]; /* this will feed 512 samples each frame until we get to our maximum. */
|
||||
int i;
|
||||
|
||||
/* generate a 440Hz pure tone */
|
||||
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.
|
||||
https://en.wikipedia.org/wiki/Sine_wave */
|
||||
const float time = total_samples_generated / 8000.0f;
|
||||
const int sine_freq = 500; /* run the wave at 500Hz */
|
||||
samples[i] = SDL_sinf(6.283185f * sine_freq * time);
|
||||
total_samples_generated++;
|
||||
const int freq = 440;
|
||||
const float phase = current_sine_sample * freq / 8000.0f;
|
||||
samples[i] = SDL_sinf(phase * 2 * SDL_PI_F);
|
||||
current_sine_sample++;
|
||||
}
|
||||
|
||||
/* wrapping around to avoid floating-point errors */
|
||||
current_sine_sample %= 8000;
|
||||
|
||||
/* feed the new data to the stream. It will queue at the end, and trickle out as the hardware needs more data. */
|
||||
SDL_PutAudioStreamData(stream, samples, sizeof (samples));
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
static SDL_Window *window = NULL;
|
||||
static SDL_Renderer *renderer = NULL;
|
||||
static SDL_AudioStream *stream = NULL;
|
||||
static int total_samples_generated = 0;
|
||||
static int current_sine_sample = 0;
|
||||
|
||||
/* this function will be called (usually in a background thread) when the audio stream is consuming data. */
|
||||
static void SDLCALL FeedTheAudioStreamMore(void *userdata, SDL_AudioStream *astream, int additional_amount, int total_amount)
|
||||
@@ -33,15 +33,17 @@ static void SDLCALL FeedTheAudioStreamMore(void *userdata, SDL_AudioStream *astr
|
||||
const int total = SDL_min(additional_amount, SDL_arraysize(samples));
|
||||
int i;
|
||||
|
||||
/* generate a 440Hz pure tone */
|
||||
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.
|
||||
https://en.wikipedia.org/wiki/Sine_wave */
|
||||
const float time = total_samples_generated / 8000.0f;
|
||||
const int sine_freq = 500; /* run the wave at 500Hz */
|
||||
samples[i] = SDL_sinf(6.283185f * sine_freq * time);
|
||||
total_samples_generated++;
|
||||
const int freq = 440;
|
||||
const float phase = current_sine_sample * freq / 8000.0f;
|
||||
samples[i] = SDL_sinf(phase * 2 * SDL_PI_F);
|
||||
current_sine_sample++;
|
||||
}
|
||||
|
||||
/* wrapping around to avoid floating-point errors */
|
||||
current_sine_sample %= 8000;
|
||||
|
||||
/* feed the new data to the stream. It will queue at the end, and trickle out as the hardware needs more data. */
|
||||
SDL_PutAudioStreamData(astream, samples, total * sizeof (float));
|
||||
additional_amount -= total; /* subtract what we've just fed the stream. */
|
||||
|
||||
Reference in New Issue
Block a user