summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2003-04-01 20:58:31 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2003-04-01 20:58:31 +0000
commit2bf4a0541067360c76f7cd2cf058613512c32ee6 (patch)
tree6319d6c1e542a40f8b116e0f5562c24b0233fd2a /firmware
parent156632db32109b60fd1ee3baa435c1b6e1023519 (diff)
downloadrockbox-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 'firmware')
-rw-r--r--firmware/export/mpeg.h1
-rw-r--r--firmware/mpeg.c94
2 files changed, 12 insertions, 83 deletions
diff --git a/firmware/export/mpeg.h b/firmware/export/mpeg.h
index 9ce03daa7d..6b44363f8f 100644
--- a/firmware/export/mpeg.h
+++ b/firmware/export/mpeg.h
@@ -90,7 +90,6 @@ unsigned long mpeg_num_recorded_bytes(void);
#endif
void mpeg_get_debugdata(struct mpeg_debug *dbgdata);
void mpeg_set_buffer_margin(int seconds);
-int mpeg_create_xing_header(char *filename, void (*progressfunc)(int));
#define SOUND_VOLUME 0
#define SOUND_BASS 1
diff --git a/firmware/mpeg.c b/firmware/mpeg.c
index bd90e9f1d6..15d531ea1f 100644
--- a/firmware/mpeg.c
+++ b/firmware/mpeg.c
@@ -715,6 +715,7 @@ static long timing_info[1024];
#endif
static bool inverted_pr;
static unsigned long num_rec_bytes;
+static unsigned long num_recorded_frames;
void drain_dma_buffer(void)
{
@@ -1851,7 +1852,7 @@ static void mpeg_thread(void)
panicf("recfile: %d", mpeg_file);
break;
-
+
case MPEG_STOP:
DEBUGF("MPEG_STOP\n");
demand_irq_enable(false);
@@ -1872,8 +1873,9 @@ static void mpeg_thread(void)
if(mpeg_file < 0)
panicf("rec upd: %d", mpeg_file);
- create_xing_header(mpeg_file, 0, mpeg_num_recorded_bytes(),
- xingbuf, 0, NULL, false);
+ create_xing_header(mpeg_file, 0, num_rec_bytes,
+ xingbuf, num_recorded_frames, NULL,
+ false);
lseek(mpeg_file, 4096, SEEK_SET);
write(mpeg_file, xingbuf, 417);
@@ -2209,6 +2211,8 @@ static void start_recording(void)
{
unsigned long val;
+ num_recorded_frames = 0;
+
/* Stop monitoring and record for real */
mas_readmem(MAS_BANK_D0, 0x7f1, &val, 1);
val &= ~(1 << 10);
@@ -2236,6 +2240,9 @@ static void stop_recording(void)
unsigned long val;
is_recording = false;
+
+ /* Read the number of frames recorded */
+ mas_readmem(MAS_BANK_D0, 0xfd0, &num_recorded_frames, 1);
/* Start monitoring */
mas_readmem(MAS_BANK_D0, 0x7f1, &val, 1);
@@ -2266,6 +2273,7 @@ unsigned long mpeg_num_recorded_bytes(void)
else
return 0;
}
+
#endif
void mpeg_play(int offset)
@@ -2853,6 +2861,7 @@ void mpeg_set_recording_gain(int left, int right, int mic)
(mic?0x0008:0) | /* Connect left A/D to mic */
0x0007);
}
+
#endif
#ifdef SIMULATOR
@@ -2999,82 +3008,3 @@ void mpeg_init(int volume, int bass, int treble, int balance, int loudness,
dbg_cnt2us(0);
#endif
}
-
-int d_1;
-int d_2;
-
-int mpeg_create_xing_header(char *filename, void (*progressfunc)(int))
-{
- struct mp3entry entry;
- int fd;
- int rc;
- int flen;
- int num_frames;
- int fpos;
-
- if(progressfunc)
- progressfunc(0);
-
- rc = mp3info(&entry, filename);
- if(rc < 0)
- return rc * 10 - 1;
-
- fd = open(filename, O_RDWR);
- if(fd < 0)
- return fd * 10 - 2;
-
- flen = lseek(fd, 0, SEEK_END);
-
- d_1 = entry.first_frame_offset;
- d_2 = entry.filesize;
-
- if(progressfunc)
- progressfunc(0);
-
- num_frames = count_mp3_frames(fd, entry.first_frame_offset,
- flen, progressfunc);
-
- if(num_frames)
- {
- create_xing_header(fd, entry.first_frame_offset,
- flen, xingbuf, num_frames, progressfunc, true);
-
- /* Try to fit the Xing header first in the stream. Replace the existing
- Xing header if there is one, else see if there is room between the
- ID3 tag and the first MP3 frame. */
- if(entry.vbr_header_pos)
- {
- /* Reuse existing Xing header */
- fpos = entry.vbr_header_pos;
-
- DEBUGF("Reusing Xing header at %d\n", fpos);
- }
- else
- {
- /* Any room between ID3 tag and first MP3 frame? */
- if(entry.first_frame_offset - entry.id3v2len > 417)
- {
- fpos = entry.first_frame_offset - 417;
- }
- else
- {
- close(fd);
- return -3;
- }
- }
-
- lseek(fd, fpos, SEEK_SET);
- write(fd, xingbuf, 417);
- close(fd);
-
- if(progressfunc)
- progressfunc(100);
- return 0;
- }
- else
- {
- /* Not a VBR file */
- DEBUGF("Not a VBR file\n");
- return -9;
- }
-}