player_thread: don't use precalculated size_to_time

Calculate the total play time with the audio_format object each time,
using audio_format_time_to_size().  The function
audioFormatSizeToTime() is not needed anymore, and will be removed
with this patch.
This commit is contained in:
Max Kellermann 2009-07-23 12:27:05 +02:00
parent 0749dbfadf
commit caf48ee973
2 changed files with 4 additions and 22 deletions

View File

@ -172,13 +172,4 @@ static inline double audio_format_time_to_size(const struct audio_format *af)
return af->sample_rate * audio_format_frame_size(af); return af->sample_rate * audio_format_frame_size(af);
} }
/**
* Returns the floating point factor which converts a storage size in
* bytes to a time span.
*/
static inline double audioFormatSizeToTime(const struct audio_format *af)
{
return 1.0 / audio_format_time_to_size(af);
}
#endif #endif

View File

@ -93,12 +93,6 @@ struct player {
* The current audio format for the audio outputs. * The current audio format for the audio outputs.
*/ */
struct audio_format play_audio_format; struct audio_format play_audio_format;
/**
* Coefficient for converting a PCM buffer size into a time
* span.
*/
double size_to_time;
}; };
static struct music_buffer *player_buffer; static struct music_buffer *player_buffer;
@ -200,8 +194,6 @@ player_check_decoder_startup(struct player *player)
pc.total_time = dc.total_time; pc.total_time = dc.total_time;
pc.audio_format = dc.in_audio_format; pc.audio_format = dc.in_audio_format;
player->play_audio_format = dc.out_audio_format; player->play_audio_format = dc.out_audio_format;
player->size_to_time =
audioFormatSizeToTime(&dc.out_audio_format);
player->decoder_starting = false; player->decoder_starting = false;
if (!player->paused && if (!player->paused &&
@ -446,7 +438,7 @@ update_song_tag(struct song *song, const struct tag *new_tag)
*/ */
static bool static bool
play_chunk(struct song *song, struct music_chunk *chunk, play_chunk(struct song *song, struct music_chunk *chunk,
const struct audio_format *format, double sizeToTime) const struct audio_format *format)
{ {
assert(music_chunk_check_format(chunk, format)); assert(music_chunk_check_format(chunk, format));
@ -469,7 +461,8 @@ play_chunk(struct song *song, struct music_chunk *chunk,
return false; return false;
} }
pc.total_play_time += sizeToTime * chunk->length; pc.total_play_time += (double)chunk->length /
audio_format_time_to_size(format);
return true; return true;
} }
@ -540,8 +533,7 @@ play_next_chunk(struct player *player)
/* play the current chunk */ /* play the current chunk */
success = play_chunk(player->song, chunk, &player->play_audio_format, success = play_chunk(player->song, chunk, &player->play_audio_format);
player->size_to_time);
if (!success) { if (!success) {
music_buffer_return(player_buffer, chunk); music_buffer_return(player_buffer, chunk);
@ -608,7 +600,6 @@ static void do_play(void)
.xfade = XFADE_UNKNOWN, .xfade = XFADE_UNKNOWN,
.cross_fading = false, .cross_fading = false,
.cross_fade_chunks = 0, .cross_fade_chunks = 0,
.size_to_time = 0.0,
}; };
player.pipe = music_pipe_new(); player.pipe = music_pipe_new();