diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2003-04-01 20:58:31 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2003-04-01 20:58:31 +0000 |
commit | 2bf4a0541067360c76f7cd2cf058613512c32ee6 (patch) | |
tree | 6319d6c1e542a40f8b116e0f5562c24b0233fd2a /apps | |
parent | 156632db32109b60fd1ee3baa435c1b6e1023519 (diff) | |
download | rockbox-2bf4a0541067360c76f7cd2cf058613512c32ee6.tar.gz rockbox-2bf4a0541067360c76f7cd2cf058613512c32ee6.zip |
Recorded files shorter than 3 hours now show correct average bitrate even without VBRFix.
Moved some code around.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3505 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/onplay.c | 92 |
1 files changed, 72 insertions, 20 deletions
diff --git a/apps/onplay.c b/apps/onplay.c index 3814e2554b..232bda2694 100644 --- a/apps/onplay.c +++ b/apps/onplay.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | #include <stdbool.h> | 22 | #include <stdbool.h> |
23 | 23 | ||
24 | #include "debug.h" | ||
24 | #include "sprintf.h" | 25 | #include "sprintf.h" |
25 | #include "lcd.h" | 26 | #include "lcd.h" |
26 | #include "dir.h" | 27 | #include "dir.h" |
@@ -32,6 +33,9 @@ | |||
32 | #include "button.h" | 33 | #include "button.h" |
33 | #include "kernel.h" | 34 | #include "kernel.h" |
34 | #include "keyboard.h" | 35 | #include "keyboard.h" |
36 | #include "mp3data.h" | ||
37 | #include "id3.h" | ||
38 | #include "screens.h" | ||
35 | #include "tree.h" | 39 | #include "tree.h" |
36 | 40 | ||
37 | static char* selected_file = NULL; | 41 | static char* selected_file = NULL; |
@@ -99,41 +103,89 @@ static bool rename_file(void) | |||
99 | return false; | 103 | return false; |
100 | } | 104 | } |
101 | 105 | ||
102 | extern int d_1; | ||
103 | extern int d_2; | ||
104 | |||
105 | static void xingupdate(int percent) | 106 | static void xingupdate(int percent) |
106 | { | 107 | { |
107 | char buf[32]; | 108 | char buf[32]; |
108 | 109 | ||
109 | snprintf(buf, 32, "%d%%", percent); | 110 | snprintf(buf, 32, "%d%%", percent); |
110 | lcd_puts(0, 3, buf); | 111 | lcd_puts(0, 1, buf); |
111 | snprintf(buf, 32, "%x", d_1); | ||
112 | lcd_puts(0, 4, buf); | ||
113 | snprintf(buf, 32, "%x", d_2); | ||
114 | lcd_puts(0, 5, buf); | ||
115 | lcd_update(); | 112 | lcd_update(); |
116 | } | 113 | } |
117 | 114 | ||
118 | static bool vbr_fix(void) | 115 | static bool vbr_fix(void) |
119 | { | 116 | { |
120 | char buf[32]; | 117 | unsigned char xingbuf[417]; |
121 | unsigned long start_tick; | 118 | struct mp3entry entry; |
122 | unsigned long end_tick; | 119 | int fd; |
120 | int rc; | ||
121 | int flen; | ||
122 | int num_frames; | ||
123 | int fpos; | ||
124 | |||
123 | 125 | ||
124 | lcd_clear_display(); | 126 | lcd_clear_display(); |
125 | lcd_puts(0, 0, selected_file); | 127 | lcd_puts_scroll(0, 0, selected_file); |
126 | lcd_update(); | 128 | lcd_update(); |
127 | 129 | ||
128 | start_tick = current_tick; | 130 | xingupdate(0); |
129 | mpeg_create_xing_header(selected_file, xingupdate); | ||
130 | end_tick = current_tick; | ||
131 | 131 | ||
132 | snprintf(buf, 32, "%d ticks", (int)(end_tick - start_tick)); | 132 | rc = mp3info(&entry, selected_file); |
133 | lcd_puts(0, 1, buf); | 133 | if(rc < 0) |
134 | snprintf(buf, 32, "%d seconds", (int)(end_tick - start_tick)/HZ); | 134 | return rc * 10 - 1; |
135 | lcd_puts(0, 2, buf); | 135 | |
136 | lcd_update(); | 136 | fd = open(selected_file, O_RDWR); |
137 | if(fd < 0) | ||
138 | return fd * 10 - 2; | ||
139 | |||
140 | flen = lseek(fd, 0, SEEK_END); | ||
141 | |||
142 | xingupdate(0); | ||
143 | |||
144 | num_frames = count_mp3_frames(fd, entry.first_frame_offset, | ||
145 | flen, xingupdate); | ||
146 | |||
147 | if(num_frames) | ||
148 | { | ||
149 | create_xing_header(fd, entry.first_frame_offset, | ||
150 | flen, xingbuf, num_frames, xingupdate, true); | ||
151 | |||
152 | /* Try to fit the Xing header first in the stream. Replace the existing | ||
153 | Xing header if there is one, else see if there is room between the | ||
154 | ID3 tag and the first MP3 frame. */ | ||
155 | if(entry.vbr_header_pos) | ||
156 | { | ||
157 | /* Reuse existing Xing header */ | ||
158 | fpos = entry.vbr_header_pos; | ||
159 | |||
160 | DEBUGF("Reusing Xing header at %d\n", fpos); | ||
161 | } | ||
162 | else | ||
163 | { | ||
164 | /* Any room between ID3 tag and first MP3 frame? */ | ||
165 | if(entry.first_frame_offset - entry.id3v2len > 417) | ||
166 | { | ||
167 | fpos = entry.first_frame_offset - 417; | ||
168 | } | ||
169 | else | ||
170 | { | ||
171 | close(fd); | ||
172 | splash(HZ*2, 0, true, "No room for header"); | ||
173 | return -3; | ||
174 | } | ||
175 | } | ||
176 | |||
177 | lseek(fd, fpos, SEEK_SET); | ||
178 | write(fd, xingbuf, 417); | ||
179 | close(fd); | ||
180 | |||
181 | xingupdate(100); | ||
182 | } | ||
183 | else | ||
184 | { | ||
185 | /* Not a VBR file */ | ||
186 | DEBUGF("Not a VBR file\n"); | ||
187 | splash(HZ*2, 0, true, "Not a VBR file"); | ||
188 | } | ||
137 | 189 | ||
138 | return false; | 190 | return false; |
139 | } | 191 | } |