summaryrefslogtreecommitdiff
path: root/apps/beep.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2012-02-18 04:50:33 -0500
committerMichael Sevakis <jethead71@rockbox.org>2012-02-18 04:50:33 -0500
commit9a32a7b40442e54ee6d8e2403e0f9a154dc4c77f (patch)
treed5aac8ee6999c701c19e69a5f7391517c40216e3 /apps/beep.c
parenta794aaa38c9d40e4f0131cd11d8a41441dcd6c4f (diff)
downloadrockbox-9a32a7b40442e54ee6d8e2403e0f9a154dc4c77f.tar.gz
rockbox-9a32a7b40442e54ee6d8e2403e0f9a154dc4c77f.zip
Split CPU-optimized beep code into the firmware/asm tree.
For now due to current lack of an apps/asm, place the ASM/generic code in the firmware/asm directory. Additionally, make generic beep code more generic. Change-Id: I4a69b6ffcbb97d9e6dfde2209c5a118de19e5638
Diffstat (limited to 'apps/beep.c')
-rw-r--r--apps/beep.c80
1 files changed, 19 insertions, 61 deletions
diff --git a/apps/beep.c b/apps/beep.c
index a6244d932c..79c7f1d2bc 100644
--- a/apps/beep.c
+++ b/apps/beep.c
@@ -26,71 +26,22 @@
26#include "pcm_mixer.h" 26#include "pcm_mixer.h"
27#include "misc.h" 27#include "misc.h"
28 28
29static int32_t beep_phase; /* Phase of square wave generator */ 29/** Beep generation, CPU optimized **/
30#include "../firmware/asm/beep.c"
31
32static uint32_t beep_phase; /* Phase of square wave generator */
30static uint32_t beep_step; /* Step of square wave generator on each sample */ 33static uint32_t beep_step; /* Step of square wave generator on each sample */
34#ifdef BEEP_GENERIC
35static int16_t beep_amplitude; /* Amplitude of square wave generator */
36#else
37/* Optimized routines do XOR with phase sign bit in both channels at once */
31static uint32_t beep_amplitude; /* Amplitude of square wave generator */ 38static uint32_t beep_amplitude; /* Amplitude of square wave generator */
39#endif
32static int beep_count; /* Number of samples remaining to generate */ 40static int beep_count; /* Number of samples remaining to generate */
33 41
34/* Reserve enough static space for keyclick to fit */ 42/* Reserve enough static space for keyclick to fit */
35#define BEEP_BUF_COUNT (NATIVE_FREQUENCY / 1000 * KEYCLICK_DURATION) 43#define BEEP_BUF_COUNT (NATIVE_FREQUENCY / 1000 * KEYCLICK_DURATION)
36static uint32_t beep_buf[BEEP_BUF_COUNT] IBSS_ATTR; 44static int16_t beep_buf[BEEP_BUF_COUNT*2] IBSS_ATTR __attribute__((aligned(4)));
37
38/* Actually output samples into beep_buf */
39#if defined(CPU_ARM)
40static FORCE_INLINE void beep_generate(int count)
41{
42 uint32_t *out = beep_buf;
43 uint32_t s;
44
45 asm volatile (
46 "1: \n"
47 "eor %3, %5, %1, asr #31 \n"
48 "subs %2, %2, #1 \n"
49 "str %3, [%0], #4 \n"
50 "add %1, %1, %4 \n"
51 "bgt 1b \n"
52 : "+r"(out), "+r"(beep_phase), "+r"(count),
53 "=&r"(s)
54 : "r"(beep_step), "r"(beep_amplitude));
55}
56#elif defined (CPU_COLDFIRE)
57static FORCE_INLINE void beep_generate(int count)
58{
59 uint32_t *out = beep_buf;
60 uint32_t s;
61
62 asm volatile (
63 "1: \n"
64 "move.l %1, %3 \n"
65 "add.l %4, %1 \n"
66 "add.l %3, %3 \n"
67 "subx.l %3, %3 \n"
68 "eor.l %5, %3 \n"
69 "move.l %3, (%0)+ \n"
70 "subq.l #1, %2 \n"
71 "bgt.b 1b \n"
72 : "+a"(out), "+d"(beep_phase), "+d"(count),
73 "=&d"(s)
74 : "r"(beep_step), "d"(beep_amplitude));
75}
76#else
77static FORCE_INLINE void beep_generate(int count)
78{
79 uint32_t *out = beep_buf;
80 uint32_t amplitude = beep_amplitude;
81 uint32_t step = beep_step;
82 int32_t phase = beep_phase;
83
84 do
85 {
86 *out++ = (phase >> 31) ^ amplitude;
87 phase += step;
88 }
89 while (--count > 0);
90
91 beep_phase = phase;
92}
93#endif
94 45
95/* Callback to generate the beep frames - also don't want inlining of 46/* Callback to generate the beep frames - also don't want inlining of
96 call below in beep_play */ 47 call below in beep_play */
@@ -104,8 +55,9 @@ beep_get_more(unsigned char **start, size_t *size)
104 count = MIN(count, BEEP_BUF_COUNT); 55 count = MIN(count, BEEP_BUF_COUNT);
105 beep_count -= count; 56 beep_count -= count;
106 *start = (unsigned char *)beep_buf; 57 *start = (unsigned char *)beep_buf;
107 *size = count * sizeof(uint32_t); 58 *size = count * 2 * sizeof (int16_t);
108 beep_generate(count); 59 beep_generate((void *)beep_buf, count, &beep_phase,
60 beep_step, beep_amplitude);
109 } 61 }
110} 62}
111 63
@@ -126,7 +78,13 @@ void beep_play(unsigned int frequency, unsigned int duration,
126 beep_phase = 0; 78 beep_phase = 0;
127 beep_step = 0xffffffffu / NATIVE_FREQUENCY * frequency; 79 beep_step = 0xffffffffu / NATIVE_FREQUENCY * frequency;
128 beep_count = NATIVE_FREQUENCY / 1000 * duration; 80 beep_count = NATIVE_FREQUENCY / 1000 * duration;
81
82#ifdef BEEP_GENERIC
83 beep_amplitude = amplitude;
84#else
85 /* Optimized routines do XOR with phase sign bit in both channels at once */
129 beep_amplitude = amplitude | (amplitude << 16); /* Word:|AMP16|AMP16| */ 86 beep_amplitude = amplitude | (amplitude << 16); /* Word:|AMP16|AMP16| */
87#endif
130 88
131 /* If it fits - avoid cb overhead */ 89 /* If it fits - avoid cb overhead */
132 unsigned char *start; 90 unsigned char *start;