forked from len0rd/rockbox
Big Patch adds primarily: Samplerate and format selection to recording for SWCODEC. Supprort for samplerates changing in playback (just goes with the recording part inseparably). Samplerates to all encoders. Encoders can be configured individually on a menu specific to the encoder in the recording menu. File creation is delayed until flush time to reduce spinups when splitting. Misc: statusbar icons for numbers are individual digits to display any number. Audio buffer was rearranged to maximize memory available to recording and properly reinitialized when trashed. ColdFire PCM stuff moved to target tree to avoid a complicated mess when adding samplerate switching. Some needed API changes and to neaten up growing gap between hardware and software codecs.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11452 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
0b22795e26
commit
0f5cb94aa4
58 changed files with 4769 additions and 2781 deletions
|
@ -73,6 +73,9 @@ pcmbuf.c
|
|||
playback.c
|
||||
codecs.c
|
||||
dsp.c
|
||||
#ifdef HAVE_RECORDING
|
||||
enc_config.c
|
||||
#endif
|
||||
eq.c
|
||||
#if defined(CPU_COLDFIRE) && !defined(SIMULATOR)
|
||||
dsp_cf.S
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "sound.h"
|
||||
#include "database.h"
|
||||
#include "splash.h"
|
||||
#include "general.h"
|
||||
|
||||
#ifdef SIMULATOR
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
|
@ -104,6 +105,7 @@ struct codec_api ci = {
|
|||
PREFIX(remove),
|
||||
PREFIX(rename),
|
||||
PREFIX(ftruncate),
|
||||
PREFIX(fsync),
|
||||
fdprintf,
|
||||
read_line,
|
||||
settings_parseline,
|
||||
|
@ -187,6 +189,7 @@ struct codec_api ci = {
|
|||
get_time,
|
||||
set_time,
|
||||
plugin_get_audio_buffer,
|
||||
round_value_to_list32,
|
||||
|
||||
#if defined(DEBUG) || defined(SIMULATOR)
|
||||
debugf,
|
||||
|
@ -213,11 +216,11 @@ struct codec_api ci = {
|
|||
false,
|
||||
enc_get_inputs,
|
||||
enc_set_parameters,
|
||||
enc_alloc_chunk,
|
||||
enc_free_chunk,
|
||||
enc_wavbuf_near_empty,
|
||||
enc_get_wav_data,
|
||||
&enc_set_header_callback,
|
||||
enc_get_chunk,
|
||||
enc_finish_chunk,
|
||||
enc_pcm_buf_near_empty,
|
||||
enc_get_pcm_data,
|
||||
enc_unget_pcm_data
|
||||
#endif
|
||||
|
||||
/* new stuff at the end, sort into place next time
|
||||
|
@ -225,10 +228,10 @@ struct codec_api ci = {
|
|||
|
||||
};
|
||||
|
||||
void codec_get_full_path(char *path, const char *codec_fn)
|
||||
void codec_get_full_path(char *path, const char *codec_root_fn)
|
||||
{
|
||||
/* Create full codec path */
|
||||
snprintf(path, MAX_PATH-1, CODECS_DIR "/%s", codec_fn);
|
||||
snprintf(path, MAX_PATH-1, CODECS_DIR "/%s." CODEC_EXTENSION,
|
||||
codec_root_fn);
|
||||
}
|
||||
|
||||
int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap,
|
||||
|
@ -254,7 +257,11 @@ int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap,
|
|||
hdr = (struct codec_header *)codecbuf;
|
||||
|
||||
if (size <= (signed)sizeof(struct codec_header)
|
||||
|| hdr->magic != CODEC_MAGIC
|
||||
|| (hdr->magic != CODEC_MAGIC
|
||||
#ifdef HAVE_RECORDING
|
||||
&& hdr->magic != CODEC_ENC_MAGIC
|
||||
#endif
|
||||
)
|
||||
|| hdr->target_id != TARGET_ID
|
||||
|| hdr->load_addr != codecbuf
|
||||
|| hdr->end_addr > codecbuf + CODEC_SIZE)
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
#include "profile.h"
|
||||
#endif
|
||||
#if (CONFIG_CODEC == SWCODEC)
|
||||
#if !defined(SIMULATOR)
|
||||
#if !defined(SIMULATOR) && defined(HAVE_RECORDING)
|
||||
#include "pcm_record.h"
|
||||
#endif
|
||||
#include "dsp.h"
|
||||
|
@ -84,15 +84,18 @@
|
|||
#define PREFIX(_x_) _x_
|
||||
#endif
|
||||
|
||||
/* magic for normal codecs */
|
||||
#define CODEC_MAGIC 0x52434F44 /* RCOD */
|
||||
/* magic for encoder codecs */
|
||||
#define CODEC_ENC_MAGIC 0x52454E43 /* RENC */
|
||||
|
||||
/* increase this every time the api struct changes */
|
||||
#define CODEC_API_VERSION 9
|
||||
#define CODEC_API_VERSION 10
|
||||
|
||||
/* update this to latest version if a change to the api struct breaks
|
||||
backwards compatibility (and please take the opportunity to sort in any
|
||||
new function which are "waiting" at the end of the function table) */
|
||||
#define CODEC_MIN_API_VERSION 8
|
||||
#define CODEC_MIN_API_VERSION 10
|
||||
|
||||
/* codec return codes */
|
||||
enum codec_status {
|
||||
|
@ -176,6 +179,7 @@ struct codec_api {
|
|||
int (*PREFIX(remove))(const char* pathname);
|
||||
int (*PREFIX(rename))(const char* path, const char* newname);
|
||||
int (*PREFIX(ftruncate))(int fd, off_t length);
|
||||
int (*PREFIX(fsync))(int fd);
|
||||
|
||||
int (*fdprintf)(int fd, const char *fmt, ...);
|
||||
int (*read_line)(int fd, char* buffer, int buffer_size);
|
||||
|
@ -232,7 +236,8 @@ struct codec_api {
|
|||
/* sound */
|
||||
void (*sound_set)(int setting, int value);
|
||||
#ifndef SIMULATOR
|
||||
void (*mp3_play_data)(const unsigned char* start, int size, void (*get_more)(unsigned char** start, int* size));
|
||||
void (*mp3_play_data)(const unsigned char* start,
|
||||
int size, void (*get_more)(unsigned char** start, int* size));
|
||||
void (*mp3_play_pause)(bool play);
|
||||
void (*mp3_play_stop)(void);
|
||||
bool (*mp3_is_playing)(void);
|
||||
|
@ -263,6 +268,10 @@ struct codec_api {
|
|||
struct tm* (*get_time)(void);
|
||||
int (*set_time)(const struct tm *tm);
|
||||
void* (*plugin_get_audio_buffer)(int* buffer_size);
|
||||
int (*round_value_to_list32)(unsigned long value,
|
||||
const unsigned long list[],
|
||||
int count,
|
||||
bool signd);
|
||||
|
||||
#if defined(DEBUG) || defined(SIMULATOR)
|
||||
void (*debugf)(const char *fmt, ...);
|
||||
|
@ -291,18 +300,14 @@ struct codec_api {
|
|||
#endif
|
||||
|
||||
#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
|
||||
bool enc_codec_loaded;
|
||||
void (*enc_get_inputs)(int *buffer_size,
|
||||
int *channels, int *quality);
|
||||
void (*enc_set_parameters)(int chunk_size, int num_chunks,
|
||||
int samp_per_chunk, char *head_ptr, int head_size,
|
||||
int enc_id);
|
||||
unsigned int* (*enc_alloc_chunk)(void);
|
||||
void (*enc_free_chunk)(void);
|
||||
int (*enc_wavbuf_near_empty)(void);
|
||||
char* (*enc_get_wav_data)(int size);
|
||||
void (**enc_set_header_callback)(void *head_buffer,
|
||||
int head_size, int num_samples, bool is_file_header);
|
||||
volatile int enc_codec_loaded; /* <0=error, 0=pending, >0=ok */
|
||||
void (*enc_get_inputs)(struct enc_inputs *inputs);
|
||||
void (*enc_set_parameters)(struct enc_parameters *params);
|
||||
struct enc_chunk_hdr * (*enc_get_chunk)(void);
|
||||
void (*enc_finish_chunk)(void);
|
||||
int (*enc_pcm_buf_near_empty)(void);
|
||||
unsigned char * (*enc_get_pcm_data)(size_t size);
|
||||
size_t (*enc_unget_pcm_data)(size_t size);
|
||||
#endif
|
||||
|
||||
/* new stuff at the end, sort into place next time
|
||||
|
@ -312,34 +317,49 @@ struct codec_api {
|
|||
|
||||
/* codec header */
|
||||
struct codec_header {
|
||||
unsigned long magic;
|
||||
unsigned long magic; /* RCOD or RENC */
|
||||
unsigned short target_id;
|
||||
unsigned short api_version;
|
||||
unsigned char *load_addr;
|
||||
unsigned char *end_addr;
|
||||
enum codec_status(*entry_point)(struct codec_api*);
|
||||
};
|
||||
|
||||
#ifdef CODEC
|
||||
#ifndef SIMULATOR
|
||||
/* plugin_* is correct, codecs use the plugin linker script */
|
||||
extern unsigned char plugin_start_addr[];
|
||||
extern unsigned char plugin_end_addr[];
|
||||
/* decoders */
|
||||
#define CODEC_HEADER \
|
||||
const struct codec_header __header \
|
||||
__attribute__ ((section (".header")))= { \
|
||||
CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
|
||||
plugin_start_addr, plugin_end_addr, codec_start };
|
||||
#else /* SIMULATOR */
|
||||
/* encoders */
|
||||
#define CODEC_ENC_HEADER \
|
||||
const struct codec_header __header \
|
||||
__attribute__ ((section (".header")))= { \
|
||||
CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
|
||||
plugin_start_addr, plugin_end_addr, codec_start };
|
||||
|
||||
#else /* def SIMULATOR */
|
||||
/* decoders */
|
||||
#define CODEC_HEADER \
|
||||
const struct codec_header __header = { \
|
||||
CODEC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
|
||||
NULL, NULL, codec_start };
|
||||
#endif
|
||||
#endif
|
||||
/* encoders */
|
||||
#define CODEC_ENC_HEADER \
|
||||
const struct codec_header __header = { \
|
||||
CODEC_ENC_MAGIC, TARGET_ID, CODEC_API_VERSION, \
|
||||
NULL, NULL, codec_start };
|
||||
#endif /* SIMULATOR */
|
||||
#endif /* CODEC */
|
||||
|
||||
/* create full codec path from filenames in audio_formats[]
|
||||
/* create full codec path from root filenames in audio_formats[]
|
||||
assumes buffer size is MAX_PATH */
|
||||
void codec_get_full_path(char *path, const char *codec_fn);
|
||||
void codec_get_full_path(char *path, const char *codec_root_fn);
|
||||
|
||||
/* defined by the codec loader (codec.c) */
|
||||
int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap,
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
// the malloc() system is provided.
|
||||
|
||||
#include "wavpack.h"
|
||||
#include "system.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
@ -118,19 +119,16 @@ uint32_t bs_close_write (Bitstream *bs)
|
|||
void little_endian_to_native (void *data, char *format)
|
||||
{
|
||||
uchar *cp = (uchar *) data;
|
||||
int32_t temp;
|
||||
|
||||
while (*format) {
|
||||
switch (*format) {
|
||||
case 'L':
|
||||
temp = cp [0] + ((int32_t) cp [1] << 8) + ((int32_t) cp [2] << 16) + ((int32_t) cp [3] << 24);
|
||||
* (int32_t *) cp = temp;
|
||||
*(long *)cp = letoh32(*(long *)cp);
|
||||
cp += 4;
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
temp = cp [0] + (cp [1] << 8);
|
||||
* (short *) cp = (short) temp;
|
||||
*(short *)cp = letoh16(*(short *)cp);
|
||||
cp += 2;
|
||||
break;
|
||||
|
||||
|
@ -148,28 +146,22 @@ void little_endian_to_native (void *data, char *format)
|
|||
void native_to_little_endian (void *data, char *format)
|
||||
{
|
||||
uchar *cp = (uchar *) data;
|
||||
int32_t temp;
|
||||
|
||||
while (*format) {
|
||||
switch (*format) {
|
||||
case 'L':
|
||||
temp = * (int32_t *) cp;
|
||||
*cp++ = (uchar) temp;
|
||||
*cp++ = (uchar) (temp >> 8);
|
||||
*cp++ = (uchar) (temp >> 16);
|
||||
*cp++ = (uchar) (temp >> 24);
|
||||
*(long *)cp = htole32(*(long *)cp);
|
||||
cp += 4;
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
temp = * (short *) cp;
|
||||
*cp++ = (uchar) temp;
|
||||
*cp++ = (uchar) (temp >> 8);
|
||||
*(short *)cp = htole16(*(short *)cp);
|
||||
cp += 2;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (*format >= '0' && *format <= '9')
|
||||
cp += *format - '0';
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -19,140 +19,364 @@
|
|||
|
||||
#ifndef SIMULATOR
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "codeclib.h"
|
||||
|
||||
CODEC_HEADER
|
||||
CODEC_ENC_HEADER
|
||||
|
||||
#ifdef USE_IRAM
|
||||
extern char iramcopy[];
|
||||
extern char iramstart[];
|
||||
extern char iramend[];
|
||||
extern char iedata[];
|
||||
extern char iend[];
|
||||
#endif
|
||||
|
||||
struct riff_header
|
||||
{
|
||||
uint8_t riff_id[4]; /* 00h - "RIFF" */
|
||||
uint32_t riff_size; /* 04h - sz following headers + data_size */
|
||||
/* format header */
|
||||
uint8_t format[4]; /* 08h - "WAVE" */
|
||||
uint8_t format_id[4]; /* 0Ch - "fmt " */
|
||||
uint32_t format_size; /* 10h - 16 for PCM (sz format data) */
|
||||
/* format data */
|
||||
uint16_t audio_format; /* 14h - 1=PCM */
|
||||
uint16_t num_channels; /* 16h - 1=M, 2=S, etc. */
|
||||
uint32_t sample_rate; /* 18h - HZ */
|
||||
uint32_t byte_rate; /* 1Ch - num_channels*sample_rate*bits_per_sample/8 */
|
||||
uint16_t block_align; /* 20h - num_channels*bits_per_samples/8 */
|
||||
uint16_t bits_per_sample; /* 22h - 8=8 bits, 16=16 bits, etc. */
|
||||
/* Not for audio_format=1 (PCM) */
|
||||
/* unsigned short extra_param_size; 24h - size of extra data */
|
||||
/* unsigned char *extra_params; */
|
||||
/* data header */
|
||||
uint8_t data_id[4]; /* 24h - "data" */
|
||||
uint32_t data_size; /* 28h - num_samples*num_channels*bits_per_sample/8 */
|
||||
/* unsigned char *data; 2ch - actual sound data */
|
||||
};
|
||||
|
||||
#define RIFF_FMT_HEADER_SIZE 12 /* format -> format_size */
|
||||
#define RIFF_FMT_DATA_SIZE 16 /* audio_format -> bits_per_sample */
|
||||
#define RIFF_DATA_HEADER_SIZE 8 /* data_id -> data_size */
|
||||
|
||||
#define PCM_DEPTH_BYTES 2
|
||||
#define PCM_DEPTH_BITS 16
|
||||
#define PCM_SAMP_PER_CHUNK 2048
|
||||
#define PCM_CHUNK_SIZE (PCM_SAMP_PER_CHUNK*4)
|
||||
|
||||
static struct codec_api *ci;
|
||||
static int enc_channels;
|
||||
static int num_channels;
|
||||
uint32_t sample_rate;
|
||||
uint32_t enc_size;
|
||||
|
||||
#define CHUNK_SIZE 8192
|
||||
|
||||
static unsigned char wav_header[44] =
|
||||
{'R','I','F','F',0,0,0,0,'W','A','V','E','f','m','t',' ',16,
|
||||
0,0,0,1,0,2,0,0x44,0xac,0,0,0x10,0xb1,2,0,4,0,16,0,'d','a','t','a',0,0,0,0};
|
||||
|
||||
static unsigned char wav_header_mono[44] =
|
||||
{'R','I','F','F',0,0,0,0,'W','A','V','E','f','m','t',' ',16,
|
||||
0,0,0,1,0,1,0,0x44,0xac,0,0,0x88,0x58,1,0,2,0,16,0,'d','a','t','a',0,0,0,0};
|
||||
|
||||
/* update file header info callback function (called by main application) */
|
||||
void enc_set_header(void *head_buffer, /* ptr to the file header data */
|
||||
int head_size, /* size of this header data */
|
||||
int num_pcm_samples, /* amount of processed pcm samples */
|
||||
bool is_file_header)
|
||||
static const struct riff_header riff_header =
|
||||
{
|
||||
int num_file_bytes = num_pcm_samples * 2 * enc_channels;
|
||||
/* "RIFF" header */
|
||||
{ 'R', 'I', 'F', 'F' }, /* riff_id */
|
||||
0, /* riff_size (*) */
|
||||
/* format header */
|
||||
{ 'W', 'A', 'V', 'E' }, /* format */
|
||||
{ 'f', 'm', 't', ' ' }, /* format_id */
|
||||
H_TO_LE32(16), /* format_size */
|
||||
/* format data */
|
||||
H_TO_LE16(1), /* audio_format */
|
||||
0, /* num_channels (*) */
|
||||
0, /* sample_rate (*) */
|
||||
0, /* byte_rate (*) */
|
||||
0, /* block_align (*) */
|
||||
H_TO_LE16(PCM_DEPTH_BITS), /* bits_per_sample */
|
||||
/* data header */
|
||||
{ 'd', 'a', 't', 'a' }, /* data_id */
|
||||
0 /* data_size (*) */
|
||||
/* (*) updated during ENC_END_FILE event */
|
||||
};
|
||||
|
||||
if(is_file_header)
|
||||
/* called version often - inline */
|
||||
static inline bool is_file_data_ok(struct enc_file_event_data *data) ICODE_ATTR;
|
||||
static inline bool is_file_data_ok(struct enc_file_event_data *data)
|
||||
{
|
||||
return data->rec_file >= 0 && (long)data->chunk->flags >= 0;
|
||||
} /* is_file_data_ok */
|
||||
|
||||
/* called version often - inline */
|
||||
static inline bool on_write_chunk(struct enc_file_event_data *data) ICODE_ATTR;
|
||||
static inline bool on_write_chunk(struct enc_file_event_data *data)
|
||||
{
|
||||
if (!is_file_data_ok(data))
|
||||
return false;
|
||||
|
||||
if (data->chunk->enc_data == NULL)
|
||||
{
|
||||
/* update file header before file closing */
|
||||
if((int)sizeof(wav_header) < head_size)
|
||||
{
|
||||
/* update wave header size entries: special to WAV format */
|
||||
*(long*)(head_buffer+ 4) = htole32(num_file_bytes + 36);
|
||||
*(long*)(head_buffer+40) = htole32(num_file_bytes);
|
||||
}
|
||||
#ifdef ROCKBOX_HAS_LOGF
|
||||
ci->logf("wav enc: NULL data");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (ci->write(data->rec_file, data->chunk->enc_data,
|
||||
data->chunk->enc_size) != (ssize_t)data->chunk->enc_size)
|
||||
return false;
|
||||
|
||||
data->num_pcm_samples += data->chunk->num_pcm;
|
||||
return true;
|
||||
} /* on_write_chunk */
|
||||
|
||||
static bool on_start_file(struct enc_file_event_data *data)
|
||||
{
|
||||
if ((data->chunk->flags & CHUNKF_ERROR) || *data->filename == '\0')
|
||||
return false;
|
||||
|
||||
data->rec_file = ci->open(data->filename, O_RDWR|O_CREAT|O_TRUNC);
|
||||
|
||||
if (data->rec_file < 0)
|
||||
return false;
|
||||
|
||||
/* reset sample count */
|
||||
data->num_pcm_samples = 0;
|
||||
|
||||
/* write template header */
|
||||
if (ci->write(data->rec_file, &riff_header, sizeof (riff_header))
|
||||
!= sizeof (riff_header))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
data->new_enc_size += sizeof (riff_header);
|
||||
return true;
|
||||
} /* on_start_file */
|
||||
|
||||
static bool on_end_file(struct enc_file_event_data *data)
|
||||
{
|
||||
/* update template header */
|
||||
struct riff_header hdr;
|
||||
uint32_t data_size;
|
||||
|
||||
if (!is_file_data_ok(data))
|
||||
return false;
|
||||
|
||||
if (ci->lseek(data->rec_file, 0, SEEK_SET) != 0 ||
|
||||
ci->read(data->rec_file, &hdr, sizeof (hdr)) != sizeof (hdr))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
data_size = data->num_pcm_samples*num_channels*PCM_DEPTH_BYTES;
|
||||
|
||||
/* "RIFF" header */
|
||||
hdr.riff_size = htole32(RIFF_FMT_HEADER_SIZE + RIFF_FMT_DATA_SIZE
|
||||
+ RIFF_DATA_HEADER_SIZE + data_size);
|
||||
|
||||
/* format data */
|
||||
hdr.num_channels = htole16(num_channels);
|
||||
hdr.sample_rate = htole32(sample_rate);
|
||||
hdr.byte_rate = htole32(sample_rate*num_channels* PCM_DEPTH_BYTES);
|
||||
hdr.block_align = htole16(num_channels*PCM_DEPTH_BYTES);
|
||||
|
||||
/* data header */
|
||||
hdr.data_size = htole32(data_size);
|
||||
|
||||
if (ci->lseek(data->rec_file, 0, SEEK_SET) != 0 ||
|
||||
ci->write(data->rec_file, &hdr, sizeof (hdr)) != sizeof (hdr))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ci->fsync(data->rec_file);
|
||||
ci->close(data->rec_file);
|
||||
data->rec_file = -1;
|
||||
|
||||
return true;
|
||||
} /* on_end_file */
|
||||
|
||||
static void enc_events_callback(enum enc_events event, void *data) ICODE_ATTR;
|
||||
static void enc_events_callback(enum enc_events event, void *data)
|
||||
{
|
||||
if (event == ENC_WRITE_CHUNK)
|
||||
{
|
||||
if (on_write_chunk((struct enc_file_event_data *)data))
|
||||
return;
|
||||
}
|
||||
else if (event == ENC_START_FILE)
|
||||
{
|
||||
if (on_start_file((struct enc_file_event_data *)data))
|
||||
return;
|
||||
}
|
||||
else if (event == ENC_END_FILE)
|
||||
{
|
||||
if (on_end_file((struct enc_file_event_data *)data))
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
((struct enc_file_event_data *)data)->chunk->flags |= CHUNKF_ERROR;
|
||||
} /* enc_events_callback */
|
||||
|
||||
/* convert native pcm samples to wav format samples */
|
||||
static void chunk_to_wav_format(uint32_t *src, uint32_t *dst) ICODE_ATTR;
|
||||
static void chunk_to_wav_format(uint32_t *src, uint32_t *dst)
|
||||
{
|
||||
if (num_channels == 1)
|
||||
{
|
||||
/* On big endian:
|
||||
* |LLLLLLLLllllllll|RRRRRRRRrrrrrrrr|
|
||||
* |LLLLLLLLllllllll|RRRRRRRRrrrrrrrr| =>
|
||||
* |mmmmmmmmMMMMMMMM|mmmmmmmmMMMMMMMM|
|
||||
*
|
||||
* On little endian:
|
||||
* |llllllllLLLLLLLL|rrrrrrrrRRRRRRRR|
|
||||
* |llllllllLLLLLLLL|rrrrrrrrRRRRRRRR| =>
|
||||
* |mmmmmmmmMMMMMMMM|mmmmmmmmMMMMMMMM|
|
||||
*/
|
||||
uint32_t *src_end = src + PCM_SAMP_PER_CHUNK;
|
||||
|
||||
inline void to_mono(uint32_t **src, uint32_t **dst)
|
||||
{
|
||||
int32_t lr1, lr2;
|
||||
|
||||
lr1 = *(*src)++;
|
||||
lr1 = ((int16_t)lr1 + (lr1 >> 16)) >> 1;
|
||||
|
||||
lr2 = *(*src)++;
|
||||
lr2 = ((int16_t)lr2 + (lr2 >> 16)) >> 1;
|
||||
*(*dst)++ = swap_odd_even_be32((lr1 << 16) | (uint16_t)lr2);
|
||||
} /* to_mono */
|
||||
|
||||
do
|
||||
{
|
||||
to_mono(&src, &dst);
|
||||
to_mono(&src, &dst);
|
||||
to_mono(&src, &dst);
|
||||
to_mono(&src, &dst);
|
||||
to_mono(&src, &dst);
|
||||
to_mono(&src, &dst);
|
||||
to_mono(&src, &dst);
|
||||
to_mono(&src, &dst);
|
||||
}
|
||||
while (src < src_end);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef ROCKBOX_BIG_ENDIAN
|
||||
/* |LLLLLLLLllllllll|RRRRRRRRrrrrrrrr| =>
|
||||
* |llllllllLLLLLLLL|rrrrrrrrRRRRRRRR|
|
||||
*/
|
||||
uint32_t *src_end = src + PCM_SAMP_PER_CHUNK;
|
||||
|
||||
do
|
||||
{
|
||||
*dst++ = swap_odd_even32(*src++);
|
||||
*dst++ = swap_odd_even32(*src++);
|
||||
*dst++ = swap_odd_even32(*src++);
|
||||
*dst++ = swap_odd_even32(*src++);
|
||||
*dst++ = swap_odd_even32(*src++);
|
||||
*dst++ = swap_odd_even32(*src++);
|
||||
*dst++ = swap_odd_even32(*src++);
|
||||
*dst++ = swap_odd_even32(*src++);
|
||||
}
|
||||
while (src < src_end);
|
||||
#else
|
||||
/* |llllllllLLLLLLLL|rrrrrrrrRRRRRRRR| =>
|
||||
* |llllllllLLLLLLLL|rrrrrrrrRRRRRRRR|
|
||||
*/
|
||||
ci->memcpy(dst, src, PCM_CHUNK_SIZE);
|
||||
#endif
|
||||
}
|
||||
} /* chunk_to_wav_format */
|
||||
|
||||
static bool init_encoder(void)
|
||||
{
|
||||
struct enc_inputs inputs;
|
||||
struct enc_parameters params;
|
||||
|
||||
if (ci->enc_get_inputs == NULL ||
|
||||
ci->enc_set_parameters == NULL ||
|
||||
ci->enc_get_chunk == NULL ||
|
||||
ci->enc_finish_chunk == NULL ||
|
||||
ci->enc_pcm_buf_near_empty == NULL ||
|
||||
ci->enc_get_pcm_data == NULL )
|
||||
return false;
|
||||
|
||||
ci->enc_get_inputs(&inputs);
|
||||
|
||||
if (inputs.config->afmt != AFMT_PCM_WAV)
|
||||
return false;
|
||||
|
||||
sample_rate = inputs.sample_rate;
|
||||
num_channels = inputs.num_channels;
|
||||
|
||||
/* configure the buffer system */
|
||||
params.afmt = AFMT_PCM_WAV;
|
||||
enc_size = PCM_CHUNK_SIZE*inputs.num_channels / 2;
|
||||
params.chunk_size = enc_size;
|
||||
params.enc_sample_rate = sample_rate;
|
||||
params.reserve_bytes = 0;
|
||||
params.events_callback = enc_events_callback;
|
||||
ci->enc_set_parameters(¶ms);
|
||||
|
||||
return true;
|
||||
} /* init_encoder */
|
||||
|
||||
/* main codec entry point */
|
||||
enum codec_status codec_start(struct codec_api* api)
|
||||
{
|
||||
int i;
|
||||
long lr;
|
||||
unsigned long t;
|
||||
unsigned long *src;
|
||||
unsigned long *dst;
|
||||
int chunk_size, num_chunks, samp_per_chunk;
|
||||
int enc_buffer_size;
|
||||
int enc_quality;
|
||||
bool cpu_boosted = true; /* start boosted */
|
||||
bool cpu_boosted;
|
||||
|
||||
ci = api; // copy to global api pointer
|
||||
|
||||
if(ci->enc_get_inputs == NULL ||
|
||||
ci->enc_set_parameters == NULL ||
|
||||
ci->enc_alloc_chunk == NULL ||
|
||||
ci->enc_free_chunk == NULL ||
|
||||
ci->enc_wavbuf_near_empty == NULL ||
|
||||
ci->enc_get_wav_data == NULL ||
|
||||
ci->enc_set_header_callback == NULL )
|
||||
#ifdef USE_IRAM
|
||||
ci->memcpy(iramstart, iramcopy, iramend - iramstart);
|
||||
ci->memset(iedata, 0, iend - iedata);
|
||||
#endif
|
||||
|
||||
if (!init_encoder())
|
||||
{
|
||||
ci->enc_codec_loaded = -1;
|
||||
return CODEC_ERROR;
|
||||
|
||||
ci->cpu_boost(true);
|
||||
|
||||
*ci->enc_set_header_callback = enc_set_header;
|
||||
ci->enc_get_inputs(&enc_buffer_size, &enc_channels, &enc_quality);
|
||||
|
||||
/* configure the buffer system */
|
||||
chunk_size = sizeof(long) + CHUNK_SIZE * enc_channels / 2;
|
||||
num_chunks = enc_buffer_size / chunk_size;
|
||||
samp_per_chunk = CHUNK_SIZE / 4;
|
||||
|
||||
/* inform the main program about buffer dimensions and other params */
|
||||
ci->enc_set_parameters(chunk_size, num_chunks, samp_per_chunk,
|
||||
(enc_channels == 2) ? wav_header : wav_header_mono,
|
||||
sizeof(wav_header), AFMT_PCM_WAV);
|
||||
}
|
||||
|
||||
/* main application waits for this flag during encoder loading */
|
||||
ci->enc_codec_loaded = true;
|
||||
ci->enc_codec_loaded = 1;
|
||||
|
||||
ci->cpu_boost(true);
|
||||
cpu_boosted = true;
|
||||
|
||||
/* main encoding loop */
|
||||
while(!ci->stop_codec)
|
||||
{
|
||||
while((src = (unsigned long*)ci->enc_get_wav_data(CHUNK_SIZE)) != NULL)
|
||||
uint32_t *src;
|
||||
|
||||
while ((src = (uint32_t *)ci->enc_get_pcm_data(PCM_CHUNK_SIZE)) != NULL)
|
||||
{
|
||||
if(ci->stop_codec)
|
||||
struct enc_chunk_hdr *chunk;
|
||||
|
||||
if (ci->stop_codec)
|
||||
break;
|
||||
|
||||
if(ci->enc_wavbuf_near_empty() == 0)
|
||||
if (!cpu_boosted && ci->enc_pcm_buf_near_empty() == 0)
|
||||
{
|
||||
if(!cpu_boosted)
|
||||
{
|
||||
ci->cpu_boost(true);
|
||||
cpu_boosted = true;
|
||||
}
|
||||
ci->cpu_boost(true);
|
||||
cpu_boosted = true;
|
||||
}
|
||||
|
||||
dst = (unsigned long*)ci->enc_alloc_chunk();
|
||||
*dst++ = CHUNK_SIZE * enc_channels / 2; /* set size info */
|
||||
chunk = ci->enc_get_chunk();
|
||||
chunk->enc_size = enc_size;
|
||||
chunk->num_pcm = PCM_SAMP_PER_CHUNK;
|
||||
chunk->enc_data = ENC_CHUNK_SKIP_HDR(chunk->enc_data, chunk);
|
||||
|
||||
if(enc_channels == 2)
|
||||
{
|
||||
/* swap byte order & copy to destination */
|
||||
for (i=0; i<CHUNK_SIZE/4; i++)
|
||||
{
|
||||
t = *src++;
|
||||
*dst++ = ((t >> 8) & 0xff00ff) | ((t << 8) & 0xff00ff00);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* mix left/right, swap byte order & copy to destination */
|
||||
for (i=0; i<CHUNK_SIZE/8; i++)
|
||||
{
|
||||
lr = (long)*src++;
|
||||
lr = (((lr<<16)>>16) + (lr>>16)) >> 1; /* left+right */
|
||||
t = (lr << 16);
|
||||
lr = (long)*src++;
|
||||
lr = (((lr<<16)>>16) + (lr>>16)) >> 1; /* left+right */
|
||||
t |= lr & 0xffff;
|
||||
*dst++ = ((t >> 8) & 0xff00ff) | ((t << 8) & 0xff00ff00);
|
||||
}
|
||||
}
|
||||
chunk_to_wav_format(src, (uint32_t *)chunk->enc_data);
|
||||
|
||||
ci->enc_free_chunk();
|
||||
ci->enc_finish_chunk();
|
||||
ci->yield();
|
||||
}
|
||||
|
||||
if(ci->enc_wavbuf_near_empty())
|
||||
if (cpu_boosted && ci->enc_pcm_buf_near_empty() != 0)
|
||||
{
|
||||
if(cpu_boosted)
|
||||
{
|
||||
ci->cpu_boost(false);
|
||||
cpu_boosted = false;
|
||||
}
|
||||
ci->cpu_boost(false);
|
||||
cpu_boosted = false;
|
||||
}
|
||||
|
||||
ci->yield();
|
||||
|
@ -162,11 +386,12 @@ enum codec_status codec_start(struct codec_api* api)
|
|||
ci->cpu_boost(false);
|
||||
|
||||
/* reset parameters to initial state */
|
||||
ci->enc_set_parameters(0, 0, 0, 0, 0, 0);
|
||||
ci->enc_set_parameters(NULL);
|
||||
|
||||
/* main application waits for this flag during encoder removing */
|
||||
ci->enc_codec_loaded = false;
|
||||
ci->enc_codec_loaded = 0;
|
||||
|
||||
return CODEC_OK;
|
||||
}
|
||||
#endif
|
||||
} /* codec_start */
|
||||
|
||||
#endif /* ndef SIMULATOR */
|
||||
|
|
|
@ -22,201 +22,474 @@
|
|||
#include "codeclib.h"
|
||||
#include "libwavpack/wavpack.h"
|
||||
|
||||
CODEC_HEADER
|
||||
CODEC_ENC_HEADER
|
||||
|
||||
typedef unsigned long uint32;
|
||||
typedef unsigned short uint16;
|
||||
typedef unsigned char uint8;
|
||||
#ifdef USE_IRAM
|
||||
extern char iramcopy[];
|
||||
extern char iramstart[];
|
||||
extern char iramend[];
|
||||
extern char iedata[];
|
||||
extern char iend[];
|
||||
#endif
|
||||
|
||||
static unsigned char wav_header_ster [46] =
|
||||
{33,22,'R','I','F','F',0,0,0,0,'W','A','V','E','f','m','t',' ',16,
|
||||
0,0,0,1,0,2,0,0x44,0xac,0,0,0x10,0xb1,2,0,4,0,16,0,'d','a','t','a',0,0,0,0};
|
||||
|
||||
static unsigned char wav_header_mono [46] =
|
||||
{33,22,'R','I','F','F',0,0,0,0,'W','A','V','E','f','m','t',' ',16,
|
||||
0,0,0,1,0,1,0,0x44,0xac,0,0,0x88,0x58,1,0,2,0,16,0,'d','a','t','a',0,0,0,0};
|
||||
|
||||
static struct codec_api *ci;
|
||||
static int enc_channels;
|
||||
|
||||
#define CHUNK_SIZE 20000
|
||||
|
||||
static long input_buffer[CHUNK_SIZE/2] IBSS_ATTR;
|
||||
|
||||
/* update file header info callback function */
|
||||
void enc_set_header(void *head_buffer, /* ptr to the file header data */
|
||||
int head_size, /* size of this header data */
|
||||
int num_pcm_sampl, /* amount of processed pcm samples */
|
||||
bool is_file_header) /* update file/chunk header */
|
||||
/** Types **/
|
||||
typedef struct
|
||||
{
|
||||
if(is_file_header)
|
||||
uint8_t type; /* Type of metadata */
|
||||
uint8_t word_size; /* Size of metadata in words */
|
||||
} WavpackMetadataHeader;
|
||||
|
||||
struct riff_header
|
||||
{
|
||||
uint8_t riff_id[4]; /* 00h - "RIFF" */
|
||||
uint32_t riff_size; /* 04h - sz following headers + data_size */
|
||||
/* format header */
|
||||
uint8_t format[4]; /* 08h - "WAVE" */
|
||||
uint8_t format_id[4]; /* 0Ch - "fmt " */
|
||||
uint32_t format_size; /* 10h - 16 for PCM (sz format data) */
|
||||
/* format data */
|
||||
uint16_t audio_format; /* 14h - 1=PCM */
|
||||
uint16_t num_channels; /* 16h - 1=M, 2=S, etc. */
|
||||
uint32_t sample_rate; /* 18h - HZ */
|
||||
uint32_t byte_rate; /* 1Ch - num_channels*sample_rate*bits_per_sample/8 */
|
||||
uint16_t block_align; /* 20h - num_channels*bits_per_samples/8 */
|
||||
uint16_t bits_per_sample; /* 22h - 8=8 bits, 16=16 bits, etc. */
|
||||
/* Not for audio_format=1 (PCM) */
|
||||
/* unsigned short extra_param_size; 24h - size of extra data */
|
||||
/* unsigned char *extra_params; */
|
||||
/* data header */
|
||||
uint8_t data_id[4]; /* 24h - "data" */
|
||||
uint32_t data_size; /* 28h - num_samples*num_channels*bits_per_sample/8 */
|
||||
/* unsigned char *data; 2ch - actual sound data */
|
||||
};
|
||||
|
||||
#define RIFF_FMT_HEADER_SIZE 12 /* format -> format_size */
|
||||
#define RIFF_FMT_DATA_SIZE 16 /* audio_format -> bits_per_sample */
|
||||
#define RIFF_DATA_HEADER_SIZE 8 /* data_id -> data_size */
|
||||
|
||||
#define PCM_DEPTH_BITS 16
|
||||
#define PCM_DEPTH_BYTES 2
|
||||
#define PCM_SAMP_PER_CHUNK 5000
|
||||
#define PCM_CHUNK_SIZE (4*PCM_SAMP_PER_CHUNK)
|
||||
|
||||
/** Data **/
|
||||
static struct codec_api *ci;
|
||||
static int8_t input_buffer[PCM_CHUNK_SIZE*2] IBSS_ATTR;
|
||||
static WavpackConfig config IBSS_ATTR;
|
||||
static WavpackContext *wpc;
|
||||
static int32_t data_size, input_size, input_step IBSS_ATTR;
|
||||
|
||||
static const WavpackMetadataHeader wvpk_mdh =
|
||||
{
|
||||
ID_RIFF_HEADER,
|
||||
sizeof (struct riff_header) / sizeof (uint16_t),
|
||||
};
|
||||
|
||||
static const struct riff_header riff_header =
|
||||
{
|
||||
/* "RIFF" header */
|
||||
{ 'R', 'I', 'F', 'F' }, /* riff_id */
|
||||
0, /* riff_size (*) */
|
||||
/* format header */
|
||||
{ 'W', 'A', 'V', 'E' }, /* format */
|
||||
{ 'f', 'm', 't', ' ' }, /* format_id */
|
||||
H_TO_LE32(16), /* format_size */
|
||||
/* format data */
|
||||
H_TO_LE16(1), /* audio_format */
|
||||
0, /* num_channels (*) */
|
||||
0, /* sample_rate (*) */
|
||||
0, /* byte_rate (*) */
|
||||
0, /* block_align (*) */
|
||||
H_TO_LE16(PCM_DEPTH_BITS), /* bits_per_sample */
|
||||
/* data header */
|
||||
{ 'd', 'a', 't', 'a' }, /* data_id */
|
||||
0 /* data_size (*) */
|
||||
/* (*) updated during ENC_END_FILE event */
|
||||
};
|
||||
|
||||
static void chunk_to_int32(int32_t *src) ICODE_ATTR;
|
||||
static void chunk_to_int32(int32_t *src)
|
||||
{
|
||||
int32_t *dst = (int32_t *)input_buffer + PCM_SAMP_PER_CHUNK;
|
||||
int32_t *src_end = dst + PCM_SAMP_PER_CHUNK;
|
||||
|
||||
/* copy to IRAM before converting data */
|
||||
memcpy(dst, src, PCM_CHUNK_SIZE);
|
||||
|
||||
src = dst;
|
||||
dst = (int32_t *)input_buffer;
|
||||
|
||||
if (config.num_channels == 1)
|
||||
{
|
||||
/* update file header before file closing */
|
||||
if(sizeof(WavpackHeader) + sizeof(wav_header_mono) < (unsigned)head_size)
|
||||
/*
|
||||
* |llllllllllllllll|rrrrrrrrrrrrrrrr| =>
|
||||
* |mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm|
|
||||
*/
|
||||
inline void to_int32(int32_t **src, int32_t **dst)
|
||||
{
|
||||
char* riff_header = (char*)head_buffer + sizeof(WavpackHeader);
|
||||
char* wv_header = (char*)head_buffer + sizeof(wav_header_mono);
|
||||
int num_file_bytes = num_pcm_sampl * 2 * enc_channels;
|
||||
unsigned long ckSize;
|
||||
int32_t t = *(*src)++;
|
||||
/* endianness irrelevant */
|
||||
*(*dst)++ = ((int16_t)t + (t >> 16)) >> 1;
|
||||
} /* to_int32 */
|
||||
|
||||
/* RIFF header and WVPK header have to be swapped */
|
||||
/* copy wavpack header to file start position */
|
||||
ci->memcpy(head_buffer, wv_header, sizeof(WavpackHeader));
|
||||
wv_header = head_buffer; /* recalc wavpack header position */
|
||||
|
||||
if(enc_channels == 2)
|
||||
ci->memcpy(riff_header, wav_header_ster, sizeof(wav_header_ster));
|
||||
else
|
||||
ci->memcpy(riff_header, wav_header_mono, sizeof(wav_header_mono));
|
||||
|
||||
/* update the Wavpack header first chunk size & total frame count */
|
||||
ckSize = htole32(((WavpackHeader*)wv_header)->ckSize)
|
||||
+ sizeof(wav_header_mono);
|
||||
((WavpackHeader*)wv_header)->total_samples = htole32(num_pcm_sampl);
|
||||
((WavpackHeader*)wv_header)->ckSize = htole32(ckSize);
|
||||
|
||||
/* update the RIFF WAV header size entries */
|
||||
*(long*)(riff_header+ 6) = htole32(num_file_bytes + 36);
|
||||
*(long*)(riff_header+42) = htole32(num_file_bytes);
|
||||
do
|
||||
{
|
||||
/* read 10 longs and write 10 longs */
|
||||
to_int32(&src, &dst);
|
||||
to_int32(&src, &dst);
|
||||
to_int32(&src, &dst);
|
||||
to_int32(&src, &dst);
|
||||
to_int32(&src, &dst);
|
||||
to_int32(&src, &dst);
|
||||
to_int32(&src, &dst);
|
||||
to_int32(&src, &dst);
|
||||
to_int32(&src, &dst);
|
||||
to_int32(&src, &dst);
|
||||
}
|
||||
while(src < src_end);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* update timestamp (block_index) */
|
||||
((WavpackHeader*)head_buffer)->block_index = htole32(num_pcm_sampl);
|
||||
/*
|
||||
* |llllllllllllllll|rrrrrrrrrrrrrrrr| =>
|
||||
* |llllllllllllllllllllllllllllllll|rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr|
|
||||
*/
|
||||
inline void to_int32(int32_t **src, int32_t **dst)
|
||||
{
|
||||
int32_t t = *(*src)++;
|
||||
#ifdef ROCKBOX_BIG_ENDIAN
|
||||
*(*dst)++ = t >> 16, *(*dst)++ = (int16_t)t;
|
||||
#else
|
||||
*(*dst)++ = (int16_t)t, *(*dst)++ = t >> 16;
|
||||
#endif
|
||||
} /* to_int32 */
|
||||
|
||||
do
|
||||
{
|
||||
/* read 10 longs and write 20 longs */
|
||||
to_int32(&src, &dst);
|
||||
to_int32(&src, &dst);
|
||||
to_int32(&src, &dst);
|
||||
to_int32(&src, &dst);
|
||||
to_int32(&src, &dst);
|
||||
to_int32(&src, &dst);
|
||||
to_int32(&src, &dst);
|
||||
to_int32(&src, &dst);
|
||||
to_int32(&src, &dst);
|
||||
to_int32(&src, &dst);
|
||||
}
|
||||
while (src < src_end);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
} /* chunk_to_int32 */
|
||||
|
||||
|
||||
enum codec_status codec_start(struct codec_api* api)
|
||||
/* called very often - inline */
|
||||
static inline bool is_file_data_ok(struct enc_file_event_data *data) ICODE_ATTR;
|
||||
static inline bool is_file_data_ok(struct enc_file_event_data *data)
|
||||
{
|
||||
int i;
|
||||
long t;
|
||||
uint32 *src;
|
||||
uint32 *dst;
|
||||
int chunk_size, num_chunks, samp_per_chunk;
|
||||
int enc_buffer_size;
|
||||
int enc_quality;
|
||||
WavpackConfig config;
|
||||
WavpackContext *wpc;
|
||||
bool cpu_boosted = true; /* start boosted */
|
||||
return data->rec_file >= 0 && (long)data->chunk->flags >= 0;
|
||||
} /* is_file_data_ok */
|
||||
|
||||
ci = api; // copy to global api pointer
|
||||
/* called very often - inline */
|
||||
static inline bool on_write_chunk(struct enc_file_event_data *data) ICODE_ATTR;
|
||||
static inline bool on_write_chunk(struct enc_file_event_data *data)
|
||||
{
|
||||
if (!is_file_data_ok(data))
|
||||
return false;
|
||||
|
||||
if (data->chunk->enc_data == NULL)
|
||||
{
|
||||
#ifdef ROCKBOX_HAS_LOGF
|
||||
ci->logf("wvpk enc: NULL data");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
/* update timestamp (block_index) */
|
||||
((WavpackHeader *)data->chunk->enc_data)->block_index =
|
||||
htole32(data->num_pcm_samples);
|
||||
|
||||
if (ci->write(data->rec_file, data->chunk->enc_data,
|
||||
data->chunk->enc_size) != (ssize_t)data->chunk->enc_size)
|
||||
return false;
|
||||
|
||||
data->num_pcm_samples += data->chunk->num_pcm;
|
||||
return true;
|
||||
} /* on_write_chunk */
|
||||
|
||||
static bool on_start_file(struct enc_file_event_data *data)
|
||||
{
|
||||
if ((data->chunk->flags & CHUNKF_ERROR) || *data->filename == '\0')
|
||||
return false;
|
||||
|
||||
data->rec_file = ci->open(data->filename, O_RDWR|O_CREAT|O_TRUNC);
|
||||
|
||||
if (data->rec_file < 0)
|
||||
return false;
|
||||
|
||||
/* reset sample count */
|
||||
data->num_pcm_samples = 0;
|
||||
|
||||
/* write template headers */
|
||||
if (ci->write(data->rec_file, &wvpk_mdh, sizeof (wvpk_mdh))
|
||||
!= sizeof (wvpk_mdh) ||
|
||||
ci->write(data->rec_file, &riff_header, sizeof (riff_header))
|
||||
!= sizeof (riff_header))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
data->new_enc_size += sizeof(wvpk_mdh) + sizeof(riff_header);
|
||||
return true;
|
||||
} /* on_start_file */
|
||||
|
||||
static bool on_end_file(struct enc_file_event_data *data)
|
||||
{
|
||||
struct
|
||||
{
|
||||
WavpackMetadataHeader wpmdh;
|
||||
struct riff_header rhdr;
|
||||
WavpackHeader wph;
|
||||
} __attribute__ ((packed)) h;
|
||||
|
||||
uint32_t data_size;
|
||||
|
||||
if (!is_file_data_ok(data))
|
||||
return false;
|
||||
|
||||
/* read template headers at start */
|
||||
if (ci->lseek(data->rec_file, 0, SEEK_SET) != 0 ||
|
||||
ci->read(data->rec_file, &h, sizeof (h)) != sizeof (h))
|
||||
return false;
|
||||
|
||||
data_size = data->num_pcm_samples*config.num_channels*PCM_DEPTH_BYTES;
|
||||
|
||||
/** "RIFF" header **/
|
||||
h.rhdr.riff_size = htole32(RIFF_FMT_HEADER_SIZE +
|
||||
RIFF_FMT_DATA_SIZE + RIFF_DATA_HEADER_SIZE + data_size);
|
||||
|
||||
/* format data */
|
||||
h.rhdr.num_channels = htole16(config.num_channels);
|
||||
h.rhdr.sample_rate = htole32(config.sample_rate);
|
||||
h.rhdr.byte_rate = htole32(config.sample_rate*config.num_channels*
|
||||
PCM_DEPTH_BYTES);
|
||||
h.rhdr.block_align = htole16(config.num_channels*PCM_DEPTH_BYTES);
|
||||
|
||||
/* data header */
|
||||
h.rhdr.data_size = htole32(data_size);
|
||||
|
||||
/** Wavpack header **/
|
||||
h.wph.ckSize = htole32(letoh32(h.wph.ckSize) + sizeof (h.wpmdh)
|
||||
+ sizeof (h.rhdr));
|
||||
h.wph.total_samples = htole32(data->num_pcm_samples);
|
||||
|
||||
/* MDH|RIFF|WVPK => WVPK|MDH|RIFF */
|
||||
if (ci->lseek(data->rec_file, 0, SEEK_SET)
|
||||
!= 0 ||
|
||||
ci->write(data->rec_file, &h.wph, sizeof (h.wph))
|
||||
!= sizeof (h.wph) ||
|
||||
ci->write(data->rec_file, &h.wpmdh, sizeof (h.wpmdh))
|
||||
!= sizeof (h.wpmdh) ||
|
||||
ci->write(data->rec_file, &h.rhdr, sizeof (h.rhdr))
|
||||
!= sizeof (h.rhdr))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ci->fsync(data->rec_file);
|
||||
ci->close(data->rec_file);
|
||||
data->rec_file = -1;
|
||||
|
||||
return true;
|
||||
} /* on_end_file */
|
||||
|
||||
static void enc_events_callback(enum enc_events event, void *data) ICODE_ATTR;
|
||||
static void enc_events_callback(enum enc_events event, void *data)
|
||||
{
|
||||
if (event == ENC_WRITE_CHUNK)
|
||||
{
|
||||
if (on_write_chunk((struct enc_file_event_data *)data))
|
||||
return;
|
||||
}
|
||||
else if (event == ENC_START_FILE)
|
||||
{
|
||||
/* write metadata header and RIFF header */
|
||||
if (on_start_file((struct enc_file_event_data *)data))
|
||||
return;
|
||||
}
|
||||
else if (event == ENC_END_FILE)
|
||||
{
|
||||
if (on_end_file((struct enc_file_event_data *)data))
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
((struct enc_file_event_data *)data)->chunk->flags |= CHUNKF_ERROR;
|
||||
} /* enc_events_callback */
|
||||
|
||||
static bool init_encoder(void)
|
||||
{
|
||||
struct enc_inputs inputs;
|
||||
struct enc_parameters params;
|
||||
|
||||
codec_init(ci);
|
||||
|
||||
if(ci->enc_get_inputs == NULL ||
|
||||
ci->enc_set_parameters == NULL ||
|
||||
ci->enc_alloc_chunk == NULL ||
|
||||
ci->enc_free_chunk == NULL ||
|
||||
ci->enc_wavbuf_near_empty == NULL ||
|
||||
ci->enc_get_wav_data == NULL ||
|
||||
ci->enc_set_header_callback == NULL )
|
||||
return CODEC_ERROR;
|
||||
if (ci->enc_get_inputs == NULL ||
|
||||
ci->enc_set_parameters == NULL ||
|
||||
ci->enc_get_chunk == NULL ||
|
||||
ci->enc_finish_chunk == NULL ||
|
||||
ci->enc_pcm_buf_near_empty == NULL ||
|
||||
ci->enc_get_pcm_data == NULL ||
|
||||
ci->enc_unget_pcm_data == NULL )
|
||||
return false;
|
||||
|
||||
ci->cpu_boost(true);
|
||||
ci->enc_get_inputs(&inputs);
|
||||
|
||||
*ci->enc_set_header_callback = enc_set_header;
|
||||
ci->enc_get_inputs(&enc_buffer_size, &enc_channels, &enc_quality);
|
||||
if (inputs.config->afmt != AFMT_WAVPACK)
|
||||
return false;
|
||||
|
||||
/* configure the buffer system */
|
||||
chunk_size = sizeof(long) + CHUNK_SIZE * enc_channels / 2;
|
||||
num_chunks = enc_buffer_size / chunk_size;
|
||||
samp_per_chunk = CHUNK_SIZE / 4;
|
||||
|
||||
/* inform the main program about buffer dimensions and other params */
|
||||
/* add wav_header_mono as place holder to file start position */
|
||||
/* wav header and wvpk header have to be reordered later */
|
||||
ci->enc_set_parameters(chunk_size, num_chunks, samp_per_chunk,
|
||||
wav_header_mono, sizeof(wav_header_mono),
|
||||
AFMT_WAVPACK);
|
||||
memset(&config, 0, sizeof (config));
|
||||
config.bits_per_sample = PCM_DEPTH_BITS;
|
||||
config.bytes_per_sample = PCM_DEPTH_BYTES;
|
||||
config.sample_rate = inputs.sample_rate;
|
||||
config.num_channels = inputs.num_channels;
|
||||
|
||||
wpc = WavpackOpenFileOutput ();
|
||||
|
||||
memset (&config, 0, sizeof (config));
|
||||
config.bits_per_sample = 16;
|
||||
config.bytes_per_sample = 2;
|
||||
config.sample_rate = 44100;
|
||||
config.num_channels = enc_channels;
|
||||
if (!WavpackSetConfiguration(wpc, &config, -1))
|
||||
return false;
|
||||
|
||||
if (!WavpackSetConfiguration (wpc, &config, 1))
|
||||
/* configure the buffer system */
|
||||
params.afmt = AFMT_WAVPACK;
|
||||
input_size = PCM_CHUNK_SIZE*inputs.num_channels / 2;
|
||||
data_size = 105*input_size / 100;
|
||||
input_size *= 2;
|
||||
input_step = input_size / 4;
|
||||
params.chunk_size = data_size;
|
||||
params.enc_sample_rate = inputs.sample_rate;
|
||||
params.reserve_bytes = 0;
|
||||
params.events_callback = enc_events_callback;
|
||||
|
||||
ci->enc_set_parameters(¶ms);
|
||||
|
||||
return true;
|
||||
} /* init_encoder */
|
||||
|
||||
enum codec_status codec_start(struct codec_api* api)
|
||||
{
|
||||
bool cpu_boosted;
|
||||
|
||||
ci = api; /* copy to global api pointer */
|
||||
|
||||
#ifdef USE_IRAM
|
||||
ci->memcpy(iramstart, iramcopy, iramend - iramstart);
|
||||
ci->memset(iedata, 0, iend - iedata);
|
||||
#endif
|
||||
|
||||
/* initialize params and config */
|
||||
if (!init_encoder())
|
||||
{
|
||||
ci->enc_codec_loaded = -1;
|
||||
return CODEC_ERROR;
|
||||
}
|
||||
|
||||
/* main application waits for this flag during encoder loading */
|
||||
ci->enc_codec_loaded = true;
|
||||
ci->enc_codec_loaded = 1;
|
||||
|
||||
ci->cpu_boost(true);
|
||||
cpu_boosted = true;
|
||||
|
||||
/* main encoding loop */
|
||||
while(!ci->stop_codec)
|
||||
{
|
||||
while((src = (uint32*)ci->enc_get_wav_data(CHUNK_SIZE)) != NULL)
|
||||
uint8_t *src;
|
||||
|
||||
while ((src = ci->enc_get_pcm_data(PCM_CHUNK_SIZE)) != NULL)
|
||||
{
|
||||
struct enc_chunk_hdr *chunk;
|
||||
bool abort_chunk;
|
||||
uint8_t *dst;
|
||||
uint8_t *src_end;
|
||||
|
||||
if(ci->stop_codec)
|
||||
break;
|
||||
|
||||
if(ci->enc_wavbuf_near_empty() == 0)
|
||||
abort_chunk = true;
|
||||
|
||||
if (!cpu_boosted && ci->enc_pcm_buf_near_empty() == 0)
|
||||
{
|
||||
if(!cpu_boosted)
|
||||
{
|
||||
ci->cpu_boost(true);
|
||||
cpu_boosted = true;
|
||||
}
|
||||
ci->cpu_boost(true);
|
||||
cpu_boosted = true;
|
||||
}
|
||||
|
||||
dst = (uint32*)ci->enc_alloc_chunk() + 1;
|
||||
chunk = ci->enc_get_chunk();
|
||||
|
||||
WavpackStartBlock (wpc, (uint8*)dst, (uint8*)dst + CHUNK_SIZE);
|
||||
/* reset counts and pointer */
|
||||
chunk->enc_size = 0;
|
||||
chunk->num_pcm = 0;
|
||||
chunk->enc_data = NULL;
|
||||
|
||||
if(enc_channels == 2)
|
||||
dst = ENC_CHUNK_SKIP_HDR(dst, chunk);
|
||||
|
||||
WavpackStartBlock(wpc, dst, dst + data_size);
|
||||
|
||||
chunk_to_int32((uint32_t*)src);
|
||||
src = input_buffer;
|
||||
src_end = src + input_size;
|
||||
|
||||
/* encode chunk in four steps yielding between each */
|
||||
do
|
||||
{
|
||||
for (i=0; i<CHUNK_SIZE/4; i++)
|
||||
if (WavpackPackSamples(wpc, (int32_t *)src,
|
||||
PCM_SAMP_PER_CHUNK/4))
|
||||
{
|
||||
t = (long)*src++;
|
||||
|
||||
input_buffer[2*i + 0] = t >> 16;
|
||||
input_buffer[2*i + 1] = (short)t;
|
||||
chunk->num_pcm += PCM_SAMP_PER_CHUNK/4;
|
||||
ci->yield();
|
||||
/* could've been stopped in some way */
|
||||
abort_chunk = ci->stop_codec ||
|
||||
(chunk->flags & CHUNKF_ABORT);
|
||||
}
|
||||
|
||||
src += input_step;
|
||||
}
|
||||
else
|
||||
while (!abort_chunk && src < src_end);
|
||||
|
||||
if (!abort_chunk)
|
||||
{
|
||||
for (i=0; i<CHUNK_SIZE/4; i++)
|
||||
{
|
||||
t = (long)*src++;
|
||||
t = (((t<<16)>>16) + (t>>16)) >> 1; /* left+right */
|
||||
|
||||
input_buffer[i] = t;
|
||||
}
|
||||
}
|
||||
|
||||
if (!WavpackPackSamples (wpc, input_buffer, CHUNK_SIZE/4))
|
||||
return CODEC_ERROR;
|
||||
|
||||
chunk->enc_data = dst;
|
||||
if (chunk->num_pcm < PCM_SAMP_PER_CHUNK)
|
||||
ci->enc_unget_pcm_data(PCM_CHUNK_SIZE - chunk->num_pcm*4);
|
||||
/* finish the chunk and store chunk size info */
|
||||
dst[-1] = WavpackFinishBlock (wpc);
|
||||
|
||||
ci->enc_free_chunk();
|
||||
ci->yield();
|
||||
}
|
||||
|
||||
if(ci->enc_wavbuf_near_empty())
|
||||
{
|
||||
if(cpu_boosted)
|
||||
{
|
||||
ci->cpu_boost(false);
|
||||
cpu_boosted = false;
|
||||
chunk->enc_size = WavpackFinishBlock(wpc);
|
||||
ci->enc_finish_chunk();
|
||||
}
|
||||
}
|
||||
|
||||
if (cpu_boosted && ci->enc_pcm_buf_near_empty() != 0)
|
||||
{
|
||||
ci->cpu_boost(false);
|
||||
cpu_boosted = false;
|
||||
}
|
||||
|
||||
ci->yield();
|
||||
}
|
||||
|
||||
if(cpu_boosted) /* set initial boost state */
|
||||
if (cpu_boosted) /* set initial boost state */
|
||||
ci->cpu_boost(false);
|
||||
|
||||
/* reset parameters to initial state */
|
||||
ci->enc_set_parameters(0, 0, 0, 0, 0, 0);
|
||||
ci->enc_set_parameters(NULL);
|
||||
|
||||
/* main application waits for this flag during encoder removing */
|
||||
ci->enc_codec_loaded = false;
|
||||
ci->enc_codec_loaded = 0;
|
||||
|
||||
return CODEC_OK;
|
||||
}
|
||||
#endif
|
||||
} /* codec_start */
|
||||
|
||||
#endif /* ndef SIMULATOR */
|
||||
|
|
|
@ -710,7 +710,8 @@ static bool eq_save_preset(void)
|
|||
char filename[MAX_PATH];
|
||||
int *setting;
|
||||
|
||||
create_numbered_filename(filename, EQS_DIR, "eq", ".cfg", 2);
|
||||
create_numbered_filename(filename, EQS_DIR, "eq", ".cfg", 2
|
||||
IF_CNFN_NUM_(, NULL));
|
||||
|
||||
/* allow user to modify filename */
|
||||
while (true) {
|
||||
|
|
|
@ -124,19 +124,6 @@
|
|||
#endif
|
||||
#define STATUSBAR_TIME_X_END(statusbar_width) statusbar_width - 1 - \
|
||||
STATUSBAR_DISK_WIDTH
|
||||
#if defined(HAVE_RECORDING)
|
||||
/* analogue frequency numbers taken from the order of frequencies in sample_rate */
|
||||
#define FREQ_44 7
|
||||
#define FREQ_48 8
|
||||
#define FREQ_32 6
|
||||
#define FREQ_22 4
|
||||
#define FREQ_24 5
|
||||
#define FREQ_16 3
|
||||
#ifdef HAVE_SPDIF_IN
|
||||
#define SOURCE_SPDIF 2
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct gui_syncstatusbar statusbars;
|
||||
|
||||
void gui_statusbar_init(struct gui_statusbar * bar)
|
||||
|
@ -600,41 +587,113 @@ void gui_statusbar_time(struct screen * display, int hour, int minute)
|
|||
#endif
|
||||
|
||||
#ifdef HAVE_RECORDING
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
/**
|
||||
* Write a number to the display using bitmaps and return new position
|
||||
*/
|
||||
static int write_bitmap_number(struct screen * display, int value,
|
||||
int x, int y)
|
||||
{
|
||||
char buf[12], *ptr;
|
||||
snprintf(buf, sizeof(buf), "%d", value);
|
||||
|
||||
for (ptr = buf; *ptr != '\0'; ptr++, x += BM_GLYPH_WIDTH)
|
||||
display->mono_bitmap(bitmap_glyphs_4x8[*ptr - '0'], x, y,
|
||||
BM_GLYPH_WIDTH, STATUSBAR_HEIGHT);
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write format info bitmaps - right justified
|
||||
*/
|
||||
static void gui_statusbar_write_format_info(struct screen * display)
|
||||
{
|
||||
/* Can't fit info for sw codec targets in statusbar using FONT_SYSFIXED
|
||||
so must use icons */
|
||||
int rec_format = global_settings.rec_format;
|
||||
unsigned bitrk = 0; /* compiler warns about unitialized use !! */
|
||||
int xpos = STATUSBAR_ENCODER_X_POS;
|
||||
int width = STATUSBAR_ENCODER_WIDTH;
|
||||
const unsigned char *bm = bitmap_formats_18x8[rec_format];
|
||||
|
||||
if (rec_format == REC_FORMAT_MPA_L3)
|
||||
{
|
||||
/* Special handling for mp3 */
|
||||
bitrk = global_settings.mp3_enc_config.bitrate;
|
||||
bitrk = mp3_enc_bitr[bitrk];
|
||||
|
||||
width = BM_MPA_L3_M_WIDTH;
|
||||
|
||||
/* Slide 'M' to right if fewer than three digits used */
|
||||
if (bitrk > 999)
|
||||
bitrk = 999; /* neurotic safety check if corrupted */
|
||||
else
|
||||
{
|
||||
if (bitrk < 100)
|
||||
xpos += BM_GLYPH_WIDTH;
|
||||
if (bitrk < 10)
|
||||
xpos += BM_GLYPH_WIDTH;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Show bitmap - clipping right edge if needed */
|
||||
display->mono_bitmap_part(bm, 0, 0, STATUSBAR_ENCODER_WIDTH,
|
||||
xpos, STATUSBAR_Y_POS, width, STATUSBAR_HEIGHT);
|
||||
|
||||
if (rec_format == REC_FORMAT_MPA_L3)
|
||||
{
|
||||
xpos += BM_MPA_L3_M_WIDTH; /* to right of 'M' */
|
||||
write_bitmap_number(display, bitrk, xpos, STATUSBAR_Y_POS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write sample rate using bitmaps - left justified
|
||||
*/
|
||||
static void gui_statusbar_write_samplerate_info(struct screen * display)
|
||||
{
|
||||
unsigned long samprk;
|
||||
int xpos;
|
||||
|
||||
#ifdef SIMULATOR
|
||||
samprk = 44100;
|
||||
#else
|
||||
#ifdef HAVE_SPDIF_IN
|
||||
if (global_settings.rec_source == AUDIO_SRC_SPDIF)
|
||||
/* Use rate in use, not current measured rate if it changed */
|
||||
samprk = pcm_rec_sample_rate();
|
||||
else
|
||||
#endif
|
||||
samprk = rec_freq_sampr[global_settings.rec_frequency];
|
||||
#endif /* SIMULATOR */
|
||||
|
||||
samprk /= 1000;
|
||||
if (samprk > 99)
|
||||
samprk = 99; /* Limit to 3 glyphs */
|
||||
|
||||
xpos = write_bitmap_number(display, (unsigned)samprk,
|
||||
STATUSBAR_RECFREQ_X_POS, STATUSBAR_Y_POS);
|
||||
|
||||
/* write the 'k' */
|
||||
display->mono_bitmap(bitmap_glyphs_4x8[Glyph_4x8_k], xpos,
|
||||
STATUSBAR_Y_POS, BM_GLYPH_WIDTH,
|
||||
STATUSBAR_HEIGHT);
|
||||
}
|
||||
#endif /* CONFIG_CODEC == SWCODEC */
|
||||
|
||||
void gui_statusbar_icon_recording_info(struct screen * display)
|
||||
{
|
||||
#if (CONFIG_CODEC != SWCODEC) || (defined(SIMULATOR) && defined(HAVE_SPDIF_IN))
|
||||
char buffer[3];
|
||||
#endif
|
||||
#if CONFIG_CODEC != SWCODEC
|
||||
char buffer[3];
|
||||
int width, height;
|
||||
static char* const sample_rate[12] =
|
||||
{
|
||||
"8",
|
||||
"11",
|
||||
"12",
|
||||
"16",
|
||||
"22",
|
||||
"24",
|
||||
"32",
|
||||
"44",
|
||||
"48",
|
||||
"64",
|
||||
"88",
|
||||
"96"
|
||||
};
|
||||
|
||||
display->setfont(FONT_SYSFIXED);
|
||||
#endif
|
||||
#endif /* CONFIG_CODEC != SWCODEC */
|
||||
|
||||
/* Display Codec info in statusbar */
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
/* Can't fit info for sw codec targets in statusbar using FONT_SYSFIXED
|
||||
so must use icons */
|
||||
display->mono_bitmap(bitmap_icons_18x8[global_settings.rec_quality],
|
||||
STATUSBAR_ENCODER_X_POS, STATUSBAR_Y_POS,
|
||||
STATUSBAR_ENCODER_WIDTH, STATUSBAR_HEIGHT);
|
||||
#else
|
||||
|
||||
gui_statusbar_write_format_info(display);
|
||||
#else /* !SWCODEC */
|
||||
display->mono_bitmap(bitmap_icons_5x8[Icon_q],
|
||||
STATUSBAR_ENCODER_X_POS + 8, STATUSBAR_Y_POS,
|
||||
5, STATUSBAR_HEIGHT);
|
||||
|
@ -643,56 +702,37 @@ void gui_statusbar_icon_recording_info(struct screen * display)
|
|||
display->getstringsize(buffer, &width, &height);
|
||||
if (height <= STATUSBAR_HEIGHT)
|
||||
display->putsxy(STATUSBAR_ENCODER_X_POS + 13, STATUSBAR_Y_POS, buffer);
|
||||
#endif
|
||||
#endif /* CONFIG_CODEC == SWCODEC */
|
||||
|
||||
/* Display Samplerate info in statusbar */
|
||||
#if defined(HAVE_SPDIF_IN)
|
||||
if (global_settings.rec_source == SOURCE_SPDIF)
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
/* SWCODEC targets use bitmaps for glyphs */
|
||||
gui_statusbar_write_samplerate_info(display);
|
||||
#else /* !SWCODEC */
|
||||
/* hwcodec targets have sysfont characters */
|
||||
#ifdef HAVE_SPDIF_IN
|
||||
if (global_settings.rec_source == AUDIO_SRC_SPDIF)
|
||||
{
|
||||
#if (CONFIG_CODEC != MAS3587F) && !defined(SIMULATOR)
|
||||
display->mono_bitmap(bitmap_icons_12x8[audio_get_spdif_sample_rate()],
|
||||
STATUSBAR_RECFREQ_X_POS, STATUSBAR_Y_POS,
|
||||
STATUSBAR_RECFREQ_WIDTH, STATUSBAR_HEIGHT);
|
||||
#else
|
||||
/* Can't measure S/PDIF sample rate on Archos/Sim yet */
|
||||
snprintf(buffer, sizeof(buffer), "--");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_SPDIF_IN */
|
||||
{
|
||||
/* Analogue frequency in wrong order so remap settings numbers */
|
||||
int freq = global_settings.rec_frequency;
|
||||
if (freq == 0)
|
||||
freq = FREQ_44;
|
||||
else if (freq == 1)
|
||||
freq = FREQ_48;
|
||||
else if (freq == 2)
|
||||
freq = FREQ_32;
|
||||
else if (freq == 3)
|
||||
freq = FREQ_22;
|
||||
else if (freq == 4)
|
||||
freq = FREQ_24;
|
||||
else if (freq == 5)
|
||||
freq = FREQ_16;
|
||||
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
/* samplerate icons for swcodec targets*/
|
||||
display->mono_bitmap(bitmap_icons_12x8[freq],
|
||||
STATUSBAR_RECFREQ_X_POS, STATUSBAR_Y_POS,
|
||||
STATUSBAR_RECFREQ_WIDTH, STATUSBAR_HEIGHT);
|
||||
}
|
||||
#else
|
||||
/* hwcodec targets have sysfont characters */
|
||||
snprintf(buffer, sizeof(buffer), "%s", sample_rate[freq]);
|
||||
display->getstringsize(buffer, &width, &height);
|
||||
static char const * const freq_strings[12] =
|
||||
{ "44", "48", "32", "22", "24", "16" };
|
||||
snprintf(buffer, sizeof(buffer), "%s",
|
||||
freq_strings[global_settings.rec_frequency]);
|
||||
}
|
||||
|
||||
if (height <= STATUSBAR_HEIGHT)
|
||||
display->putsxy(STATUSBAR_RECFREQ_X_POS, STATUSBAR_Y_POS, buffer);
|
||||
display->getstringsize(buffer, &width, &height);
|
||||
|
||||
if (height <= STATUSBAR_HEIGHT)
|
||||
display->putsxy(STATUSBAR_RECFREQ_X_POS, STATUSBAR_Y_POS, buffer);
|
||||
|
||||
display->setfont(FONT_UI);
|
||||
#endif /* CONFIG_CODEC == SWCODEC */
|
||||
|
||||
display->setfont(FONT_UI);
|
||||
#endif
|
||||
/* Display Channel status in status bar */
|
||||
if(global_settings.rec_channels)
|
||||
{
|
||||
|
|
|
@ -9802,7 +9802,7 @@
|
|||
</phrase>
|
||||
<phrase>
|
||||
id: VOICE_KBIT_PER_SEC
|
||||
desc: spoken only, for file extension
|
||||
desc: spoken only, a unit postfix
|
||||
user:
|
||||
<source>
|
||||
*: ""
|
||||
|
@ -10032,3 +10032,115 @@
|
|||
*: ""
|
||||
</voice>
|
||||
</phrase>
|
||||
<phrase>
|
||||
id: LANG_RECORDING_FORMAT
|
||||
desc: audio format item in recording menu
|
||||
user:
|
||||
<source>
|
||||
*: "Format"
|
||||
</source>
|
||||
<dest>
|
||||
*: "Format"
|
||||
</dest>
|
||||
<voice>
|
||||
*: "Format"
|
||||
</voice>
|
||||
</phrase>
|
||||
<phrase>
|
||||
id: LANG_AFMT_MPA_L3
|
||||
desc: audio format description
|
||||
user:
|
||||
<source>
|
||||
*: "MPEG Layer 3"
|
||||
</source>
|
||||
<dest>
|
||||
*: "MPEG Layer 3"
|
||||
</dest>
|
||||
<voice>
|
||||
*: "MPEG Layer 3"
|
||||
</voice>
|
||||
</phrase>
|
||||
<phrase>
|
||||
id: LANG_AFMT_PCM_WAV
|
||||
desc: audio format description
|
||||
user:
|
||||
<source>
|
||||
*: "PCM Wave"
|
||||
</source>
|
||||
<dest>
|
||||
*: "PCM Wave"
|
||||
</dest>
|
||||
<voice>
|
||||
*: "PCM Wave"
|
||||
</voice>
|
||||
</phrase>
|
||||
<phrase>
|
||||
id: LANG_AFMT_WAVPACK
|
||||
desc: audio format description
|
||||
user:
|
||||
<source>
|
||||
*: "WavPack"
|
||||
</source>
|
||||
<dest>
|
||||
*: "WavPack"
|
||||
</dest>
|
||||
<voice>
|
||||
*: "WavPack"
|
||||
</voice>
|
||||
</phrase>
|
||||
<phrase>
|
||||
id: LANG_ENCODER_SETTINGS
|
||||
desc: encoder settings
|
||||
user:
|
||||
<source>
|
||||
*: "Encoder Settings"
|
||||
</source>
|
||||
<dest>
|
||||
*: "Encoder Settings"
|
||||
</dest>
|
||||
<voice>
|
||||
*: "Encoder Settings"
|
||||
</voice>
|
||||
</phrase>
|
||||
<phrase>
|
||||
id: LANG_NO_SETTINGS
|
||||
desc: when something has settings in a certain context
|
||||
user:
|
||||
<source>
|
||||
*: "(No Settings)"
|
||||
</source>
|
||||
<dest>
|
||||
*: "(No Settings)"
|
||||
</dest>
|
||||
<voice>
|
||||
*: "No settings available"
|
||||
</voice>
|
||||
</phrase>
|
||||
<phrase>
|
||||
id: LANG_SOURCE_FREQUENCY
|
||||
desc: when recording source frequency setting must follow source
|
||||
user:
|
||||
<source>
|
||||
*: "(Same As Source)"
|
||||
</source>
|
||||
<dest>
|
||||
*: "(Same As Source)"
|
||||
</dest>
|
||||
<voice>
|
||||
*: "Same As Source"
|
||||
</voice>
|
||||
</phrase>
|
||||
<phrase>
|
||||
id: LANG_BITRATE
|
||||
desc: bits-kilobits per unit time
|
||||
user:
|
||||
<source>
|
||||
*: "Bitrate"
|
||||
</source>
|
||||
<dest>
|
||||
*: "Bitrate"
|
||||
</dest>
|
||||
<voice>
|
||||
*: "Bitrate"
|
||||
</voice>
|
||||
</phrase>
|
||||
|
|
|
@ -286,6 +286,9 @@ void init(void)
|
|||
|
||||
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
||||
set_cpu_frequency(CPUFREQ_NORMAL);
|
||||
#ifdef CPU_COLDFIRE
|
||||
coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS);
|
||||
#endif
|
||||
cpu_boost_id(true, CPUBOOSTID_MAININIT);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -88,36 +88,6 @@ struct apetag_item_header
|
|||
long flags;
|
||||
};
|
||||
|
||||
struct format_list
|
||||
{
|
||||
char format;
|
||||
char extension[5];
|
||||
};
|
||||
|
||||
static const struct format_list formats[] =
|
||||
{
|
||||
{ AFMT_MPA_L1, "mp1" },
|
||||
{ AFMT_MPA_L2, "mp2" },
|
||||
{ AFMT_MPA_L2, "mpa" },
|
||||
{ AFMT_MPA_L3, "mp3" },
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
{ AFMT_OGG_VORBIS, "ogg" },
|
||||
{ AFMT_PCM_WAV, "wav" },
|
||||
{ AFMT_FLAC, "flac" },
|
||||
{ AFMT_MPC, "mpc" },
|
||||
{ AFMT_A52, "a52" },
|
||||
{ AFMT_A52, "ac3" },
|
||||
{ AFMT_WAVPACK, "wv" },
|
||||
{ AFMT_ALAC, "m4a" },
|
||||
{ AFMT_AAC, "mp4" },
|
||||
{ AFMT_SHN, "shn" },
|
||||
{ AFMT_AIFF, "aif" },
|
||||
{ AFMT_AIFF, "aiff" },
|
||||
{ AFMT_SID, "sid" },
|
||||
{ AFMT_ADX, "adx" },
|
||||
#endif
|
||||
};
|
||||
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
static const unsigned short a52_bitrates[] =
|
||||
{
|
||||
|
@ -1691,14 +1661,24 @@ unsigned int probe_file_format(const char *filename)
|
|||
return AFMT_UNKNOWN;
|
||||
}
|
||||
|
||||
suffix += 1;
|
||||
|
||||
for (i = 0; i < sizeof(formats) / sizeof(formats[0]); i++)
|
||||
/* skip '.' */
|
||||
suffix++;
|
||||
|
||||
for (i = 1; i < AFMT_NUM_CODECS; i++)
|
||||
{
|
||||
if (strcasecmp(suffix, formats[i].extension) == 0)
|
||||
/* search extension list for type */
|
||||
const char *ext = audio_formats[i].ext_list;
|
||||
|
||||
do
|
||||
{
|
||||
if (strcasecmp(suffix, ext) == 0)
|
||||
{
|
||||
return formats[i].format;
|
||||
return i;
|
||||
}
|
||||
|
||||
ext += strlen(ext) + 1;
|
||||
}
|
||||
while (*ext != '\0');
|
||||
}
|
||||
|
||||
return AFMT_UNKNOWN;
|
||||
|
|
57
apps/misc.c
57
apps/misc.c
|
@ -58,6 +58,8 @@
|
|||
#endif /* End HAVE_LCD_BITMAP */
|
||||
#include "gui/gwps-common.h"
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
/* Format a large-range value for output, using the appropriate unit so that
|
||||
* the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
|
||||
* units) if possible, and 3 significant digits are shown. If a buffer is
|
||||
|
@ -114,16 +116,20 @@ char *output_dyn_value(char *buf, int buf_size, int value,
|
|||
}
|
||||
|
||||
/* Create a filename with a number part in a way that the number is 1
|
||||
higher than the highest numbered file matching the same pattern.
|
||||
It is allowed that buffer and path point to the same memory location,
|
||||
saving a strcpy(). Path must always be given without trailing slash,. */
|
||||
* higher than the highest numbered file matching the same pattern.
|
||||
* It is allowed that buffer and path point to the same memory location,
|
||||
* saving a strcpy(). Path must always be given without trailing slash.
|
||||
* "num" can point to an int specifying the number to use or NULL or a value
|
||||
* less than zero to number automatically. The final number used will also
|
||||
* be returned in *num. If *num is >= 0 then *num will be incremented by
|
||||
* one. */
|
||||
char *create_numbered_filename(char *buffer, const char *path,
|
||||
const char *prefix, const char *suffix,
|
||||
int numberlen)
|
||||
int numberlen IF_CNFN_NUM_(, int *num))
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
int max_num = 0;
|
||||
int max_num;
|
||||
int pathlen;
|
||||
int prefixlen = strlen(prefix);
|
||||
char fmtstring[12];
|
||||
|
@ -133,6 +139,18 @@ char *create_numbered_filename(char *buffer, const char *path,
|
|||
|
||||
pathlen = strlen(buffer);
|
||||
|
||||
#ifdef IF_CNFN_NUM
|
||||
if (num && *num >= 0)
|
||||
{
|
||||
/* number specified */
|
||||
max_num = *num;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/* automatic numbering */
|
||||
max_num = 0;
|
||||
|
||||
dir = opendir(pathlen ? buffer : "/");
|
||||
if (!dir)
|
||||
return NULL;
|
||||
|
@ -149,11 +167,20 @@ char *create_numbered_filename(char *buffer, const char *path,
|
|||
if (curr_num > max_num)
|
||||
max_num = curr_num;
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
max_num++;
|
||||
|
||||
snprintf(fmtstring, sizeof(fmtstring), "/%%s%%0%dd%%s", numberlen);
|
||||
snprintf(buffer + pathlen, MAX_PATH - pathlen, fmtstring, prefix,
|
||||
max_num + 1, suffix);
|
||||
max_num, suffix);
|
||||
|
||||
#ifdef IF_CNFN_NUM
|
||||
if (num)
|
||||
*num = max_num;
|
||||
#endif
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
@ -161,13 +188,22 @@ char *create_numbered_filename(char *buffer, const char *path,
|
|||
#ifdef CONFIG_RTC
|
||||
/* Create a filename with a date+time part.
|
||||
It is allowed that buffer and path point to the same memory location,
|
||||
saving a strcpy(). Path must always be given without trailing slash. */
|
||||
saving a strcpy(). Path must always be given without trailing slash.
|
||||
unique_time as true makes the function wait until the current time has
|
||||
changed. */
|
||||
char *create_datetime_filename(char *buffer, const char *path,
|
||||
const char *prefix, const char *suffix)
|
||||
const char *prefix, const char *suffix,
|
||||
bool unique_time)
|
||||
{
|
||||
struct tm *tm = get_time();
|
||||
static struct tm last_tm;
|
||||
int pathlen;
|
||||
|
||||
while (unique_time && !memcmp(get_time(), &last_tm, sizeof (struct tm)))
|
||||
sleep(HZ/10);
|
||||
|
||||
last_tm = *tm;
|
||||
|
||||
if (buffer != path)
|
||||
strncpy(buffer, path, MAX_PATH);
|
||||
|
||||
|
@ -356,9 +392,10 @@ void screen_dump(void)
|
|||
#endif
|
||||
|
||||
#ifdef CONFIG_RTC
|
||||
create_datetime_filename(filename, "", "dump ", ".bmp");
|
||||
create_datetime_filename(filename, "", "dump ", ".bmp", false);
|
||||
#else
|
||||
create_numbered_filename(filename, "", "dump_", ".bmp", 4);
|
||||
create_numbered_filename(filename, "", "dump_", ".bmp", 4
|
||||
IF_CNFN_NUM_(, NULL));
|
||||
#endif
|
||||
|
||||
fh = creat(filename, O_WRONLY);
|
||||
|
|
35
apps/misc.h
35
apps/misc.h
|
@ -19,21 +19,46 @@
|
|||
#ifndef MISC_H
|
||||
#define MISC_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
/* Format a large-range value for output, using the appropriate unit so that
|
||||
* the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
|
||||
* units) if possible, and 3 significant digits are shown. If a buffer is
|
||||
* given, the result is snprintf()'d into that buffer, otherwise the result is
|
||||
* voiced.*/
|
||||
void output_dyn_value(char *buf, int buf_size, int value,
|
||||
char *output_dyn_value(char *buf, int buf_size, int value,
|
||||
const unsigned char **units, bool bin_scale);
|
||||
|
||||
/* Create a filename with a number part in a way that the number is 1
|
||||
* higher than the highest numbered file matching the same pattern.
|
||||
* It is allowed that buffer and path point to the same memory location,
|
||||
* saving a strcpy(). Path must always be given without trailing slash.
|
||||
*
|
||||
* "num" can point to an int specifying the number to use or NULL or a value
|
||||
* less than zero to number automatically. The final number used will also
|
||||
* be returned in *num. If *num is >= 0 then *num will be incremented by
|
||||
* one. */
|
||||
#if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING) && !defined(CONFIG_RTC)
|
||||
/* this feature is needed by SWCODEC recording without a RTC to prevent
|
||||
disk access when changing files */
|
||||
#define IF_CNFN_NUM_(...) __VA_ARGS__
|
||||
#define IF_CNFN_NUM
|
||||
#else
|
||||
#define IF_CNFN_NUM_(...)
|
||||
#endif
|
||||
char *create_numbered_filename(char *buffer, const char *path,
|
||||
const char *prefix, const char *suffix,
|
||||
int numberlen);
|
||||
int numberlen IF_CNFN_NUM_(, int *num));
|
||||
#ifdef CONFIG_RTC
|
||||
/* Create a filename with a date+time part.
|
||||
It is allowed that buffer and path point to the same memory location,
|
||||
saving a strcpy(). Path must always be given without trailing slash.
|
||||
unique_time as true makes the function wait until the current time has
|
||||
changed. */
|
||||
char *create_datetime_filename(char *buffer, const char *path,
|
||||
const char *prefix, const char *suffix);
|
||||
#endif
|
||||
const char *prefix, const char *suffix,
|
||||
bool unique_time);
|
||||
#endif /* CONFIG_RTC */
|
||||
|
||||
/* Read (up to) a line of text from fd into buffer and return number of bytes
|
||||
* read (which may be larger than the number of bytes stored in buffer). If
|
||||
|
@ -57,4 +82,4 @@ long default_event_handler(long event);
|
|||
void car_adapter_mode_init(void);
|
||||
extern int show_logo(void);
|
||||
|
||||
#endif
|
||||
#endif /* MISC_H */
|
||||
|
|
|
@ -51,9 +51,11 @@ struct pcmbufdesc
|
|||
void (*callback)(void);
|
||||
};
|
||||
|
||||
#define PCMBUF_DESCS(bufsize) ((bufsize) / PCMBUF_MINAVG_CHUNK)
|
||||
|
||||
/* Size of the PCM buffer. */
|
||||
static size_t pcmbuf_size IDATA_ATTR = 0;
|
||||
|
||||
static char *pcmbuf_bufend IDATA_ATTR;
|
||||
static char *audiobuffer IDATA_ATTR;
|
||||
/* Current audio buffer write index. */
|
||||
static size_t audiobuffer_pos IDATA_ATTR;
|
||||
|
@ -360,7 +362,7 @@ int pcmbuf_used_descs(void) {
|
|||
}
|
||||
|
||||
int pcmbuf_descs(void) {
|
||||
return pcmbuf_size / PCMBUF_MINAVG_CHUNK;
|
||||
return PCMBUF_DESCS(pcmbuf_size);
|
||||
}
|
||||
|
||||
size_t get_pcmbuf_descsize(void) {
|
||||
|
@ -371,28 +373,37 @@ static void pcmbuf_init_pcmbuffers(void) {
|
|||
struct pcmbufdesc *next = pcmbuf_write;
|
||||
next++;
|
||||
pcmbuf_write_end = pcmbuf_write;
|
||||
while ((void *)next < (void *)audiobufend) {
|
||||
while ((void *)next < (void *)pcmbuf_bufend) {
|
||||
pcmbuf_write_end->link=next;
|
||||
pcmbuf_write_end=next;
|
||||
next++;
|
||||
}
|
||||
}
|
||||
|
||||
bool pcmbuf_is_same_size(size_t bufsize)
|
||||
{
|
||||
/* keep calculations synced with pcmbuf_init */
|
||||
bufsize += PCMBUF_MIX_CHUNK * 2 + PCMBUF_DESCS(bufsize);
|
||||
return bufsize == (size_t)(pcmbuf_bufend - audiobuffer);
|
||||
}
|
||||
|
||||
/* Initialize the pcmbuffer the structure looks like this:
|
||||
* ...CODECBUFFER|---------PCMBUF---------|GUARDBUF|DESCS| */
|
||||
void pcmbuf_init(size_t bufsize)
|
||||
* ...|---------PCMBUF---------|FADEBUF|VOICEBUF|DESCS|... */
|
||||
size_t pcmbuf_init(size_t bufsize, char *bufend)
|
||||
{
|
||||
pcmbuf_size = bufsize;
|
||||
pcmbuf_bufend = bufend;
|
||||
pcmbuf_descsize = pcmbuf_descs()*sizeof(struct pcmbufdesc);
|
||||
audiobuffer = (char *)&audiobuf[(audiobufend - audiobuf) -
|
||||
(pcmbuf_size + PCMBUF_MIX_CHUNK * 2 + pcmbuf_descsize)];
|
||||
audiobuffer = pcmbuf_bufend - (pcmbuf_size + PCMBUF_MIX_CHUNK * 2
|
||||
+ pcmbuf_descsize);
|
||||
fadebuf = &audiobuffer[pcmbuf_size];
|
||||
voicebuf = &fadebuf[PCMBUF_MIX_CHUNK];
|
||||
pcmbuf_write = (struct pcmbufdesc *)(&voicebuf[PCMBUF_MIX_CHUNK]);
|
||||
pcmbuf_write = (struct pcmbufdesc *)&voicebuf[PCMBUF_MIX_CHUNK];
|
||||
pcmbuf_init_pcmbuffers();
|
||||
position_callback = NULL;
|
||||
pcmbuf_event_handler = NULL;
|
||||
pcmbuf_play_stop();
|
||||
return pcmbuf_bufend - audiobuffer;
|
||||
}
|
||||
|
||||
size_t pcmbuf_get_bufsize(void)
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
/* Returns true if the buffer needs to change size */
|
||||
bool pcmbuf_is_same_size(size_t bufsize);
|
||||
void pcmbuf_init(size_t bufsize);
|
||||
size_t pcmbuf_init(size_t bufsize, char *bufend);
|
||||
/* Size in bytes used by the pcmbuffer */
|
||||
size_t pcmbuf_get_bufsize(void);
|
||||
size_t get_pcmbuf_descsize(void);
|
||||
|
|
262
apps/playback.c
262
apps/playback.c
|
@ -54,8 +54,6 @@
|
|||
#include "playlist.h"
|
||||
#include "playback.h"
|
||||
#include "pcmbuf.h"
|
||||
#include "pcm_playback.h"
|
||||
#include "pcm_record.h"
|
||||
#include "buffer.h"
|
||||
#include "dsp.h"
|
||||
#include "abrepeat.h"
|
||||
|
@ -78,6 +76,7 @@
|
|||
|
||||
#ifdef HAVE_RECORDING
|
||||
#include "recording.h"
|
||||
#include "talk.h"
|
||||
#endif
|
||||
|
||||
#define PLAYBACK_VOICE
|
||||
|
@ -93,9 +92,13 @@
|
|||
* for their correct seeek target, 32k seems a good size */
|
||||
#define AUDIO_REBUFFER_GUESS_SIZE (1024*32)
|
||||
|
||||
/* macros to enable logf for queues */
|
||||
/* macros to enable logf for queues
|
||||
logging on SYS_TIMEOUT can be disabled */
|
||||
#ifdef SIMULATOR
|
||||
#define PLAYBACK_LOGQUEUES /* Define this for logf output of all queuing */
|
||||
/* Define this for logf output of all queuing except SYS_TIMEOUT */
|
||||
#define PLAYBACK_LOGQUEUES
|
||||
/* Define this to logf SYS_TIMEOUT messages */
|
||||
#define PLAYBACK_LOGQUEUES_SYS_TIMEOUT
|
||||
#endif
|
||||
|
||||
#ifdef PLAYBACK_LOGQUEUES
|
||||
|
@ -104,6 +107,18 @@
|
|||
#define LOGFQUEUE(s)
|
||||
#endif
|
||||
|
||||
#ifdef PLAYBACK_LOGQUEUES_SYS_TIMEOUT
|
||||
#define LOGFQUEUE_SYS_TIMEOUT(s) logf("%s", s)
|
||||
#else
|
||||
#define LOGFQUEUE_SYS_TIMEOUT(s)
|
||||
#endif
|
||||
|
||||
|
||||
/* Define one constant that includes recording related functionality */
|
||||
#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
|
||||
#define AUDIO_HAVE_RECORDING
|
||||
#endif
|
||||
|
||||
enum {
|
||||
Q_AUDIO_PLAY = 1,
|
||||
Q_AUDIO_STOP,
|
||||
|
@ -122,6 +137,9 @@ enum {
|
|||
#if MEM > 8
|
||||
Q_AUDIO_FILL_BUFFER_IF_ACTIVE_ATA,
|
||||
#endif
|
||||
#ifdef AUDIO_HAVE_RECORDING
|
||||
Q_AUDIO_LOAD_ENCODER,
|
||||
#endif
|
||||
|
||||
Q_CODEC_REQUEST_PENDING,
|
||||
Q_CODEC_REQUEST_COMPLETE,
|
||||
|
@ -133,7 +151,7 @@ enum {
|
|||
Q_CODEC_LOAD,
|
||||
Q_CODEC_LOAD_DISK,
|
||||
|
||||
#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
|
||||
#ifdef AUDIO_HAVE_RECORDING
|
||||
Q_ENCODER_LOAD_DISK,
|
||||
Q_ENCODER_RECORD,
|
||||
#endif
|
||||
|
@ -178,11 +196,16 @@ static volatile bool paused; /* Is audio paused? (A/C-) */
|
|||
static volatile bool filling IDATA_ATTR; /* Is file buffer currently being refilled? (A/C-) */
|
||||
|
||||
/* Ring buffer where tracks and codecs are loaded */
|
||||
static char *filebuf; /* Pointer to start of ring buffer (A/C-) */
|
||||
static unsigned char *filebuf; /* Pointer to start of ring buffer (A/C-) */
|
||||
size_t filebuflen; /* Total size of the ring buffer FIXME: make static (A/C-)*/
|
||||
static volatile size_t buf_ridx IDATA_ATTR; /* Ring buffer read position (A/C) FIXME? should be (C/A-) */
|
||||
static volatile size_t buf_widx IDATA_ATTR; /* Ring buffer read position (A/C-) */
|
||||
|
||||
#define BUFFER_STATE_TRASHED -1 /* Buffer is in a trashed state and must be reset */
|
||||
#define BUFFER_STATE_NORMAL 0 /* Buffer is arranged for voice and audio */
|
||||
#define BUFFER_STATE_VOICED_ONLY 1 /* Buffer is arranged for voice-only use */
|
||||
static int buffer_state = BUFFER_STATE_TRASHED; /* Buffer state */
|
||||
|
||||
#define RINGBUF_ADD(p,v) ((p+v)<filebuflen ? p+v : p+v-filebuflen)
|
||||
#define RINGBUF_SUB(p,v) ((p>=v) ? p-v : p+filebuflen-v)
|
||||
#define RINGBUF_ADD_CROSS(p1,v,p2) ((p1<p2)?(int)(p1+v)-(int)p2:(int)(p1+v-p2)-(int)filebuflen)
|
||||
|
@ -235,7 +258,7 @@ static const char audio_thread_name[] = "audio";
|
|||
static void audio_thread(void);
|
||||
static void audio_initiate_track_change(long direction);
|
||||
static bool audio_have_tracks(void);
|
||||
static void audio_reset_buffer(void);
|
||||
static void audio_reset_buffer(size_t pcmbufsize);
|
||||
|
||||
/* Codec thread */
|
||||
extern struct codec_api ci;
|
||||
|
@ -294,6 +317,10 @@ static void voice_thread(void);
|
|||
void mp3_play_data(const unsigned char* start, int size,
|
||||
void (*get_more)(unsigned char** start, int* size))
|
||||
{
|
||||
/* must reset the buffer before any playback begins if needed */
|
||||
if (buffer_state == BUFFER_STATE_TRASHED)
|
||||
audio_reset_buffer(pcmbuf_get_bufsize());
|
||||
|
||||
#ifdef PLAYBACK_VOICE
|
||||
static struct voice_info voice_clip;
|
||||
voice_clip.callback = get_more;
|
||||
|
@ -330,38 +357,95 @@ void mpeg_id3_options(bool _v1first)
|
|||
v1first = _v1first;
|
||||
}
|
||||
|
||||
void audio_load_encoder(int enc_id)
|
||||
unsigned char *audio_get_buffer(bool talk_buf, size_t *buffer_size)
|
||||
{
|
||||
#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
|
||||
const char *enc_fn = get_codec_filename(enc_id | CODEC_TYPE_ENCODER);
|
||||
unsigned char *buf = audiobuf;
|
||||
unsigned char *end = audiobufend;
|
||||
|
||||
audio_stop();
|
||||
|
||||
if (talk_buf || !talk_voice_required()
|
||||
|| buffer_state == BUFFER_STATE_TRASHED)
|
||||
{
|
||||
logf("get buffer: talk_buf");
|
||||
/* ok to use everything from audiobuf to audiobufend */
|
||||
if (buffer_state != BUFFER_STATE_TRASHED)
|
||||
talk_buffer_steal();
|
||||
buffer_state = BUFFER_STATE_TRASHED;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* skip talk buffer and move pcm buffer to end */
|
||||
logf("get buffer: voice");
|
||||
mp3_play_stop();
|
||||
buf += talk_get_bufsize();
|
||||
end -= pcmbuf_init(pcmbuf_get_bufsize(), audiobufend);
|
||||
buffer_state = BUFFER_STATE_VOICED_ONLY;
|
||||
}
|
||||
|
||||
*buffer_size = end - buf;
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
#ifdef HAVE_RECORDING
|
||||
unsigned char *audio_get_recording_buffer(size_t *buffer_size)
|
||||
{
|
||||
/* don't allow overwrite of voice swap area or we'll trash the
|
||||
swapped-out voice codec but can use whole thing if none */
|
||||
unsigned char *end = iram_buf[CODEC_IDX_VOICE] ?
|
||||
iram_buf[CODEC_IDX_VOICE] : audiobufend;
|
||||
|
||||
audio_stop();
|
||||
talk_buffer_steal();
|
||||
|
||||
buffer_state = BUFFER_STATE_TRASHED;
|
||||
|
||||
*buffer_size = end - audiobuf;
|
||||
|
||||
return (unsigned char *)audiobuf;
|
||||
}
|
||||
|
||||
bool audio_load_encoder(int afmt)
|
||||
{
|
||||
#ifndef SIMULATOR
|
||||
const char *enc_fn = get_codec_filename(afmt | CODEC_TYPE_ENCODER);
|
||||
if (!enc_fn)
|
||||
return;
|
||||
return false;
|
||||
|
||||
audio_remove_encoder();
|
||||
ci.enc_codec_loaded = 0; /* clear any previous error condition */
|
||||
|
||||
LOGFQUEUE("audio > codec Q_ENCODER_LOAD_DISK");
|
||||
queue_post(&codec_queue, Q_ENCODER_LOAD_DISK, (void *)enc_fn);
|
||||
LOGFQUEUE("audio > Q_AUDIO_LOAD_ENCODER");
|
||||
queue_post(&audio_queue, Q_AUDIO_LOAD_ENCODER, (void *)enc_fn);
|
||||
|
||||
while (!ci.enc_codec_loaded)
|
||||
while (ci.enc_codec_loaded == 0)
|
||||
yield();
|
||||
|
||||
logf("codec loaded: %d", ci.enc_codec_loaded);
|
||||
|
||||
return ci.enc_codec_loaded > 0;
|
||||
#else
|
||||
(void)afmt;
|
||||
return true;
|
||||
#endif
|
||||
return;
|
||||
(void)enc_id;
|
||||
} /* audio_load_encoder */
|
||||
|
||||
void audio_remove_encoder(void)
|
||||
{
|
||||
#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
|
||||
/* force encoder codec unload (if previously loaded) */
|
||||
if (!ci.enc_codec_loaded)
|
||||
#ifndef SIMULATOR
|
||||
/* force encoder codec unload (if currently loaded) */
|
||||
if (ci.enc_codec_loaded <= 0)
|
||||
return;
|
||||
|
||||
ci.stop_codec = true;
|
||||
while (ci.enc_codec_loaded)
|
||||
while (ci.enc_codec_loaded > 0)
|
||||
yield();
|
||||
#endif
|
||||
} /* audio_remove_encoder */
|
||||
|
||||
#endif /* HAVE_RECORDING */
|
||||
|
||||
struct mp3entry* audio_current_track(void)
|
||||
{
|
||||
const char *filename;
|
||||
|
@ -553,6 +637,9 @@ void audio_flush_and_reload_tracks(void)
|
|||
|
||||
void audio_error_clear(void)
|
||||
{
|
||||
#ifdef AUDIO_HAVE_RECORDING
|
||||
pcm_rec_error_clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
int audio_status(void)
|
||||
|
@ -573,11 +660,6 @@ int audio_status(void)
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool audio_query_poweroff(void)
|
||||
{
|
||||
return !(playing && paused);
|
||||
}
|
||||
|
||||
int audio_get_file_pos(void)
|
||||
{
|
||||
return 0;
|
||||
|
@ -617,7 +699,7 @@ void audio_set_crossfade(int enable)
|
|||
enable = 0;
|
||||
size = NATIVE_FREQUENCY*2;
|
||||
#endif
|
||||
if (pcmbuf_get_bufsize() == size)
|
||||
if (buffer_state == BUFFER_STATE_NORMAL && pcmbuf_is_same_size(size))
|
||||
return ;
|
||||
|
||||
if (was_playing)
|
||||
|
@ -633,9 +715,8 @@ void audio_set_crossfade(int enable)
|
|||
voice_stop();
|
||||
|
||||
/* Re-initialize audio system. */
|
||||
pcmbuf_init(size);
|
||||
audio_reset_buffer(size);
|
||||
pcmbuf_crossfade_enable(enable);
|
||||
audio_reset_buffer();
|
||||
logf("abuf:%dB", pcmbuf_get_bufsize());
|
||||
logf("fbuf:%dB", filebuflen);
|
||||
|
||||
|
@ -714,8 +795,7 @@ void voice_stop(void)
|
|||
{
|
||||
#ifdef PLAYBACK_VOICE
|
||||
/* Messages should not be posted to voice codec queue unless it is the
|
||||
current codec or deadlocks happen.
|
||||
-- jhMikeS */
|
||||
current codec or deadlocks happen. */
|
||||
if (current_codec != CODEC_IDX_VOICE)
|
||||
return;
|
||||
|
||||
|
@ -784,21 +864,32 @@ static void set_filebuf_watermark(int seconds)
|
|||
conf_watermark = bytes;
|
||||
}
|
||||
|
||||
static const char * get_codec_filename(int enc_spec)
|
||||
static const char * get_codec_filename(int cod_spec)
|
||||
{
|
||||
const char *fname;
|
||||
int type = enc_spec & CODEC_TYPE_MASK;
|
||||
int afmt = enc_spec & CODEC_AFMT_MASK;
|
||||
|
||||
#ifdef HAVE_RECORDING
|
||||
/* Can choose decoder or encoder if one available */
|
||||
int type = cod_spec & CODEC_TYPE_MASK;
|
||||
int afmt = cod_spec & CODEC_AFMT_MASK;
|
||||
|
||||
if ((unsigned)afmt >= AFMT_NUM_CODECS)
|
||||
type = AFMT_UNKNOWN | (type & CODEC_TYPE_MASK);
|
||||
|
||||
fname = (type == CODEC_TYPE_DECODER) ?
|
||||
audio_formats[afmt].codec_fn : audio_formats[afmt].codec_enc_fn;
|
||||
fname = (type == CODEC_TYPE_ENCODER) ?
|
||||
audio_formats[afmt].codec_enc_root_fn :
|
||||
audio_formats[afmt].codec_root_fn;
|
||||
|
||||
logf("%s: %d - %s",
|
||||
(type == CODEC_TYPE_ENCODER) ? "Encoder" : "Decoder",
|
||||
afmt, fname ? fname : "<unknown>");
|
||||
#else /* !HAVE_RECORDING */
|
||||
/* Always decoder */
|
||||
if ((unsigned)cod_spec >= AFMT_NUM_CODECS)
|
||||
cod_spec = AFMT_UNKNOWN;
|
||||
fname = audio_formats[cod_spec].codec_root_fn;
|
||||
logf("Codec: %d - %s", cod_spec, fname ? fname : "<unknown>");
|
||||
#endif /* HAVE_RECORDING */
|
||||
|
||||
return fname;
|
||||
} /* get_codec_filename */
|
||||
|
@ -940,7 +1031,7 @@ static void* voice_request_buffer_callback(size_t *realsize, size_t reqsize)
|
|||
}
|
||||
break;
|
||||
|
||||
#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
|
||||
#ifdef AUDIO_HAVE_RECORDING
|
||||
case Q_ENCODER_RECORD:
|
||||
LOGFQUEUE("voice < Q_ENCODER_RECORD");
|
||||
swap_codec();
|
||||
|
@ -995,7 +1086,7 @@ static void* voice_request_buffer_callback(size_t *realsize, size_t reqsize)
|
|||
goto voice_play_clip;
|
||||
|
||||
case SYS_TIMEOUT:
|
||||
LOGFQUEUE("voice < SYS_TIMEOUT");
|
||||
LOGFQUEUE_SYS_TIMEOUT("voice < SYS_TIMEOUT");
|
||||
goto voice_play_clip;
|
||||
|
||||
default:
|
||||
|
@ -1773,7 +1864,7 @@ static void codec_thread(void)
|
|||
#endif
|
||||
break ;
|
||||
|
||||
#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
|
||||
#ifdef AUDIO_HAVE_RECORDING
|
||||
case Q_ENCODER_LOAD_DISK:
|
||||
LOGFQUEUE("codec < Q_ENCODER_LOAD_DISK");
|
||||
audio_codec_loaded = false; /* Not audio codec! */
|
||||
|
@ -1785,12 +1876,14 @@ static void codec_thread(void)
|
|||
}
|
||||
#endif
|
||||
mutex_lock(&mutex_codecthread);
|
||||
logf("loading encoder");
|
||||
current_codec = CODEC_IDX_AUDIO;
|
||||
ci.stop_codec = false;
|
||||
status = codec_load_file((const char *)ev.data, &ci);
|
||||
mutex_unlock(&mutex_codecthread);
|
||||
logf("encoder stopped");
|
||||
break;
|
||||
#endif
|
||||
#endif /* AUDIO_HAVE_RECORDING */
|
||||
|
||||
#ifndef SIMULATOR
|
||||
case SYS_USB_CONNECTED:
|
||||
|
@ -1872,6 +1965,24 @@ static void codec_thread(void)
|
|||
}
|
||||
break;
|
||||
|
||||
#ifdef AUDIO_HAVE_RECORDING
|
||||
case Q_ENCODER_LOAD_DISK:
|
||||
LOGFQUEUE("codec < Q_ENCODER_LOAD_DISK");
|
||||
|
||||
if (status == CODEC_OK)
|
||||
break;
|
||||
|
||||
logf("Encoder failure");
|
||||
gui_syncsplash(HZ*2, true, "Encoder failure");
|
||||
|
||||
if (ci.enc_codec_loaded < 0)
|
||||
break;
|
||||
|
||||
logf("Encoder failed to load");
|
||||
ci.enc_codec_loaded = -1;
|
||||
break;
|
||||
#endif /* AUDIO_HAVE_RECORDING */
|
||||
|
||||
default:
|
||||
LOGFQUEUE("codec < default");
|
||||
|
||||
|
@ -2992,6 +3103,10 @@ static void audio_play_start(size_t offset)
|
|||
/* Wait for any previously playing audio to flush - TODO: Not necessary? */
|
||||
audio_stop_codec_flush();
|
||||
|
||||
/* must reset the buffer before any playback begins if needed */
|
||||
if (buffer_state != BUFFER_STATE_NORMAL)
|
||||
audio_reset_buffer(pcmbuf_get_bufsize());
|
||||
|
||||
track_changed = true;
|
||||
playlist_end = false;
|
||||
|
||||
|
@ -3084,51 +3199,60 @@ static void audio_initiate_dir_change(long direction)
|
|||
ci.new_track = direction;
|
||||
}
|
||||
|
||||
static void audio_reset_buffer(void)
|
||||
/*
|
||||
* Layout audio buffer as follows:
|
||||
* [|TALK]|MALLOC|FILE|GUARD|PCM|AUDIOCODEC|[VOICECODEC|]
|
||||
*/
|
||||
static void audio_reset_buffer(size_t pcmbufsize)
|
||||
{
|
||||
/* see audio_get_recording_buffer if this is modified */
|
||||
size_t offset;
|
||||
|
||||
/* Set up file buffer as all space available */
|
||||
filebuf = (char *)&audiobuf[talk_get_bufsize()+MALLOC_BUFSIZE];
|
||||
filebuflen = audiobufend - (unsigned char *) filebuf - GUARD_BUFSIZE -
|
||||
(pcmbuf_get_bufsize() + get_pcmbuf_descsize() + PCMBUF_MIX_CHUNK * 2);
|
||||
logf("audio_reset_buffer");
|
||||
logf(" size:%08X", pcmbufsize);
|
||||
|
||||
/* Allow for codec(s) at end of file buffer */
|
||||
/* Initially set up file buffer as all space available */
|
||||
filebuf = audiobuf + MALLOC_BUFSIZE + talk_get_bufsize();
|
||||
filebuflen = audiobufend - filebuf;
|
||||
|
||||
/* Allow for codec(s) at end of audio buffer */
|
||||
if (talk_voice_required())
|
||||
{
|
||||
/* Allow 2 codecs at end of file buffer */
|
||||
#ifdef PLAYBACK_VOICE
|
||||
/* Allow 2 codecs at end of audio buffer */
|
||||
filebuflen -= 2 * (CODEC_IRAM_SIZE + CODEC_SIZE);
|
||||
|
||||
#ifdef PLAYBACK_VOICE
|
||||
iram_buf[0] = &filebuf[filebuflen];
|
||||
iram_buf[1] = &filebuf[filebuflen+CODEC_IRAM_SIZE];
|
||||
dram_buf[0] = (unsigned char *)&filebuf[filebuflen+CODEC_IRAM_SIZE*2];
|
||||
dram_buf[1] = (unsigned char *)&filebuf[filebuflen+CODEC_IRAM_SIZE*2+CODEC_SIZE];
|
||||
iram_buf[CODEC_IDX_AUDIO] = filebuf + filebuflen;
|
||||
dram_buf[CODEC_IDX_AUDIO] = iram_buf[CODEC_IDX_AUDIO] + CODEC_IRAM_SIZE;
|
||||
iram_buf[CODEC_IDX_VOICE] = dram_buf[CODEC_IDX_AUDIO] + CODEC_SIZE;
|
||||
dram_buf[CODEC_IDX_VOICE] = iram_buf[CODEC_IDX_VOICE] + CODEC_IRAM_SIZE;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Allow for 1 codec at end of file buffer */
|
||||
#ifdef PLAYBACK_VOICE
|
||||
/* Allow for 1 codec at end of audio buffer */
|
||||
filebuflen -= CODEC_IRAM_SIZE + CODEC_SIZE;
|
||||
|
||||
#ifdef PLAYBACK_VOICE
|
||||
iram_buf[0] = &filebuf[filebuflen];
|
||||
iram_buf[1] = NULL;
|
||||
dram_buf[0] = (unsigned char *)&filebuf[filebuflen+CODEC_IRAM_SIZE];
|
||||
dram_buf[1] = NULL;
|
||||
iram_buf[CODEC_IDX_AUDIO] = filebuf + filebuflen;
|
||||
dram_buf[CODEC_IDX_AUDIO] = iram_buf[CODEC_IDX_AUDIO] + CODEC_IRAM_SIZE;
|
||||
iram_buf[CODEC_IDX_VOICE] = NULL;
|
||||
dram_buf[CODEC_IDX_VOICE] = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
filebuflen -= pcmbuf_init(pcmbufsize, filebuf + filebuflen) + GUARD_BUFSIZE;
|
||||
|
||||
/* Ensure that file buffer is aligned */
|
||||
offset = (-(size_t)filebuf) & 3;
|
||||
offset = -(size_t)filebuf & 3;
|
||||
filebuf += offset;
|
||||
filebuflen -= offset;
|
||||
filebuflen &= ~3;
|
||||
|
||||
/* Clear any references to the file buffer */
|
||||
buffer_state = BUFFER_STATE_NORMAL;
|
||||
}
|
||||
|
||||
|
||||
#ifdef ROCKBOX_HAS_LOGF
|
||||
static void audio_test_track_changed_event(struct mp3entry *id3)
|
||||
{
|
||||
|
@ -3149,9 +3273,8 @@ static void audio_playback_init(void)
|
|||
logf("playback api init");
|
||||
pcm_init();
|
||||
|
||||
#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
|
||||
/* Set the input multiplexer to Line In */
|
||||
pcm_rec_mux(0);
|
||||
#ifdef AUDIO_HAVE_RECORDING
|
||||
rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
|
||||
#endif
|
||||
|
||||
#ifdef ROCKBOX_HAS_LOGF
|
||||
|
@ -3219,8 +3342,9 @@ static void audio_playback_init(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
filebuf = (char *)&audiobuf[MALLOC_BUFSIZE]; /* Will be reset by reset_buffer */
|
||||
|
||||
/* initialize the buffer */
|
||||
filebuf = audiobuf; /* must be non-NULL for audio_set_crossfade */
|
||||
buffer_state = BUFFER_STATE_TRASHED; /* force it */
|
||||
audio_set_crossfade(global_settings.crossfade);
|
||||
|
||||
audio_is_initialized = true;
|
||||
|
@ -3358,6 +3482,14 @@ static void audio_thread(void)
|
|||
playlist_update_resume_info(audio_current_track());
|
||||
break ;
|
||||
|
||||
#ifdef AUDIO_HAVE_RECORDING
|
||||
case Q_AUDIO_LOAD_ENCODER:
|
||||
LOGFQUEUE("audio < Q_AUDIO_LOAD_ENCODER");
|
||||
LOGFQUEUE("audio > codec Q_ENCODER_LOAD_DISK");
|
||||
queue_post(&codec_queue, Q_ENCODER_LOAD_DISK, ev.data);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef SIMULATOR
|
||||
case SYS_USB_CONNECTED:
|
||||
LOGFQUEUE("audio < SYS_USB_CONNECTED");
|
||||
|
@ -3368,7 +3500,7 @@ static void audio_thread(void)
|
|||
#endif
|
||||
|
||||
case SYS_TIMEOUT:
|
||||
LOGFQUEUE("audio < SYS_TIMEOUT");
|
||||
LOGFQUEUE_SYS_TIMEOUT("audio < SYS_TIMEOUT");
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -155,7 +155,7 @@ static int recreate_control(struct playlist_info* playlist);
|
|||
static void update_playlist_filename(struct playlist_info* playlist,
|
||||
const char *dir, const char *file);
|
||||
static int add_indices_to_playlist(struct playlist_info* playlist,
|
||||
char* buffer, int buflen);
|
||||
char* buffer, size_t buflen);
|
||||
static int add_track_to_playlist(struct playlist_info* playlist,
|
||||
const char *filename, int position,
|
||||
bool queue, int seek_pos);
|
||||
|
@ -457,7 +457,7 @@ static void update_playlist_filename(struct playlist_info* playlist,
|
|||
* calculate track offsets within a playlist file
|
||||
*/
|
||||
static int add_indices_to_playlist(struct playlist_info* playlist,
|
||||
char* buffer, int buflen)
|
||||
char* buffer, size_t buflen)
|
||||
{
|
||||
unsigned int nread;
|
||||
unsigned int i = 0;
|
||||
|
@ -489,8 +489,7 @@ static int add_indices_to_playlist(struct playlist_info* playlist,
|
|||
buflen = (audiobufend - audiobuf);
|
||||
buffer = (char *)audiobuf;
|
||||
#else
|
||||
buflen = (audiobufend - audiobuf - talk_get_bufsize());
|
||||
buffer = (char *)&audiobuf[talk_get_bufsize()];
|
||||
buffer = (char *)audio_get_buffer(false, &buflen);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1853,7 +1852,7 @@ int playlist_resume(void)
|
|||
{
|
||||
struct playlist_info* playlist = ¤t_playlist;
|
||||
char *buffer;
|
||||
int buflen;
|
||||
size_t buflen;
|
||||
int nread;
|
||||
int total_read = 0;
|
||||
int control_file_size = 0;
|
||||
|
@ -1866,8 +1865,7 @@ int playlist_resume(void)
|
|||
buflen = (audiobufend - audiobuf);
|
||||
buffer = (char *)audiobuf;
|
||||
#else
|
||||
buflen = (audiobufend - audiobuf - talk_get_bufsize());
|
||||
buffer = (char *)&audiobuf[talk_get_bufsize()];
|
||||
buffer = (char *)audio_get_buffer(false, &buflen);
|
||||
#endif
|
||||
|
||||
empty_playlist(playlist, true);
|
||||
|
|
|
@ -674,12 +674,18 @@ void* plugin_get_buffer(int* buffer_size)
|
|||
}
|
||||
|
||||
/* Returns a pointer to the mp3 buffer.
|
||||
Playback gets stopped, to avoid conflicts. */
|
||||
Playback gets stopped, to avoid conflicts.
|
||||
Talk buffer is stolen as well.
|
||||
*/
|
||||
void* plugin_get_audio_buffer(int* buffer_size)
|
||||
{
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
return audio_get_buffer(true, (size_t *)buffer_size);
|
||||
#else
|
||||
audio_stop();
|
||||
talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
|
||||
*buffer_size = audiobufend - audiobuf;
|
||||
#endif
|
||||
return audiobuf;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,12 +30,17 @@
|
|||
|
||||
const unsigned char bitmap_icons_5x8[][5] =
|
||||
{
|
||||
[Icon_Lock_Main] ={0x78,0x7f,0x49,0x7f,0x78}, /* Lock Main */
|
||||
[Icon_Lock_Remote]={0x78,0x7f,0x49,0x7f,0x78}, /* Lock Remote */
|
||||
[Icon_Stereo]={0x7f, 0x1c, 0x00, 0x1c, 0x7f}, /* Stereo recording */
|
||||
[Icon_Mono]={0x00, 0x1c, 0x7f, 0x00, 0x00}, /* Mono recording */
|
||||
[Icon_Lock_Main] =
|
||||
{0x78, 0x7f, 0x49, 0x7f, 0x78}, /* Lock Main */
|
||||
[Icon_Lock_Remote] =
|
||||
{0x78, 0x7f, 0x49, 0x7f, 0x78}, /* Lock Remote */
|
||||
[Icon_Stereo] =
|
||||
{0x7f, 0x22, 0x1c, 0x22, 0x7f}, /* Stereo recording */
|
||||
[Icon_Mono] =
|
||||
{0x00, 0x1c, 0x22, 0x7f, 0x00}, /* Mono recording */
|
||||
#if CONFIG_CODEC != SWCODEC
|
||||
[Icon_q]={0x1e, 0x21, 0x31, 0x21, 0x5e} /* Q icon */
|
||||
[Icon_q] =
|
||||
{0x1e, 0x21, 0x31, 0x21, 0x5e} /* Q icon */
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -81,45 +86,52 @@ const unsigned char bitmap_icons_7x8[][7] =
|
|||
{0x7f,0x04,0x4e,0x5f,0x44,0x38,0x7f} /* Repeat-AB playmode */
|
||||
};
|
||||
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
const unsigned char bitmap_icons_18x8[][18] =
|
||||
#if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING)
|
||||
const unsigned char bitmap_glyphs_4x8[][4] =
|
||||
{
|
||||
{0x00, 0x00, 0x00, 0x00,0x3e, 0x04, 0x08, 0x04, 0x3e, 0x00, 0x3e, 0x2a,
|
||||
0x3a, 0x00, 0x0e, 0x08, 0x3e, 0x00}, /* mp3 64kbps */
|
||||
{0x00, 0x00, 0x00, 0x00,0x3e, 0x04, 0x08, 0x04, 0x3e, 0x00, 0x0e, 0x0a,
|
||||
0x3e, 0x00, 0x3e, 0x2a, 0x3a, 0x00}, /* mp3 96kbps */
|
||||
{0x3e, 0x04, 0x08, 0x04, 0x3e, 0x00, 0x24, 0x3e, 0x20, 0x00, 0x3a, 0x2a,
|
||||
0x2e, 0x00, 0x3e, 0x2a, 0x3e, 0x00}, /* mp3 128kbps */
|
||||
{0x3e, 0x04, 0x08, 0x04, 0x3e, 0x00, 0x24, 0x3e, 0x20, 0x00, 0x3e, 0x2a,
|
||||
0x3a, 0x00, 0x3e, 0x22, 0x3e, 0x00}, /* mp3 160kbps */
|
||||
{0x3e, 0x04, 0x08, 0x04, 0x3e, 0x00, 0x24, 0x3e, 0x20, 0x00, 0x0e, 0x0a,
|
||||
0x3e, 0x00, 0x3a, 0x2a, 0x2e, 0x00}, /* mp3 192kbps */
|
||||
{0x3e, 0x04, 0x08, 0x04, 0x3e, 0x00, 0x3a, 0x2a, 0x2e, 0x00, 0x3a, 0x2a,
|
||||
0x2e, 0x00, 0x0e, 0x08, 0x3e, 0x00}, /* mp3 224kbps */
|
||||
{0x3e, 0x04, 0x08, 0x04, 0x3e, 0x00, 0x22, 0x2a, 0x36, 0x00, 0x3a, 0x2a,
|
||||
0x2e, 0x00, 0x3e, 0x22, 0x3e, 0x00}, /* mp3 320kbps */
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x1e, 0x20, 0x18, 0x20, 0x1e,
|
||||
0x00, 0x1e, 0x20, 0x18, 0x06, 0x00}, /* wv */
|
||||
{0x00, 0x00, 0x1e, 0x20, 0x18, 0x20, 0x1e, 0x00, 0x3c, 0x12, 0x12, 0x3c,
|
||||
0x00, 0x1e, 0x20, 0x18, 0x06, 0x00} /* wav */
|
||||
/* Keep digits together and first! */
|
||||
[0] =
|
||||
{0x00, 0x3e, 0x22, 0x3e}, /* 0 */
|
||||
[1] =
|
||||
{0x00, 0x24, 0x3e, 0x20}, /* 1 */
|
||||
[2] =
|
||||
{0x00, 0x3a, 0x2a, 0x2e}, /* 2 */
|
||||
[3] =
|
||||
{0x00, 0x22, 0x2a, 0x36}, /* 3 */
|
||||
[4] =
|
||||
{0x00, 0x0e, 0x08, 0x3e}, /* 4 */
|
||||
[5] =
|
||||
{0x00, 0x2e, 0x2a, 0x3a}, /* 5 */
|
||||
[6] =
|
||||
{0x00, 0x3e, 0x2a, 0x3a}, /* 6 */
|
||||
[7] =
|
||||
{0x00, 0x02, 0x02, 0x3e}, /* 7 */
|
||||
[8] =
|
||||
{0x00, 0x3e, 0x2a, 0x3e}, /* 8 */
|
||||
[9] =
|
||||
{0x00, 0x0e, 0x0a, 0x3e}, /* 9 */
|
||||
[10 ... Glyph_4x8Last-1] =
|
||||
{0x00, 0x00, 0x00, 0x00}, /* auto-blank */
|
||||
[Glyph_4x8_k] =
|
||||
{0x00, 0x3e, 0x10, 0x28}, /* k */
|
||||
};
|
||||
|
||||
const unsigned char bitmap_icons_12x8[][12] =
|
||||
const unsigned char bitmap_formats_18x8[Format_18x8Last][18]=
|
||||
{
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x2a, 0x3e, 0x00, 0x3e, 0x10, 0x28}, /* 8khz */
|
||||
{0x00, 0x24, 0x3e, 0x20, 0x00, 0x24, 0x3e, 0x20, 0x00, 0x3e, 0x10, 0x28}, /* 11khz */
|
||||
{0x00, 0x24, 0x3e, 0x20, 0x00, 0x3a, 0x2a, 0x2e, 0x00, 0x3e, 0x10, 0x28}, /* 12khz */
|
||||
{0x00, 0x24, 0x3e, 0x20, 0x00, 0x3e, 0x2a, 0x3a, 0x00, 0x3e, 0x10, 0x28}, /* 16khz */
|
||||
{0x00, 0x3a, 0x2a, 0x2e, 0x00, 0x3a, 0x2a, 0x2e, 0x00, 0x3e, 0x10, 0x28}, /* 22khz */
|
||||
{0x00, 0x3a, 0x2a, 0x2e, 0x00, 0x0e, 0x08, 0x3e, 0x00, 0x3e, 0x10, 0x28}, /* 24khz */
|
||||
{0x00, 0x22, 0x2a, 0x36, 0x00, 0x3a, 0x2a, 0x2e, 0x00, 0x3e, 0x10, 0x28}, /* 32khz */
|
||||
{0x00, 0x0e, 0x08, 0x3e, 0x00, 0x0e, 0x08, 0x3e, 0x00, 0x3e, 0x10, 0x28}, /* 44.1khz */
|
||||
{0x00, 0x0e, 0x08, 0x3e, 0x00, 0x3e, 0x2a, 0x3e, 0x00, 0x3e, 0x10, 0x28}, /* 48khz */
|
||||
{0x00, 0x3e, 0x2a, 0x3a, 0x00, 0x0e, 0x08, 0x3e, 0x00, 0x3e, 0x10, 0x28}, /* 64khz */
|
||||
{0x00, 0x3e, 0x2a, 0x3e, 0x00, 0x3e, 0x2a, 0x3e, 0x00, 0x3e, 0x10, 0x28}, /* 88.2khz */
|
||||
{0x00, 0x0e, 0x0a, 0x3e, 0x00, 0x3e, 0x2a, 0x3a, 0x00, 0x3e, 0x10, 0x28} /* 96khz */
|
||||
[0 ... Format_18x8Last-1] = /* auto-blank */
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* ___ */
|
||||
[Format_18x8_MPA_L3] =
|
||||
{0x00, 0x3e, 0x04, 0x08, 0x04, 0x3e, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* M__ */
|
||||
[Format_18x8_WAVPACK] =
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x20,
|
||||
0x18, 0x20, 0x1e, 0x00, 0x0e, 0x10, 0x20, 0x10, 0x0e}, /* _WV */
|
||||
[Format_18x8_PCM_WAV] =
|
||||
{0x00, 0x1e, 0x20, 0x18, 0x20, 0x1e, 0x00, 0x3c, 0x0a,
|
||||
0x0a, 0x0a, 0x3c, 0x00, 0x0e, 0x10, 0x20, 0x10, 0x0e}, /* WAV */
|
||||
};
|
||||
#endif
|
||||
#endif /* CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING) */
|
||||
|
||||
/* Disk/MMC activity */
|
||||
const unsigned char bitmap_icon_disk[12] =
|
||||
|
|
|
@ -89,44 +89,40 @@ enum icons_7x8 {
|
|||
Icon7x8Last
|
||||
};
|
||||
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
enum icons_12x8 {
|
||||
Icon_8000,
|
||||
Icon_11025,
|
||||
Icon_12000,
|
||||
Icon_16000,
|
||||
Icon_22050,
|
||||
Icon_24000,
|
||||
Icon_32000,
|
||||
Icon_44100,
|
||||
Icon_48000,
|
||||
Icon_64000,
|
||||
Icon_88200,
|
||||
Icon_96000,
|
||||
Icon12x8Last
|
||||
#if CONFIG_CODEC == SWCODEC && defined (HAVE_RECORDING)
|
||||
#define BM_GLYPH_WIDTH 4
|
||||
enum Glyphs_4x8 {
|
||||
Glyph_4x8_0 = 0,
|
||||
Glyph_4x8_1,
|
||||
Glyph_4x8_2,
|
||||
Glyph_4x8_3,
|
||||
Glyph_4x8_4,
|
||||
Glyph_4x8_5,
|
||||
Glyph_4x8_6,
|
||||
Glyph_4x8_7,
|
||||
Glyph_4x8_8,
|
||||
Glyph_4x8_9,
|
||||
Glyph_4x8_k,
|
||||
Glyph_4x8Last
|
||||
};
|
||||
extern const unsigned char bitmap_glyphs_4x8[Glyph_4x8Last][4];
|
||||
|
||||
enum icons_18x8 {
|
||||
Icon_mp364,
|
||||
Icon_mp396,
|
||||
Icon_mp3128,
|
||||
Icon_mp3160,
|
||||
Icon_mp3192,
|
||||
Icon_mp3224,
|
||||
Icon_mp3320,
|
||||
Icon_wv,
|
||||
Icon_wav,
|
||||
Icon18x8Last
|
||||
#define BM_MPA_L3_M_WIDTH 6
|
||||
#ifdef ID3_H
|
||||
/* This enum is redundant but sort of in keeping with the style */
|
||||
enum rec_format_18x8 {
|
||||
Format_18x8_MPA_L3 = REC_FORMAT_MPA_L3,
|
||||
Format_18x8_WAVPACK = REC_FORMAT_WAVPACK,
|
||||
Format_18x8_PCM_WAV = REC_FORMAT_PCM_WAV,
|
||||
Format_18x8Last = REC_NUM_FORMATS
|
||||
};
|
||||
#endif
|
||||
extern const unsigned char bitmap_formats_18x8[Format_18x8Last][18];
|
||||
#endif /* ID3_H */
|
||||
#endif /* CONFIG_CODEC == SWCODEC && defined (HAVE_RECORDING) */
|
||||
|
||||
extern const unsigned char bitmap_icons_5x8[Icon5x8Last][5];
|
||||
extern const unsigned char bitmap_icons_6x8[Icon6x8Last][6];
|
||||
extern const unsigned char bitmap_icons_7x8[Icon7x8Last][7];
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
extern const unsigned char bitmap_icons_12x8[Icon12x8Last][12];
|
||||
extern const unsigned char bitmap_icons_18x8[Icon18x8Last][18];
|
||||
#endif
|
||||
extern const unsigned char bitmap_icon_disk[];
|
||||
|
||||
#define STATUSBAR_X_POS 0
|
||||
|
|
|
@ -540,10 +540,8 @@ void peak_meter_peek(void)
|
|||
if (pm_playback)
|
||||
pcm_calculate_peaks(&pm_cur_left, &pm_cur_right);
|
||||
#ifdef HAVE_RECORDING
|
||||
if (!pm_playback)
|
||||
{
|
||||
pcm_rec_get_peaks(&pm_cur_left, &pm_cur_right);
|
||||
}
|
||||
else
|
||||
pcm_calculate_rec_peaks(&pm_cur_left, &pm_cur_right);
|
||||
#endif
|
||||
left = pm_cur_left;
|
||||
right = pm_cur_right;
|
||||
|
|
|
@ -386,6 +386,7 @@ bool radio_screen(void)
|
|||
unsigned int last_seconds = 0;
|
||||
#if CONFIG_CODEC != SWCODEC
|
||||
int hours, minutes;
|
||||
struct audio_recording_options rec_options;
|
||||
#endif
|
||||
bool keep_playing = false;
|
||||
bool statusbar = global_settings.statusbar;
|
||||
|
@ -436,12 +437,9 @@ bool radio_screen(void)
|
|||
|
||||
peak_meter_enabled = true;
|
||||
|
||||
rec_set_recording_options(global_settings.rec_frequency,
|
||||
global_settings.rec_quality,
|
||||
AUDIO_SRC_LINEIN, 0,
|
||||
global_settings.rec_channels,
|
||||
global_settings.rec_editable,
|
||||
global_settings.rec_prerecord_time);
|
||||
rec_init_recording_options(&rec_options);
|
||||
rec_options.rec_source = AUDIO_SRC_LINEIN;
|
||||
rec_set_recording_options(&rec_options);
|
||||
|
||||
audio_set_recording_gain(sound_default(SOUND_LEFT_GAIN),
|
||||
sound_default(SOUND_RIGHT_GAIN), AUDIO_GAIN_LINEIN);
|
||||
|
@ -881,7 +879,7 @@ bool radio_screen(void)
|
|||
}
|
||||
else
|
||||
{
|
||||
if(global_settings.rec_prerecord_time)
|
||||
if(rec_options.rec_prerecord_time)
|
||||
{
|
||||
snprintf(buf, 32, "%s %02d",
|
||||
str(LANG_RECORD_PRERECORD), seconds%60);
|
||||
|
@ -1173,7 +1171,8 @@ bool save_preset_list(void)
|
|||
if(!opendir(FMPRESET_PATH)) /* Check if there is preset folder */
|
||||
mkdir(FMPRESET_PATH, 0);
|
||||
|
||||
create_numbered_filename(filepreset,FMPRESET_PATH,"preset",".fmr",2);
|
||||
create_numbered_filename(filepreset, FMPRESET_PATH, "preset",
|
||||
".fmr", 2 IF_CNFN_NUM_(, NULL));
|
||||
|
||||
while(bad_file_name)
|
||||
{
|
||||
|
@ -1534,12 +1533,10 @@ static bool fm_recording_settings(void)
|
|||
#if CONFIG_CODEC != SWCODEC
|
||||
if (!ret)
|
||||
{
|
||||
rec_set_recording_options(global_settings.rec_frequency,
|
||||
global_settings.rec_quality,
|
||||
AUDIO_SRC_LINEIN, 0,
|
||||
global_settings.rec_channels,
|
||||
global_settings.rec_editable,
|
||||
global_settings.rec_prerecord_time);
|
||||
struct audio_recording_options rec_options;
|
||||
rec_init_recording_options(&rec_options);
|
||||
rec_options.rec_source = AUDIO_SRC_LINEIN;
|
||||
rec_set_recording_options(&rec_options);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -30,8 +30,10 @@
|
|||
#include "mpeg.h"
|
||||
#include "audio.h"
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
#include "pcm_record.h"
|
||||
#include "thread.h"
|
||||
#include "pcm_playback.h"
|
||||
#include "playback.h"
|
||||
#include "enc_config.h"
|
||||
#endif
|
||||
#ifdef HAVE_UDA1380
|
||||
#include "uda1380.h"
|
||||
|
@ -73,36 +75,40 @@
|
|||
|
||||
#define PM_HEIGHT ((LCD_HEIGHT >= 72) ? 2 : 1)
|
||||
|
||||
#if CONFIG_KEYPAD == RECORDER_PAD
|
||||
bool f2_rec_screen(void);
|
||||
bool f3_rec_screen(void);
|
||||
#endif
|
||||
|
||||
#define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */
|
||||
|
||||
int screen_update = NB_SCREENS;
|
||||
bool remote_display_on = true;
|
||||
const char* const freq_str[6] =
|
||||
{
|
||||
"44.1kHz",
|
||||
"48kHz",
|
||||
"32kHz",
|
||||
"22.05kHz",
|
||||
"24kHz",
|
||||
"16kHz"
|
||||
};
|
||||
|
||||
/** File name creation **/
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
#define REC_ENCODER_ID(q) \
|
||||
rec_quality_info_afmt[q]
|
||||
#define REC_QUALITY_LABEL(q) \
|
||||
(audio_formats[REC_ENCODER_ID(q)].label)
|
||||
#define REC_FILE_ENDING(q) \
|
||||
(audio_formats[REC_ENCODER_ID(q)].ext)
|
||||
#else
|
||||
/* default record file extension for HWCODEC */
|
||||
#define REC_QUALITY_LABEL(q) "MP3"
|
||||
#define REC_FILE_ENDING(q) ".mp3"
|
||||
#endif
|
||||
|
||||
#ifdef IF_CNFN_NUM
|
||||
/* current file number to assist in creating unique numbered filenames
|
||||
without actually having to create the file on disk */
|
||||
static int file_number = -1;
|
||||
#endif /* IF_CNFN_NUM */
|
||||
|
||||
#define REC_FILE_ENDING(rec_format) \
|
||||
(audio_formats[rec_format_afmt[rec_format]].ext_list)
|
||||
|
||||
#else /* CONFIG_CODEC != SWCODEC */
|
||||
|
||||
/* default record file extension for HWCODEC */
|
||||
#define REC_FILE_ENDING(rec_format) \
|
||||
(audio_formats[AFMT_MPA_L3].ext_list)
|
||||
|
||||
#endif /* CONFIG_CODEC == SWCODEC */
|
||||
|
||||
/* path for current file */
|
||||
static char path_buffer[MAX_PATH];
|
||||
|
||||
/** Automatic Gain Control (AGC) **/
|
||||
#ifdef HAVE_AGC
|
||||
/* Timing counters:
|
||||
* peak_time is incremented every 0.2s, every 2nd run of record screen loop.
|
||||
|
@ -496,20 +502,24 @@ void adjust_cursor(void)
|
|||
|
||||
char *rec_create_filename(char *buffer)
|
||||
{
|
||||
char ext[16];
|
||||
|
||||
if(global_settings.rec_directory)
|
||||
getcwd(buffer, MAX_PATH);
|
||||
else
|
||||
strncpy(buffer, rec_base_directory, MAX_PATH);
|
||||
|
||||
snprintf(ext, sizeof(ext), ".%s",
|
||||
REC_FILE_ENDING(global_settings.rec_format));
|
||||
|
||||
#ifdef CONFIG_RTC
|
||||
create_datetime_filename(buffer, buffer, "R",
|
||||
REC_FILE_ENDING(global_settings.rec_quality));
|
||||
/* We'll wait at least up to the start of the next second so no duplicate
|
||||
names are created */
|
||||
return create_datetime_filename(buffer, buffer, "R", ext, true);
|
||||
#else
|
||||
create_numbered_filename(buffer, buffer, "rec_",
|
||||
REC_FILE_ENDING(global_settings.rec_quality), 4);
|
||||
return create_numbered_filename(buffer, buffer, "rec_", ext, 4
|
||||
IF_CNFN_NUM_(, &file_number));
|
||||
#endif
|
||||
return buffer;
|
||||
}
|
||||
|
||||
int rec_create_directory(void)
|
||||
|
@ -557,9 +567,15 @@ static void rec_boost(bool state)
|
|||
|
||||
/**
|
||||
* Selects an audio source for recording or playback
|
||||
* powers/unpowers related devices.
|
||||
* powers/unpowers related devices and sets up monitoring.
|
||||
* Here because it calls app code and used only for HAVE_RECORDING atm.
|
||||
* Would like it in pcm_record.c.
|
||||
*
|
||||
* Behaves like a firmware function in that it does not use global settings
|
||||
* to determine the state.
|
||||
*
|
||||
* The order of setting monitoring may need tweaking dependent upon the
|
||||
* selected source to get the smoothest transition.
|
||||
*/
|
||||
#if defined(HAVE_UDA1380)
|
||||
#define ac_disable_recording uda1380_disable_recording
|
||||
|
@ -571,7 +587,13 @@ static void rec_boost(bool state)
|
|||
#define ac_set_monitor tlv320_set_monitor
|
||||
#endif
|
||||
|
||||
void rec_set_source(int source, int flags)
|
||||
#ifdef HAVE_SPDIF_IN
|
||||
#define rec_spdif_set_monitor(m) audio_spdif_set_monitor(m)
|
||||
#else
|
||||
#define rec_spdif_set_monitor(m)
|
||||
#endif
|
||||
|
||||
void rec_set_source(int source, unsigned flags)
|
||||
{
|
||||
/* Prevent pops from unneeded switching */
|
||||
static int last_source = AUDIO_SRC_PLAYBACK;
|
||||
|
@ -586,7 +608,9 @@ void rec_set_source(int source, int flags)
|
|||
|
||||
/** Do power up/down of associated device(s) **/
|
||||
|
||||
/** SPDIF **/
|
||||
#ifdef HAVE_SPDIF_IN
|
||||
/* Always boost for SPDIF */
|
||||
if ((source == AUDIO_SRC_SPDIF) != (source == last_source))
|
||||
rec_boost(source == AUDIO_SRC_SPDIF);
|
||||
|
||||
|
@ -595,10 +619,11 @@ void rec_set_source(int source, int flags)
|
|||
both optical in and out is controlled by the same power source, which is
|
||||
the case on H1x0. */
|
||||
spdif_power_enable((source == AUDIO_SRC_SPDIF) ||
|
||||
global_settings.spdif_enable);
|
||||
audio_get_spdif_power_setting());
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** Tuner **/
|
||||
#ifdef CONFIG_TUNER
|
||||
/* Switch radio off or on per source and flags. */
|
||||
if (source != AUDIO_SRC_FMRADIO)
|
||||
|
@ -612,12 +637,15 @@ void rec_set_source(int source, int flags)
|
|||
switch (source)
|
||||
{
|
||||
default: /* playback - no recording */
|
||||
source = AUDIO_SRC_PLAYBACK;
|
||||
case AUDIO_SRC_PLAYBACK:
|
||||
pm_playback = true;
|
||||
if (source == last_source)
|
||||
break;
|
||||
ac_disable_recording();
|
||||
ac_set_monitor(false);
|
||||
pcm_rec_mux(0); /* line in */
|
||||
rec_spdif_set_monitor(-1); /* silence it */
|
||||
break;
|
||||
|
||||
case AUDIO_SRC_MIC: /* recording only */
|
||||
|
@ -625,6 +653,7 @@ void rec_set_source(int source, int flags)
|
|||
break;
|
||||
ac_enable_recording(true); /* source mic */
|
||||
pcm_rec_mux(0); /* line in */
|
||||
rec_spdif_set_monitor(0);
|
||||
break;
|
||||
|
||||
case AUDIO_SRC_LINEIN: /* recording only */
|
||||
|
@ -632,29 +661,20 @@ void rec_set_source(int source, int flags)
|
|||
break;
|
||||
pcm_rec_mux(0); /* line in */
|
||||
ac_enable_recording(false); /* source line */
|
||||
rec_spdif_set_monitor(0);
|
||||
break;
|
||||
|
||||
#ifdef HAVE_SPDIF_IN
|
||||
case AUDIO_SRC_SPDIF: /* recording only */
|
||||
if (recording)
|
||||
{
|
||||
/* This was originally done in audio_set_recording_options only */
|
||||
#ifdef HAVE_SPDIF_POWER
|
||||
EBU1CONFIG = global_settings.spdif_enable ? (1 << 2) : 0;
|
||||
/* Input source is EBUin1, Feed-through monitoring if desired */
|
||||
#else
|
||||
EBU1CONFIG = (1 << 2);
|
||||
/* Input source is EBUin1, Feed-through monitoring */
|
||||
#endif
|
||||
}
|
||||
|
||||
if (source != last_source)
|
||||
uda1380_disable_recording();
|
||||
if (source == last_source)
|
||||
break;
|
||||
ac_disable_recording();
|
||||
audio_spdif_set_monitor(1);
|
||||
break;
|
||||
#endif /* HAVE_SPDIF_IN */
|
||||
|
||||
#ifdef HAVE_FMRADIO_IN
|
||||
case AUDIO_SRC_FMRADIO:
|
||||
case AUDIO_SRC_FMRADIO: /* recording and playback */
|
||||
if (!recording)
|
||||
{
|
||||
audio_set_recording_gain(sound_default(SOUND_LEFT_GAIN),
|
||||
|
@ -687,6 +707,8 @@ void rec_set_source(int source, int flags)
|
|||
tlv320_set_monitor(true); /* analog bypass */
|
||||
}
|
||||
#endif
|
||||
|
||||
rec_spdif_set_monitor(0);
|
||||
break;
|
||||
/* #elif defined(CONFIG_TUNER) */
|
||||
/* Have radio but cannot record it */
|
||||
|
@ -702,33 +724,50 @@ void rec_set_source(int source, int flags)
|
|||
} /* rec_set_source */
|
||||
#endif /* CONFIG_CODEC == SWCODEC && !defined(SIMULATOR) */
|
||||
|
||||
/* steal the mp3 buffer then actually set options */
|
||||
void rec_set_recording_options(int frequency, int quality,
|
||||
int source, int source_flags,
|
||||
int channel_mode, bool editable,
|
||||
int prerecord_time)
|
||||
void rec_init_recording_options(struct audio_recording_options *options)
|
||||
{
|
||||
options->rec_source = global_settings.rec_source;
|
||||
options->rec_frequency = global_settings.rec_frequency;
|
||||
options->rec_channels = global_settings.rec_channels;
|
||||
options->rec_prerecord_time = global_settings.rec_prerecord_time;
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
options->rec_source_flags = 0;
|
||||
options->enc_config.rec_format = global_settings.rec_format;
|
||||
global_to_encoder_config(&options->enc_config);
|
||||
#else
|
||||
options->rec_quality = global_settings.rec_quality;
|
||||
options->rec_editable = global_settings.rec_editable;
|
||||
#endif
|
||||
}
|
||||
|
||||
void rec_set_recording_options(struct audio_recording_options *options)
|
||||
{
|
||||
#if CONFIG_CODEC != SWCODEC
|
||||
if (global_settings.rec_prerecord_time)
|
||||
#endif
|
||||
talk_buffer_steal(); /* will use the mp3 buffer */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SPDIF_IN
|
||||
#ifdef HAVE_SPDIF_POWER
|
||||
audio_set_spdif_power_setting(global_settings.spdif_enable);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
rec_set_source(source, source_flags | SRCF_RECORDING);
|
||||
#else
|
||||
(void)source_flags;
|
||||
rec_set_source(options->rec_source,
|
||||
options->rec_source_flags | SRCF_RECORDING);
|
||||
#endif
|
||||
|
||||
audio_set_recording_options(frequency, quality, source,
|
||||
channel_mode, editable, prerecord_time);
|
||||
audio_set_recording_options(options);
|
||||
}
|
||||
|
||||
static char path_buffer[MAX_PATH];
|
||||
|
||||
/* steals mp3 buffer, creates unique filename and starts recording */
|
||||
void rec_record(void)
|
||||
{
|
||||
#if CONFIG_CODEC != SWCODEC
|
||||
talk_buffer_steal(); /* we use the mp3 buffer */
|
||||
#endif
|
||||
IF_CNFN_NUM_(file_number = -1;) /* Hit disk for number */
|
||||
audio_record(rec_create_filename(path_buffer));
|
||||
}
|
||||
|
||||
|
@ -753,7 +792,6 @@ static void trigger_listener(int trigger_status)
|
|||
case TRIG_GO:
|
||||
if((audio_status() & AUDIO_STATUS_RECORD) != AUDIO_STATUS_RECORD)
|
||||
{
|
||||
talk_buffer_steal(); /* we use the mp3 buffer */
|
||||
rec_record();
|
||||
/* give control to mpeg thread so that it can start
|
||||
recording */
|
||||
|
@ -831,6 +869,8 @@ bool recording_screen(bool no_source)
|
|||
ID2P(LANG_GIGABYTE)
|
||||
};
|
||||
|
||||
struct audio_recording_options rec_options;
|
||||
|
||||
global_settings.recscreen_on = true;
|
||||
cursor = 0;
|
||||
#if (CONFIG_LED == LED_REAL) && !defined(SIMULATOR)
|
||||
|
@ -838,35 +878,26 @@ bool recording_screen(bool no_source)
|
|||
#endif
|
||||
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
audio_stop();
|
||||
voice_stop();
|
||||
/* recording_menu gets messed up: so reset talk_menu */
|
||||
talk_menu = global_settings.talk_menu;
|
||||
global_settings.talk_menu = 0;
|
||||
/* audio_init_recording stops anything playing when it takes the audio
|
||||
buffer */
|
||||
#else
|
||||
/* Yes, we use the D/A for monitoring */
|
||||
peak_meter_enabled = true;
|
||||
peak_meter_playback(true);
|
||||
#endif
|
||||
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
audio_init_recording(talk_get_bufsize());
|
||||
#else
|
||||
audio_init_recording(0);
|
||||
#endif
|
||||
sound_set_volume(global_settings.volume);
|
||||
|
||||
#ifdef HAVE_AGC
|
||||
peak_meter_get_peakhold(&peak_l, &peak_r);
|
||||
#endif
|
||||
|
||||
rec_set_recording_options(global_settings.rec_frequency,
|
||||
global_settings.rec_quality,
|
||||
global_settings.rec_source,
|
||||
0,
|
||||
global_settings.rec_channels,
|
||||
global_settings.rec_editable,
|
||||
global_settings.rec_prerecord_time);
|
||||
rec_init_recording_options(&rec_options);
|
||||
rec_set_recording_options(&rec_options);
|
||||
|
||||
set_gain();
|
||||
settings_apply_trigger();
|
||||
|
@ -1025,7 +1056,6 @@ bool recording_screen(bool no_source)
|
|||
{
|
||||
/* manual recording */
|
||||
have_recorded = true;
|
||||
talk_buffer_steal(); /* we use the mp3 buffer */
|
||||
rec_record();
|
||||
last_seconds = 0;
|
||||
if (talk_menu)
|
||||
|
@ -1253,16 +1283,10 @@ bool recording_screen(bool no_source)
|
|||
#if CONFIG_CODEC == SWCODEC
|
||||
/* reinit after submenu exit */
|
||||
audio_close_recording();
|
||||
audio_init_recording(talk_get_bufsize());
|
||||
audio_init_recording(0);
|
||||
#endif
|
||||
rec_set_recording_options(
|
||||
global_settings.rec_frequency,
|
||||
global_settings.rec_quality,
|
||||
global_settings.rec_source,
|
||||
0,
|
||||
global_settings.rec_channels,
|
||||
global_settings.rec_editable,
|
||||
global_settings.rec_prerecord_time);
|
||||
rec_init_recording_options(&rec_options);
|
||||
rec_set_recording_options(&rec_options);
|
||||
|
||||
if(rec_create_directory() > 0)
|
||||
have_recorded = true;
|
||||
|
@ -1739,11 +1763,7 @@ bool recording_screen(bool no_source)
|
|||
}
|
||||
} /* end while(!done) */
|
||||
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
audio_stat = pcm_rec_status();
|
||||
#else
|
||||
audio_stat = audio_status();
|
||||
#endif
|
||||
if (audio_stat & AUDIO_STATUS_ERROR)
|
||||
{
|
||||
gui_syncsplash(0, true, str(LANG_SYSFONT_DISK_FULL));
|
||||
|
@ -1804,11 +1824,22 @@ bool recording_screen(bool no_source)
|
|||
#if CONFIG_KEYPAD == RECORDER_PAD
|
||||
bool f2_rec_screen(void)
|
||||
{
|
||||
static const char* const freq_str[6] =
|
||||
{
|
||||
"44.1kHz",
|
||||
"48kHz",
|
||||
"32kHz",
|
||||
"22.05kHz",
|
||||
"24kHz",
|
||||
"16kHz"
|
||||
};
|
||||
|
||||
bool exit = false;
|
||||
bool used = false;
|
||||
int w, h, i;
|
||||
char buf[32];
|
||||
int button;
|
||||
struct audio_recording_options rec_options;
|
||||
|
||||
FOR_NB_SCREENS(i)
|
||||
{
|
||||
|
@ -1919,13 +1950,8 @@ bool f2_rec_screen(void)
|
|||
}
|
||||
}
|
||||
|
||||
rec_set_recording_options(global_settings.rec_frequency,
|
||||
global_settings.rec_quality,
|
||||
global_settings.rec_source,
|
||||
0,
|
||||
global_settings.rec_channels,
|
||||
global_settings.rec_editable,
|
||||
global_settings.rec_prerecord_time);
|
||||
rec_init_recording_options(&rec_options);
|
||||
rec_set_recording_options(&rec_options);
|
||||
|
||||
set_gain();
|
||||
|
||||
|
@ -1948,6 +1974,8 @@ bool f3_rec_screen(void)
|
|||
str(LANG_SYSFONT_RECORDING_SRC_LINE),
|
||||
str(LANG_SYSFONT_RECORDING_SRC_DIGITAL)
|
||||
};
|
||||
struct audio_recording_options rec_options;
|
||||
|
||||
FOR_NB_SCREENS(i)
|
||||
{
|
||||
screens[i].setfont(FONT_SYSFIXED);
|
||||
|
@ -2019,13 +2047,8 @@ bool f3_rec_screen(void)
|
|||
}
|
||||
}
|
||||
|
||||
rec_set_recording_options(global_settings.rec_frequency,
|
||||
global_settings.rec_quality,
|
||||
global_settings.rec_source,
|
||||
0,
|
||||
global_settings.rec_channels,
|
||||
global_settings.rec_editable,
|
||||
global_settings.rec_prerecord_time);
|
||||
rec_init_recording_options(&rec_options);
|
||||
rec_set_recording_options(&rec_options);
|
||||
|
||||
set_gain();
|
||||
|
||||
|
@ -2066,23 +2089,30 @@ unsigned long audio_num_recorded_bytes(void)
|
|||
}
|
||||
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
void rec_set_source(int source, int flags)
|
||||
void rec_set_source(int source, unsigned flags)
|
||||
{
|
||||
source = source;
|
||||
flags = flags;
|
||||
}
|
||||
#endif
|
||||
|
||||
void audio_set_recording_options(int frequency, int quality,
|
||||
int source, int channel_mode,
|
||||
bool editable, int prerecord_time)
|
||||
#ifdef HAVE_SPDIF_IN
|
||||
#ifdef HAVE_SPDIF_POWER
|
||||
void audio_set_spdif_power_setting(bool on)
|
||||
{
|
||||
frequency = frequency;
|
||||
quality = quality;
|
||||
source = source;
|
||||
channel_mode = channel_mode;
|
||||
editable = editable;
|
||||
prerecord_time = prerecord_time;
|
||||
on = on;
|
||||
}
|
||||
|
||||
bool audio_get_spdif_power_setting(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif /* HAVE_SPDIF_POWER */
|
||||
#endif /* HAVE_SPDIF_IN */
|
||||
#endif /* CONFIG_CODEC == SWCODEC */
|
||||
|
||||
void audio_set_recording_options(struct audio_recording_options *options)
|
||||
{
|
||||
options = options;
|
||||
}
|
||||
|
||||
void audio_set_recording_gain(int left, int right, int type)
|
||||
|
@ -2104,7 +2134,7 @@ void audio_resume_recording(void)
|
|||
{
|
||||
}
|
||||
|
||||
void pcm_rec_get_peaks(int *left, int *right)
|
||||
void pcm_calculate_rec_peaks(int *left, int *right)
|
||||
{
|
||||
if (left)
|
||||
*left = 0;
|
||||
|
|
|
@ -32,15 +32,16 @@ int rec_create_directory(void);
|
|||
#define SRCF_FMRADIO_PLAYING 0x0000 /* default */
|
||||
#define SRCF_FMRADIO_PAUSED 0x2000
|
||||
#endif
|
||||
void rec_set_source(int source, int flags);
|
||||
void rec_set_source(int source, unsigned flags);
|
||||
#endif /* CONFIG_CODEC == SW_CODEC */
|
||||
|
||||
/* Initializes a recording_options structure with global settings.
|
||||
pass returned data to audio_set_recording_options or
|
||||
rec_set_recording_options */
|
||||
void rec_init_recording_options(struct audio_recording_options *options);
|
||||
/* steals mp3 buffer, sets source and then options */
|
||||
/* SRCF_RECORDING is implied */
|
||||
void rec_set_recording_options(int frequency, int quality,
|
||||
int source, int source_flags,
|
||||
int channel_mode, bool editable,
|
||||
int prerecord_time);
|
||||
/* SRCF_RECORDING is implied for SWCODEC */
|
||||
void rec_set_recording_options(struct audio_recording_options *options);
|
||||
|
||||
/* steals mp3 buffer, creates unique filename and starts recording */
|
||||
void rec_record(void);
|
||||
|
|
|
@ -90,13 +90,16 @@ const char rec_base_directory[] = REC_BASE_DIR;
|
|||
#include "pcmbuf.h"
|
||||
#include "pcm_playback.h"
|
||||
#include "dsp.h"
|
||||
#ifdef HAVE_RECORDING
|
||||
#include "enc_config.h"
|
||||
#endif
|
||||
#endif /* CONFIG_CODEC == SWCODEC */
|
||||
|
||||
#ifdef HAVE_WM8758
|
||||
#include "eq_menu.h"
|
||||
#endif
|
||||
|
||||
#define CONFIG_BLOCK_VERSION 55
|
||||
#define CONFIG_BLOCK_VERSION 56
|
||||
#define CONFIG_BLOCK_SIZE 512
|
||||
#define RTC_BLOCK_SIZE 44
|
||||
|
||||
|
@ -514,7 +517,7 @@ static const struct bit_entry hd_bits[] =
|
|||
{1, S_O(rec_editable), false, "editable recordings", off_on },
|
||||
#endif /* CONFIG_CODEC == MAS3587F */
|
||||
|
||||
#if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING)
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
#ifdef HAVE_UDA1380
|
||||
{8|SIGNED, S_O(rec_mic_gain), 16 /* 8 dB */, "rec mic gain", NULL }, /* -128...+108 */
|
||||
#endif
|
||||
|
@ -524,16 +527,20 @@ static const struct bit_entry hd_bits[] =
|
|||
#endif
|
||||
{8|SIGNED, S_O(rec_left_gain), 0, "rec left gain", NULL }, /* -128...+96 */
|
||||
{8|SIGNED, S_O(rec_right_gain), 0, "rec right gain", NULL }, /* -128...+96 */
|
||||
#if 0 /* Till samplerates are added for SWCODEC */
|
||||
{3, S_O(rec_frequency), 0, /* 0=44.1kHz */
|
||||
"rec frequency", "44,48,32,22,24,16" },
|
||||
#else
|
||||
{3, S_O(rec_frequency), 0, /* 0=44.1kHz */
|
||||
"rec frequency", "44" },
|
||||
#endif
|
||||
|
||||
{4, S_O(rec_quality), 4 /* MP3 L3 192 kBit/s */, "rec quality", NULL },
|
||||
#endif /* CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING) */
|
||||
{REC_FREQ_CFG_NUM_BITS, S_O(rec_frequency), REC_FREQ_DEFAULT,
|
||||
"rec frequency", REC_FREQ_CFG_VAL_LIST },
|
||||
{REC_FORMAT_CFG_NUM_BITS ,S_O(rec_format), REC_FORMAT_DEFAULT,
|
||||
"rec format", REC_FORMAT_CFG_VAL_LIST },
|
||||
/** Encoder settings start - keep these together **/
|
||||
/* mp3_enc */
|
||||
{5,S_O(mp3_enc_config.bitrate), MP3_ENC_BITRATE_CFG_DEFAULT,
|
||||
"mp3_enc bitrate", MP3_ENC_BITRATE_CFG_VALUE_LIST },
|
||||
/* wav_enc */
|
||||
/* (no settings yet) */
|
||||
/* wavpack_enc */
|
||||
/* (no settings yet) */
|
||||
/** Encoder settings end **/
|
||||
#endif /* CONFIG_CODEC == SWCODEC */
|
||||
|
||||
/* values for the trigger */
|
||||
{8 | SIGNED, S_O(rec_start_thres), -35, "trigger start threshold", NULL},
|
||||
|
@ -1301,6 +1308,11 @@ void settings_apply(void)
|
|||
lcd_set_sleep_after_backlight_off(global_settings.lcd_sleep_after_backlight_off);
|
||||
#endif
|
||||
#endif /* CONFIG_BACKLIGHT */
|
||||
|
||||
/* This should stay last */
|
||||
#if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
|
||||
enc_global_settings_apply();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -1727,13 +1739,13 @@ static void save_cfg_table(const struct bit_entry* p_table, int count, int fd)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
bool settings_save_config(void)
|
||||
{
|
||||
int fd;
|
||||
char filename[MAX_PATH];
|
||||
|
||||
create_numbered_filename(filename, ROCKBOX_DIR, "config", ".cfg", 2);
|
||||
create_numbered_filename(filename, ROCKBOX_DIR, "config", ".cfg", 2
|
||||
IF_CNFN_NUM_(, NULL));
|
||||
|
||||
/* allow user to modify filename */
|
||||
while (true) {
|
||||
|
@ -1887,6 +1899,10 @@ void settings_reset(void) {
|
|||
global_settings.kbd_file[0] = '\0';
|
||||
#endif
|
||||
global_settings.hold_lr_for_scroll_in_list = true;
|
||||
|
||||
#if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
|
||||
enc_global_settings_reset();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool set_bool(const char* string, bool* variable )
|
||||
|
|
|
@ -29,6 +29,10 @@
|
|||
#include "tagcache.h"
|
||||
#include "button.h"
|
||||
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
#include "audio.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_BACKLIGHT_BRIGHTNESS
|
||||
#include "backlight.h" /* for [MIN|MAX]_BRIGHTNESS_SETTING */
|
||||
#endif
|
||||
|
@ -142,18 +146,22 @@ struct user_settings
|
|||
int crossfade_fade_out_mixmode; /* Fade out mode (0=crossfade,1=mix) */
|
||||
#endif
|
||||
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
int rec_format; /* record format index */
|
||||
#else
|
||||
int rec_quality; /* 0-7 */
|
||||
int rec_source; /* 0=mic, 1=line, 2=S/PDIF */
|
||||
int rec_frequency; /* 0 = 44.1kHz
|
||||
#endif /* CONFIG_CODEC == SWCODEC */
|
||||
int rec_source; /* 0=mic, 1=line, 2=S/PDIF, 2 or 3=FM Radio */
|
||||
int rec_frequency; /* 0 = 44.1kHz (depends on target)
|
||||
1 = 48kHz
|
||||
2 = 32kHz
|
||||
3 = 22.05kHz
|
||||
4 = 24kHz
|
||||
5 = 16kHz */
|
||||
int rec_channels; /* 0=Stereo, 1=Mono */
|
||||
int rec_mic_gain; /* 0-15 */
|
||||
int rec_left_gain; /* 0-15 */
|
||||
int rec_right_gain; /* 0-15 */
|
||||
int rec_mic_gain; /* depends on target */
|
||||
int rec_left_gain; /* depends on target */
|
||||
int rec_right_gain; /* depands on target */
|
||||
bool rec_editable; /* true means that the bit reservoir is off */
|
||||
bool recscreen_on; /* true if using the recording screen */
|
||||
|
||||
|
@ -504,6 +512,20 @@ struct user_settings
|
|||
#endif
|
||||
bool audioscrobbler; /* Audioscrobbler logging */
|
||||
|
||||
/* If values are just added to the end, no need to bump plugin API
|
||||
version. */
|
||||
/* new stuff to be added at the end */
|
||||
|
||||
#if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
|
||||
/* Encoder Settings Start - keep these together */
|
||||
struct mp3_enc_config mp3_enc_config;
|
||||
#if 0 /* These currently contain no members but their places in line
|
||||
should be held */
|
||||
struct wav_enc_config wav_enc_config;
|
||||
struct wavpack_enc_config wavpack_enc_config;
|
||||
#endif
|
||||
/* Encoder Settings End */
|
||||
#endif /* CONFIG_CODEC == SWCODEC */
|
||||
};
|
||||
|
||||
enum optiontype { INT, BOOL };
|
||||
|
@ -584,7 +606,7 @@ extern const char rec_base_directory[];
|
|||
|
||||
/* argument bits for settings_load() */
|
||||
#define SETTINGS_RTC 1 /* only the settings from the RTC nonvolatile RAM */
|
||||
#define SETTINGS_HD 2 /* only the settings fron the disk sector */
|
||||
#define SETTINGS_HD 2 /* only the settings from the disk sector */
|
||||
#define SETTINGS_ALL 3 /* both */
|
||||
|
||||
/* repeat mode options */
|
||||
|
|
|
@ -54,6 +54,10 @@
|
|||
#include "dsp.h"
|
||||
#include "eq_menu.h"
|
||||
#include "pcmbuf.h"
|
||||
#ifdef HAVE_RECORDING
|
||||
#include "enc_config.h"
|
||||
#endif
|
||||
#include "general.h"
|
||||
#endif
|
||||
#include "action.h"
|
||||
|
||||
|
@ -308,22 +312,20 @@ static bool recsource(void)
|
|||
{
|
||||
int n_opts = AUDIO_NUM_SOURCES;
|
||||
|
||||
struct opt_items names[AUDIO_NUM_SOURCES] = {
|
||||
{ STR(LANG_RECORDING_SRC_MIC) },
|
||||
{ STR(LANG_RECORDING_SRC_LINE) },
|
||||
static const struct opt_items names[AUDIO_NUM_SOURCES] = {
|
||||
[AUDIO_SRC_MIC] = { STR(LANG_RECORDING_SRC_MIC) },
|
||||
[AUDIO_SRC_LINEIN] = { STR(LANG_RECORDING_SRC_LINE) },
|
||||
#ifdef HAVE_SPDIF_IN
|
||||
{ STR(LANG_RECORDING_SRC_DIGITAL) },
|
||||
[AUDIO_SRC_SPDIF] = { STR(LANG_RECORDING_SRC_DIGITAL) },
|
||||
#endif
|
||||
#ifdef HAVE_FMRADIO_IN
|
||||
[AUDIO_SRC_FMRADIO] = { STR(LANG_FM_RADIO) }
|
||||
#endif
|
||||
};
|
||||
|
||||
/* caveat: assumes it's the last item! */
|
||||
#ifdef HAVE_FMRADIO_IN
|
||||
if (radio_hardware_present())
|
||||
{
|
||||
names[AUDIO_SRC_FMRADIO].string = ID2P(LANG_FM_RADIO);
|
||||
names[AUDIO_SRC_FMRADIO].voice_id = LANG_FM_RADIO;
|
||||
}
|
||||
else
|
||||
if (!radio_hardware_present())
|
||||
n_opts--;
|
||||
#endif
|
||||
|
||||
|
@ -332,28 +334,7 @@ static bool recsource(void)
|
|||
n_opts, NULL );
|
||||
}
|
||||
|
||||
/* To be removed when we add support for sample rates and channel settings */
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
static bool recquality(void)
|
||||
{
|
||||
static const struct opt_items names[] = {
|
||||
{ "MP3 64 kBit/s", TALK_ID( 64, UNIT_KBIT) },
|
||||
{ "MP3 96 kBit/s", TALK_ID( 96, UNIT_KBIT) },
|
||||
{ "MP3 128 kBit/s", TALK_ID( 128, UNIT_KBIT) },
|
||||
{ "MP3 160 kBit/s", TALK_ID( 160, UNIT_KBIT) },
|
||||
{ "MP3 192 kBit/s", TALK_ID( 192, UNIT_KBIT) },
|
||||
{ "MP3 224 kBit/s", TALK_ID( 224, UNIT_KBIT) },
|
||||
{ "MP3 320 kBit/s", TALK_ID( 320, UNIT_KBIT) },
|
||||
{ "WV 900 kBit/s", TALK_ID( 900, UNIT_KBIT) },
|
||||
{ "WAV 1411 kBit/s", TALK_ID(1411, UNIT_KBIT) }
|
||||
};
|
||||
|
||||
return set_option(str(LANG_RECORDING_QUALITY),
|
||||
&global_settings.rec_quality, INT,
|
||||
names, sizeof (names)/sizeof(struct opt_items),
|
||||
NULL );
|
||||
}
|
||||
#elif CONFIG_CODEC == MAS3587F
|
||||
#if CONFIG_CODEC == MAS3587F
|
||||
static bool recquality(void)
|
||||
{
|
||||
return set_int(str(LANG_RECORDING_QUALITY), "", UNIT_INT,
|
||||
|
@ -368,32 +349,182 @@ static bool receditable(void)
|
|||
}
|
||||
#endif /* CONFIG_CODEC == MAS3587F */
|
||||
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
/* Makes an options list from a source list of options and indexes */
|
||||
void make_options_from_indexes(const struct opt_items *src_names,
|
||||
const long *src_indexes,
|
||||
int n_indexes,
|
||||
struct opt_items *dst_names)
|
||||
{
|
||||
while (--n_indexes >= 0)
|
||||
dst_names[n_indexes] = src_names[src_indexes[n_indexes]];
|
||||
} /* make_options_from_indexes */
|
||||
|
||||
static bool recformat(void)
|
||||
{
|
||||
static const struct opt_items names[REC_NUM_FORMATS] = {
|
||||
[REC_FORMAT_MPA_L3] = { STR(LANG_AFMT_MPA_L3) },
|
||||
[REC_FORMAT_WAVPACK] = { STR(LANG_AFMT_WAVPACK) },
|
||||
[REC_FORMAT_PCM_WAV] = { STR(LANG_AFMT_PCM_WAV) },
|
||||
};
|
||||
|
||||
int rec_format = global_settings.rec_format;
|
||||
bool res = set_option(str(LANG_RECORDING_FORMAT), &rec_format, INT,
|
||||
names, REC_NUM_FORMATS, NULL );
|
||||
|
||||
if (rec_format != global_settings.rec_format)
|
||||
{
|
||||
global_settings.rec_format = rec_format;
|
||||
enc_global_settings_apply();
|
||||
}
|
||||
|
||||
return res;
|
||||
} /* recformat */
|
||||
|
||||
#endif /* CONFIG_CODEC == SWCODEC */
|
||||
|
||||
static bool recfrequency(void)
|
||||
{
|
||||
static const struct opt_items names[] = {
|
||||
#if CONFIG_CODEC == MAS3587F
|
||||
static const struct opt_items names[6] = {
|
||||
{ "44.1kHz", TALK_ID(44, UNIT_KHZ) },
|
||||
#if CONFIG_CODEC != SWCODEC /* This is temporary */
|
||||
{ "48kHz", TALK_ID(48, UNIT_KHZ) },
|
||||
{ "32kHz", TALK_ID(32, UNIT_KHZ) },
|
||||
{ "22.05kHz", TALK_ID(22, UNIT_KHZ) },
|
||||
{ "24kHz", TALK_ID(24, UNIT_KHZ) },
|
||||
{ "16kHz", TALK_ID(16, UNIT_KHZ) }
|
||||
#endif
|
||||
};
|
||||
return set_option(str(LANG_RECORDING_FREQUENCY),
|
||||
&global_settings.rec_frequency, INT,
|
||||
names, sizeof(names)/sizeof(*names), NULL );
|
||||
names, 6, NULL );
|
||||
#endif /* CONFIG_CODEC == MAS3587F */
|
||||
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
static const struct opt_items names[REC_NUM_FREQ] = {
|
||||
REC_HAVE_96_([REC_FREQ_96] = { "96kHz", TALK_ID(96, UNIT_KHZ) },)
|
||||
REC_HAVE_88_([REC_FREQ_88] = { "88.2kHz", TALK_ID(88, UNIT_KHZ) },)
|
||||
REC_HAVE_64_([REC_FREQ_64] = { "64kHz", TALK_ID(64, UNIT_KHZ) },)
|
||||
REC_HAVE_48_([REC_FREQ_48] = { "48kHz", TALK_ID(48, UNIT_KHZ) },)
|
||||
REC_HAVE_44_([REC_FREQ_44] = { "44.1kHz", TALK_ID(44, UNIT_KHZ) },)
|
||||
REC_HAVE_32_([REC_FREQ_32] = { "32kHz", TALK_ID(32, UNIT_KHZ) },)
|
||||
REC_HAVE_24_([REC_FREQ_24] = { "24kHz", TALK_ID(24, UNIT_KHZ) },)
|
||||
REC_HAVE_22_([REC_FREQ_22] = { "22.05kHz", TALK_ID(22, UNIT_KHZ) },)
|
||||
REC_HAVE_16_([REC_FREQ_16] = { "16kHz", TALK_ID(16, UNIT_KHZ) },)
|
||||
REC_HAVE_12_([REC_FREQ_12] = { "12kHz", TALK_ID(12, UNIT_KHZ) },)
|
||||
REC_HAVE_11_([REC_FREQ_11] = { "11.025kHz", TALK_ID(11, UNIT_KHZ) },)
|
||||
REC_HAVE_8_( [REC_FREQ_8 ] = { "8kHz", TALK_ID( 8, UNIT_KHZ) },)
|
||||
};
|
||||
|
||||
struct opt_items opts[REC_NUM_FREQ];
|
||||
unsigned long table[REC_NUM_FREQ];
|
||||
int n_opts;
|
||||
int rec_frequency;
|
||||
bool ret;
|
||||
|
||||
#ifdef HAVE_SPDIF_IN
|
||||
if (global_settings.rec_source == AUDIO_SRC_SPDIF)
|
||||
{
|
||||
/* Inform user that frequency follows the source's frequency */
|
||||
opts[0].string = ID2P(LANG_SOURCE_FREQUENCY);
|
||||
opts[0].voice_id = LANG_SOURCE_FREQUENCY;
|
||||
n_opts = 1;
|
||||
rec_frequency = 0;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
struct encoder_caps caps;
|
||||
struct encoder_config cfg;
|
||||
|
||||
cfg.rec_format = global_settings.rec_format;
|
||||
global_to_encoder_config(&cfg);
|
||||
|
||||
if (!enc_get_caps(&cfg, &caps, true))
|
||||
return false;
|
||||
|
||||
/* Construct samplerate menu based upon encoder settings */
|
||||
n_opts = make_list_from_caps32(REC_SAMPR_CAPS, NULL,
|
||||
caps.samplerate_caps, table);
|
||||
|
||||
if (n_opts == 0)
|
||||
return false; /* No common flags...?? */
|
||||
|
||||
make_options_from_indexes(names, table, n_opts, opts);
|
||||
|
||||
/* Find closest rate that the potentially restricted list
|
||||
comes to */
|
||||
make_list_from_caps32(REC_SAMPR_CAPS, rec_freq_sampr,
|
||||
caps.samplerate_caps, table);
|
||||
|
||||
rec_frequency = round_value_to_list32(
|
||||
rec_freq_sampr[global_settings.rec_frequency],
|
||||
table, n_opts, false);
|
||||
}
|
||||
|
||||
ret = set_option(str(LANG_RECORDING_FREQUENCY),
|
||||
&rec_frequency, INT, opts, n_opts, NULL );
|
||||
|
||||
if (!ret
|
||||
#ifdef HAVE_SPDIF_IN
|
||||
&& global_settings.rec_source != AUDIO_SRC_SPDIF
|
||||
#endif
|
||||
)
|
||||
{
|
||||
/* Translate back to full index */
|
||||
global_settings.rec_frequency =
|
||||
round_value_to_list32(table[rec_frequency],
|
||||
rec_freq_sampr,
|
||||
REC_NUM_FREQ,
|
||||
false);
|
||||
}
|
||||
|
||||
return ret;
|
||||
#endif /* CONFIG_CODEC == SWCODEC */
|
||||
} /* recfrequency */
|
||||
|
||||
static bool recchannels(void)
|
||||
{
|
||||
static const struct opt_items names[] = {
|
||||
{ STR(LANG_CHANNEL_STEREO) },
|
||||
{ STR(LANG_CHANNEL_MONO) }
|
||||
static const struct opt_items names[CHN_NUM_MODES] = {
|
||||
[CHN_MODE_STEREO] = { STR(LANG_CHANNEL_STEREO) },
|
||||
[CHN_MODE_MONO] = { STR(LANG_CHANNEL_MONO) }
|
||||
};
|
||||
#if CONFIG_CODEC == MAS3587F
|
||||
return set_option(str(LANG_RECORDING_CHANNELS),
|
||||
&global_settings.rec_channels, INT,
|
||||
names, 2, NULL );
|
||||
names, CHN_NUM_MODES, NULL );
|
||||
#endif /* CONFIG_CODEC == MAS3587F */
|
||||
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
struct opt_items opts[CHN_NUM_MODES];
|
||||
long table[CHN_NUM_MODES];
|
||||
struct encoder_caps caps;
|
||||
struct encoder_config cfg;
|
||||
int n_opts;
|
||||
int rec_channels;
|
||||
bool ret;
|
||||
|
||||
cfg.rec_format = global_settings.rec_format;
|
||||
global_to_encoder_config(&cfg);
|
||||
|
||||
if (!enc_get_caps(&cfg, &caps, true))
|
||||
return false;
|
||||
|
||||
n_opts = make_list_from_caps32(CHN_CAP_ALL, NULL,
|
||||
caps.channel_caps, table);
|
||||
|
||||
rec_channels = round_value_to_list32(global_settings.rec_channels,
|
||||
table, n_opts, false);
|
||||
|
||||
make_options_from_indexes(names, table, n_opts, opts);
|
||||
|
||||
ret = set_option(str(LANG_RECORDING_CHANNELS), &rec_channels,
|
||||
INT, opts, n_opts, NULL );
|
||||
|
||||
if (!ret)
|
||||
global_settings.rec_channels = table[rec_channels];
|
||||
|
||||
return ret;
|
||||
#endif /* CONFIG_CODEC == SWCODEC */
|
||||
}
|
||||
|
||||
static bool rectimesplit(void)
|
||||
|
@ -1049,58 +1180,59 @@ bool rectrigger(void)
|
|||
action_signalscreenchange();
|
||||
return retval;
|
||||
}
|
||||
#endif
|
||||
#endif /* !defined(SIMULATOR) && CONFIG_CODEC == MAS3587F */
|
||||
|
||||
bool recording_menu(bool no_source)
|
||||
{
|
||||
int m;
|
||||
int i = 0;
|
||||
struct menu_item items[13];
|
||||
bool result;
|
||||
|
||||
#if CONFIG_CODEC == MAS3587F || CONFIG_CODEC == SWCODEC
|
||||
items[i].desc = ID2P(LANG_RECORDING_QUALITY);
|
||||
items[i++].function = recquality;
|
||||
#endif
|
||||
items[i].desc = ID2P(LANG_RECORDING_FREQUENCY);
|
||||
items[i++].function = recfrequency;
|
||||
if(!no_source) {
|
||||
items[i].desc = ID2P(LANG_RECORDING_SOURCE);
|
||||
items[i++].function = recsource;
|
||||
}
|
||||
items[i].desc = ID2P(LANG_RECORDING_CHANNELS);
|
||||
items[i++].function = recchannels;
|
||||
static const struct menu_item static_items[] = {
|
||||
#if CONFIG_CODEC == MAS3587F
|
||||
items[i].desc = ID2P(LANG_RECORDING_EDITABLE);
|
||||
items[i++].function = receditable;
|
||||
{ ID2P(LANG_RECORDING_QUALITY), recquality },
|
||||
#endif
|
||||
items[i].desc = ID2P(LANG_RECORD_TIMESPLIT);
|
||||
items[i++].function = filesplitoptionsmenu;
|
||||
items[i].desc = ID2P(LANG_RECORD_PRERECORD_TIME);
|
||||
items[i++].function = recprerecord;
|
||||
items[i].desc = ID2P(LANG_RECORD_DIRECTORY);
|
||||
items[i++].function = recdirectory;
|
||||
items[i].desc = ID2P(LANG_RECORD_STARTUP);
|
||||
items[i++].function = reconstartup;
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
{ ID2P(LANG_RECORDING_FORMAT), recformat },
|
||||
{ ID2P(LANG_ENCODER_SETTINGS), enc_global_config_menu },
|
||||
#endif
|
||||
{ ID2P(LANG_RECORDING_FREQUENCY), recfrequency },
|
||||
{ ID2P(LANG_RECORDING_SOURCE), recsource }, /* not shown if no_source */
|
||||
{ ID2P(LANG_RECORDING_CHANNELS), recchannels },
|
||||
#if CONFIG_CODEC == MAS3587F
|
||||
{ ID2P(LANG_RECORDING_EDITABLE), receditable },
|
||||
#endif
|
||||
{ ID2P(LANG_RECORD_TIMESPLIT), filesplitoptionsmenu },
|
||||
{ ID2P(LANG_RECORD_PRERECORD_TIME), recprerecord },
|
||||
{ ID2P(LANG_RECORD_DIRECTORY), recdirectory },
|
||||
{ ID2P(LANG_RECORD_STARTUP), reconstartup },
|
||||
#ifdef CONFIG_BACKLIGHT
|
||||
items[i].desc = ID2P(LANG_CLIP_LIGHT);
|
||||
items[i++].function = cliplight;
|
||||
{ ID2P(LANG_CLIP_LIGHT), cliplight },
|
||||
#endif
|
||||
#if !defined(SIMULATOR) && CONFIG_CODEC == MAS3587F
|
||||
items[i].desc = ID2P(LANG_RECORD_TRIGGER);
|
||||
items[i++].function = rectrigger;
|
||||
{ ID2P(LANG_RECORD_TRIGGER), rectrigger },
|
||||
#endif
|
||||
#ifdef HAVE_AGC
|
||||
items[i].desc = ID2P(LANG_RECORD_AGC_PRESET);
|
||||
items[i++].function = agc_preset;
|
||||
items[i].desc = ID2P(LANG_RECORD_AGC_CLIPTIME);
|
||||
items[i++].function = agc_cliptime;
|
||||
{ ID2P(LANG_RECORD_AGC_PRESET), agc_preset },
|
||||
{ ID2P(LANG_RECORD_AGC_CLIPTIME), agc_cliptime },
|
||||
#endif
|
||||
};
|
||||
|
||||
m=menu_init( items, i, NULL, NULL, NULL, NULL);
|
||||
struct menu_item items[ARRAYLEN(static_items)];
|
||||
int i, n_items;
|
||||
int m;
|
||||
|
||||
bool result;
|
||||
|
||||
for (i = 0, n_items = 0; i < (int)ARRAYLEN(items); i++)
|
||||
{
|
||||
const struct menu_item *mi = &static_items[i];
|
||||
if (no_source && mi->function == recsource)
|
||||
continue;
|
||||
items[n_items++] = *mi;
|
||||
}
|
||||
|
||||
m = menu_init(items, n_items, NULL, NULL, NULL, NULL);
|
||||
result = menu_run(m);
|
||||
menu_exit(m);
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
} /* recording_menu */
|
||||
|
||||
#endif /* HAVE_RECORDING */
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
#ifdef CONFIG_TUNER
|
||||
#include "radio.h"
|
||||
#endif
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
#if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
|
||||
#include "pcm_record.h"
|
||||
#endif
|
||||
|
||||
|
@ -87,10 +87,6 @@ int current_playmode(void)
|
|||
}
|
||||
|
||||
#ifdef HAVE_RECORDING
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
audio_stat = pcm_rec_status();
|
||||
#endif
|
||||
|
||||
if(audio_stat & AUDIO_STATUS_RECORD)
|
||||
{
|
||||
if(audio_stat & AUDIO_STATUS_PAUSE)
|
||||
|
|
27
apps/talk.c
27
apps/talk.c
|
@ -46,13 +46,17 @@
|
|||
|
||||
MASCODEC | MASCODEC | SWCODEC
|
||||
(playing) | (stopped) |
|
||||
audiobuf-----------+-----------+-----------
|
||||
audiobuf-----------+-----------+------------
|
||||
audio | voice | thumbnail
|
||||
|-----------|----------- filebuf
|
||||
|-----------|------------
|
||||
| thumbnail | voice
|
||||
| |-----------
|
||||
| |------------
|
||||
| | filebuf
|
||||
| |------------
|
||||
| | audio
|
||||
audiobufend----------+-----------+-----------
|
||||
| |------------
|
||||
| | codec swap
|
||||
audiobufend----------+-----------+------------
|
||||
|
||||
SWCODEC allocates dedicated buffers, MASCODEC reuses audiobuf. */
|
||||
|
||||
|
@ -102,7 +106,7 @@ struct queue_entry /* one entry of the internal queue */
|
|||
|
||||
/***************** Globals *****************/
|
||||
|
||||
static unsigned char* p_thumbnail; /* buffer for thumbnail */
|
||||
static unsigned char* p_thumbnail = NULL; /* buffer for thumbnail */
|
||||
static long size_for_thumbnail; /* leftover buffer size for it */
|
||||
static struct voicefile* p_voicefile; /* loaded voicefile */
|
||||
static bool has_voicefile; /* a voicefile file is present */
|
||||
|
@ -479,11 +483,14 @@ static void reset_state(void)
|
|||
queue_write = queue_read = 0; /* reset the queue */
|
||||
p_voicefile = NULL; /* indicate no voicefile (trashed) */
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
/* Allocate a dedicated thumbnail buffer */
|
||||
size_for_thumbnail = audiobufend - audiobuf;
|
||||
if (size_for_thumbnail > MAX_THUMBNAIL_BUFSIZE)
|
||||
size_for_thumbnail = MAX_THUMBNAIL_BUFSIZE;
|
||||
p_thumbnail = buffer_alloc(size_for_thumbnail);
|
||||
/* Allocate a dedicated thumbnail buffer - once */
|
||||
if (p_thumbnail == NULL)
|
||||
{
|
||||
size_for_thumbnail = audiobufend - audiobuf;
|
||||
if (size_for_thumbnail > MAX_THUMBNAIL_BUFSIZE)
|
||||
size_for_thumbnail = MAX_THUMBNAIL_BUFSIZE;
|
||||
p_thumbnail = buffer_alloc(size_for_thumbnail);
|
||||
}
|
||||
#else
|
||||
/* Just use the audiobuf, without allocating anything */
|
||||
p_thumbnail = audiobuf;
|
||||
|
|
|
@ -58,7 +58,9 @@
|
|||
#include "misc.h"
|
||||
#include "filetree.h"
|
||||
#include "tagtree.h"
|
||||
#ifdef HAVE_RECORDING
|
||||
#include "recorder/recording.h"
|
||||
#endif
|
||||
#include "rtc.h"
|
||||
#include "dircache.h"
|
||||
#ifdef HAVE_TAGCACHE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue