Bump version to 3.12
[maemo-rb.git] / firmware / asm / pcm-mixer.c
blob9bdb9625761a4242b2716fb0eede55626acfbc8e
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2011 by Michael Sevakis
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #if defined(CPU_ARM)
23 #include "arm/pcm-mixer.c"
24 #elif defined(CPU_COLDFIRE)
25 #include "m68k/pcm-mixer.c"
26 #else
28 #include "dsp-util.h" /* for clip_sample_16 */
29 /* Mix channels' samples and apply gain factors */
30 static FORCE_INLINE void mix_samples(int16_t *out,
31 const int16_t *src0,
32 int32_t src0_amp,
33 const int16_t *src1,
34 int32_t src1_amp,
35 size_t size)
37 if (src0_amp == MIX_AMP_UNITY && src1_amp == MIX_AMP_UNITY)
39 /* Both are unity amplitude */
42 int32_t l = *src0++ + *src1++;
43 int32_t h = *src0++ + *src1++;
44 *out++ = clip_sample_16(l);
45 *out++ = clip_sample_16(h);
47 while ((size -= 2*sizeof(int16_t)) > 0);
49 else if (src0_amp != MIX_AMP_UNITY && src1_amp != MIX_AMP_UNITY)
51 /* Neither are unity amplitude */
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++ = clip_sample_16(l);
57 *out++ = clip_sample_16(h);
59 while ((size -= 2*sizeof(int16_t)) > 0);
61 else
63 /* One is unity amplitude */
64 if (src0_amp != MIX_AMP_UNITY)
66 /* Keep unity in src0, amp0 */
67 const int16_t *src_tmp = src0;
68 src0 = src1;
69 src1 = src_tmp;
70 src1_amp = src0_amp;
71 src0_amp = MIX_AMP_UNITY;
76 int32_t l = *src0++ + (*src1++ * src1_amp >> 16);
77 int32_t h = *src0++ + (*src1++ * src1_amp >> 16);
78 *out++ = clip_sample_16(l);
79 *out++ = clip_sample_16(h);
81 while ((size -= 2*sizeof(int16_t)) > 0);
85 /* Write channel's samples and apply gain factor */
86 static FORCE_INLINE void write_samples(int16_t *out,
87 const int16_t *src,
88 int32_t amp,
89 size_t size)
91 if (LIKELY(amp == MIX_AMP_UNITY))
93 /* Channel is unity amplitude */
94 memcpy(out, src, size);
96 else
98 /* Channel needs amplitude cut */
101 int32_t l = *src++ * amp >> 16;
102 int32_t h = *src++ * amp >> 16;
103 *out++ = l;
104 *out++ = h;
106 while ((size -= 2*sizeof(int16_t)) > 0);
111 #endif /* CPU_* */
113 #ifndef mixer_buffer_callback_exit
114 #define mixer_buffer_callback_exit() do{}while(0)
115 #endif