2007-05-07 17:23:31 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2007-05-10 21:56:34 +00:00
|
|
|
* $Id$
|
2007-05-07 17:23:31 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Dave Chapman
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-05-07 17:23:31 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "plugin.h"
|
2012-01-26 23:15:15 +00:00
|
|
|
#include "lib/pluginlib_touchscreen.h"
|
|
|
|
#include "lib/pluginlib_exit.h"
|
2007-05-07 17:23:31 +00:00
|
|
|
|
2008-03-22 10:24:28 +00:00
|
|
|
/* All swcodec targets have BUTTON_SELECT apart from the H10 and M3 */
|
2007-05-23 20:51:47 +00:00
|
|
|
|
|
|
|
#if CONFIG_KEYPAD == IRIVER_H10_PAD
|
|
|
|
#define TESTCODEC_EXITBUTTON BUTTON_RIGHT
|
2008-03-22 10:24:28 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
|
|
|
|
#define TESTCODEC_EXITBUTTON BUTTON_RC_PLAY
|
2009-08-04 03:08:32 +00:00
|
|
|
#elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
|
|
|
|
#define TESTCODEC_EXITBUTTON BUTTON_PLAY
|
2010-12-02 20:25:04 +00:00
|
|
|
#elif CONFIG_KEYPAD == COWON_D2_PAD || CONFIG_KEYPAD == ONDAVX747_PAD \
|
|
|
|
|| CONFIG_KEYPAD == PHILIPS_HDD6330_PAD
|
2008-06-23 17:47:09 +00:00
|
|
|
#define TESTCODEC_EXITBUTTON BUTTON_POWER
|
2010-02-14 21:56:53 +00:00
|
|
|
#elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
|
|
|
|
#define TESTCODEC_EXITBUTTON BUTTON_REC
|
2010-11-30 10:52:14 +00:00
|
|
|
#elif CONFIG_KEYPAD == MPIO_HD200_PAD
|
|
|
|
#define TESTCODEC_EXITBUTTON (BUTTON_REC | BUTTON_PLAY)
|
|
|
|
#elif CONFIG_KEYPAD == MPIO_HD300_PAD
|
|
|
|
#define TESTCODEC_EXITBUTTON (BUTTON_REC | BUTTON_REPEAT)
|
2011-09-06 12:39:49 +00:00
|
|
|
#elif CONFIG_KEYPAD == RK27XX_GENERIC_PAD
|
|
|
|
#define TESTCODEC_EXITBUTTON (BUTTON_M | BUTTON_REPEAT)
|
Initial commit of the Samsung YP-R0 port.
This port is a hybrid native/RaaA port. It runs on a embedded linux system,
but is the only application. It therefore can implement lots of stuff that
native targets also implement, while leveraging the underlying linux kernel.
The port is quite advanced. User interface, audio playback, plugins work
mostly fine. Missing is e.g. power mangement and USB (see SamsungYPR0 wiki page).
Included in utils/ypr0tools are scripts and programs required to generate
a patched firmware. The patched firmware has the rootfs modified to load
Rockbox. It includes a early/safe USB mode.
This port needs a new toolchain, one that includes glibc headers and libraries.
rockboxdev.sh can generate it, but e.g. codesourcey and distro packages may
also work.
Most of the initial effort is done by Lorenzo Miori and others (on ABI),
including reverse engineering and patching of the original firmware,
initial drivers, and more. Big thanks to you.
Flyspray: FS#12348
Author: Lorenzo Miori, myself
Merry christmas to ypr0 owners! :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31415 a1c6a512-1295-4272-9138-f99709370657
2011-12-24 11:56:46 +00:00
|
|
|
#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
|
|
|
|
#define TESTCODEC_EXITBUTTON BUTTON_BACK
|
2009-11-07 22:56:00 +00:00
|
|
|
#elif defined(HAVE_TOUCHSCREEN)
|
2012-01-26 23:15:15 +00:00
|
|
|
#define TESTCODEC_EXITBUTTON (BUTTON_BOTTOMMIDDLE|BUTTON_REL)
|
2007-05-23 20:51:47 +00:00
|
|
|
#else
|
|
|
|
#define TESTCODEC_EXITBUTTON BUTTON_SELECT
|
|
|
|
#endif
|
|
|
|
|
2010-11-22 02:22:56 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
static unsigned int boost =1;
|
|
|
|
|
|
|
|
static const struct opt_items boost_settings[2] = {
|
|
|
|
{ "No", -1 },
|
|
|
|
{ "Yes", -1 },
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2007-06-19 00:25:36 +00:00
|
|
|
/* Log functions copied from test_disk.c */
|
|
|
|
static int line = 0;
|
|
|
|
static int max_line = 0;
|
|
|
|
static int log_fd = -1;
|
|
|
|
|
2010-05-31 21:07:25 +00:00
|
|
|
static void log_close(void)
|
|
|
|
{
|
|
|
|
if (log_fd >= 0)
|
|
|
|
rb->close(log_fd);
|
|
|
|
}
|
|
|
|
|
2007-06-19 00:25:36 +00:00
|
|
|
static bool log_init(bool use_logfile)
|
|
|
|
{
|
|
|
|
int h;
|
2010-06-22 10:43:45 +00:00
|
|
|
char logfilename[MAX_PATH];
|
2007-06-19 00:25:36 +00:00
|
|
|
|
|
|
|
rb->lcd_getstringsize("A", NULL, &h);
|
|
|
|
max_line = LCD_HEIGHT / h;
|
|
|
|
line = 0;
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->lcd_update();
|
|
|
|
|
|
|
|
if (use_logfile) {
|
2010-05-31 21:07:25 +00:00
|
|
|
log_close();
|
2011-12-25 20:11:18 +00:00
|
|
|
rb->create_numbered_filename(logfilename, HOME_DIR, "test_codec_log_", ".txt",
|
2007-06-19 00:25:36 +00:00
|
|
|
2 IF_CNFN_NUM_(, NULL));
|
2010-05-06 17:35:13 +00:00
|
|
|
log_fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666);
|
2007-06-19 00:25:36 +00:00
|
|
|
return log_fd >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void log_text(char *text, bool advance)
|
|
|
|
{
|
|
|
|
rb->lcd_puts(0, line, text);
|
|
|
|
rb->lcd_update();
|
|
|
|
if (advance)
|
|
|
|
{
|
|
|
|
if (++line >= max_line)
|
|
|
|
line = 0;
|
|
|
|
if (log_fd >= 0)
|
|
|
|
rb->fdprintf(log_fd, "%s\n", text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-13 00:11:25 +00:00
|
|
|
struct wavinfo_t
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int samplerate;
|
|
|
|
int channels;
|
|
|
|
int sampledepth;
|
|
|
|
int stereomode;
|
|
|
|
int totalsamples;
|
|
|
|
};
|
|
|
|
|
2007-05-07 17:23:31 +00:00
|
|
|
static void* audiobuf;
|
|
|
|
static void* codec_mallocbuf;
|
|
|
|
static size_t audiosize;
|
2010-07-06 00:11:30 +00:00
|
|
|
static size_t audiobufsize;
|
|
|
|
static int offset;
|
|
|
|
static int fd;
|
2007-05-07 17:23:31 +00:00
|
|
|
|
|
|
|
/* Our local implementation of the codec API */
|
|
|
|
static struct codec_api ci;
|
|
|
|
|
2007-11-12 22:10:36 +00:00
|
|
|
struct test_track_info {
|
|
|
|
struct mp3entry id3; /* TAG metadata */
|
|
|
|
size_t filesize; /* File total length */
|
|
|
|
};
|
|
|
|
|
2007-10-02 07:47:43 +00:00
|
|
|
static struct test_track_info track;
|
2007-05-07 17:23:31 +00:00
|
|
|
|
2009-08-12 18:12:25 +00:00
|
|
|
static bool use_dsp;
|
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
static bool checksum;
|
|
|
|
static uint32_t crc32;
|
|
|
|
|
2007-05-07 22:30:23 +00:00
|
|
|
static volatile unsigned int elapsed;
|
|
|
|
static volatile bool codec_playing;
|
2011-05-15 01:41:25 +00:00
|
|
|
static volatile enum codec_command_action codec_action;
|
2008-11-23 23:54:27 +00:00
|
|
|
static volatile long endtick;
|
2010-07-06 00:11:30 +00:00
|
|
|
static volatile long rebuffertick;
|
2007-05-13 00:11:25 +00:00
|
|
|
struct wavinfo_t wavinfo;
|
|
|
|
|
|
|
|
static unsigned char wav_header[44] =
|
|
|
|
{
|
|
|
|
'R','I','F','F', // 0 - ChunkID
|
|
|
|
0,0,0,0, // 4 - ChunkSize (filesize-8)
|
|
|
|
'W','A','V','E', // 8 - Format
|
|
|
|
'f','m','t',' ', // 12 - SubChunkID
|
|
|
|
16,0,0,0, // 16 - SubChunk1ID // 16 for PCM
|
|
|
|
1,0, // 20 - AudioFormat (1=16-bit)
|
|
|
|
0,0, // 22 - NumChannels
|
|
|
|
0,0,0,0, // 24 - SampleRate in Hz
|
|
|
|
0,0,0,0, // 28 - Byte Rate (SampleRate*NumChannels*(BitsPerSample/8)
|
|
|
|
0,0, // 32 - BlockAlign (== NumChannels * BitsPerSample/8)
|
|
|
|
16,0, // 34 - BitsPerSample
|
|
|
|
'd','a','t','a', // 36 - Subchunk2ID
|
|
|
|
0,0,0,0 // 40 - Subchunk2Size
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void int2le32(unsigned char* buf, int32_t x)
|
|
|
|
{
|
|
|
|
buf[0] = (x & 0xff);
|
|
|
|
buf[1] = (x & 0xff00) >> 8;
|
|
|
|
buf[2] = (x & 0xff0000) >> 16;
|
|
|
|
buf[3] = (x & 0xff000000) >>24;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void int2le24(unsigned char* buf, int32_t x)
|
|
|
|
{
|
|
|
|
buf[0] = (x & 0xff);
|
|
|
|
buf[1] = (x & 0xff00) >> 8;
|
|
|
|
buf[2] = (x & 0xff0000) >> 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void int2le16(unsigned char* buf, int16_t x)
|
|
|
|
{
|
|
|
|
buf[0] = (x & 0xff);
|
|
|
|
buf[1] = (x & 0xff00) >> 8;
|
|
|
|
}
|
|
|
|
|
2010-06-22 10:43:50 +00:00
|
|
|
static unsigned char *wavbuffer;
|
|
|
|
static unsigned char *dspbuffer;
|
2009-08-12 18:12:25 +00:00
|
|
|
|
2007-05-13 00:11:25 +00:00
|
|
|
void init_wav(char* filename)
|
|
|
|
{
|
|
|
|
wavinfo.totalsamples = 0;
|
|
|
|
|
2010-05-06 17:35:04 +00:00
|
|
|
wavinfo.fd = rb->creat(filename, 0666);
|
2007-05-13 00:11:25 +00:00
|
|
|
|
|
|
|
if (wavinfo.fd >= 0)
|
|
|
|
{
|
|
|
|
/* Write WAV header - we go back and fill in the details at the end */
|
|
|
|
rb->write(wavinfo.fd, wav_header, sizeof(wav_header));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
void close_wav(void)
|
|
|
|
{
|
|
|
|
int filesize = rb->filesize(wavinfo.fd);
|
|
|
|
int channels = (wavinfo.stereomode == STEREO_MONO) ? 1 : 2;
|
|
|
|
int bps = 16; /* TODO */
|
2007-05-13 00:11:25 +00:00
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
/* We assume 16-bit, Stereo */
|
2007-05-13 00:11:25 +00:00
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
rb->lseek(wavinfo.fd,0,SEEK_SET);
|
2007-05-13 00:11:25 +00:00
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
int2le32(wav_header+4, filesize-8); /* ChunkSize */
|
2007-05-13 00:11:25 +00:00
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
int2le16(wav_header+22, channels);
|
2007-05-13 00:11:25 +00:00
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
int2le32(wav_header+24, wavinfo.samplerate);
|
2007-05-13 00:11:25 +00:00
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
int2le32(wav_header+28, wavinfo.samplerate * channels * (bps / 8)); /* ByteRate */
|
2007-05-13 00:11:25 +00:00
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
int2le16(wav_header+32, channels * (bps / 8));
|
2007-05-13 00:11:25 +00:00
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
int2le32(wav_header+40, filesize - 44); /* Subchunk2Size */
|
2007-05-13 00:11:25 +00:00
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
rb->write(wavinfo.fd, wav_header, sizeof(wav_header));
|
2007-05-13 00:11:25 +00:00
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
rb->close(wavinfo.fd);
|
2007-05-13 00:11:25 +00:00
|
|
|
}
|
2007-05-07 17:23:31 +00:00
|
|
|
|
|
|
|
/* Returns buffer to malloc array. Only codeclib should need this. */
|
2008-10-22 18:42:55 +00:00
|
|
|
static void* codec_get_buffer(size_t *size)
|
2007-05-07 17:23:31 +00:00
|
|
|
{
|
2008-10-22 18:42:55 +00:00
|
|
|
*size = CODEC_SIZE;
|
2007-05-07 17:23:31 +00:00
|
|
|
return codec_mallocbuf;
|
|
|
|
}
|
|
|
|
|
2009-08-12 18:12:25 +00:00
|
|
|
static int process_dsp(const void *ch1, const void *ch2, int count)
|
|
|
|
{
|
|
|
|
const char *src[2] = { ch1, ch2 };
|
|
|
|
int written_count = 0;
|
|
|
|
char *dest = dspbuffer;
|
|
|
|
|
|
|
|
while (count > 0)
|
|
|
|
{
|
|
|
|
int out_count = rb->dsp_output_count(ci.dsp, count);
|
|
|
|
|
|
|
|
int inp_count = rb->dsp_input_count(ci.dsp, out_count);
|
|
|
|
|
|
|
|
if (inp_count <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (inp_count > count)
|
|
|
|
inp_count = count;
|
|
|
|
|
|
|
|
out_count = rb->dsp_process(ci.dsp, dest, src, inp_count);
|
|
|
|
|
|
|
|
if (out_count <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
written_count += out_count;
|
|
|
|
dest += out_count * 4;
|
|
|
|
|
|
|
|
count -= inp_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return written_count;
|
|
|
|
}
|
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
static inline int32_t clip_sample(int32_t sample)
|
|
|
|
{
|
|
|
|
if ((int16_t)sample != sample)
|
|
|
|
sample = 0x7fff ^ (sample >> 31);
|
|
|
|
|
|
|
|
return sample;
|
|
|
|
}
|
|
|
|
|
2007-05-13 00:11:25 +00:00
|
|
|
/* Null output */
|
2009-11-11 07:02:18 +00:00
|
|
|
static void pcmbuf_insert_null(const void *ch1, const void *ch2, int count)
|
2007-05-07 17:23:31 +00:00
|
|
|
{
|
2009-11-22 18:48:07 +00:00
|
|
|
if (use_dsp)
|
|
|
|
process_dsp(ch1, ch2, count);
|
2007-05-07 17:23:31 +00:00
|
|
|
|
2007-06-19 00:25:36 +00:00
|
|
|
/* Prevent idle poweroff */
|
|
|
|
rb->reset_poweroff_timer();
|
2007-05-07 17:23:31 +00:00
|
|
|
}
|
|
|
|
|
2010-07-06 00:11:30 +00:00
|
|
|
/*
|
|
|
|
* Helper function used when the file is larger then the available memory.
|
|
|
|
* Rebuffers the file by setting the start of the audio buffer to be
|
|
|
|
* new_offset and filling from there.
|
|
|
|
*/
|
|
|
|
static int fill_buffer(int new_offset){
|
|
|
|
size_t n, bytestoread;
|
|
|
|
long temp = *rb->current_tick;
|
|
|
|
rb->lseek(fd,new_offset,SEEK_SET);
|
|
|
|
|
|
|
|
if(new_offset + audiobufsize <= track.filesize)
|
|
|
|
bytestoread = audiobufsize;
|
|
|
|
else
|
|
|
|
bytestoread = track.filesize-new_offset;
|
|
|
|
|
|
|
|
n = rb->read(fd, audiobuf,bytestoread);
|
|
|
|
|
|
|
|
if (n != bytestoread)
|
|
|
|
{
|
|
|
|
log_text("Read failed.",true);
|
|
|
|
DEBUGF("read fail: got %d bytes, expected %d\n", (int)n, (int)audiobufsize);
|
|
|
|
rb->backlight_on();
|
|
|
|
|
|
|
|
if (fd >= 0)
|
|
|
|
{
|
|
|
|
rb->close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
offset = new_offset;
|
|
|
|
|
|
|
|
/*keep track of how much time we spent buffering*/
|
|
|
|
rebuffertick += *rb->current_tick-temp;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-08 12:08:29 +00:00
|
|
|
/* WAV output or calculate crc32 of output*/
|
|
|
|
static void pcmbuf_insert_wav_checksum(const void *ch1, const void *ch2, int count)
|
2007-05-13 00:11:25 +00:00
|
|
|
{
|
|
|
|
const int16_t* data1_16;
|
|
|
|
const int16_t* data2_16;
|
|
|
|
const int32_t* data1_32;
|
|
|
|
const int32_t* data2_32;
|
|
|
|
unsigned char* p = wavbuffer;
|
2007-08-29 14:32:52 +00:00
|
|
|
const int scale = wavinfo.sampledepth - 15;
|
|
|
|
const int dc_bias = 1 << (scale - 1);
|
2009-08-12 18:12:25 +00:00
|
|
|
int channels = (wavinfo.stereomode == STEREO_MONO) ? 1 : 2;
|
2007-05-13 00:11:25 +00:00
|
|
|
|
2007-06-19 00:25:36 +00:00
|
|
|
/* Prevent idle poweroff */
|
|
|
|
rb->reset_poweroff_timer();
|
|
|
|
|
2009-08-12 18:12:25 +00:00
|
|
|
if (use_dsp) {
|
|
|
|
count = process_dsp(ch1, ch2, count);
|
|
|
|
wavinfo.totalsamples += count;
|
|
|
|
if (channels == 1)
|
|
|
|
{
|
|
|
|
unsigned char *s = dspbuffer, *d = dspbuffer;
|
|
|
|
int c = count;
|
|
|
|
while (c-- > 0)
|
|
|
|
{
|
|
|
|
*d++ = *s++;
|
|
|
|
*d++ = *s++;
|
|
|
|
s++;
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
2010-03-08 12:08:29 +00:00
|
|
|
if (checksum)
|
|
|
|
crc32 = rb->crc_32(dspbuffer, count * 2 * channels, crc32);
|
|
|
|
else
|
|
|
|
rb->write(wavinfo.fd, dspbuffer, count * 2 * channels);
|
2009-11-22 18:48:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (wavinfo.sampledepth <= 16) {
|
|
|
|
data1_16 = ch1;
|
|
|
|
data2_16 = ch2;
|
2007-05-13 00:11:25 +00:00
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
switch(wavinfo.stereomode)
|
|
|
|
{
|
|
|
|
case STEREO_INTERLEAVED:
|
|
|
|
while (count--) {
|
|
|
|
int2le16(p,*data1_16++);
|
|
|
|
p += 2;
|
|
|
|
int2le16(p,*data1_16++);
|
|
|
|
p += 2;
|
|
|
|
}
|
|
|
|
break;
|
2007-05-13 00:11:25 +00:00
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
case STEREO_NONINTERLEAVED:
|
|
|
|
while (count--) {
|
|
|
|
int2le16(p,*data1_16++);
|
|
|
|
p += 2;
|
|
|
|
int2le16(p,*data2_16++);
|
|
|
|
p += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STEREO_MONO:
|
|
|
|
while (count--) {
|
|
|
|
int2le16(p,*data1_16++);
|
|
|
|
p += 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
data1_32 = ch1;
|
|
|
|
data2_32 = ch2;
|
2007-05-13 00:11:25 +00:00
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
switch(wavinfo.stereomode)
|
|
|
|
{
|
|
|
|
case STEREO_INTERLEAVED:
|
|
|
|
while (count--) {
|
|
|
|
int2le16(p, clip_sample((*data1_32++ + dc_bias) >> scale));
|
|
|
|
p += 2;
|
|
|
|
int2le16(p, clip_sample((*data1_32++ + dc_bias) >> scale));
|
|
|
|
p += 2;
|
|
|
|
}
|
|
|
|
break;
|
2007-05-13 00:11:25 +00:00
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
case STEREO_NONINTERLEAVED:
|
|
|
|
while (count--) {
|
|
|
|
int2le16(p, clip_sample((*data1_32++ + dc_bias) >> scale));
|
|
|
|
p += 2;
|
|
|
|
int2le16(p, clip_sample((*data2_32++ + dc_bias) >> scale));
|
|
|
|
p += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STEREO_MONO:
|
|
|
|
while (count--) {
|
|
|
|
int2le16(p, clip_sample((*data1_32++ + dc_bias) >> scale));
|
|
|
|
p += 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-05-13 00:11:25 +00:00
|
|
|
}
|
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
wavinfo.totalsamples += count;
|
2010-03-08 12:08:29 +00:00
|
|
|
if (checksum)
|
|
|
|
crc32 = rb->crc_32(wavbuffer, p - wavbuffer, crc32);
|
|
|
|
else
|
|
|
|
rb->write(wavinfo.fd, wavbuffer, p - wavbuffer);
|
2009-08-12 18:12:25 +00:00
|
|
|
} /* else */
|
2007-05-13 00:11:25 +00:00
|
|
|
}
|
|
|
|
|
2007-05-07 17:23:31 +00:00
|
|
|
/* Set song position in WPS (value in ms). */
|
2009-11-05 17:32:32 +00:00
|
|
|
static void set_elapsed(unsigned long value)
|
2007-05-07 17:23:31 +00:00
|
|
|
{
|
2007-05-07 22:30:23 +00:00
|
|
|
elapsed = value;
|
2011-04-27 03:08:23 +00:00
|
|
|
ci.id3->elapsed = value;
|
2007-05-07 17:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Read next <size> amount bytes from file buffer to <ptr>.
|
|
|
|
Will return number of bytes read or 0 if end of file. */
|
2008-03-28 12:51:33 +00:00
|
|
|
static size_t read_filebuf(void *ptr, size_t size)
|
2007-05-07 17:23:31 +00:00
|
|
|
{
|
|
|
|
if (ci.curpos > (off_t)track.filesize)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
} else {
|
2010-07-06 00:11:30 +00:00
|
|
|
size_t realsize = MIN(track.filesize-ci.curpos,size);
|
|
|
|
|
|
|
|
/* check if we have enough bytes ready*/
|
|
|
|
if(realsize >(audiobufsize - (ci.curpos-offset)))
|
|
|
|
{
|
|
|
|
/*rebuffer so that we start at ci.curpos*/
|
|
|
|
fill_buffer(ci.curpos);
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->memcpy(ptr, audiobuf + (ci.curpos-offset), realsize);
|
|
|
|
ci.curpos += realsize;
|
|
|
|
return realsize;
|
2007-05-07 17:23:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Request pointer to file buffer which can be used to read
|
|
|
|
<realsize> amount of data. <reqsize> tells the buffer system
|
|
|
|
how much data it should try to allocate. If <realsize> is 0,
|
|
|
|
end of file is reached. */
|
2008-03-28 12:51:33 +00:00
|
|
|
static void* request_buffer(size_t *realsize, size_t reqsize)
|
2007-05-07 17:23:31 +00:00
|
|
|
{
|
|
|
|
*realsize = MIN(track.filesize-ci.curpos,reqsize);
|
|
|
|
|
2010-07-06 00:11:30 +00:00
|
|
|
/*check if we have enough bytes ready - requested > bufsize-currentbufpos*/
|
|
|
|
if(*realsize>(audiobufsize - (ci.curpos-offset)))
|
|
|
|
{
|
|
|
|
/*rebuffer so that we start at ci.curpos*/
|
|
|
|
fill_buffer(ci.curpos);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (audiobuf + (ci.curpos-offset));
|
2007-05-07 17:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Advance file buffer position by <amount> amount of bytes. */
|
2008-03-28 12:51:33 +00:00
|
|
|
static void advance_buffer(size_t amount)
|
2007-05-07 17:23:31 +00:00
|
|
|
{
|
|
|
|
ci.curpos += amount;
|
2011-04-27 03:08:23 +00:00
|
|
|
ci.id3->offset = ci.curpos;
|
2007-05-07 17:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Seek file buffer to position <newpos> beginning of file. */
|
2008-03-28 12:51:33 +00:00
|
|
|
static bool seek_buffer(size_t newpos)
|
2007-05-07 17:23:31 +00:00
|
|
|
{
|
|
|
|
ci.curpos = newpos;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Codec should call this function when it has done the seeking. */
|
|
|
|
static void seek_complete(void)
|
|
|
|
{
|
|
|
|
/* Do nothing */
|
|
|
|
}
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Codec calls this to know what it should do next. */
|
|
|
|
static enum codec_command_action get_command(intptr_t *param)
|
2007-05-07 17:23:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
rb->yield();
|
2011-05-15 01:41:25 +00:00
|
|
|
return codec_action;
|
2011-04-27 03:08:23 +00:00
|
|
|
(void)param;
|
2007-05-07 17:23:31 +00:00
|
|
|
}
|
|
|
|
|
2011-08-30 19:40:09 +00:00
|
|
|
/* Some codecs call this to determine whether they should loop. */
|
|
|
|
static bool loop_track(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-03-28 12:51:33 +00:00
|
|
|
static void set_offset(size_t value)
|
2007-05-07 17:23:31 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
ci.id3->offset = value;
|
2007-05-07 17:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Configure different codec buffer parameters. */
|
|
|
|
static void configure(int setting, intptr_t value)
|
|
|
|
{
|
2009-08-12 18:12:25 +00:00
|
|
|
if (use_dsp)
|
|
|
|
rb->dsp_configure(ci.dsp, setting, value);
|
2007-05-13 00:11:25 +00:00
|
|
|
switch(setting)
|
|
|
|
{
|
|
|
|
case DSP_SWITCH_FREQUENCY:
|
|
|
|
case DSP_SET_FREQUENCY:
|
|
|
|
DEBUGF("samplerate=%d\n",(int)value);
|
|
|
|
wavinfo.samplerate = (int)value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DSP_SET_SAMPLE_DEPTH:
|
|
|
|
DEBUGF("sampledepth = %d\n",(int)value);
|
|
|
|
wavinfo.sampledepth=(int)value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DSP_SET_STEREO_MODE:
|
|
|
|
DEBUGF("Stereo mode = %d\n",(int)value);
|
|
|
|
wavinfo.stereomode=(int)value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-05-07 17:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void init_ci(void)
|
|
|
|
{
|
|
|
|
/* --- Our "fake" implementations of the codec API functions. --- */
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
ci.dsp = (struct dsp_config *)rb->dsp_configure(NULL, DSP_MYDSP,
|
|
|
|
CODEC_IDX_AUDIO);
|
|
|
|
|
2008-10-22 18:42:55 +00:00
|
|
|
ci.codec_get_buffer = codec_get_buffer;
|
2007-05-13 00:11:25 +00:00
|
|
|
|
2010-03-08 12:08:29 +00:00
|
|
|
if (wavinfo.fd >= 0 || checksum) {
|
|
|
|
ci.pcmbuf_insert = pcmbuf_insert_wav_checksum;
|
2007-05-13 00:11:25 +00:00
|
|
|
} else {
|
|
|
|
ci.pcmbuf_insert = pcmbuf_insert_null;
|
|
|
|
}
|
2009-11-22 18:48:07 +00:00
|
|
|
|
2007-05-07 17:23:31 +00:00
|
|
|
ci.set_elapsed = set_elapsed;
|
|
|
|
ci.read_filebuf = read_filebuf;
|
|
|
|
ci.request_buffer = request_buffer;
|
|
|
|
ci.advance_buffer = advance_buffer;
|
|
|
|
ci.seek_buffer = seek_buffer;
|
|
|
|
ci.seek_complete = seek_complete;
|
|
|
|
ci.set_offset = set_offset;
|
|
|
|
ci.configure = configure;
|
2011-04-27 03:08:23 +00:00
|
|
|
ci.get_command = get_command;
|
2011-08-30 19:40:09 +00:00
|
|
|
ci.loop_track = loop_track;
|
2007-05-07 17:23:31 +00:00
|
|
|
|
|
|
|
/* --- "Core" functions --- */
|
|
|
|
|
|
|
|
/* kernel/ system */
|
2009-01-08 22:37:51 +00:00
|
|
|
ci.sleep = rb->sleep;
|
2007-05-07 17:23:31 +00:00
|
|
|
ci.yield = rb->yield;
|
|
|
|
|
|
|
|
/* strings and memory */
|
|
|
|
ci.strcpy = rb->strcpy;
|
|
|
|
ci.strlen = rb->strlen;
|
|
|
|
ci.strcmp = rb->strcmp;
|
|
|
|
ci.strcat = rb->strcat;
|
|
|
|
ci.memset = rb->memset;
|
|
|
|
ci.memcpy = rb->memcpy;
|
|
|
|
ci.memmove = rb->memmove;
|
|
|
|
ci.memcmp = rb->memcmp;
|
|
|
|
ci.memchr = rb->memchr;
|
|
|
|
#if defined(DEBUG) || defined(SIMULATOR)
|
|
|
|
ci.debugf = rb->debugf;
|
|
|
|
#endif
|
|
|
|
#ifdef ROCKBOX_HAS_LOGF
|
|
|
|
ci.logf = rb->logf;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ci.qsort = rb->qsort;
|
|
|
|
|
|
|
|
#ifdef RB_PROFILE
|
|
|
|
ci.profile_thread = rb->profile_thread;
|
|
|
|
ci.profstop = rb->profstop;
|
|
|
|
ci.profile_func_enter = rb->profile_func_enter;
|
|
|
|
ci.profile_func_exit = rb->profile_func_exit;
|
|
|
|
#endif
|
2007-10-08 18:17:46 +00:00
|
|
|
|
2011-12-17 13:43:54 +00:00
|
|
|
ci.commit_dcache = rb->commit_dcache;
|
|
|
|
ci.commit_discard_dcache = rb->commit_discard_dcache;
|
|
|
|
ci.commit_discard_idcache = rb->commit_discard_idcache;
|
2008-09-20 22:13:39 +00:00
|
|
|
|
|
|
|
#if NUM_CORES > 1
|
|
|
|
ci.create_thread = rb->create_thread;
|
|
|
|
ci.thread_thaw = rb->thread_thaw;
|
|
|
|
ci.thread_wait = rb->thread_wait;
|
|
|
|
ci.semaphore_init = rb->semaphore_init;
|
|
|
|
ci.semaphore_wait = rb->semaphore_wait;
|
|
|
|
ci.semaphore_release = rb->semaphore_release;
|
|
|
|
#endif
|
|
|
|
|
2010-10-10 14:43:40 +00:00
|
|
|
#if defined(CPU_ARM) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
|
2009-01-24 03:47:09 +00:00
|
|
|
ci.__div0 = rb->__div0;
|
|
|
|
#endif
|
2007-05-07 17:23:31 +00:00
|
|
|
}
|
|
|
|
|
2007-05-07 22:30:23 +00:00
|
|
|
static void codec_thread(void)
|
|
|
|
{
|
|
|
|
const char* codecname;
|
2011-04-27 03:08:23 +00:00
|
|
|
int res;
|
2007-05-07 22:30:23 +00:00
|
|
|
|
|
|
|
codecname = rb->get_codec_filename(track.id3.codectype);
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Load the codec */
|
|
|
|
res = rb->codec_load_file(codecname, &ci);
|
2011-02-23 14:31:13 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
if (res >= 0)
|
2011-02-23 14:31:13 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Decode the file */
|
|
|
|
res = rb->codec_run_proc();
|
2011-02-23 14:31:13 +00:00
|
|
|
}
|
2007-05-07 22:30:23 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Clean up */
|
|
|
|
rb->codec_close();
|
|
|
|
|
2007-05-07 22:30:23 +00:00
|
|
|
/* Signal to the main thread that we are done */
|
2010-07-06 00:11:30 +00:00
|
|
|
endtick = *rb->current_tick - rebuffertick;
|
2007-05-07 22:30:23 +00:00
|
|
|
codec_playing = false;
|
|
|
|
}
|
|
|
|
|
2008-05-13 12:03:07 +00:00
|
|
|
static enum plugin_status test_track(const char* filename)
|
2007-05-07 17:23:31 +00:00
|
|
|
{
|
|
|
|
size_t n;
|
2007-12-15 13:54:58 +00:00
|
|
|
enum plugin_status res = PLUGIN_ERROR;
|
2008-11-23 23:54:27 +00:00
|
|
|
long starttick;
|
|
|
|
long ticks;
|
2007-05-07 17:23:31 +00:00
|
|
|
unsigned long speed;
|
|
|
|
unsigned long duration;
|
2008-05-13 12:03:07 +00:00
|
|
|
const char* ch;
|
2010-06-22 10:43:45 +00:00
|
|
|
char str[MAX_PATH];
|
2010-07-06 00:11:30 +00:00
|
|
|
offset=0;
|
2007-05-07 23:54:10 +00:00
|
|
|
|
2007-06-19 00:25:36 +00:00
|
|
|
/* Display filename (excluding any path)*/
|
|
|
|
ch = rb->strrchr(filename, '/');
|
|
|
|
if (ch==NULL)
|
|
|
|
ch = filename;
|
|
|
|
else
|
|
|
|
ch++;
|
2007-05-07 22:30:23 +00:00
|
|
|
|
2007-06-19 00:25:36 +00:00
|
|
|
rb->snprintf(str,sizeof(str),"%s",ch);
|
|
|
|
log_text(str,true);
|
2007-05-07 22:30:23 +00:00
|
|
|
|
2007-06-19 00:25:36 +00:00
|
|
|
log_text("Loading...",false);
|
2007-05-07 22:30:23 +00:00
|
|
|
|
2007-06-19 00:25:36 +00:00
|
|
|
fd = rb->open(filename,O_RDONLY);
|
2007-05-07 17:23:31 +00:00
|
|
|
if (fd < 0)
|
|
|
|
{
|
2007-06-19 00:25:36 +00:00
|
|
|
log_text("Cannot open file",true);
|
2007-12-15 13:54:58 +00:00
|
|
|
goto exit;
|
2007-05-07 17:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
track.filesize = rb->filesize(fd);
|
|
|
|
|
2007-06-19 00:25:36 +00:00
|
|
|
/* Clear the id3 struct */
|
|
|
|
rb->memset(&track.id3, 0, sizeof(struct mp3entry));
|
|
|
|
|
2007-09-19 10:40:55 +00:00
|
|
|
if (!rb->get_metadata(&(track.id3), fd, filename))
|
2007-05-07 17:23:31 +00:00
|
|
|
{
|
2007-06-19 00:25:36 +00:00
|
|
|
log_text("Cannot read metadata",true);
|
2007-12-15 13:54:58 +00:00
|
|
|
goto exit;
|
2007-05-07 17:23:31 +00:00
|
|
|
}
|
2010-07-06 00:11:30 +00:00
|
|
|
|
2007-05-07 17:23:31 +00:00
|
|
|
if (track.filesize > audiosize)
|
|
|
|
{
|
2010-07-06 00:11:30 +00:00
|
|
|
audiobufsize=audiosize;
|
|
|
|
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
audiobufsize=track.filesize;
|
2007-05-07 17:23:31 +00:00
|
|
|
}
|
|
|
|
|
2010-07-06 00:11:30 +00:00
|
|
|
n = rb->read(fd, audiobuf, audiobufsize);
|
2007-05-07 17:23:31 +00:00
|
|
|
|
2010-07-06 00:11:30 +00:00
|
|
|
if (n != audiobufsize)
|
2007-05-07 17:23:31 +00:00
|
|
|
{
|
2007-06-19 00:25:36 +00:00
|
|
|
log_text("Read failed.",true);
|
2007-05-13 00:11:25 +00:00
|
|
|
goto exit;
|
2007-05-07 17:23:31 +00:00
|
|
|
}
|
2010-07-06 00:11:30 +00:00
|
|
|
|
2007-05-07 17:23:31 +00:00
|
|
|
|
|
|
|
/* Initialise the function pointers in the codec API */
|
|
|
|
init_ci();
|
|
|
|
|
|
|
|
/* Prepare the codec struct for playing the whole file */
|
|
|
|
ci.filesize = track.filesize;
|
|
|
|
ci.id3 = &track.id3;
|
|
|
|
ci.curpos = 0;
|
|
|
|
|
2009-08-12 18:12:25 +00:00
|
|
|
if (use_dsp)
|
|
|
|
rb->dsp_configure(ci.dsp, DSP_RESET, 0);
|
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
if (checksum)
|
|
|
|
crc32 = 0xffffffff;
|
|
|
|
|
2010-07-06 00:11:30 +00:00
|
|
|
rebuffertick=0;
|
2007-05-07 17:23:31 +00:00
|
|
|
starttick = *rb->current_tick;
|
|
|
|
|
2007-05-07 22:30:23 +00:00
|
|
|
codec_playing = true;
|
2011-05-15 01:41:25 +00:00
|
|
|
codec_action = CODEC_ACTION_NULL;
|
2007-05-07 17:23:31 +00:00
|
|
|
|
2009-01-05 10:31:19 +00:00
|
|
|
rb->codec_thread_do_callback(codec_thread, NULL);
|
2007-05-07 22:30:23 +00:00
|
|
|
|
|
|
|
/* Wait for codec thread to die */
|
|
|
|
while (codec_playing)
|
|
|
|
{
|
2011-05-15 01:41:25 +00:00
|
|
|
if (rb->button_get_w_tmo(HZ) == TESTCODEC_EXITBUTTON)
|
|
|
|
{
|
|
|
|
codec_action = CODEC_ACTION_HALT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-05-07 22:30:23 +00:00
|
|
|
rb->snprintf(str,sizeof(str),"%d of %d",elapsed,(int)track.id3.length);
|
2007-06-19 00:25:36 +00:00
|
|
|
log_text(str,false);
|
2007-05-07 22:30:23 +00:00
|
|
|
}
|
2008-11-23 23:54:27 +00:00
|
|
|
ticks = endtick - starttick;
|
2007-06-19 00:25:36 +00:00
|
|
|
|
2007-10-22 05:57:38 +00:00
|
|
|
/* Be sure it is done */
|
2009-01-05 10:31:19 +00:00
|
|
|
rb->codec_thread_do_callback(NULL, NULL);
|
2010-07-06 00:11:30 +00:00
|
|
|
rb->backlight_on();
|
2007-06-19 00:25:36 +00:00
|
|
|
log_text(str,true);
|
2011-05-15 01:41:25 +00:00
|
|
|
|
|
|
|
if (codec_action == CODEC_ACTION_HALT)
|
|
|
|
{
|
|
|
|
/* User aborted test */
|
|
|
|
}
|
|
|
|
else if (checksum)
|
2009-11-22 18:48:07 +00:00
|
|
|
{
|
2010-06-17 15:27:42 +00:00
|
|
|
rb->snprintf(str, sizeof(str), "CRC32 - %08x", (unsigned)crc32);
|
2009-11-22 18:48:07 +00:00
|
|
|
log_text(str,true);
|
|
|
|
}
|
|
|
|
else if (wavinfo.fd < 0)
|
2007-12-15 13:54:58 +00:00
|
|
|
{
|
2007-05-13 00:11:25 +00:00
|
|
|
/* Display benchmark information */
|
|
|
|
rb->snprintf(str,sizeof(str),"Decode time - %d.%02ds",(int)ticks/100,(int)ticks%100);
|
2007-06-19 00:25:36 +00:00
|
|
|
log_text(str,true);
|
2007-05-07 17:23:31 +00:00
|
|
|
|
2007-05-13 00:11:25 +00:00
|
|
|
duration = track.id3.length / 10;
|
|
|
|
rb->snprintf(str,sizeof(str),"File duration - %d.%02ds",(int)duration/100,(int)duration%100);
|
2007-06-19 00:25:36 +00:00
|
|
|
log_text(str,true);
|
2007-05-07 17:23:31 +00:00
|
|
|
|
2007-05-13 00:11:25 +00:00
|
|
|
if (ticks > 0)
|
|
|
|
speed = duration * 10000 / ticks;
|
|
|
|
else
|
|
|
|
speed = 0;
|
2007-05-07 17:23:31 +00:00
|
|
|
|
2007-05-13 00:11:25 +00:00
|
|
|
rb->snprintf(str,sizeof(str),"%d.%02d%% realtime",(int)speed/100,(int)speed%100);
|
2007-06-19 00:25:36 +00:00
|
|
|
log_text(str,true);
|
2008-06-04 06:07:43 +00:00
|
|
|
|
2010-06-21 16:53:00 +00:00
|
|
|
#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
|
2008-06-04 06:07:43 +00:00
|
|
|
/* show effective clockrate in MHz needed for realtime decoding */
|
|
|
|
if (speed > 0)
|
|
|
|
{
|
2010-11-22 02:22:56 +00:00
|
|
|
int freq = CPUFREQ_MAX;
|
|
|
|
|
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
if(!boost)
|
|
|
|
freq = CPUFREQ_NORMAL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
speed = freq / speed;
|
2008-06-04 06:07:43 +00:00
|
|
|
rb->snprintf(str,sizeof(str),"%d.%02dMHz needed for realtime",
|
|
|
|
(int)speed/100,(int)speed%100);
|
|
|
|
log_text(str,true);
|
|
|
|
}
|
|
|
|
#endif
|
2007-06-19 00:25:36 +00:00
|
|
|
}
|
|
|
|
|
2007-12-15 13:54:58 +00:00
|
|
|
res = PLUGIN_OK;
|
2007-06-19 00:25:36 +00:00
|
|
|
|
|
|
|
exit:
|
2007-12-15 13:54:58 +00:00
|
|
|
rb->backlight_on();
|
|
|
|
|
|
|
|
if (fd >= 0)
|
|
|
|
{
|
|
|
|
rb->close(fd);
|
|
|
|
}
|
|
|
|
|
2007-06-19 00:25:36 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-01-26 23:15:15 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
void cleanup(void)
|
|
|
|
{
|
|
|
|
rb->screens[0]->set_viewport(NULL);
|
|
|
|
}
|
2012-01-29 20:47:56 +00:00
|
|
|
#endif
|
2012-01-26 23:15:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
static struct touchbutton button[] = {
|
|
|
|
{
|
|
|
|
.action = ACTION_STD_OK,
|
|
|
|
.title = "OK",
|
|
|
|
/* viewport runtime initialized, rest false/NULL */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void plugin_quit(void)
|
|
|
|
{
|
|
|
|
int btn;
|
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
struct viewport *vp = &button[0].vp;
|
|
|
|
struct screen *lcd = rb->screens[SCREEN_MAIN];
|
|
|
|
rb->viewport_set_defaults(vp, SCREEN_MAIN);
|
|
|
|
const int border = 10;
|
|
|
|
const int height = 50;
|
|
|
|
|
|
|
|
lcd->set_viewport(vp);
|
|
|
|
/* button matches the bottom center in the grid */
|
|
|
|
vp->x = lcd->lcdwidth/3;
|
|
|
|
vp->width = lcd->lcdwidth/3;
|
|
|
|
vp->height = height;
|
|
|
|
vp->y = lcd->lcdheight - height - border;
|
|
|
|
|
|
|
|
touchbutton_draw(button, ARRAYLEN(button));
|
|
|
|
lcd->update_viewport();
|
|
|
|
if (rb->touchscreen_get_mode() == TOUCHSCREEN_POINT)
|
|
|
|
{
|
|
|
|
while (codec_action != CODEC_ACTION_HALT &&
|
|
|
|
touchbutton_get(button, ARRAYLEN(button)) != ACTION_STD_OK);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
do {
|
|
|
|
btn = rb->button_get(true);
|
|
|
|
exit_on_usb(btn);
|
|
|
|
} while (codec_action != CODEC_ACTION_HALT && btn != TESTCODEC_EXITBUTTON);
|
|
|
|
}
|
|
|
|
|
2007-06-19 00:25:36 +00:00
|
|
|
/* plugin entry point */
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2007-06-19 00:25:36 +00:00
|
|
|
{
|
|
|
|
int result, selection = 0;
|
|
|
|
enum plugin_status res = PLUGIN_OK;
|
|
|
|
int scandir;
|
|
|
|
struct dirent *entry;
|
|
|
|
DIR* dir;
|
|
|
|
char* ch;
|
|
|
|
char dirpath[MAX_PATH];
|
|
|
|
char filename[MAX_PATH];
|
2010-06-22 10:43:50 +00:00
|
|
|
size_t buffer_size;
|
2007-06-19 00:25:36 +00:00
|
|
|
|
|
|
|
if (parameter == NULL)
|
|
|
|
{
|
|
|
|
rb->splash(HZ*2, "No File");
|
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
|
2010-06-22 10:43:50 +00:00
|
|
|
wavbuffer = rb->plugin_get_buffer(&buffer_size);
|
|
|
|
dspbuffer = wavbuffer + buffer_size / 2;
|
|
|
|
|
2007-10-19 09:11:23 +00:00
|
|
|
codec_mallocbuf = rb->plugin_get_audio_buffer(&audiosize);
|
2010-10-27 15:07:05 +00:00
|
|
|
/* Align codec_mallocbuf to pointer size, tlsf wants that */
|
|
|
|
codec_mallocbuf = (void*)(((intptr_t)codec_mallocbuf +
|
|
|
|
sizeof(intptr_t)-1) & ~(sizeof(intptr_t)-1));
|
2009-01-05 10:31:19 +00:00
|
|
|
audiobuf = SKIPBYTES(codec_mallocbuf, CODEC_SIZE);
|
|
|
|
audiosize -= CODEC_SIZE;
|
2007-06-19 00:25:36 +00:00
|
|
|
|
|
|
|
rb->lcd_clear_display();
|
2007-05-07 17:23:31 +00:00
|
|
|
rb->lcd_update();
|
|
|
|
|
2012-01-26 23:15:15 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
rb->touchscreen_set_mode(rb->global_settings->touch_mode);
|
|
|
|
#endif
|
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
enum
|
|
|
|
{
|
2011-08-29 13:48:31 +00:00
|
|
|
SPEED_TEST = 0,
|
2011-08-29 13:00:35 +00:00
|
|
|
SPEED_TEST_DIR,
|
2009-11-22 18:48:07 +00:00
|
|
|
WRITE_WAV,
|
|
|
|
SPEED_TEST_WITH_DSP,
|
|
|
|
SPEED_TEST_DIR_WITH_DSP,
|
|
|
|
WRITE_WAV_WITH_DSP,
|
|
|
|
CHECKSUM,
|
|
|
|
CHECKSUM_DIR,
|
|
|
|
QUIT,
|
2011-08-29 13:48:31 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
BOOST,
|
|
|
|
#endif
|
2009-11-22 18:48:07 +00:00
|
|
|
};
|
|
|
|
|
2007-06-19 00:25:36 +00:00
|
|
|
MENUITEM_STRINGLIST(
|
|
|
|
menu, "test_codec", NULL,
|
2011-08-29 13:00:35 +00:00
|
|
|
"Speed test",
|
|
|
|
"Speed test folder",
|
2007-06-19 00:25:36 +00:00
|
|
|
"Write WAV",
|
2009-09-23 14:56:32 +00:00
|
|
|
"Speed test with DSP",
|
|
|
|
"Speed test folder with DSP",
|
|
|
|
"Write WAV with DSP",
|
2009-11-22 18:48:07 +00:00
|
|
|
"Checksum",
|
|
|
|
"Checksum folder",
|
2009-08-12 18:12:25 +00:00
|
|
|
"Quit",
|
2011-08-29 13:48:31 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
"Boosting",
|
|
|
|
#endif
|
2007-06-19 00:25:36 +00:00
|
|
|
);
|
2010-11-22 02:22:56 +00:00
|
|
|
|
2007-06-19 00:25:36 +00:00
|
|
|
|
2009-08-12 18:12:25 +00:00
|
|
|
show_menu:
|
2007-06-19 00:25:36 +00:00
|
|
|
rb->lcd_clear_display();
|
|
|
|
|
2010-11-22 02:22:56 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
menu:
|
2010-11-22 02:28:12 +00:00
|
|
|
#endif
|
2007-06-19 00:25:36 +00:00
|
|
|
|
2010-11-22 02:28:12 +00:00
|
|
|
result = rb->do_menu(&menu, &selection, NULL, false);
|
2010-11-22 02:22:56 +00:00
|
|
|
|
2011-08-29 13:00:35 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2010-11-22 02:22:56 +00:00
|
|
|
if (result == BOOST)
|
|
|
|
{
|
|
|
|
rb->set_option("Boosting", &boost, INT,
|
|
|
|
boost_settings, 2, NULL);
|
|
|
|
goto menu;
|
|
|
|
}
|
2011-02-15 20:10:50 +00:00
|
|
|
if(boost)
|
|
|
|
rb->cpu_boost(true);
|
2010-11-22 02:22:56 +00:00
|
|
|
#endif
|
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
if (result == QUIT)
|
2009-08-12 18:12:25 +00:00
|
|
|
{
|
|
|
|
res = PLUGIN_OK;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2007-06-19 00:25:36 +00:00
|
|
|
scandir = 0;
|
|
|
|
|
2011-08-29 13:00:35 +00:00
|
|
|
/* Map test runs with checksum calcualtion to standard runs
|
|
|
|
* SPEED_TEST and SPEED_TEST_DIR and set the 'checksum' flag. */
|
|
|
|
if ((checksum = (result == CHECKSUM ||
|
|
|
|
result == CHECKSUM_DIR)))
|
2009-11-22 18:48:07 +00:00
|
|
|
result -= 6;
|
|
|
|
|
2011-08-29 13:00:35 +00:00
|
|
|
/* Map test runs with DSP to standard runs SPEED_TEST,
|
|
|
|
* SPEED_TEST_DIR and WRITE_WAV and set the 'use_dsp' flag. */
|
|
|
|
if ((use_dsp = (result >= SPEED_TEST_WITH_DSP &&
|
|
|
|
result <= WRITE_WAV_WITH_DSP)))
|
2009-08-12 18:12:25 +00:00
|
|
|
result -= 3;
|
2011-08-29 13:00:35 +00:00
|
|
|
|
2009-11-22 18:48:07 +00:00
|
|
|
if (result == SPEED_TEST) {
|
2007-06-19 00:25:36 +00:00
|
|
|
wavinfo.fd = -1;
|
|
|
|
log_init(false);
|
2009-11-22 18:48:07 +00:00
|
|
|
} else if (result == SPEED_TEST_DIR) {
|
2007-06-19 00:25:36 +00:00
|
|
|
wavinfo.fd = -1;
|
|
|
|
scandir = 1;
|
|
|
|
|
|
|
|
/* Only create a log file when we are testing a folder */
|
|
|
|
if (!log_init(true)) {
|
|
|
|
rb->splash(HZ*2, "Cannot create logfile");
|
|
|
|
res = PLUGIN_ERROR;
|
|
|
|
goto exit;
|
|
|
|
}
|
2009-11-22 18:48:07 +00:00
|
|
|
} else if (result == WRITE_WAV) {
|
2007-06-19 00:25:36 +00:00
|
|
|
log_init(false);
|
|
|
|
init_wav("/test.wav");
|
|
|
|
if (wavinfo.fd < 0) {
|
|
|
|
rb->splash(HZ*2, "Cannot create /test.wav");
|
|
|
|
res = PLUGIN_ERROR;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
} else if (result == MENU_ATTACHED_USB) {
|
|
|
|
res = PLUGIN_USB_CONNECTED;
|
|
|
|
goto exit;
|
|
|
|
} else if (result < 0) {
|
|
|
|
res = PLUGIN_OK;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scandir) {
|
|
|
|
/* Test all files in the same directory as the file selected by the
|
|
|
|
user */
|
|
|
|
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(dirpath,parameter,sizeof(dirpath));
|
2007-06-19 00:25:36 +00:00
|
|
|
ch = rb->strrchr(dirpath,'/');
|
|
|
|
ch[1]=0;
|
|
|
|
|
|
|
|
DEBUGF("Scanning directory \"%s\"\n",dirpath);
|
|
|
|
dir = rb->opendir(dirpath);
|
|
|
|
if (dir) {
|
|
|
|
entry = rb->readdir(dir);
|
|
|
|
while (entry) {
|
2010-09-02 12:10:37 +00:00
|
|
|
struct dirinfo info = rb->dir_get_info(dir, entry);
|
|
|
|
if (!(info.attribute & ATTR_DIRECTORY)) {
|
2007-06-19 00:25:36 +00:00
|
|
|
rb->snprintf(filename,sizeof(filename),"%s%s",dirpath,entry->d_name);
|
|
|
|
test_track(filename);
|
2011-05-15 01:41:25 +00:00
|
|
|
|
|
|
|
if (codec_action == CODEC_ACTION_HALT)
|
|
|
|
break;
|
|
|
|
|
2007-12-15 13:54:58 +00:00
|
|
|
log_text("", true);
|
2007-06-19 00:25:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read next entry */
|
|
|
|
entry = rb->readdir(dir);
|
|
|
|
}
|
2007-12-15 13:54:58 +00:00
|
|
|
|
|
|
|
rb->closedir(dir);
|
2007-06-19 00:25:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Just test the file */
|
|
|
|
res = test_track(parameter);
|
|
|
|
|
2007-12-15 13:54:58 +00:00
|
|
|
/* Close WAV file (if there was one) */
|
|
|
|
if (wavinfo.fd >= 0) {
|
|
|
|
close_wav();
|
|
|
|
log_text("Wrote /test.wav",true);
|
|
|
|
}
|
2007-06-19 00:25:36 +00:00
|
|
|
}
|
2012-01-26 23:15:15 +00:00
|
|
|
plugin_quit();
|
2010-11-22 02:22:56 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
if(boost)
|
|
|
|
rb->cpu_boost(false);
|
|
|
|
#endif
|
|
|
|
|
2010-05-31 21:07:25 +00:00
|
|
|
rb->button_clear_queue();
|
2009-08-12 18:12:25 +00:00
|
|
|
goto show_menu;
|
2007-05-07 17:23:31 +00:00
|
|
|
|
2007-05-07 22:30:23 +00:00
|
|
|
exit:
|
2007-06-19 00:25:36 +00:00
|
|
|
log_close();
|
|
|
|
|
2007-05-13 00:11:25 +00:00
|
|
|
return res;
|
2007-05-07 17:23:31 +00:00
|
|
|
}
|