summaryrefslogtreecommitdiff
path: root/firmware/asm/pcm-mixer.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/asm/pcm-mixer.c')
-rw-r--r--firmware/asm/pcm-mixer.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/firmware/asm/pcm-mixer.c b/firmware/asm/pcm-mixer.c
new file mode 100644
index 0000000000..369e830427
--- /dev/null
+++ b/firmware/asm/pcm-mixer.c
@@ -0,0 +1,108 @@
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
22#if defined(CPU_ARM)
23 #include "arm/pcm-mixer.c"
24#elif defined(CPU_COLDFIRE)
25 #include "m68k/pcm-mixer.c"
26#else
27
28/* generic pcm-mixer.c */
29#include "dsp-util.h" /* for clip_sample_16 */
30/* Mix channels' samples and apply gain factors */
31static FORCE_INLINE void mix_samples(uint32_t *out,
32 int16_t *src0,
33 int32_t src0_amp,
34 int16_t *src1,
35 int32_t src1_amp,
36 size_t size)
37{
38 if (src0_amp == MIX_AMP_UNITY && src1_amp == MIX_AMP_UNITY)
39 {
40 /* Both are unity amplitude */
41 do
42 {
43 int32_t l = *src0++ + *src1++;
44 int32_t h = *src0++ + *src1++;
45 *out++ = (uint16_t)clip_sample_16(l) | (clip_sample_16(h) << 16);
46 }
47 while ((size -= 4) > 0);
48 }
49 else if (src0_amp != MIX_AMP_UNITY && src1_amp != MIX_AMP_UNITY)
50 {
51 /* Neither are unity amplitude */
52 do
53 {
54 int32_t l = (*src0++ * src0_amp >> 16) + (*src1++ * src1_amp >> 16);
55 int32_t h = (*src0++ * src0_amp >> 16) + (*src1++ * src1_amp >> 16);
56 *out++ = (uint16_t)clip_sample_16(l) | (clip_sample_16(h) << 16);
57 }
58 while ((size -= 4) > 0);
59 }
60 else
61 {
62 /* One is unity amplitude */
63 if (src0_amp != MIX_AMP_UNITY)
64 {
65 /* Keep unity in src0, amp0 */
66 int16_t *src_tmp = src0;
67 src0 = src1;
68 src1 = src_tmp;
69 src1_amp = src0_amp;
70 src0_amp = MIX_AMP_UNITY;
71 }
72
73 do
74 {
75 int32_t l = *src0++ + (*src1++ * src1_amp >> 16);
76 int32_t h = *src0++ + (*src1++ * src1_amp >> 16);
77 *out++ = (uint16_t)clip_sample_16(l) | (clip_sample_16(h) << 16);
78 }
79 while ((size -= 4) > 0);
80 }
81}
82
83/* Write channel's samples and apply gain factor */
84static FORCE_INLINE void write_samples(uint32_t *out,
85 int16_t *src,
86 int32_t amp,
87 size_t size)
88{
89 if (LIKELY(amp == MIX_AMP_UNITY))
90 {
91 /* Channel is unity amplitude */
92 memcpy(out, src, size);
93 }
94 else
95 {
96 /* Channel needs amplitude cut */
97 do
98 {
99 int32_t l = *src++ * amp >> 16;
100 int32_t h = *src++ * amp & 0xffff0000;
101 *out++ = (uint16_t)l | h;
102 }
103 while ((size -= 4) > 0);
104 }
105}
106
107
108#endif