1
0
Fork 0
forked from len0rd/rockbox

SPC Codec: Refactor for CPU and clean up some things.

CPU optimization gets its own files in which to fill-in optimizable
routines.

Some pointless #if 0's for profiling need removal. Those macros are
empty if not profiling.

Force some functions that are undesirable to be force-inlined by the
compiler to be not inlined.

Change-Id: Ia7b7e45380d7efb20c9b1a4d52e05db3ef6bbaab
This commit is contained in:
Michael Sevakis 2013-05-18 01:45:03 -04:00
parent a17d6de5bc
commit 87021f7c0a
12 changed files with 1693 additions and 1298 deletions

View file

@ -0,0 +1,253 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2007-2010 Michael Sevakis (jhMikeS)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#if !SPC_NOINTERP
#define SPC_GAUSSIAN_FAST_INTERP
static inline int gaussian_fast_interp( int16_t const* samples,
int32_t position,
int16_t const* fwd,
int16_t const* rev )
{
int output;
int t0, t1, t2, t3;
asm volatile (
"ldrsh %[t0], [%[samp]] \n"
"ldrsh %[t2], [%[fwd]] \n"
"ldrsh %[t1], [%[samp], #2] \n"
"ldrsh %[t3], [%[fwd], #2] \n"
"mul %[out], %[t0], %[t2] \n" /* out= fwd[0]*samp[0] */
"ldrsh %[t0], [%[samp], #4] \n"
"ldrsh %[t2], [%[rev], #2] \n"
"mla %[out], %[t1], %[t3], %[out] \n" /* out+=fwd[1]*samp[1] */
"ldrsh %[t1], [%[samp], #6] \n"
"ldrsh %[t3], [%[rev]] \n"
"mla %[out], %[t0], %[t2], %[out] \n" /* out+=rev[1]*samp[2] */
"mla %[out], %[t1], %[t3], %[out] \n" /* out+=rev[0]*samp[3] */
: [out]"=&r"(output),
[t0]"=&r"(t0), [t1]"=&r"(t1), [t2]"=&r"(t2), [t3]"=&r"(t3)
: [fwd]"r"(fwd), [rev]"r"(rev),
[samp]"r"(samples + (position >> 12)));
return output;
}
#define SPC_GAUSSIAN_FAST_AMP
static inline int gaussian_fast_amp( struct voice_t* voice, int output,
int* amp_0, int* amp_1 )
{
int t0;
asm volatile (
"mov %[t0], %[out], asr #11 \n"
"mul %[out], %[t0], %[envx] \n"
: [out]"+r"(output), [t0]"=&r"(t0)
: [envx]"r"((int) voice->envx));
asm volatile (
"mov %[out], %[out], asr #11 \n"
"mul %[a0], %[out], %[v0] \n"
"mul %[a1], %[out], %[v1] \n"
: [out]"+r"(output),
[a0]"=&r"(*amp_0), [a1]"=r"(*amp_1)
: [v0]"r"((int) voice->volume [0]),
[v1]"r"((int) voice->volume [1]));
return output;
}
#define SPC_GAUSSIAN_SLOW_INTERP
static inline int gaussian_slow_interp( int16_t const* samples,
int32_t position,
int16_t const* fwd,
int16_t const* rev )
{
int output;
int t0, t1, t2, t3;
asm volatile (
"ldrsh %[t0], [%[samp]] \n"
"ldrsh %[t2], [%[fwd]] \n"
"ldrsh %[t1], [%[samp], #2] \n"
"ldrsh %[t3], [%[fwd], #2] \n"
"mul %[out], %[t2], %[t0] \n" /* fwd[0]*samp[0] */
"ldrsh %[t2], [%[rev], #2] \n"
"mul %[t0], %[t3], %[t1] \n" /* fwd[1]*samp[1] */
"ldrsh %[t1], [%[samp], #4] \n"
"mov %[out], %[out], asr #12 \n"
"ldrsh %[t3], [%[rev]] \n"
"mul %[t2], %[t1], %[t2] \n" /* rev[1]*samp[2] */
"ldrsh %[t1], [%[samp], #6] \n"
"add %[t0], %[out], %[t0], asr #12 \n"
"mul %[t3], %[t1], %[t3] \n" /* rev[0]*samp[3] */
"add %[t2], %[t0], %[t2], asr #12 \n"
"mov %[t2], %[t2], lsl #17 \n"
"mov %[t3], %[t3], asr #12 \n"
"mov %[t3], %[t3], asl #1 \n"
"add %[out], %[t3], %[t2], asr #16 \n"
: [out]"=&r"(output),
[t0]"=&r"(t0), [t1]"=&r"(t1), [t2]"=&r"(t2), [t3]"=&r"(t3)
: [fwd]"r"(fwd), [rev]"r"(rev),
[samp]"r"(samples + (position >> 12)));
return CLAMP16( output );
}
#define SPC_GAUSSIAN_SLOW_AMP
static inline int gaussian_slow_amp( struct voice_t* voice, int output,
int* amp_0, int* amp_1 )
{
int t0;
asm volatile (
"mul %[t0], %[out], %[envx]"
: [t0]"=r"(t0)
: [out]"r"(output), [envx]"r"((int) voice->envx));
asm volatile (
"mov %[t0], %[t0], asr #11 \n"
"bic %[t0], %[t0], #0x1 \n"
"mul %[a0], %[t0], %[v0] \n"
"mul %[a1], %[t0], %[v1] \n"
: [t0]"+r"(t0),
[a0]"=&r"(*amp_0), [a1]"=r"(*amp_1)
: [v0]"r"((int) voice->volume [0]),
[v1]"r"((int) voice->volume [1]));
return t0;
}
#else /* SPC_NOINTERP */
#define SPC_LINEAR_INTERP
static inline int linear_interp( int16_t const* samples, int32_t position )
{
int output = (int) samples;
int y1;
asm volatile(
"mov %[y1], %[f], lsr #12 \n"
"eor %[f], %[f], %[y1], lsl #12 \n"
"add %[y1], %[y0], %[y1], lsl #1 \n"
"ldrsh %[y0], [%[y1], #2] \n"
"ldrsh %[y1], [%[y1], #4] \n"
"sub %[y1], %[y1], %[y0] \n"
"mul %[f], %[y1], %[f] \n"
"add %[y0], %[y0], %[f], asr #12 \n"
: [f]"+r"(position), [y0]"+r"(output), [y1]"=&r"(y1));
return output;
}
#define SPC_LINEAR_AMP
static inline int linear_amp( struct voice_t* voice, int output,
int* amp_0, int* amp_1 )
{
int t0;
asm volatile(
"mul %[t0], %[out], %[envx]"
: [t0]"=&r"(t0)
: [out]"r"(output), [envx]"r"(voice->envx));
asm volatile(
"mov %[t0], %[t0], asr #11 \n"
"mul %[a1], %[t0], %[v1] \n"
"mul %[a0], %[t0], %[v0] \n"
: [t0]"+r"(t0),
[a0]"=&r"(*amp_0), [a1]"=&r"(*amp_1)
: [v0]"r"((int) voice->volume [0]),
[v1]"r"((int) voice->volume [1]));
return t0;
}
#endif /* !SPC_NOINTERP */
#if !SPC_NOECHO
#define SPC_DSP_ECHO_APPLY
/* Echo filter history */
static int32_t fir_buf[FIR_BUF_CNT] IBSS_ATTR_SPC
__attribute__(( aligned(FIR_BUF_ALIGN*1) ));
static inline void echo_init( struct Spc_Dsp* this )
{
this->fir.ptr = fir_buf;
ci->memset( fir_buf, 0, sizeof fir_buf );
}
static inline void echo_apply( struct Spc_Dsp* this, uint8_t *echo_ptr,
int* out_0, int* out_1 )
{
int t0 = GET_LE16SA( echo_ptr );
int t1 = GET_LE16SA( echo_ptr + 2 );
/* Keep last 8 samples */
int32_t *fir_ptr;
asm volatile (
"add %[p], %[t_p], #8 \n"
"bic %[t_p], %[p], %[mask] \n"
"str %[t0], [%[p], #-8] \n"
"str %[t1], [%[p], #-4] \n"
/* duplicate at +8 eliminates wrap checking below */
"str %[t0], [%[p], #56] \n"
"str %[t1], [%[p], #60] \n"
: [p]"=&r"(fir_ptr), [t_p]"+r"(this->fir.ptr)
: [t0]"r"(t0), [t1]"r"(t1), [mask]"i"(~FIR_BUF_MASK));
int32_t *fir_coeff = this->fir.coeff;
asm volatile (
"ldmia %[c]!, { r0-r1 } \n"
"ldmia %[p]!, { r4-r5 } \n"
"mul %[acc0], r0, %[acc0] \n"
"mul %[acc1], r0, %[acc1] \n"
"mla %[acc0], r4, r1, %[acc0] \n"
"mla %[acc1], r5, r1, %[acc1] \n"
"ldmia %[c]!, { r0-r1 } \n"
"ldmia %[p]!, { r2-r5 } \n"
"mla %[acc0], r2, r0, %[acc0] \n"
"mla %[acc1], r3, r0, %[acc1] \n"
"mla %[acc0], r4, r1, %[acc0] \n"
"mla %[acc1], r5, r1, %[acc1] \n"
"ldmia %[c]!, { r0-r1 } \n"
"ldmia %[p]!, { r2-r5 } \n"
"mla %[acc0], r2, r0, %[acc0] \n"
"mla %[acc1], r3, r0, %[acc1] \n"
"mla %[acc0], r4, r1, %[acc0] \n"
"mla %[acc1], r5, r1, %[acc1] \n"
"ldmia %[c]!, { r0-r1 } \n"
"ldmia %[p]!, { r2-r5 } \n"
"mla %[acc0], r2, r0, %[acc0] \n"
"mla %[acc1], r3, r0, %[acc1] \n"
"mla %[acc0], r4, r1, %[acc0] \n"
"mla %[acc1], r5, r1, %[acc1] \n"
: [acc0]"+r"(t0), [acc1]"+r"(t1),
[p]"+r"(fir_ptr), [c]"+r"(fir_coeff)
:
: "r0", "r1", "r2", "r3", "r4", "r5");
*out_0 = t0;
*out_1 = t1;
}
#endif /* SPC_NOECHO */

View file

@ -0,0 +1,45 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2007-2010 Michael Sevakis (jhMikeS)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#if !SPC_NOECHO
#define SPC_DSP_ECHO_APPLY
enum
{
FIR_BUF_CNT = FIR_BUF_HALF * 2 * 2,
FIR_BUF_SIZE = FIR_BUF_CNT * sizeof ( int32_t ),
FIR_BUF_ALIGN = FIR_BUF_SIZE,
FIR_BUF_MASK = ~((FIR_BUF_ALIGN / 2) | (sizeof ( int32_t ) * 2 - 1))
};
/* Echo filter structure embedded in struct Spc_Dsp */
struct echo_filter
{
/* fir_buf [i + 8] == fir_buf [i], to avoid wrap checking in FIR code */
int32_t* ptr;
/* FIR history is interleaved with guard to eliminate wrap checking
* when convolving.
* |LL|RR|LL|RR|LL|RR|LL|RR|LL|RR|LL|RR|LL|RR|LL|RR|...
* |--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--| */
/* copy of echo FIR constants as int32_t, for faster access */
int32_t coeff [VOICE_COUNT];
};
#endif /* SPC_NOECHO */

View file

@ -0,0 +1,244 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2010 Michael Sevakis (jhMikeS)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#if !SPC_NOINTERP
#define SPC_GAUSSIAN_FAST_INTERP
static inline int gaussian_fast_interp( int16_t const* samples,
int32_t position,
int16_t const* fwd,
int16_t const* rev )
{
int output;
int t0, t1, t2, t3;
asm volatile (
/* NOTE: often-unaligned accesses */
"ldr %[t0], [%[samp]] \n" /* t0=i0i1 */
"ldr %[t2], [%[fwd]] \n" /* t2=f0f1 */
"ldr %[t1], [%[samp], #4] \n" /* t1=i2i3 */
"ldr %[t3], [%[rev]] \n" /* t3=r0r1 */
"smuad %[out], %[t0], %[t2] \n" /* out=f0*i0+f1*i1 */
"smladx %[out], %[t1], %[t3], %[out] \n" /* out+=r1*i2+r0*i3 */
: [out]"=r"(output),
[t0]"=&r"(t0), [t1]"=&r"(t1), [t2]"=&r"(t2), [t3]"=r"(t3)
: [fwd]"r"(fwd), [rev]"r"(rev),
[samp]"r"(samples + (position >> 12)));
return output;
}
#define SPC_GAUSSIAN_FAST_AMP
static inline int gaussian_fast_amp( struct voice_t* voice, int output,
int* amp_0, int* amp_1 )
{
int t0;
asm volatile (
"mov %[t0], %[out], asr #(11-5) \n" /* To do >> 16 below */
"mul %[out], %[t0], %[envx] \n"
: [out]"+r"(output), [t0]"=&r"(t0)
: [envx]"r"((int) voice->envx));
asm volatile (
"smulwb %[a0], %[out], %[v0] \n" /* amp * vol >> 16 */
"smulwb %[a1], %[out], %[v1] \n"
: [a0]"=&r"(*amp_0), [a1]"=r"(*amp_1)
: [out]"r"(output),
[v0]"r"(voice->volume [0]),
[v1]"r"(voice->volume [1]));
return output >> 5; /* 'output' still 5 bits too big */
}
#define SPC_GAUSSIAN_SLOW_INTERP
static inline int gaussian_slow_interp( int16_t const* samples,
int32_t position,
int16_t const* fwd,
int16_t const* rev )
{
int output;
int t0, t1, t2, t3;
asm volatile (
/* NOTE: often-unaligned accesses */
"ldr %[t0], [%[samp]] \n" /* t0=i0i1 */
"ldr %[t2], [%[fwd]] \n" /* t2=f0f1 */
"ldr %[t1], [%[samp], #4] \n" /* t1=i2i3 */
"ldr %[t3], [%[rev]] \n" /* t3=f2f3 */
"smulbb %[out], %[t0], %[t2] \n" /* out=f0*i0 */
"smultt %[t0], %[t0], %[t2] \n" /* t0=f1*i1 */
"smulbt %[t2], %[t1], %[t3] \n" /* t2=r1*i2 */
"smultb %[t3], %[t1], %[t3] \n" /* t3=r0*i3 */
: [out]"=r"(output),
[t0]"=&r"(t0), [t1]"=&r"(t1), [t2]"=&r"(t2), [t3]"=r"(t3)
: [fwd]"r"(fwd), [rev]"r"(rev),
[samp]"r"(samples + (position >> 12)));
asm volatile (
"mov %[out], %[out], asr #12 \n"
"add %[t0], %[out], %[t0], asr #12 \n"
"add %[t2], %[t0], %[t2], asr #12 \n"
"pkhbt %[t0], %[t2], %[t3], asl #4 \n" /* t3[31:16], t2[15:0] */
"sadd16 %[t0], %[t0], %[t0] \n" /* t3[31:16]*2, t2[15:0]*2 */
"qsubaddx %[out], %[t0], %[t0] \n" /* out[15:0]=
* sat16(t3[31:16]+t2[15:0]) */
: [out]"+r"(output),
[t0]"+r"(t0), [t2]"+r"(t2), [t3]"+r"(t3));
/* output will be sign-extended in next step */
return output;
}
#define SPC_GAUSSIAN_SLOW_AMP
static inline int gaussian_slow_amp( struct voice_t* voice, int output,
int* amp_0, int* amp_1 )
{
asm volatile (
"smulbb %[out], %[out], %[envx]"
: [out]"+r"(output)
: [envx]"r"(voice->envx));
asm volatile (
"mov %[out], %[out], asr #11 \n"
"bic %[out], %[out], #0x1 \n"
"smulbb %[amp_0], %[out], %[v0] \n"
"smulbb %[amp_1], %[out], %[v1] \n"
: [out]"+r"(output),
[amp_0]"=&r"(*amp_0), [amp_1]"=r"(*amp_1)
: [v0]"r"(voice->volume[0]), [v1]"r"(voice->volume[1]));
return output;
}
#endif /* !SPC_NOINTERP */
#if !SPC_NOECHO
#define SPC_DSP_ECHO_APPLY
/* Echo filter history */
static int32_t fir_buf[FIR_BUF_CNT] IBSS_ATTR_SPC
__attribute__(( aligned(FIR_BUF_ALIGN*1) ));
static inline void echo_init( struct Spc_Dsp* this )
{
this->fir.ptr = fir_buf;
ci->memset( fir_buf, 0, sizeof fir_buf );
}
static inline void echo_apply(struct Spc_Dsp* this,
uint8_t* const echo_ptr, int* out_0, int* out_1)
{
/* Keep last 8 samples */
int32_t* fir_ptr;
int t0;
asm volatile (
"ldr %[t0], [%[ep]] \n"
"add %[p], %[t_p], #4 \n"
"bic %[t_p], %[p], %[mask] \n"
"str %[t0], [%[p], #-4] \n"
/* duplicate at +8 eliminates wrap checking below */
"str %[t0], [%[p], #28] \n"
: [p]"=&r"(fir_ptr), [t_p]"+r"(this->fir.ptr),
[t0]"=&r"(t0)
: [ep]"r"(echo_ptr), [mask]"i"(~FIR_BUF_MASK));
int32_t* fir_coeff = (int32_t *)this->fir.coeff;
asm volatile ( /* L0R0 = acc0 */
"ldmia %[p]!, { r2-r5 } \n" /* L1R1-L4R4 = r2-r5 */
"ldmia %[c]!, { r0-r1 } \n" /* C0C1-C2C3 = r0-r1 */
"pkhbt %[acc0], %[t0], r2, asl #16 \n" /* L0R0,L1R1->L0L1,R0R1 */
"pkhtb r2, r2, %[t0], asr #16 \n"
"smuad %[acc0], %[acc0], r0 \n" /* acc0=L0*C0+L1*C1 */
"smuad %[acc1], r2, r0 \n" /* acc1=R0*C0+R1*C1 */
"pkhbt %[t0], r3, r4, asl #16 \n" /* L2R2,L3R3->L2L3,R2R3 */
"pkhtb r4, r4, r3, asr #16 \n"
"smlad %[acc0], %[t0], r1, %[acc0] \n" /* acc0+=L2*C2+L3*C3 */
"smlad %[acc1], r4, r1, %[acc1] \n" /* acc1+=R2*C2+R3*C3 */
"ldmia %[p], { r2-r4 } \n" /* L5R5-L7R7 = r2-r4 */
"ldmia %[c], { r0-r1 } \n" /* C4C5-C6C7 = r0-r1 */
"pkhbt %[t0], r5, r2, asl #16 \n" /* L4R4,L5R5->L4L5,R4R5 */
"pkhtb r2, r2, r5, asr #16 \n"
"smlad %[acc0], %[t0], r0, %[acc0] \n" /* acc0+=L4*C4+L5*C5 */
"smlad %[acc1], r2, r0, %[acc1] \n" /* acc1+=R4*C4+R5*C5 */
"pkhbt %[t0], r3, r4, asl #16 \n" /* L6R6,L7R7->L6L7,R6R7 */
"pkhtb r4, r4, r3, asr #16 \n"
"smlad %[acc0], %[t0], r1, %[acc0] \n" /* acc0+=L6*C6+L7*C7 */
"smlad %[acc1], r4, r1, %[acc1] \n" /* acc1+=R6*C6+R7*C7 */
: [t0]"+r"(t0), [acc0]"=&r"(*out_0), [acc1]"=&r"(*out_1),
[p]"+r"(fir_ptr), [c]"+r"(fir_coeff)
:
: "r0", "r1", "r2", "r3", "r4", "r5");
}
#define SPC_DSP_ECHO_FEEDBACK
static inline void echo_feedback(struct Spc_Dsp* this, uint8_t* echo_ptr,
int echo_0, int echo_1, int fb_0, int fb_1)
{
int e0, e1;
asm volatile (
"mov %[e0], %[ei0], asl #7 \n"
"mov %[e1], %[ei1], asl #7 \n"
"mla %[e0], %[fb0], %[ef], %[e0] \n"
"mla %[e1], %[fb1], %[ef], %[e1] \n"
: [e0]"=&r"(e0), [e1]"=&r"(e1)
: [ei0]"r"(echo_0), [ei1]"r"(echo_1),
[fb0]"r"(fb_0), [fb1]"r"(fb_1),
[ef]"r"((int)this->r.g.echo_feedback));
asm volatile (
"ssat %[e0], #16, %[e0], asr #14 \n"
"ssat %[e1], #16, %[e1], asr #14 \n"
"pkhbt %[e0], %[e0], %[e1], lsl #16 \n"
"str %[e0], [%[ep]] \n"
: [e0]"+r"(e0), [e1]"+r"(e1)
: [ep]"r"((int32_t *)echo_ptr));
}
#define SPC_DSP_GENERATE_OUTPUT
static inline void echo_output( struct Spc_Dsp* this, int global_muting,
int global_vol_0, int global_vol_1, int chans_0, int chans_1,
int fb_0, int fb_1, int* out_0, int* out_1 )
{
int t0, t1;
asm volatile (
"mul %[t0], %[gv0], %[ch0] \n"
"mul %[t1], %[gv1], %[ch1] \n"
: [t0]"=&r"(t0), [t1]"=r"(t1)
: [gv0]"r"(global_vol_0), [gv1]"r"(global_vol_1),
[ch0]"r"(chans_0), [ch1]"r"(chans_1));
asm volatile (
"mla %[t0], %[i0], %[ev0], %[t0] \n"
"mla %[t1], %[i1], %[ev1], %[t1] \n"
: [t0]"+r"(t0), [t1]"+r"(t1)
: [i0]"r"(fb_0), [i1]"r"(fb_1),
[ev0]"r"((int)this->r.g.echo_volume_0),
[ev1]"r"((int)this->r.g.echo_volume_1));
asm volatile (
"mov %[o0], %[t0], asr %[gm] \n"
"mov %[o1], %[t1], asr %[gm] \n"
: [o0]"=&r"(*out_0), [o1]"=r"(*out_1)
: [t0]"r"(t0), [t1]"r"(t1),
[gm]"r"(global_muting));
}
#endif /* SPC_NOECHO */

View file

@ -0,0 +1,45 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2010 Michael Sevakis (jhMikeS)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#if !SPC_NOECHO
#define SPC_DSP_ECHO_APPLY
enum
{
FIR_BUF_CNT = FIR_BUF_HALF * 2,
FIR_BUF_SIZE = FIR_BUF_CNT * sizeof ( int32_t ),
FIR_BUF_ALIGN = FIR_BUF_SIZE,
FIR_BUF_MASK = ~((FIR_BUF_ALIGN / 2) | (sizeof ( int32_t ) - 1))
};
/* Echo filter structure embedded in struct Spc_Dsp */
struct echo_filter
{ /* fir_buf [i + 8] == fir_buf [i], to avoid wrap checking in FIR code */
int32_t* ptr;
/* FIR history is interleaved with guard to eliminate wrap checking
* when convolving.
* |LR|LR|LR|LR|LR|LR|LR|LR|--|--|--|--|--|--|--|--| */
/* copy of echo FIR constants as int16_t, loaded as int32 for
* halfword, packed multiples */
int16_t coeff [VOICE_COUNT];
};
#endif /* SPC_NOECHO */

View file

@ -0,0 +1,198 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2007 Michael Sevakis (jhMikeS)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#if SPC_NOINTERP
#define SPC_LINEAR_INTERP
static inline int linear_interp( int16_t const* samples, int32_t position )
{
uint32_t f = position;
int32_t y0, y1;
/**
* output = y0 + f*y1 - f*y0
*/
asm volatile (
"move.l %[f], %[y1] \n" /* separate frac and whole */
"and.l #0xfff, %[f] \n"
"asr.l %[sh], %[y1] \n"
"move.l 2(%[s], %[y1].l*2), %[y1] \n" /* y0=upper, y1=lower */
"mac.w %[f]l, %[y1]l, %%acc0 \n" /* %acc0 = f*y1 */
"msac.w %[f]l, %[y1]u, %%acc0 \n" /* %acc0 -= f*y0 */
"swap %[y1] \n" /* separate out y0 and sign extend */
"movea.w %[y1], %[y0] \n"
"movclr.l %%acc0, %[y1] \n" /* fetch, scale down, add y0 */
"asr.l %[sh], %[y1] \n" /* output = y0 + (result >> 12) */
"add.l %[y0], %[y1] \n"
: [f]"+d"(f), [y0]"=&a"(y0), [y1]"=&d"(y1)
: [s]"a"(samples), [sh]"d"(12));
return y1;
}
#define SPC_LINEAR_AMP
static inline int linear_amp( struct voice_t* voice, int output,
int* amp_0, int* amp_1 )
{
asm volatile (
"mac.w %[out]l, %[envx]l, %%acc0"
:
: [out]"r"(output), [envx]"r"(voice->envx));
asm volatile (
"movclr.l %%acc0, %[out] \n"
"asr.l #8, %[out] \n"
"mac.l %[v0], %[out], %%acc0 \n"
"mac.l %[v1], %[out], %%acc1 \n"
"asr.l #3, %[out] \n"
: [out]"+r"(output)
: [v0]"r"((int) voice->volume [0]),
[v1]"r"((int) voice->volume [1]));
asm volatile (
"movclr.l %%acc0, %[a0] \n"
"asr.l #3, %[a0] \n"
"movclr.l %%acc1, %[a1] \n"
"asr.l #3, %[a1] \n"
: [a0]"=d"(*amp_0), [a1]"=d"(*amp_1));
return output;
}
#endif /* SPC_NOINTERP */
#if !SPC_NOECHO
#define SPC_DSP_ECHO_APPLY
/* Echo filter history */
static int32_t fir_buf[FIR_BUF_CNT] IBSS_ATTR_SPC
__attribute__(( aligned(FIR_BUF_ALIGN*1) ));
static inline void echo_init( struct Spc_Dsp* this )
{
/* Initialize mask register with the buffer address mask */
asm volatile ("move.l %0, %%mask" : : "i"(FIR_BUF_MASK));
this->fir.ptr = fir_buf;
this->fir.hist_ptr = &fir_buf [1];
ci->memset( fir_buf, 0, sizeof fir_buf );
}
static inline void echo_apply( struct Spc_Dsp* this, uint8_t* echo_ptr,
int* out_0, int* out_1 )
{
int t0, t1, t2;
t1 = swap_odd_even32( *(int32_t *)echo_ptr );
/* Keep last 8 samples */
*this->fir.ptr = t1;
this->fir.ptr = this->fir.hist_ptr;
asm volatile (
"move.l (%[c]) , %[t2] \n"
"mac.w %[t1]u, %[t2]u, <<, (%[p])+&, %[t0], %%acc0 \n"
"mac.w %[t1]l, %[t2]u, <<, (%[p])& , %[t1], %%acc1 \n"
"mac.w %[t0]u, %[t2]l, << , %%acc0 \n"
"mac.w %[t0]l, %[t2]l, <<, 4(%[c]) , %[t2], %%acc1 \n"
"mac.w %[t1]u, %[t2]u, <<, 4(%[p])& , %[t0], %%acc0 \n"
"mac.w %[t1]l, %[t2]u, <<, 8(%[p])& , %[t1], %%acc1 \n"
"mac.w %[t0]u, %[t2]l, << , %%acc0 \n"
"mac.w %[t0]l, %[t2]l, <<, 8(%[c]) , %[t2], %%acc1 \n"
"mac.w %[t1]u, %[t2]u, <<, 12(%[p])& , %[t0], %%acc0 \n"
"mac.w %[t1]l, %[t2]u, <<, 16(%[p])& , %[t1], %%acc1 \n"
"mac.w %[t0]u, %[t2]l, << , %%acc0 \n"
"mac.w %[t0]l, %[t2]l, <<, 12(%[c]) , %[t2], %%acc1 \n"
"mac.w %[t1]u, %[t2]u, <<, 20(%[p])& , %[t0], %%acc0 \n"
"mac.w %[t1]l, %[t2]u, << , %%acc1 \n"
"mac.w %[t0]u, %[t2]l, << , %%acc0 \n"
"mac.w %[t0]l, %[t2]l, << , %%acc1 \n"
: [t0]"=&r"(t0), [t1]"+r"(t1), [t2]"=&r"(t2),
[p]"+a"(this->fir.hist_ptr)
: [c]"a"(this->fir.coeff));
asm volatile (
"movclr.l %%acc0, %[o0] \n"
"movclr.l %%acc1, %[o1] \n"
"mac.l %[ev0], %[o0], >>, %%acc2 \n" /* echo volume */
"mac.l %[ev1], %[o1], >>, %%acc3 \n"
: [o0]"=&r"(*out_0), [o1]"=&r"(*out_1)
: [ev0]"r"((int) this->r.g.echo_volume_0),
[ev1]"r"((int) this->r.g.echo_volume_1));
}
#define SPC_DSP_ECHO_FEEDBACK
static inline void echo_feedback( struct Spc_Dsp* this, uint8_t* echo_ptr,
int echo_0, int echo_1, int fb_0, int fb_1 )
{
asm volatile (
/* scale echo voices; saturate if overflow */
"mac.l %[sh], %[e1] , %%acc1 \n"
"mac.l %[sh], %[e0] , %%acc0 \n"
/* add scaled output from FIR filter */
"mac.l %[fb1], %[ef], <<, %%acc1 \n"
"mac.l %[fb0], %[ef], <<, %%acc0 \n"
:
: [e0]"d"(echo_0), [e1]"d"(echo_1),
[fb0]"r"(fb_0), [fb1]"r"(fb_1),
[ef]"r"((int)this->r.g.echo_feedback),
[sh]"r"(1 << 9));
/* swap and fetch feedback results */
int t0;
asm volatile(
"move.l #0x00ff00ff, %[t0] \n"
"movclr.l %%acc1, %[e1] \n"
"swap.w %[e1] \n"
"movclr.l %%acc0, %[e0] \n"
"move.w %[e1], %[e0] \n"
"and.l %[e0], %[t0] \n"
"eor.l %[t0], %[e0] \n"
"lsl.l #8, %[t0] \n"
"lsr.l #8, %[e0] \n"
"or.l %[e0], %[t0] \n"
: [e0]"=&d"(echo_0), [e1]"=&d"(echo_1),
[t0]"=&d"(t0));
/* save final feedback into echo buffer */
*(int32_t *)echo_ptr = t0;
}
#define SPC_DSP_GENERATE_OUTPUT
static inline void echo_output( struct Spc_Dsp* this, int global_muting,
int global_vol_0, int global_vol_1, int chans_0, int chans_1,
int fb_0, int fb_1, int* out_0, int* out_1 )
{
asm volatile (
"mac.l %[ch0], %[gv0], %%acc2 \n" /* global volume */
"mac.l %[ch1], %[gv1], %%acc3 \n"
:
: [ch0]"r"(chans_0), [gv0]"r"(global_vol_0),
[ch1]"r"(chans_1), [gv1]"r"(global_vol_1));
asm volatile (
"movclr.l %%acc2, %[a0] \n" /* fetch mixed output */
"movclr.l %%acc3, %[a1] \n"
"asr.l %[gm], %[a0] \n" /* scale by global_muting shift */
"asr.l %[gm], %[a1] \n"
: [a0]"=&d"(*out_0), [a1]"=&d"(*out_1)
: [gm]"d"(global_muting));
/* scaled echo is stored in %acc2 and %acc3 */
(void)this; (void)fb_0; (void)fb_1;
}
#endif /* !SPC_NOECHO */

View file

@ -0,0 +1,45 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2007 Michael Sevakis (jhMikeS)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#if !SPC_NOECHO
#define SPC_DSP_ECHO_APPLY
enum
{
FIR_BUF_CNT = FIR_BUF_HALF,
FIR_BUF_SIZE = FIR_BUF_CNT * sizeof ( int32_t ),
FIR_BUF_ALIGN = FIR_BUF_SIZE * 2,
FIR_BUF_MASK = ~((FIR_BUF_ALIGN / 2) | (sizeof ( int32_t ) - 1))
};
/* Echo filter structure embedded in struct Spc_Dsp */
struct echo_filter
{
/* FIR history is interleaved. Hardware handles wrapping by mask.
* |LR|LR|LR|LR|LR|LR|LR|LR| */
int32_t* ptr;
/* wrapped address just behind current position -
allows mac.w to increment and mask ptr */
int32_t* hist_ptr;
/* copy of echo FIR constants as int16_t for use with mac.w */
int16_t coeff [VOICE_COUNT];
};
#endif /* !SPC_NOECHO */