1
0
Fork 0
forked from len0rd/rockbox

Accept FS#6918 - Remove Nested Functions by Tim Ross. Adjust some names. Hunt down and remove the remaining ones in the recording system as well.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12955 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Michael Sevakis 2007-03-29 01:55:47 +00:00
parent 583caa867b
commit 62e0a516a0
6 changed files with 154 additions and 150 deletions

View file

@ -221,6 +221,22 @@ STATICIRAM void enc_events_callback(enum enc_events event, void *data)
} /* enc_events_callback */ } /* enc_events_callback */
/* convert native pcm samples to aiff format samples */ /* convert native pcm samples to aiff format samples */
static inline void sample_to_mono(uint32_t **src, uint32_t **dst)
{
int32_t lr1, lr2;
lr1 = *(*src)++;
lr1 = (int16_t)lr1 + (lr1 >> 16) + err;
err = lr1 & 1;
lr1 >>= 1;
lr2 = *(*src)++;
lr2 = (int16_t)lr2 + (lr2 >> 16) + err;
err = lr2 & 1;
lr2 >>= 1;
*(*dst)++ = swap_odd_even_le32((lr1 << 16) | (uint16_t)lr2);
} /* sample_to_mono */
STATICIRAM void chunk_to_aiff_format(uint32_t *src, uint32_t *dst) ICODE_ATTR; STATICIRAM void chunk_to_aiff_format(uint32_t *src, uint32_t *dst) ICODE_ATTR;
STATICIRAM void chunk_to_aiff_format(uint32_t *src, uint32_t *dst) STATICIRAM void chunk_to_aiff_format(uint32_t *src, uint32_t *dst)
{ {
@ -238,32 +254,16 @@ STATICIRAM void chunk_to_aiff_format(uint32_t *src, uint32_t *dst)
*/ */
uint32_t *src_end = src + PCM_SAMP_PER_CHUNK; 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) + err;
err = lr1 & 1;
lr1 >>= 1;
lr2 = *(*src)++;
lr2 = (int16_t)lr2 + (lr2 >> 16) + err;
err = lr2 & 1;
lr2 >>= 1;
*(*dst)++ = swap_odd_even_le32((lr1 << 16) | (uint16_t)lr2);
} /* to_mono */
do do
{ {
to_mono(&src, &dst); sample_to_mono(&src, &dst);
to_mono(&src, &dst); sample_to_mono(&src, &dst);
to_mono(&src, &dst); sample_to_mono(&src, &dst);
to_mono(&src, &dst); sample_to_mono(&src, &dst);
to_mono(&src, &dst); sample_to_mono(&src, &dst);
to_mono(&src, &dst); sample_to_mono(&src, &dst);
to_mono(&src, &dst); sample_to_mono(&src, &dst);
to_mono(&src, &dst); sample_to_mono(&src, &dst);
} }
while (src < src_end); while (src < src_end);
} }

View file

@ -209,6 +209,22 @@ STATICIRAM void enc_events_callback(enum enc_events event, void *data)
} /* enc_events_callback */ } /* enc_events_callback */
/* convert native pcm samples to wav format samples */ /* convert native pcm samples to wav format samples */
static inline void sample_to_mono(uint32_t **src, uint32_t **dst)
{
int32_t lr1, lr2;
lr1 = *(*src)++;
lr1 = (int16_t)lr1 + (lr1 >> 16) + err;
err = lr1 & 1;
lr1 >>= 1;
lr2 = *(*src)++;
lr2 = (int16_t)lr2 + (lr2 >> 16) + err;
err = lr2 & 1;
lr2 >>= 1;
*(*dst)++ = swap_odd_even_be32((lr1 << 16) | (uint16_t)lr2);
} /* sample_to_mono */
STATICIRAM void chunk_to_wav_format(uint32_t *src, uint32_t *dst) ICODE_ATTR; STATICIRAM void chunk_to_wav_format(uint32_t *src, uint32_t *dst) ICODE_ATTR;
STATICIRAM void chunk_to_wav_format(uint32_t *src, uint32_t *dst) STATICIRAM void chunk_to_wav_format(uint32_t *src, uint32_t *dst)
{ {
@ -226,32 +242,16 @@ STATICIRAM void chunk_to_wav_format(uint32_t *src, uint32_t *dst)
*/ */
uint32_t *src_end = src + PCM_SAMP_PER_CHUNK; 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) + err;
err = lr1 & 1;
lr1 >>= 1;
lr2 = *(*src)++;
lr2 = (int16_t)lr2 + (lr2 >> 16) + err;
err = lr2 & 1;
lr2 >>= 1;
*(*dst)++ = swap_odd_even_be32((lr1 << 16) | (uint16_t)lr2);
} /* to_mono */
do do
{ {
to_mono(&src, &dst); sample_to_mono(&src, &dst);
to_mono(&src, &dst); sample_to_mono(&src, &dst);
to_mono(&src, &dst); sample_to_mono(&src, &dst);
to_mono(&src, &dst); sample_to_mono(&src, &dst);
to_mono(&src, &dst); sample_to_mono(&src, &dst);
to_mono(&src, &dst); sample_to_mono(&src, &dst);
to_mono(&src, &dst); sample_to_mono(&src, &dst);
to_mono(&src, &dst); sample_to_mono(&src, &dst);
} }
while (src < src_end); while (src < src_end);
} }

View file

@ -99,6 +99,25 @@ static const struct riff_header riff_header =
/* (*) updated during ENC_END_FILE event */ /* (*) updated during ENC_END_FILE event */
}; };
static inline void sample_to_int32_mono(int32_t **src, int32_t **dst)
{
int32_t t = *(*src)++;
/* endianness irrelevant */
t = (int16_t)t + (t >> 16) + err;
err = t & 1;
*(*dst)++ = t >> 1;
} /* sample_to_int32_mono */
static inline void sample_to_int32_stereo(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
} /* sample_to_int32_stereo */
STATICIRAM void chunk_to_int32(int32_t *src) ICODE_ATTR; STATICIRAM void chunk_to_int32(int32_t *src) ICODE_ATTR;
STATICIRAM void chunk_to_int32(int32_t *src) STATICIRAM void chunk_to_int32(int32_t *src)
{ {
@ -123,28 +142,19 @@ STATICIRAM void chunk_to_int32(int32_t *src)
* |llllllllllllllll|rrrrrrrrrrrrrrrr| => * |llllllllllllllll|rrrrrrrrrrrrrrrr| =>
* |mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm| * |mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm|
*/ */
inline void to_int32(int32_t **src, int32_t **dst)
{
int32_t t = *(*src)++;
/* endianness irrelevant */
t = (int16_t)t + (t >> 16) + err;
err = t & 1;
*(*dst)++ = t >> 1;
} /* to_int32 */
do do
{ {
/* read 10 longs and write 10 longs */ /* read 10 longs and write 10 longs */
to_int32(&src, &dst); sample_to_int32_mono(&src, &dst);
to_int32(&src, &dst); sample_to_int32_mono(&src, &dst);
to_int32(&src, &dst); sample_to_int32_mono(&src, &dst);
to_int32(&src, &dst); sample_to_int32_mono(&src, &dst);
to_int32(&src, &dst); sample_to_int32_mono(&src, &dst);
to_int32(&src, &dst); sample_to_int32_mono(&src, &dst);
to_int32(&src, &dst); sample_to_int32_mono(&src, &dst);
to_int32(&src, &dst); sample_to_int32_mono(&src, &dst);
to_int32(&src, &dst); sample_to_int32_mono(&src, &dst);
to_int32(&src, &dst); sample_to_int32_mono(&src, &dst);
} }
while(src < src_end); while(src < src_end);
@ -156,29 +166,19 @@ STATICIRAM void chunk_to_int32(int32_t *src)
* |llllllllllllllll|rrrrrrrrrrrrrrrr| => * |llllllllllllllll|rrrrrrrrrrrrrrrr| =>
* |llllllllllllllllllllllllllllllll|rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr| * |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 do
{ {
/* read 10 longs and write 20 longs */ /* read 10 longs and write 20 longs */
to_int32(&src, &dst); sample_to_int32_stereo(&src, &dst);
to_int32(&src, &dst); sample_to_int32_stereo(&src, &dst);
to_int32(&src, &dst); sample_to_int32_stereo(&src, &dst);
to_int32(&src, &dst); sample_to_int32_stereo(&src, &dst);
to_int32(&src, &dst); sample_to_int32_stereo(&src, &dst);
to_int32(&src, &dst); sample_to_int32_stereo(&src, &dst);
to_int32(&src, &dst); sample_to_int32_stereo(&src, &dst);
to_int32(&src, &dst); sample_to_int32_stereo(&src, &dst);
to_int32(&src, &dst); sample_to_int32_stereo(&src, &dst);
to_int32(&src, &dst); sample_to_int32_stereo(&src, &dst);
} }
while (src < src_end); while (src < src_end);

View file

@ -1234,26 +1234,26 @@ int dsp_stereo_mode(void)
return dsp->stereo_mode; return dsp->stereo_mode;
} }
static void dsp_set_gain_var(long *var, long value)
{
/* Voice shouldn't mess with these */
if (dsp == audio_dsp)
{
*var = value;
new_gain = true;
}
}
static void dsp_update_functions(void)
{
sample_input_new_format();
sample_output_new_format();
if (dsp == audio_dsp)
dsp_set_crossfeed(crossfeed_enabled);
}
bool dsp_configure(int setting, intptr_t value) bool dsp_configure(int setting, intptr_t value)
{ {
void set_gain_var(long *var, long value)
{
/* Voice shouldn't mess with these */
if (dsp == audio_dsp)
{
*var = value;
new_gain = true;
}
}
void update_functions(void)
{
sample_input_new_format();
sample_output_new_format();
if (dsp == audio_dsp)
dsp_set_crossfeed(crossfeed_enabled);
}
switch (setting) switch (setting)
{ {
case DSP_SWITCH_CODEC: case DSP_SWITCH_CODEC:
@ -1305,7 +1305,7 @@ bool dsp_configure(int setting, intptr_t value)
case DSP_SET_STEREO_MODE: case DSP_SET_STEREO_MODE:
dsp->stereo_mode = value; dsp->stereo_mode = value;
dsp->data.num_channels = value == STEREO_MONO ? 1 : 2; dsp->data.num_channels = value == STEREO_MONO ? 1 : 2;
update_functions(); dsp_update_functions();
break; break;
case DSP_RESET: case DSP_RESET:
@ -1328,7 +1328,7 @@ bool dsp_configure(int setting, intptr_t value)
new_gain = true; new_gain = true;
} }
update_functions(); dsp_update_functions();
resampler_new_delta(); resampler_new_delta();
break; break;
@ -1340,19 +1340,19 @@ bool dsp_configure(int setting, intptr_t value)
break; break;
case DSP_SET_TRACK_GAIN: case DSP_SET_TRACK_GAIN:
set_gain_var(&track_gain, value); dsp_set_gain_var(&track_gain, value);
break; break;
case DSP_SET_ALBUM_GAIN: case DSP_SET_ALBUM_GAIN:
set_gain_var(&album_gain, value); dsp_set_gain_var(&album_gain, value);
break; break;
case DSP_SET_TRACK_PEAK: case DSP_SET_TRACK_PEAK:
set_gain_var(&track_peak, value); dsp_set_gain_var(&track_peak, value);
break; break;
case DSP_SET_ALBUM_PEAK: case DSP_SET_ALBUM_PEAK:
set_gain_var(&album_peak, value); dsp_set_gain_var(&album_peak, value);
break; break;
default: default:

View file

@ -106,6 +106,7 @@ static const struct fm_region_setting fm_region[] = {
static int curr_preset = -1; static int curr_preset = -1;
static int curr_freq; static int curr_freq;
static int radio_mode = RADIO_SCAN_MODE; static int radio_mode = RADIO_SCAN_MODE;
static int search_dir = 0;
static int radio_status = FMRADIO_OFF; static int radio_status = FMRADIO_OFF;
static bool in_screen = false; static bool in_screen = false;
@ -389,6 +390,14 @@ static void next_station(int direction)
remember_frequency(); remember_frequency();
} }
/* Ends an in-progress search */
static void end_search(void)
{
if (search_dir != 0 && radio_status == FMRADIO_PLAYING)
radio_set(RADIO_MUTE, 0);
search_dir = 0;
}
int radio_screen(void) int radio_screen(void)
{ {
char buf[MAX_PATH]; char buf[MAX_PATH];
@ -396,7 +405,6 @@ int radio_screen(void)
int ret_val = GO_TO_ROOT; int ret_val = GO_TO_ROOT;
int button; int button;
int i; int i;
int search_dir = 0;
bool stereo = false, last_stereo = false; bool stereo = false, last_stereo = false;
int fh; int fh;
int top_of_screen = 0; int top_of_screen = 0;
@ -425,14 +433,6 @@ int radio_screen(void)
gui_buttonbar_set_display(&buttonbar, &(screens[SCREEN_MAIN]) ); gui_buttonbar_set_display(&buttonbar, &(screens[SCREEN_MAIN]) );
#endif #endif
/* Ends an in-progress search - needs access to search_dir */
void end_search(void)
{
if (search_dir != 0 && radio_status == FMRADIO_PLAYING)
radio_set(RADIO_MUTE, 0);
search_dir = 0;
}
/* change status to "in screen" */ /* change status to "in screen" */
in_screen = true; in_screen = true;

View file

@ -67,6 +67,19 @@ static int flush_interrupts = 0; /* Number of messages queued that
only interrupts a flush initiated only interrupts a flush initiated
by pcmrec_flush(0) */ by pcmrec_flush(0) */
/* Utility functions for setting/clearing flushing interrupt flag */
static inline void flush_interrupt(void)
{
flush_interrupts++;
logf("flush int: %d", flush_interrupts);
}
static inline void clear_flush_interrupt(void)
{
if (--flush_interrupts < 0)
flush_interrupts = 0;
}
/** Stats on encoded data for current file **/ /** Stats on encoded data for current file **/
static size_t num_rec_bytes; /* Num bytes recorded */ static size_t num_rec_bytes; /* Num bytes recorded */
static unsigned long num_rec_samples; /* Number of PCM samples recorded */ static unsigned long num_rec_samples; /* Number of PCM samples recorded */
@ -461,8 +474,7 @@ void audio_set_recording_options(struct audio_recording_options *options)
void audio_record(const char *filename) void audio_record(const char *filename)
{ {
logf("audio_record: %s", filename); logf("audio_record: %s", filename);
flush_interrupts++; flush_interrupt();
logf("flush int: %d", flush_interrupts);
queue_send(&pcmrec_queue, PCMREC_RECORD, (intptr_t)filename); queue_send(&pcmrec_queue, PCMREC_RECORD, (intptr_t)filename);
logf("audio_record_done"); logf("audio_record_done");
} /* audio_record */ } /* audio_record */
@ -473,8 +485,7 @@ void audio_record(const char *filename)
void audio_stop_recording(void) void audio_stop_recording(void)
{ {
logf("audio_stop_recording"); logf("audio_stop_recording");
flush_interrupts++; flush_interrupt();
logf("flush int: %d", flush_interrupts);
queue_send(&pcmrec_queue, PCMREC_STOP, 0); queue_send(&pcmrec_queue, PCMREC_STOP, 0);
logf("audio_stop_recording done"); logf("audio_stop_recording done");
} /* audio_stop_recording */ } /* audio_stop_recording */
@ -485,8 +496,7 @@ void audio_stop_recording(void)
void audio_pause_recording(void) void audio_pause_recording(void)
{ {
logf("audio_pause_recording"); logf("audio_pause_recording");
flush_interrupts++; flush_interrupt();
logf("flush int: %d", flush_interrupts);
queue_send(&pcmrec_queue, PCMREC_PAUSE, 0); queue_send(&pcmrec_queue, PCMREC_PAUSE, 0);
logf("audio_pause_recording done"); logf("audio_pause_recording done");
} /* audio_pause_recording */ } /* audio_pause_recording */
@ -1060,6 +1070,20 @@ static void pcmrec_flush(unsigned flush_num)
* chunk so it can recognize this. ENC_WRITE_CHUNK event must be able to accept * chunk so it can recognize this. ENC_WRITE_CHUNK event must be able to accept
* a NULL data pointer without error as well. * a NULL data pointer without error as well.
*/ */
static int pcmrec_get_chunk_index(struct enc_chunk_hdr *chunk)
{
return ((char *)chunk - (char *)enc_buffer) / enc_chunk_size;
} /* pcmrec_get_chunk_index */
static struct enc_chunk_hdr * pcmrec_get_prev_chunk(int index)
{
#ifdef PCMREC_PARANOID
int index_last = index;
#endif
DEC_ENC_INDEX(index);
return GET_ENC_CHUNK(index);
} /* pcmrec_get_prev_chunk */
static void pcmrec_new_stream(const char *filename, /* next file name */ static void pcmrec_new_stream(const char *filename, /* next file name */
unsigned long flags, /* CHUNKF_* flags */ unsigned long flags, /* CHUNKF_* flags */
int pre_index) /* index for prerecorded data */ int pre_index) /* index for prerecorded data */
@ -1074,20 +1098,6 @@ static void pcmrec_new_stream(const char *filename, /* next file name */
stream */ stream */
bool did_flush = false; /* did a flush occurr? */ bool did_flush = false; /* did a flush occurr? */
int get_chunk_index(struct enc_chunk_hdr *chunk)
{
return ((char *)chunk - (char *)enc_buffer) / enc_chunk_size;
}
struct enc_chunk_hdr * get_prev_chunk(int index)
{
#ifdef PCMREC_PARANOID
int index_last = index;
#endif
DEC_ENC_INDEX(index);
return GET_ENC_CHUNK(index);
}
if (filename) if (filename)
strncpy(path, filename, MAX_PATH); strncpy(path, filename, MAX_PATH);
queue_reply(&pcmrec_queue, 0); /* We have all we need */ queue_reply(&pcmrec_queue, 0); /* We have all we need */
@ -1120,7 +1130,7 @@ static void pcmrec_new_stream(const char *filename, /* next file name */
} }
else else
{ {
struct enc_chunk_hdr *last = get_prev_chunk(enc_wr_index); struct enc_chunk_hdr *last = pcmrec_get_prev_chunk(enc_wr_index);
if (last->flags & CHUNKF_END_FILE) if (last->flags & CHUNKF_END_FILE)
{ {
@ -1170,8 +1180,8 @@ static void pcmrec_new_stream(const char *filename, /* next file name */
if (flags & CHUNKF_END_FILE) if (flags & CHUNKF_END_FILE)
{ {
int i = get_chunk_index(data.chunk); int i = pcmrec_get_chunk_index(data.chunk);
get_prev_chunk(i)->flags |= CHUNKF_END_FILE; pcmrec_get_prev_chunk(i)->flags |= CHUNKF_END_FILE;
} }
if (start) if (start)
@ -1180,7 +1190,7 @@ static void pcmrec_new_stream(const char *filename, /* next file name */
{ {
/* get stats on data added to start - sort of a prerecord /* get stats on data added to start - sort of a prerecord
operation */ operation */
int i = get_chunk_index(data.chunk); int i = pcmrec_get_chunk_index(data.chunk);
#ifdef PCMREC_PARANOID #ifdef PCMREC_PARANOID
int i_last = i; int i_last = i;
#endif #endif
@ -1565,12 +1575,6 @@ static void pcmrec_thread(void)
logf("thread pcmrec start"); logf("thread pcmrec start");
void clear_flush_interrupt(void)
{
if (--flush_interrupts < 0)
flush_interrupts = 0;
}
while(1) while(1)
{ {
if (is_recording) if (is_recording)