From 735208a541df024f1cd3b9624054b6ed9724ad1e Mon Sep 17 00:00:00 2001 From: Thom Johansen Date: Wed, 7 Sep 2005 00:24:27 +0000 Subject: Adapted codecs and DSP system to having MACSR saved in thread context. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7485 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/Tremor/vorbisfile.c | 19 +++++++------------ apps/codecs/codec.h | 1 + apps/codecs/liba52/parse.c | 2 +- apps/codecs/libmad/imdct_mcf5249.S | 1 - apps/codecs/libmad/layer3.c | 2 -- apps/codecs/libmad/synth.c | 7 +++++-- apps/codecs/libmusepack/mpc_decoder.c | 4 ++++ apps/codecs/libmusepack/synth_filter.c | 3 --- apps/codecs/mpa.c | 3 --- apps/dsp.c | 15 +++++++++++---- 10 files changed, 29 insertions(+), 28 deletions(-) (limited to 'apps') diff --git a/apps/codecs/Tremor/vorbisfile.c b/apps/codecs/Tremor/vorbisfile.c index 92f42a313b..70c0cdb24e 100644 --- a/apps/codecs/Tremor/vorbisfile.c +++ b/apps/codecs/Tremor/vorbisfile.c @@ -762,6 +762,12 @@ int ov_clear(OggVorbis_File *vf){ int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes, ov_callbacks callbacks){ + #if defined(CPU_COLDFIRE) && !defined(SIMULATOR) + /* this seems to be the closest we get to an init function, let's init emac + here. rounding is disabled because of MULT31_SHIFT15, which will be + inaccurate with rounding in its current incarnation */ + coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE); + #endif int ret=_ov_open1(f,vf,initial,ibytes,callbacks); if(ret)return ret; return _ov_open2(vf); @@ -1287,15 +1293,12 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){ int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){ ogg_packet op={0,0,0,0,0,0}; ogg_page og={0,0,0,0}; + int thisblock,lastblock=0; int ret=ov_pcm_seek_page(vf,pos); if(ret<0)return(ret); _make_decode_ready(vf); -#if defined(CPU_COLDFIRE) && !defined(SIMULATOR) - mcf5249_init_mac(); -#endif - /* discard leading packets we don't need for the lapping of the position we want; don't decode them */ @@ -1553,10 +1556,6 @@ long ov_read(OggVorbis_File *vf,char *buffer,int bytes_req,int *bitstream){ if(vf->ready_stateready_state==INITSET){ samples=vorbis_synthesis_pcmout(&vf->vd,&pcm); @@ -1622,10 +1621,6 @@ long ov_read_fixed(OggVorbis_File *vf,ogg_int32_t ***pcm_channels,int length, int *bitstream){ if(vf->ready_stateready_state==INITSET){ ogg_int32_t **pcm; diff --git a/apps/codecs/codec.h b/apps/codecs/codec.h index c00d2bda95..0da653cf04 100644 --- a/apps/codecs/codec.h +++ b/apps/codecs/codec.h @@ -20,6 +20,7 @@ /* Global declarations to be used in rockbox software codecs */ #include "config.h" +#include "system.h" #include diff --git a/apps/codecs/liba52/parse.c b/apps/codecs/liba52/parse.c index d5b323c701..9e7ed47d56 100644 --- a/apps/codecs/liba52/parse.c +++ b/apps/codecs/liba52/parse.c @@ -59,7 +59,7 @@ a52_state_t * a52_init (uint32_t mm_accel) int i; #if defined(CPU_COLDFIRE) && !defined(SIMULATOR) - asm volatile ("move.l #0x30, %macsr"); /* frac. mode with rounding */ + coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_ROUND | EMAC_SATURATE); #endif /* this needs to come back if we ever want two decoder instances diff --git a/apps/codecs/libmad/imdct_mcf5249.S b/apps/codecs/libmad/imdct_mcf5249.S index 62b33c3f07..1afd910fa8 100644 --- a/apps/codecs/libmad/imdct_mcf5249.S +++ b/apps/codecs/libmad/imdct_mcf5249.S @@ -32,7 +32,6 @@ III_imdct_s: * get more low bits out of the accext01 register _before_ doing the * movclrs. */ - move.l #0xb0, %macsr /* frac mode, saturation, rounding */ sub.l %a0, %a0 /* clear loop variable */ .imdctloop: /* outer loop label */ lea.l imdct_s, %a1 /* load pointer to imdct coefs in a1 */ diff --git a/apps/codecs/libmad/layer3.c b/apps/codecs/libmad/layer3.c index b5fa2be6f5..6d528ea52c 100644 --- a/apps/codecs/libmad/layer3.c +++ b/apps/codecs/libmad/layer3.c @@ -1775,8 +1775,6 @@ void imdct36(mad_fixed_t const X[18], mad_fixed_t x[36]) mad_fixed_t t[16]; /* assumes FRACBITS = 28 */ asm volatile ( - "move.l #0xb0, %%d0\n\t" /* frac. mode, saturate, round */ - "move.l %%d0, %%macsr\n\t" "move.l (4*4, %[X]), %%d0\n\t" "move.l #0x0ec835e8, %%d1\n\t" "mac.l %%d0, %%d1, (13*4, %[X]), %%d0, %%acc0\n\t" diff --git a/apps/codecs/libmad/synth.c b/apps/codecs/libmad/synth.c index bdec4258fb..4315e239e8 100644 --- a/apps/codecs/libmad/synth.c +++ b/apps/codecs/libmad/synth.c @@ -42,6 +42,11 @@ void mad_synth_init(struct mad_synth *synth) synth->pcm.samplerate = 0; synth->pcm.channels = 0; synth->pcm.length = 0; + #if defined(CPU_COLDFIRE) && !defined(SIMULATOR) + /* init the emac unit here, since this function should always be called + before using libmad */ + coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE | EMAC_ROUND); + #endif } /* @@ -582,8 +587,6 @@ void synth_full(struct mad_synth *synth, struct mad_frame const *frame, mad_fixed_t const (*Dptr)[32]; mad_fixed64hi_t hi; - asm volatile("move.l #0x20, %macsr"); /* fractional mode */ - for (ch = 0; ch < nch; ++ch) { sbsample = &frame->sbsample[ch]; filter = &synth->filter[ch]; diff --git a/apps/codecs/libmusepack/mpc_decoder.c b/apps/codecs/libmusepack/mpc_decoder.c index 0c8b8b76a7..a37dc4583c 100644 --- a/apps/codecs/libmusepack/mpc_decoder.c +++ b/apps/codecs/libmusepack/mpc_decoder.c @@ -1173,6 +1173,10 @@ void mpc_decoder_setup(mpc_decoder *d, mpc_reader *r) mpc_decoder_initialisiere_quantisierungstabellen(d, 1.0f); mpc_decoder_init_huffman_sv6(d); mpc_decoder_init_huffman_sv7(d); + + #if defined(CPU_COLDFIRE)&& !defined(SIMULATOR) + coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_ROUND | EMAC_SATURATE); + #endif } static void mpc_decoder_set_streaminfo(mpc_decoder *d, mpc_streaminfo *si) diff --git a/apps/codecs/libmusepack/synth_filter.c b/apps/codecs/libmusepack/synth_filter.c index 7644551d16..51ffcce921 100644 --- a/apps/codecs/libmusepack/synth_filter.c +++ b/apps/codecs/libmusepack/synth_filter.c @@ -335,9 +335,6 @@ static void Synthese_Filter_float_internal(MPC_SAMPLE_FORMAT * OutData,MPC_SAMPL { mpc_uint32_t n; - #if defined(CPU_COLDFIRE) && !defined(SIMULATOR) - asm volatile ("move.l #0x20, %macsr"); /* fractional emac mode */ - #endif for ( n = 0; n < 36; n++, Y += 32 ) { V -= 64; Calculate_New_V ( Y, V ); diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c index 7beecd9edb..9970d57240 100644 --- a/apps/codecs/mpa.c +++ b/apps/codecs/mpa.c @@ -114,9 +114,6 @@ enum codec_status codec_start(struct codec_api* api) ci->memset(&Synth, 0, sizeof(struct mad_synth)); ci->memset(&Timer, 0, sizeof(mad_timer_t)); -#if defined(CPU_COLDFIRE) && !defined(SIMULATOR) - mcf5249_init_mac(); -#endif mad_stream_init(&Stream); mad_frame_init(&Frame); mad_synth_init(&Synth); diff --git a/apps/dsp.c b/apps/dsp.c index 8064a881a3..23b7ea548d 100644 --- a/apps/dsp.c +++ b/apps/dsp.c @@ -43,7 +43,6 @@ #if defined(CPU_COLDFIRE) && !defined(SIMULATOR) -#define INIT() asm volatile ("move.l #0xb0, %macsr") /* frac, round, clip */ /* Multiply two S.31 fractional integers and return the sign bit and the * 31 most significant bits of the result. */ @@ -89,7 +88,6 @@ #else -#define INIT() #define FRACMUL(x, y) (long) (((((long long) (x)) * ((long long) (y))) >> 31)) #define FRACMUL_8(x, y) (long) (((((long long) (x)) * ((long long) (y))) >> 23)) #define FRACMUL_8_LOOP(x, y, s) \ @@ -492,11 +490,17 @@ long dsp_process(char* dst, char* src[], long size) long factor; int samples; + #if defined(CPU_COLDFIRE) && !defined(SIMULATOR) + /* set emac unit for dsp processing, and save old macsr, we're running in + codec thread context at this point, so can't clobber it */ + unsigned long old_macsr = coldfire_get_macsr(); + coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_ROUND | EMAC_SATURATE); + #endif + dsp = &dsp_conf[current_codec]; factor = (dsp->stereo_mode != STEREO_MONO) ? 2 : 1; size /= dsp->sample_bytes * factor; - INIT(); dsp_set_replaygain(false); while (size > 0) @@ -510,7 +514,10 @@ long dsp_process(char* dst, char* src[], long size) dst += samples * sizeof(short) * 2; yield(); } - + #if defined(CPU_COLDFIRE) && !defined(SIMULATOR) + /* set old macsr again */ + coldfire_set_macsr(old_macsr); + #endif return written * sizeof(short) * 2; } -- cgit