mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-01 02:56:43 +01:00
emscripten_seek_audio_stream_secs: return end position after the sample has ended
Samples in Allegro return 0.0 in this case, while streams return the stream length.
This commit is contained in:
parent
5fb99a97f8
commit
fdb4a29a13
2 changed files with 11 additions and 1 deletions
|
@ -59,6 +59,7 @@ SYMBOL_EXPORT ALLEGRO_AUDIO_STREAM *emscripten_load_audio_stream(const char* fil
|
|||
EMSCRIPTEN_AUDIO_STREAM *stream = calloc(1, sizeof(EMSCRIPTEN_AUDIO_STREAM));
|
||||
stream->sample = al_load_sample(filename);
|
||||
stream->instance = al_create_sample_instance(stream->sample);
|
||||
stream->old_pos = 0.0;
|
||||
al_set_sample_instance_playing(stream->instance, true);
|
||||
return (ALLEGRO_AUDIO_STREAM*)stream;
|
||||
}
|
||||
|
@ -67,6 +68,7 @@ SYMBOL_EXPORT ALLEGRO_AUDIO_STREAM *emscripten_load_audio_stream_f(ALLEGRO_FILE
|
|||
EMSCRIPTEN_AUDIO_STREAM *stream = calloc(1, sizeof(EMSCRIPTEN_AUDIO_STREAM));
|
||||
stream->sample = al_load_sample_f(file, ident);
|
||||
stream->instance = al_create_sample_instance(stream->sample);
|
||||
stream->old_pos = 0.0;
|
||||
al_set_sample_instance_playing(stream->instance, true);
|
||||
return (ALLEGRO_AUDIO_STREAM*)stream;
|
||||
}
|
||||
|
@ -223,7 +225,14 @@ SYMBOL_EXPORT double emscripten_get_audio_stream_position_secs(ALLEGRO_AUDIO_STR
|
|||
double sample_pos = al_get_sample_instance_position(s->instance);
|
||||
double length = emscripten_get_audio_stream_length_secs(stream);
|
||||
unsigned int samples = emscripten_get_audio_stream_length(stream);
|
||||
return length * (sample_pos / (double)samples);
|
||||
double pos = length * (sample_pos / (double)samples);
|
||||
// hack needed to return the end after the stream has ended (samples rollback to 0.0 instead)
|
||||
if (s->old_pos > 0.0 && pos == 0.0) {
|
||||
return length;
|
||||
} else {
|
||||
s->old_pos = pos;
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT void emscripten_destroy_audio_stream(ALLEGRO_AUDIO_STREAM *stream) {
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
typedef struct {
|
||||
ALLEGRO_SAMPLE* sample;
|
||||
ALLEGRO_SAMPLE_INSTANCE* instance;
|
||||
double old_pos;
|
||||
} EMSCRIPTEN_AUDIO_STREAM;
|
||||
|
||||
ALLEGRO_AUDIO_STREAM* emscripten_load_audio_stream(const char* filename, size_t buffer_count, unsigned int samples);
|
||||
|
|
Loading…
Reference in a new issue