summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-03-29 01:55:47 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-03-29 01:55:47 +0000
commit62e0a516a085de93ec0fc50cfff6e346d80ccebb (patch)
tree2f37c8830318764bf49106b82a904b6c8541fc1f
parent583caa867b052e4287bf531eb9576716ee1ed5a4 (diff)
downloadrockbox-62e0a516a085de93ec0fc50cfff6e346d80ccebb.zip
rockbox-62e0a516a085de93ec0fc50cfff6e346d80ccebb.tar.gz
rockbox-62e0a516a085de93ec0fc50cfff6e346d80ccebb.tar.bz2
rockbox-62e0a516a085de93ec0fc50cfff6e346d80ccebb.tar.xz
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
-rw-r--r--apps/codecs/aiff_enc.c48
-rw-r--r--apps/codecs/wav_enc.c48
-rw-r--r--apps/codecs/wavpack_enc.c78
-rw-r--r--apps/dsp.c42
-rw-r--r--apps/recorder/radio.c18
-rw-r--r--firmware/pcm_record.c64
6 files changed, 151 insertions, 147 deletions
diff --git a/apps/codecs/aiff_enc.c b/apps/codecs/aiff_enc.c
index 1de25a4..2292bcc 100644
--- a/apps/codecs/aiff_enc.c
+++ b/apps/codecs/aiff_enc.c
@@ -221,6 +221,22 @@ STATICIRAM void enc_events_callback(enum enc_events event, void *data)
} /* enc_events_callback */
/* 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)
{
@@ -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;
- 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
{
- 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);
+ sample_to_mono(&src, &dst);
+ sample_to_mono(&src, &dst);
+ sample_to_mono(&src, &dst);
+ sample_to_mono(&src, &dst);
+ sample_to_mono(&src, &dst);
+ sample_to_mono(&src, &dst);
+ sample_to_mono(&src, &dst);
+ sample_to_mono(&src, &dst);
}
while (src < src_end);
}
diff --git a/apps/codecs/wav_enc.c b/apps/codecs/wav_enc.c
index e14b04d..ff77f13 100644
--- a/apps/codecs/wav_enc.c
+++ b/apps/codecs/wav_enc.c
@@ -209,6 +209,22 @@ STATICIRAM void enc_events_callback(enum enc_events event, void *data)
} /* enc_events_callback */
/* 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)
{
@@ -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;
- 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
{
- 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);
+ sample_to_mono(&src, &dst);
+ sample_to_mono(&src, &dst);
+ sample_to_mono(&src, &dst);
+ sample_to_mono(&src, &dst);
+ sample_to_mono(&src, &dst);
+ sample_to_mono(&src, &dst);
+ sample_to_mono(&src, &dst);
+ sample_to_mono(&src, &dst);
}
while (src < src_end);
}
diff --git a/apps/codecs/wavpack_enc.c b/apps/codecs/wavpack_enc.c
index de8fe80..7b6484d 100644
--- a/apps/codecs/wavpack_enc.c
+++ b/apps/codecs/wavpack_enc.c
@@ -99,6 +99,25 @@ static const struct riff_header riff_header =
/* (*) 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)
{
@@ -123,28 +142,19 @@ STATICIRAM void chunk_to_int32(int32_t *src)
* |llllllllllllllll|rrrrrrrrrrrrrrrr| =>
* |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
{
/* 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);
+ sample_to_int32_mono(&src, &dst);
+ sample_to_int32_mono(&src, &dst);
+ sample_to_int32_mono(&src, &dst);
+ sample_to_int32_mono(&src, &dst);
+ sample_to_int32_mono(&src, &dst);
+ sample_to_int32_mono(&src, &dst);
+ sample_to_int32_mono(&src, &dst);
+ sample_to_int32_mono(&src, &dst);
+ sample_to_int32_mono(&src, &dst);
+ sample_to_int32_mono(&src, &dst);
}
while(src < src_end);
@@ -156,29 +166,19 @@ STATICIRAM void chunk_to_int32(int32_t *src)
* |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);
+ sample_to_int32_stereo(&src, &dst);
+ sample_to_int32_stereo(&src, &dst);
+ sample_to_int32_stereo(&src, &dst);
+ sample_to_int32_stereo(&src, &dst);
+ sample_to_int32_stereo(&src, &dst);
+ sample_to_int32_stereo(&src, &dst);
+ sample_to_int32_stereo(&src, &dst);
+ sample_to_int32_stereo(&src, &dst);
+ sample_to_int32_stereo(&src, &dst);
+ sample_to_int32_stereo(&src, &dst);
}
while (src < src_end);
diff --git a/apps/dsp.c b/apps/dsp.c
index 20ce1e6..609b2d6 100644
--- a/apps/dsp.c
+++ b/apps/dsp.c
@@ -1234,26 +1234,26 @@ int dsp_stereo_mode(void)
return dsp->stereo_mode;
}
-bool dsp_configure(int setting, intptr_t value)
+static void dsp_set_gain_var(long *var, long value)
{
- void set_gain_var(long *var, long value)
+ /* Voice shouldn't mess with these */
+ if (dsp == audio_dsp)
{
- /* Voice shouldn't mess with these */
- if (dsp == audio_dsp)
- {
- *var = value;
- new_gain = true;
- }
+ *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);
- }
+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)
+{
switch (setting)
{
case DSP_SWITCH_CODEC:
@@ -1305,7 +1305,7 @@ bool dsp_configure(int setting, intptr_t value)
case DSP_SET_STEREO_MODE:
dsp->stereo_mode = value;
dsp->data.num_channels = value == STEREO_MONO ? 1 : 2;
- update_functions();
+ dsp_update_functions();
break;
case DSP_RESET:
@@ -1328,7 +1328,7 @@ bool dsp_configure(int setting, intptr_t value)
new_gain = true;
}
- update_functions();
+ dsp_update_functions();
resampler_new_delta();
break;
@@ -1340,19 +1340,19 @@ bool dsp_configure(int setting, intptr_t value)
break;
case DSP_SET_TRACK_GAIN:
- set_gain_var(&track_gain, value);
+ dsp_set_gain_var(&track_gain, value);
break;
case DSP_SET_ALBUM_GAIN:
- set_gain_var(&album_gain, value);
+ dsp_set_gain_var(&album_gain, value);
break;
case DSP_SET_TRACK_PEAK:
- set_gain_var(&track_peak, value);
+ dsp_set_gain_var(&track_peak, value);
break;
case DSP_SET_ALBUM_PEAK:
- set_gain_var(&album_peak, value);
+ dsp_set_gain_var(&album_peak, value);
break;
default:
diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c
index 5e0185d..cf305ca 100644
--- a/apps/recorder/radio.c
+++ b/apps/recorder/radio.c
@@ -106,6 +106,7 @@ static const struct fm_region_setting fm_region[] = {
static int curr_preset = -1;
static int curr_freq;
static int radio_mode = RADIO_SCAN_MODE;
+static int search_dir = 0;
static int radio_status = FMRADIO_OFF;
static bool in_screen = false;
@@ -389,6 +390,14 @@ static void next_station(int direction)
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)
{
char buf[MAX_PATH];
@@ -396,7 +405,6 @@ int radio_screen(void)
int ret_val = GO_TO_ROOT;
int button;
int i;
- int search_dir = 0;
bool stereo = false, last_stereo = false;
int fh;
int top_of_screen = 0;
@@ -425,14 +433,6 @@ int radio_screen(void)
gui_buttonbar_set_display(&buttonbar, &(screens[SCREEN_MAIN]) );
#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" */
in_screen = true;
diff --git a/firmware/pcm_record.c b/firmware/pcm_record.c
index 1c7e458..2e472c6 100644
--- a/firmware/pcm_record.c
+++ b/firmware/pcm_record.c
@@ -67,6 +67,19 @@ static int flush_interrupts = 0; /* Number of messages queued that
only interrupts a flush initiated
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 **/
static size_t num_rec_bytes; /* Num bytes 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)
{
logf("audio_record: %s", filename);
- flush_interrupts++;
- logf("flush int: %d", flush_interrupts);
+ flush_interrupt();
queue_send(&pcmrec_queue, PCMREC_RECORD, (intptr_t)filename);
logf("audio_record_done");
} /* audio_record */
@@ -473,8 +485,7 @@ void audio_record(const char *filename)
void audio_stop_recording(void)
{
logf("audio_stop_recording");
- flush_interrupts++;
- logf("flush int: %d", flush_interrupts);
+ flush_interrupt();
queue_send(&pcmrec_queue, PCMREC_STOP, 0);
logf("audio_stop_recording done");
} /* audio_stop_recording */
@@ -485,8 +496,7 @@ void audio_stop_recording(void)
void audio_pause_recording(void)
{
logf("audio_pause_recording");
- flush_interrupts++;
- logf("flush int: %d", flush_interrupts);
+ flush_interrupt();
queue_send(&pcmrec_queue, PCMREC_PAUSE, 0);
logf("audio_pause_recording done");
} /* 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
* 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 */
unsigned long flags, /* CHUNKF_* flags */
int pre_index) /* index for prerecorded data */
@@ -1074,20 +1098,6 @@ static void pcmrec_new_stream(const char *filename, /* next file name */
stream */
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)
strncpy(path, filename, MAX_PATH);
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
{
- 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)
{
@@ -1170,8 +1180,8 @@ static void pcmrec_new_stream(const char *filename, /* next file name */
if (flags & CHUNKF_END_FILE)
{
- int i = get_chunk_index(data.chunk);
- get_prev_chunk(i)->flags |= CHUNKF_END_FILE;
+ int i = pcmrec_get_chunk_index(data.chunk);
+ pcmrec_get_prev_chunk(i)->flags |= CHUNKF_END_FILE;
}
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
operation */
- int i = get_chunk_index(data.chunk);
+ int i = pcmrec_get_chunk_index(data.chunk);
#ifdef PCMREC_PARANOID
int i_last = i;
#endif
@@ -1565,12 +1575,6 @@ static void pcmrec_thread(void)
logf("thread pcmrec start");
- void clear_flush_interrupt(void)
- {
- if (--flush_interrupts < 0)
- flush_interrupts = 0;
- }
-
while(1)
{
if (is_recording)