summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@gmail.com>2008-06-22 11:32:22 +0200
committerLars-Dominik Braun <PromyLOPh@gmail.com>2008-06-22 11:32:22 +0200
commitab38ac31d09f85ceb4e47f4a18e3d71f59c2c9d4 (patch)
tree887e5098e2422e03f0f66f75fee5d9fc4f74bba4 /src
parent98c2f0b1a22f89dc971472702b3ac4e080183e48 (diff)
downloadpianobar-windows-ab38ac31d09f85ceb4e47f4a18e3d71f59c2c9d4.tar.gz
pianobar-windows-ab38ac31d09f85ceb4e47f4a18e3d71f59c2c9d4.tar.bz2
pianobar-windows-ab38ac31d09f85ceb4e47f4a18e3d71f59c2c9d4.zip
client: Time calc algo => function
Diffstat (limited to 'src')
-rw-r--r--src/main.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c
index 6580afb..872bc62 100644
--- a/src/main.c
+++ b/src/main.c
@@ -142,6 +142,12 @@ char *selectMusicId (PianoHandle_t *ph) {
return musicId;
}
+/* FIXME: this is now correct */
+inline float BarSamplesToSeconds (float samplerate, float channels,
+ float samples) {
+ return channels * 1000.0 * samples / samplerate;
+}
+
int main (int argc, char **argv) {
PianoHandle_t ph;
struct aacPlayer player;
@@ -370,14 +376,11 @@ int main (int argc, char **argv) {
/* show time */
if (player.finishedPlayback == 0 &&
player.mode >= SAMPLESIZE_INITIALIZED) {
- /* FIXME: is this calculation correct? */
- /* one frame length: T = 1/f */
- float songLength = 1.0 / (float) player.samplerate *
- (float) player.channels * 1000.0 *
- (float) player.sampleSizeN;
- float songRemaining = songLength - 1.0 / (float) player.samplerate *
- (float) player.channels * 1000.0 *
- (float) player.sampleSizeCurr;
+ float songLength = BarSamplesToSeconds (player.samplerate,
+ player.channels, player.sampleSizeN);
+ float songRemaining = songLength -
+ BarSamplesToSeconds (player.samplerate, player.channels,
+ player.sampleSizeCurr);
printf ("-%02i:%02i/%02i:%02i\r", (int) songRemaining/60,
(int) songRemaining%60, (int) songLength/60,
(int) songLength%60);