summaryrefslogtreecommitdiff
path: root/firmware/target/arm/pcm-mixer-armv6.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2011-06-29 06:37:04 +0000
committerMichael Sevakis <jethead71@rockbox.org>2011-06-29 06:37:04 +0000
commita2b6703a369f6cdbfec1f150c408dadc877631fb (patch)
tree3145a8c1372c44711d38feefeba39c7d4098f139 /firmware/target/arm/pcm-mixer-armv6.c
parent8411614b8a068a4f274c3841aa55aab1df1bc246 (diff)
downloadrockbox-a2b6703a369f6cdbfec1f150c408dadc877631fb.tar.gz
rockbox-a2b6703a369f6cdbfec1f150c408dadc877631fb.zip
Commit FS#12150 - Fully-functional audio mixer - and finally whip old limitations about playback of voice and other sounds when paused. Channels are independent in state and amplitude. Fade on stop/pause is handled by the channel's volume control rather than global volume which means it now works from anywhere. Opens up the possibility of plugin sounds during music playback by merely adding an additional channel enum. If any PCM drivers were not properly modified, see one of the last comments in the task for a description of the simple change that is expected. Some params are tunable in firmware/export/pcm-mixer.h as well.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30097 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/pcm-mixer-armv6.c')
-rw-r--r--firmware/target/arm/pcm-mixer-armv6.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/firmware/target/arm/pcm-mixer-armv6.c b/firmware/target/arm/pcm-mixer-armv6.c
new file mode 100644
index 0000000000..94eecd0f90
--- /dev/null
+++ b/firmware/target/arm/pcm-mixer-armv6.c
@@ -0,0 +1,118 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 by 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#define MIXER_OPTIMIZED_MIX_SAMPLES
22#define MIXER_OPTIMIZED_WRITE_SAMPLES
23
24/* Mix channels' samples and apply gain factors */
25static FORCE_INLINE void mix_samples(void *out,
26 void *src0,
27 int32_t src0_amp,
28 void *src1,
29 int32_t src1_amp,
30 size_t size)
31{
32 uint32_t s0, s1;
33
34 if (src0_amp == MIX_AMP_UNITY && src1_amp == MIX_AMP_UNITY)
35 {
36 /* Both are unity amplitude */
37 asm volatile (
38 "1: \n"
39 "ldr %4, [%1], #4 \n"
40 "ldr %5, [%2], #4 \n"
41 "subs %3, %3, #4 \n"
42 "qadd16 %5, %5, %4 \n"
43 "str %5, [%0], #4 \n"
44 "bhi 1b \n"
45 : "+r"(out), "+r"(src0), "+r"(src1), "+r"(size),
46 "=&r"(s0), "=&r"(s1));
47 }
48 else
49 {
50 /* One or neither are unity amplitude */
51 uint32_t tmp;
52 asm volatile (
53 "1: \n"
54 "ldr %4, [%1], #4 \n"
55 "ldr %5, [%2], #4 \n"
56 "subs %3, %3, #4 \n"
57 "smulwb %6, %7, %4 \n"
58 "smulwt %4, %7, %4 \n"
59 "smlawb %6, %8, %5, %6 \n"
60 "smlawt %4, %8, %5, %4 \n"
61 "ssat %6, #16, %6 \n"
62 "ssat %4, #16, %4 \n"
63 "pkhbt %6, %6, %4, asl #16 \n"
64 "str %6, [%0], #4 \n"
65 "bhi 1b \n"
66 : "+r"(out), "+r"(src0), "+r"(src1), "+r"(size),
67 "=&r"(s0), "=&r"(s1), "=&r"(tmp)
68 : "r"(src0_amp), "r"(src1_amp));
69 }
70}
71
72/* Write channel's samples and apply gain factor */
73static FORCE_INLINE void write_samples(void *out,
74 void *src,
75 int32_t amp,
76 size_t size)
77{
78 if (LIKELY(amp == MIX_AMP_UNITY))
79 {
80 /* Channel is unity amplitude */
81 asm volatile (
82 "ands r1, %2, #0x1f \n"
83 "beq 2f \n"
84 "1: \n"
85 "ldr r0, [%1], #4 \n"
86 "subs r1, r1, #4 \n"
87 "str r0, [%0], #4 \n"
88 "bne 1b \n"
89 "bics %2, %2, #0x1f \n"
90 "beq 3f \n"
91 "2: \n"
92 "ldmia %1!, { r0-r7 } \n"
93 "subs %2, %2, #32 \n"
94 "stmia %0!, { r0-r7 } \n"
95 "bhi 2b \n"
96 "3: \n"
97 : "+r"(out), "+r"(src), "+r"(size)
98 :
99 : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7");
100 }
101 else
102 {
103 /* Channel needs amplitude cut */
104 uint32_t s, tmp;
105 asm volatile(
106 "1: \n"
107 "ldr %3, [%1], #4 \n"
108 "subs %2, %2, #4 \n"
109 "smulwt %4, %5, %3 \n"
110 "smulwb %3, %5, %3 \n"
111 "pkhbt %4, %3, %4, asl #16 \n"
112 "str %4, [%0], #4 \n"
113 "bhi 1b \n"
114 : "+r"(out), "+r"(src), "+r"(size),
115 "=&r"(s), "=&r"(tmp)
116 : "r"(amp));
117 }
118}