mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-24 08:15:50 +00:00
Added SDL_AUDIO_FRAMESIZE
This commit is contained in:
@@ -513,7 +513,7 @@ static void StreamThing_ontick(Thing *thing, Uint64 now)
|
||||
if (!available || (SDL_GetAudioStreamFormat(thing->data.stream.stream, NULL, &spec) < 0)) {
|
||||
DestroyThingInPoof(thing);
|
||||
} else {
|
||||
const int ticksleft = (int) ((((Uint64) ((available / SDL_AUDIO_BYTESIZE(spec.format)) / spec.channels)) * 1000) / spec.freq);
|
||||
const int ticksleft = (int) ((((Uint64) (available / SDL_AUDIO_FRAMESIZE(spec))) * 1000) / spec.freq);
|
||||
const float pct = thing->data.stream.total_ticks ? (((float) (ticksleft)) / ((float) thing->data.stream.total_ticks)) : 0.0f;
|
||||
thing->progress = 1.0f - pct;
|
||||
}
|
||||
@@ -553,7 +553,7 @@ static void StreamThing_ondrop(Thing *thing, int button, float x, float y)
|
||||
SDL_UnbindAudioStream(thing->data.stream.stream); /* unbind from current device */
|
||||
if (thing->line_connected_to->what == THING_LOGDEV_CAPTURE) {
|
||||
SDL_FlushAudioStream(thing->data.stream.stream);
|
||||
thing->data.stream.total_ticks = (int) (((((Uint64) (SDL_GetAudioStreamAvailable(thing->data.stream.stream) / SDL_AUDIO_BYTESIZE(spec->format))) / spec->channels) * 1000) / spec->freq);
|
||||
thing->data.stream.total_ticks = (int) ((((Uint64) (SDL_GetAudioStreamAvailable(thing->data.stream.stream) / SDL_AUDIO_FRAMESIZE(*spec))) * 1000) / spec->freq);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -596,7 +596,7 @@ static Thing *CreateStreamThing(const SDL_AudioSpec *spec, const Uint8 *buf, con
|
||||
if (buf && buflen) {
|
||||
SDL_PutAudioStreamData(thing->data.stream.stream, buf, (int) buflen);
|
||||
SDL_FlushAudioStream(thing->data.stream.stream);
|
||||
thing->data.stream.total_ticks = (int) (((((Uint64) (SDL_GetAudioStreamAvailable(thing->data.stream.stream) / SDL_AUDIO_BYTESIZE(spec->format))) / spec->channels) * 1000) / spec->freq);
|
||||
thing->data.stream.total_ticks = (int) ((((Uint64) (SDL_GetAudioStreamAvailable(thing->data.stream.stream) / SDL_AUDIO_FRAMESIZE(*spec))) * 1000) / spec->freq);
|
||||
}
|
||||
thing->ontick = StreamThing_ontick;
|
||||
thing->ondrag = StreamThing_ondrag;
|
||||
|
||||
@@ -292,7 +292,7 @@ static void loop(void)
|
||||
|
||||
if (SDL_GetAudioStreamFormat(stream, &src_spec, &dst_spec) == 0) {
|
||||
available_bytes = SDL_GetAudioStreamAvailable(stream);
|
||||
available_seconds = (float)available_bytes / (float)(SDL_AUDIO_BYTESIZE(dst_spec.format) * dst_spec.freq * dst_spec.channels);
|
||||
available_seconds = (float)available_bytes / (float)(SDL_AUDIO_FRAMESIZE(dst_spec) * dst_spec.freq);
|
||||
|
||||
/* keep it looping. */
|
||||
if (auto_loop && (available_seconds < 10.0f)) {
|
||||
|
||||
@@ -709,13 +709,13 @@ static int audio_convertAudio(void *arg)
|
||||
Uint8 *dst_buf = NULL, *src_buf = NULL;
|
||||
int dst_len = 0, src_len = 0, real_dst_len = 0;
|
||||
int l = 64, m;
|
||||
int src_samplesize, dst_samplesize;
|
||||
int src_framesize, dst_framesize;
|
||||
int src_silence, dst_silence;
|
||||
|
||||
src_samplesize = SDL_AUDIO_BYTESIZE(spec1.format) * spec1.channels;
|
||||
dst_samplesize = SDL_AUDIO_BYTESIZE(spec2.format) * spec2.channels;
|
||||
src_framesize = SDL_AUDIO_FRAMESIZE(spec1);
|
||||
dst_framesize = SDL_AUDIO_FRAMESIZE(spec2);
|
||||
|
||||
src_len = l * src_samplesize;
|
||||
src_len = l * src_framesize;
|
||||
SDLTest_Log("Creating dummy sample buffer of %i length (%i bytes)", l, src_len);
|
||||
src_buf = (Uint8 *)SDL_malloc(src_len);
|
||||
SDLTest_AssertCheck(src_buf != NULL, "Check src data buffer to convert is not NULL");
|
||||
@@ -726,7 +726,7 @@ static int audio_convertAudio(void *arg)
|
||||
src_silence = SDL_GetSilenceValueForFormat(spec1.format);
|
||||
SDL_memset(src_buf, src_silence, src_len);
|
||||
|
||||
dst_len = ((int)((((Sint64)l * spec2.freq) - 1) / spec1.freq) + 1) * dst_samplesize;
|
||||
dst_len = ((int)((((Sint64)l * spec2.freq) - 1) / spec1.freq) + 1) * dst_framesize;
|
||||
dst_buf = (Uint8 *)SDL_malloc(dst_len);
|
||||
SDLTest_AssertCheck(dst_buf != NULL, "Check dst data buffer to convert is not NULL");
|
||||
if (dst_buf == NULL) {
|
||||
|
||||
Reference in New Issue
Block a user