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
This commit is contained in:
parent
156632db32
commit
2bf4a05410
3 changed files with 84 additions and 103 deletions
|
@ -21,6 +21,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "debug.h"
|
||||
#include "sprintf.h"
|
||||
#include "lcd.h"
|
||||
#include "dir.h"
|
||||
|
@ -32,6 +33,9 @@
|
|||
#include "button.h"
|
||||
#include "kernel.h"
|
||||
#include "keyboard.h"
|
||||
#include "mp3data.h"
|
||||
#include "id3.h"
|
||||
#include "screens.h"
|
||||
#include "tree.h"
|
||||
|
||||
static char* selected_file = NULL;
|
||||
|
@ -99,41 +103,89 @@ static bool rename_file(void)
|
|||
return false;
|
||||
}
|
||||
|
||||
extern int d_1;
|
||||
extern int d_2;
|
||||
|
||||
static void xingupdate(int percent)
|
||||
{
|
||||
char buf[32];
|
||||
|
||||
snprintf(buf, 32, "%d%%", percent);
|
||||
lcd_puts(0, 3, buf);
|
||||
snprintf(buf, 32, "%x", d_1);
|
||||
lcd_puts(0, 4, buf);
|
||||
snprintf(buf, 32, "%x", d_2);
|
||||
lcd_puts(0, 5, buf);
|
||||
lcd_puts(0, 1, buf);
|
||||
lcd_update();
|
||||
}
|
||||
|
||||
static bool vbr_fix(void)
|
||||
{
|
||||
char buf[32];
|
||||
unsigned long start_tick;
|
||||
unsigned long end_tick;
|
||||
unsigned char xingbuf[417];
|
||||
struct mp3entry entry;
|
||||
int fd;
|
||||
int rc;
|
||||
int flen;
|
||||
int num_frames;
|
||||
int fpos;
|
||||
|
||||
|
||||
lcd_clear_display();
|
||||
lcd_puts(0, 0, selected_file);
|
||||
lcd_puts_scroll(0, 0, selected_file);
|
||||
lcd_update();
|
||||
|
||||
start_tick = current_tick;
|
||||
mpeg_create_xing_header(selected_file, xingupdate);
|
||||
end_tick = current_tick;
|
||||
xingupdate(0);
|
||||
|
||||
snprintf(buf, 32, "%d ticks", (int)(end_tick - start_tick));
|
||||
lcd_puts(0, 1, buf);
|
||||
snprintf(buf, 32, "%d seconds", (int)(end_tick - start_tick)/HZ);
|
||||
lcd_puts(0, 2, buf);
|
||||
lcd_update();
|
||||
rc = mp3info(&entry, selected_file);
|
||||
if(rc < 0)
|
||||
return rc * 10 - 1;
|
||||
|
||||
fd = open(selected_file, O_RDWR);
|
||||
if(fd < 0)
|
||||
return fd * 10 - 2;
|
||||
|
||||
flen = lseek(fd, 0, SEEK_END);
|
||||
|
||||
xingupdate(0);
|
||||
|
||||
num_frames = count_mp3_frames(fd, entry.first_frame_offset,
|
||||
flen, xingupdate);
|
||||
|
||||
if(num_frames)
|
||||
{
|
||||
create_xing_header(fd, entry.first_frame_offset,
|
||||
flen, xingbuf, num_frames, xingupdate, 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);
|
||||
splash(HZ*2, 0, true, "No room for header");
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
|
||||
lseek(fd, fpos, SEEK_SET);
|
||||
write(fd, xingbuf, 417);
|
||||
close(fd);
|
||||
|
||||
xingupdate(100);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Not a VBR file */
|
||||
DEBUGF("Not a VBR file\n");
|
||||
splash(HZ*2, 0, true, "Not a VBR file");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue