1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
23 #include "arm/pcm-mixer.c"
24 #elif defined(CPU_COLDFIRE)
25 #include "m68k/pcm-mixer.c"
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
,
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);
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
;
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
,
91 if (LIKELY(amp
== MIX_AMP_UNITY
))
93 /* Channel is unity amplitude */
94 memcpy(out
, src
, size
);
98 /* Channel needs amplitude cut */
101 int32_t l
= *src
++ * amp
>> 16;
102 int32_t h
= *src
++ * amp
>> 16;
106 while ((size
-= 2*sizeof(int16_t)) > 0);
113 #ifndef mixer_buffer_callback_exit
114 #define mixer_buffer_callback_exit() do{}while(0)