summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/beep.c80
-rw-r--r--firmware/asm/arm/beep.c39
-rw-r--r--firmware/asm/beep.c51
-rw-r--r--firmware/asm/m68k/beep.c42
4 files changed, 151 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;
diff --git a/firmware/asm/arm/beep.c b/firmware/asm/arm/beep.c
new file mode 100644
index 0000000000..f3c3e2e0d2
--- /dev/null
+++ b/firmware/asm/arm/beep.c
@@ -0,0 +1,39 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2011 Michael Sevakis
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22/* Actually output samples into beep_buf */
23static FORCE_INLINE void beep_generate(uint32_t *out, int count,
24 int32_t *phase, uint32_t step,
25 uint32_t amplitude)
26{
27 uint32_t s;
28
29 asm volatile (
30 "1: \n"
31 "eor %3, %5, %1, asr #31 \n"
32 "subs %2, %2, #1 \n"
33 "str %3, [%0], #4 \n"
34 "add %1, %1, %4 \n"
35 "bgt 1b \n"
36 : "+r"(out), "+r"(*phase), "+r"(count),
37 "=&r"(s)
38 : "r"(step), "r"(amplitude));
39}
diff --git a/firmware/asm/beep.c b/firmware/asm/beep.c
new file mode 100644
index 0000000000..0314e32715
--- /dev/null
+++ b/firmware/asm/beep.c
@@ -0,0 +1,51 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2011 Michael Sevakis
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#if defined(CPU_ARM)
22#include "arm/beep.c"
23#elif defined (CPU_COLDFIRE)
24#include "m68k/beep.c"
25#else /* Generic */
26
27static FORCE_INLINE void beep_generate(int16_t *out, int count,
28 uint32_t *phase, uint32_t step,
29 int16_t amplitude)
30{
31 uint32_t ph = *phase;
32
33 do
34 {
35 int16_t amp = amplitude;
36
37 if (ph > UINT32_MAX / 2)
38 amp = -amp;
39
40 *out++ = amp;
41 *out++ = amp;
42
43 ph += step;
44 }
45 while (--count > 0);
46
47 *phase = ph;
48}
49
50#define BEEP_GENERIC
51#endif /* CPU_* */
diff --git a/firmware/asm/m68k/beep.c b/firmware/asm/m68k/beep.c
new file mode 100644
index 0000000000..5461a4ef20
--- /dev/null
+++ b/firmware/asm/m68k/beep.c
@@ -0,0 +1,42 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2011 Michael Sevakis
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22/* Actually output samples into beep_buf */
23static FORCE_INLINE void beep_generate(uint32_t *out, int count,
24 int32_t *phase, uint32_t step,
25 uint32_t amplitude)
26{
27 uint32_t s;
28
29 asm volatile (
30 "1: \n"
31 "move.l %1, %3 \n"
32 "add.l %4, %1 \n"
33 "add.l %3, %3 \n"
34 "subx.l %3, %3 \n"
35 "eor.l %5, %3 \n"
36 "move.l %3, (%0)+ \n"
37 "subq.l #1, %2 \n"
38 "bgt.b 1b \n"
39 : "+a"(out), "+d"(*phase), "+d"(count),
40 "=&d"(s)
41 : "r"(step), "d"(amplitude));
42}