diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/audio/player.c | 15 | ||||
-rw-r--r-- | src/audio/player.h | 17 |
2 files changed, 23 insertions, 9 deletions
diff --git a/src/audio/player.c b/src/audio/player.c index 2d6767ea..5b9d0103 100644 --- a/src/audio/player.c +++ b/src/audio/player.c | |||
@@ -146,6 +146,7 @@ iDeclareType(ContentSpec) | |||
146 | struct Impl_ContentSpec { | 146 | struct Impl_ContentSpec { |
147 | SDL_AudioFormat inputFormat; | 147 | SDL_AudioFormat inputFormat; |
148 | SDL_AudioSpec output; | 148 | SDL_AudioSpec output; |
149 | size_t totalInputSize; | ||
149 | uint64_t totalSamples; | 150 | uint64_t totalSamples; |
150 | iRanges wavData; | 151 | iRanges wavData; |
151 | }; | 152 | }; |
@@ -167,6 +168,7 @@ struct Impl_Decoder { | |||
167 | SDL_AudioFormat inputFormat; | 168 | SDL_AudioFormat inputFormat; |
168 | iInputBuf * input; | 169 | iInputBuf * input; |
169 | size_t inputPos; | 170 | size_t inputPos; |
171 | size_t totalInputSize; | ||
170 | iSampleBuf output; | 172 | iSampleBuf output; |
171 | iMutex outputMutex; | 173 | iMutex outputMutex; |
172 | uint64_t currentSample; | 174 | uint64_t currentSample; |
@@ -305,6 +307,7 @@ void init_Decoder(iDecoder *d, iInputBuf *input, const iContentSpec *spec) { | |||
305 | d->input = input; | 307 | d->input = input; |
306 | d->inputPos = spec->wavData.start; | 308 | d->inputPos = spec->wavData.start; |
307 | d->inputFormat = spec->inputFormat; | 309 | d->inputFormat = spec->inputFormat; |
310 | d->totalInputSize = spec->totalInputSize; | ||
308 | init_SampleBuf(&d->output, | 311 | init_SampleBuf(&d->output, |
309 | spec->output.format, | 312 | spec->output.format, |
310 | spec->output.channels, | 313 | spec->output.channels, |
@@ -365,7 +368,7 @@ static iContentSpec contentSpec_Player_(const iPlayer *d) { | |||
365 | /* Not WAV. */ | 368 | /* Not WAV. */ |
366 | return content; | 369 | return content; |
367 | } | 370 | } |
368 | readU32_Stream(is); /* file size */ | 371 | content.totalInputSize = readU32_Stream(is); /* file size */ |
369 | readData_Buffer(buf, 4, magic); | 372 | readData_Buffer(buf, 4, magic); |
370 | if (memcmp(magic, "WAVE", 4)) { | 373 | if (memcmp(magic, "WAVE", 4)) { |
371 | /* Not WAV. */ | 374 | /* Not WAV. */ |
@@ -550,3 +553,13 @@ float duration_Player(const iPlayer *d) { | |||
550 | if (!d->decoder) return 0; | 553 | if (!d->decoder) return 0; |
551 | return (float) ((double) d->decoder->totalSamples / (double) d->spec.freq); | 554 | return (float) ((double) d->decoder->totalSamples / (double) d->spec.freq); |
552 | } | 555 | } |
556 | |||
557 | float streamProgress_Player(const iPlayer *d) { | ||
558 | if (d->decoder->totalInputSize) { | ||
559 | lock_Mutex(&d->data->mtx); | ||
560 | const double inputSize = size_InputBuf(d->data); | ||
561 | unlock_Mutex(&d->data->mtx); | ||
562 | return (float) iMin(1.0, (double) inputSize / (double) d->decoder->totalInputSize); | ||
563 | } | ||
564 | return 0; | ||
565 | } | ||
diff --git a/src/audio/player.h b/src/audio/player.h index 5c17ef6c..c3552640 100644 --- a/src/audio/player.h +++ b/src/audio/player.h | |||
@@ -36,11 +36,12 @@ enum iPlayerUpdate { | |||
36 | void setFormatHint_Player (iPlayer *, const char *hint); | 36 | void setFormatHint_Player (iPlayer *, const char *hint); |
37 | void updateSourceData_Player (iPlayer *, const iBlock *data, enum iPlayerUpdate update); | 37 | void updateSourceData_Player (iPlayer *, const iBlock *data, enum iPlayerUpdate update); |
38 | 38 | ||
39 | iBool start_Player (iPlayer *); | 39 | iBool start_Player (iPlayer *); |
40 | void setPaused_Player (iPlayer *, iBool isPaused); | 40 | void setPaused_Player (iPlayer *, iBool isPaused); |
41 | void stop_Player (iPlayer *); | 41 | void stop_Player (iPlayer *); |
42 | 42 | ||
43 | iBool isStarted_Player (const iPlayer *); | 43 | iBool isStarted_Player (const iPlayer *); |
44 | iBool isPaused_Player (const iPlayer *); | 44 | iBool isPaused_Player (const iPlayer *); |
45 | float time_Player (const iPlayer *); | 45 | float time_Player (const iPlayer *); |
46 | float duration_Player (const iPlayer *); | 46 | float duration_Player (const iPlayer *); |
47 | float streamProgress_Player (const iPlayer *); /* normalized 0...1 */ | ||