diff options
author | Nicolas Pennequin <nicolas.pennequin@free.fr> | 2008-04-03 12:13:03 +0000 |
---|---|---|
committer | Nicolas Pennequin <nicolas.pennequin@free.fr> | 2008-04-03 12:13:03 +0000 |
commit | 73a71a4712795cef91849bd1eef327ac68ef19db (patch) | |
tree | c245f8f0e9fa7f473b8a81313b5420a8ccb1844b | |
parent | f51f98e13405fa46ccdda0230aafe868dec8410b (diff) | |
download | rockbox-73a71a4712795cef91849bd1eef327ac68ef19db.tar.gz rockbox-73a71a4712795cef91849bd1eef327ac68ef19db.zip |
Move audio_set_elapsed to mpa.c, as recommended by the TODO note. Please correct me if affecting ci->id3->elapsed directly (ie without using ci->set_elapsed) is wrong.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16945 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/codecs/mpa.c | 59 | ||||
-rw-r--r-- | apps/playback.c | 57 |
2 files changed, 58 insertions, 58 deletions
diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c index f9a27f5b41..a18a5e8090 100644 --- a/apps/codecs/mpa.c +++ b/apps/codecs/mpa.c | |||
@@ -109,6 +109,61 @@ int get_file_pos(int newtime) | |||
109 | return pos; | 109 | return pos; |
110 | } | 110 | } |
111 | 111 | ||
112 | static void set_elapsed(struct mp3entry* id3) | ||
113 | { | ||
114 | unsigned long offset = id3->offset > id3->first_frame_offset ? | ||
115 | id3->offset - id3->first_frame_offset : 0; | ||
116 | |||
117 | if ( id3->vbr ) { | ||
118 | if ( id3->has_toc ) { | ||
119 | /* calculate elapsed time using TOC */ | ||
120 | int i; | ||
121 | unsigned int remainder, plen, relpos, nextpos; | ||
122 | |||
123 | /* find wich percent we're at */ | ||
124 | for (i=0; i<100; i++ ) | ||
125 | if ( offset < id3->toc[i] * (id3->filesize / 256) ) | ||
126 | break; | ||
127 | |||
128 | i--; | ||
129 | if (i < 0) | ||
130 | i = 0; | ||
131 | |||
132 | relpos = id3->toc[i]; | ||
133 | |||
134 | if (i < 99) | ||
135 | nextpos = id3->toc[i+1]; | ||
136 | else | ||
137 | nextpos = 256; | ||
138 | |||
139 | remainder = offset - (relpos * (id3->filesize / 256)); | ||
140 | |||
141 | /* set time for this percent (divide before multiply to prevent | ||
142 | overflow on long files. loss of precision is negligible on | ||
143 | short files) */ | ||
144 | id3->elapsed = i * (id3->length / 100); | ||
145 | |||
146 | /* calculate remainder time */ | ||
147 | plen = (nextpos - relpos) * (id3->filesize / 256); | ||
148 | id3->elapsed += (((remainder * 100) / plen) * | ||
149 | (id3->length / 10000)); | ||
150 | } | ||
151 | else { | ||
152 | /* no TOC exists. set a rough estimate using average bitrate */ | ||
153 | int tpk = id3->length / | ||
154 | ((id3->filesize - id3->first_frame_offset - id3->id3v1len) / | ||
155 | 1024); | ||
156 | id3->elapsed = offset / 1024 * tpk; | ||
157 | } | ||
158 | } | ||
159 | else | ||
160 | { | ||
161 | /* constant bitrate, use exact calculation */ | ||
162 | if (id3->bitrate != 0) | ||
163 | id3->elapsed = offset / (id3->bitrate / 8); | ||
164 | } | ||
165 | } | ||
166 | |||
112 | /* this is the codec entry point */ | 167 | /* this is the codec entry point */ |
113 | enum codec_status codec_main(void) | 168 | enum codec_status codec_main(void) |
114 | { | 169 | { |
@@ -145,8 +200,10 @@ next_track: | |||
145 | current_frequency = ci->id3->frequency; | 200 | current_frequency = ci->id3->frequency; |
146 | codec_set_replaygain(ci->id3); | 201 | codec_set_replaygain(ci->id3); |
147 | 202 | ||
148 | if (ci->id3->offset) | 203 | if (ci->id3->offset) { |
149 | ci->seek_buffer(ci->id3->offset); | 204 | ci->seek_buffer(ci->id3->offset); |
205 | set_elapsed(ci->id3); | ||
206 | } | ||
150 | else | 207 | else |
151 | ci->seek_buffer(ci->id3->first_frame_offset); | 208 | ci->seek_buffer(ci->id3->first_frame_offset); |
152 | 209 | ||
diff --git a/apps/playback.c b/apps/playback.c index f49831ef30..2875f44505 100644 --- a/apps/playback.c +++ b/apps/playback.c | |||
@@ -1559,62 +1559,6 @@ static bool audio_loadcodec(bool start_play) | |||
1559 | return true; | 1559 | return true; |
1560 | } | 1560 | } |
1561 | 1561 | ||
1562 | /* TODO: Copied from mpeg.c. Should be moved somewhere else. */ | ||
1563 | static void audio_set_elapsed(struct mp3entry* id3) | ||
1564 | { | ||
1565 | unsigned long offset = id3->offset > id3->first_frame_offset ? | ||
1566 | id3->offset - id3->first_frame_offset : 0; | ||
1567 | |||
1568 | if ( id3->vbr ) { | ||
1569 | if ( id3->has_toc ) { | ||
1570 | /* calculate elapsed time using TOC */ | ||
1571 | int i; | ||
1572 | unsigned int remainder, plen, relpos, nextpos; | ||
1573 | |||
1574 | /* find wich percent we're at */ | ||
1575 | for (i=0; i<100; i++ ) | ||
1576 | if ( offset < id3->toc[i] * (id3->filesize / 256) ) | ||
1577 | break; | ||
1578 | |||
1579 | i--; | ||
1580 | if (i < 0) | ||
1581 | i = 0; | ||
1582 | |||
1583 | relpos = id3->toc[i]; | ||
1584 | |||
1585 | if (i < 99) | ||
1586 | nextpos = id3->toc[i+1]; | ||
1587 | else | ||
1588 | nextpos = 256; | ||
1589 | |||
1590 | remainder = offset - (relpos * (id3->filesize / 256)); | ||
1591 | |||
1592 | /* set time for this percent (divide before multiply to prevent | ||
1593 | overflow on long files. loss of precision is negligible on | ||
1594 | short files) */ | ||
1595 | id3->elapsed = i * (id3->length / 100); | ||
1596 | |||
1597 | /* calculate remainder time */ | ||
1598 | plen = (nextpos - relpos) * (id3->filesize / 256); | ||
1599 | id3->elapsed += (((remainder * 100) / plen) * | ||
1600 | (id3->length / 10000)); | ||
1601 | } | ||
1602 | else { | ||
1603 | /* no TOC exists. set a rough estimate using average bitrate */ | ||
1604 | int tpk = id3->length / | ||
1605 | ((id3->filesize - id3->first_frame_offset - id3->id3v1len) / | ||
1606 | 1024); | ||
1607 | id3->elapsed = offset / 1024 * tpk; | ||
1608 | } | ||
1609 | } | ||
1610 | else | ||
1611 | { | ||
1612 | /* constant bitrate, use exact calculation */ | ||
1613 | if (id3->bitrate != 0) | ||
1614 | id3->elapsed = offset / (id3->bitrate / 8); | ||
1615 | } | ||
1616 | } | ||
1617 | |||
1618 | /* Load one track by making the appropriate bufopen calls. Return true if | 1562 | /* Load one track by making the appropriate bufopen calls. Return true if |
1619 | everything required was loaded correctly, false if not. */ | 1563 | everything required was loaded correctly, false if not. */ |
1620 | static bool audio_load_track(int offset, bool start_play) | 1564 | static bool audio_load_track(int offset, bool start_play) |
@@ -1781,7 +1725,6 @@ static bool audio_load_track(int offset, bool start_play) | |||
1781 | if (offset > 0) { | 1725 | if (offset > 0) { |
1782 | file_offset = offset; | 1726 | file_offset = offset; |
1783 | track_id3->offset = offset; | 1727 | track_id3->offset = offset; |
1784 | audio_set_elapsed(track_id3); | ||
1785 | } | 1728 | } |
1786 | break; | 1729 | break; |
1787 | 1730 | ||