Codec lib directories renamed, except for demac.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19018 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Björn Stenberg 2008-11-05 13:30:58 +00:00
parent 7ec9ceeaaa
commit 45bd7e0246
63 changed files with 38 additions and 3373 deletions

View file

@ -17,8 +17,8 @@ ifdef APPEXTRA
endif
ifdef SOFTWARECODECS
CODECLIBS = -lspc -lmad -la52 -lffmpegFLAC -lTremor -lwavpack -lmusepack -lalac -lfaad -lm4a -lspeex -ldemac -lwma -lasap
OUTPUT = libspc libmad liba52 libffmpegFLAC libwma libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac libasap
CODECLIBS = -lspc -lmad -la52 -lffmpegFLAC -ltremor -lwavpack -lmusepack -lalac -lfaad -lm4a -lspeex -ldemac -lwma -lasap
OUTPUT = libspc libmad liba52 libffmpegFLAC libwma libtremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac libasap
endif
# we "borrow" the plugin LDS file
@ -41,7 +41,7 @@ DIRS = .
CODECLIB := $(BUILDDIR)/libcodec.a
CODECDEPS = $(LINKCODEC) $(CODECLIB)
.PHONY: libspc libmad liba52 libffmpegFLAC libTremor libspeex libwavpack libmusepack libalac libfaad libm4a libdemac libwma libasap
.PHONY: libspc libmad liba52 libffmpegFLAC libtremor libspeex libwavpack libmusepack libalac libfaad libm4a libdemac libwma libasap
all: $(LINKCODEC) $(ROCKS)
@ -53,7 +53,7 @@ $(OBJDIR)/spc.elf : $(BUILDDIR)/libspc.a
$(OBJDIR)/mpa.elf : $(BUILDDIR)/libmad.a
$(OBJDIR)/a52.elf : $(BUILDDIR)/liba52.a
$(OBJDIR)/flac.elf : $(BUILDDIR)/libffmpegFLAC.a
$(OBJDIR)/vorbis.elf : $(BUILDDIR)/libTremor.a
$(OBJDIR)/vorbis.elf : $(BUILDDIR)/libtremor.a
$(OBJDIR)/speex.elf : $(BUILDDIR)/libspeex.a
$(OBJDIR)/mpc.elf : $(BUILDDIR)/libmusepack.a
$(OBJDIR)/wavpack.elf : $(BUILDDIR)/libwavpack.a
@ -139,8 +139,8 @@ $(LINKCODEC): $(LDS)
$(BUILDDIR)/libspc.a: libspc
libspc:
$(SILENT)mkdir -p $(OBJDIR)/spc
$(call PRINTS,MAKE in spc)$(MAKE) -C spc OBJDIR=$(OBJDIR)/spc OUTPUT=$(BUILDDIR)/libspc.a
$(SILENT)mkdir -p $(OBJDIR)/libspc
$(call PRINTS,MAKE in libspc)$(MAKE) -C libspc OBJDIR=$(OBJDIR)/libspc OUTPUT=$(BUILDDIR)/libspc.a
$(BUILDDIR)/libmad.a: libmad
@ -166,11 +166,11 @@ libffmpegFLAC:
$(SILENT)mkdir -p $(OBJDIR)/libffmpegFLAC
$(call PRINTS,MAKE in libffmpegFLAC)$(MAKE) -C libffmpegFLAC OBJDIR=$(OBJDIR)/libffmpegFLAC OUTPUT=$(BUILDDIR)/libffmpegFLAC.a
$(BUILDDIR)/libTremor.a: libTremor
$(BUILDDIR)/libtremor.a: libtremor
libTremor:
$(SILENT)mkdir -p $(OBJDIR)/Tremor
$(call PRINTS,MAKE in Tremor)$(MAKE) -C Tremor OBJDIR=$(OBJDIR)/Tremor OUTPUT=$(BUILDDIR)/libTremor.a
libtremor:
$(SILENT)mkdir -p $(OBJDIR)/libtremor
$(call PRINTS,MAKE in libtremor)$(MAKE) -C libtremor OBJDIR=$(OBJDIR)/libtremor OUTPUT=$(BUILDDIR)/libtremor.a
$(BUILDDIR)/libspeex.a: libspeex
@ -217,15 +217,29 @@ libdemac:
$(BUILDDIR)/libasap.a: libasap
libasap:
$(SILENT)mkdir -p $(OBJDIR)/asap
$(call PRINTS,MAKE in asap)$(MAKE) -C asap OBJDIR=$(OBJDIR)/asap OUTPUT=$(BUILDDIR)/libasap.a
$(SILENT)mkdir -p $(OBJDIR)/libasap
$(call PRINTS,MAKE in libasap)$(MAKE) -C libasap OBJDIR=$(OBJDIR)/libasap OUTPUT=$(BUILDDIR)/libasap.a
clean:
$(call PRINTS,cleaning codecs)rm -fr $(OBJDIR)/spc $(BUILDDIR)/libspc.a $(OBJDIR)/libmad $(BUILDDIR)/libmad.a $(OBJDIR)/liba52 $(BUILDDIR)/liba52.a $(OBJDIR)/libffmpegFLAC $(BUILDDIR)/libffmpegFLAC.a $(OBJDIR)/Tremor $(BUILDDIR)/libTremor.a $(OBJDIR)/libspeex $(BUILDDIR)/libSpeex.a $(OBJDIR)/libwavpack $(BUILDDIR)/libwavpack.a $(OBJDIR)/libmusepack $(BUILDDIR)/libmusepack.a $(OBJDIR)/libalac $(BUILDDIR)/libalac.a $(OBJDIR)/libfaad $(BUILDDIR)/libfaad.a $(OBJDIR)/libm4a $(BUILDDIR)/libm4a.a $(OBJDIR)/libdemac $(BUILDDIR)/libdemac.a $(OBJDIR)/libwma $(BUILDDIR)/libwma.a
$(SILENT)$(MAKE) -C spc clean OBJDIR=$(OBJDIR)/spc
$(call PRINTS,cleaning codecs)rm -fr \
$(OBJDIR)/libspc $(BUILDDIR)/libspc.a \
$(OBJDIR)/libmad $(BUILDDIR)/libmad.a \
$(OBJDIR)/liba52 $(BUILDDIR)/liba52.a \
$(OBJDIR)/libffmpegFLAC $(BUILDDIR)/libffmpegFLAC.a \
$(OBJDIR)/libtremor $(BUILDDIR)/libtremor.a \
$(OBJDIR)/libspeex $(BUILDDIR)/libSpeex.a \
$(OBJDIR)/libwavpack $(BUILDDIR)/libwavpack.a \
$(OBJDIR)/libmusepack $(BUILDDIR)/libmusepack.a \
$(OBJDIR)/libalac $(BUILDDIR)/libalac.a \
$(OBJDIR)/libfaad $(BUILDDIR)/libfaad.a \
$(OBJDIR)/libm4a $(BUILDDIR)/libm4a.a \
$(OBJDIR)/libdemac $(BUILDDIR)/libdemac.a \
$(OBJDIR)/libwma $(BUILDDIR)/libwma.a
$(OBJDIR)/libasap $(BUILDDIR)/libasap.a
$(SILENT)$(MAKE) -C libspc clean OBJDIR=$(OBJDIR)/libspc
$(SILENT)$(MAKE) -C libmad clean OBJDIR=$(OBJDIR)/libmad
$(SILENT)$(MAKE) -C liba52 clean OBJDIR=$(OBJDIR)/liba52
$(SILENT)$(MAKE) -C libffmpegFLAC clean OBJDIR=$(OBJDIR)/libffmpegFLAC
$(SILENT)$(MAKE) -C Tremor clean OBJDIR=$(OBJDIR)/Tremor
$(SILENT)$(MAKE) -C libtremor clean OBJDIR=$(OBJDIR)/libtremor
$(SILENT)$(MAKE) -C libspeex clean OBJDIR=$(OBJDIR)/libspeex
$(SILENT)$(MAKE) -C libwavpack clean OBJDIR=$(OBJDIR)/libwavpack
$(SILENT)$(MAKE) -C libmusepack clean OBJDIR=$(OBJDIR)/libmusepack
@ -234,6 +248,7 @@ clean:
$(SILENT)$(MAKE) -C libm4a clean OBJDIR=$(OBJDIR)/libm4a
$(SILENT)$(MAKE) -C demac/libdemac clean OBJDIR=$(OBJDIR)/libdemac
$(SILENT)$(MAKE) -C libwma clean OBJDIR=$(OBJDIR)/libwma
$(SILENT)$(MAKE) -C libasap clean OBJDIR=$(OBJDIR)/libasap
$(SILENT)$(MAKE) -C lib clean OBJDIR=$(OBJDIR)/lib
ifneq ($(MAKECMDGOALS),clean)

View file

@ -20,7 +20,7 @@
****************************************************************************/
#include "codeclib.h"
#include "asap/asap.h"
#include "libasap/asap.h"
CODEC_HEADER

View file

@ -30,7 +30,7 @@ include $(TOOLSDIR)/makesrc.inc
SOURCES = $(SRC)
OBJS2 := $(SRC:%.c=$(OBJDIR)/%.o)
OBJS = $(patsubst %.S, $(OBJDIR)/%.o, $(OBJS2))
DEPFILE = $(OBJDIR)/dep-Tremor
DEPFILE = $(OBJDIR)/dep-libtremor
DIRS =
all: $(OUTPUT)
@ -42,7 +42,7 @@ $(OUTPUT): $(OBJS)
include $(TOOLSDIR)/make.inc
clean:
$(call PRINTS,cleaning Tremor)rm -f $(OBJS) $(OUTPUT) $(DEPFILE)
$(call PRINTS,cleaning libtremor)rm -f $(OBJS) $(OUTPUT) $(DEPFILE)
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPFILE)

View file

@ -26,8 +26,8 @@
/* DSP Based on Brad Martin's OpenSPC DSP emulator */
/* tag reading from sexyspc by John Brawn (John_Brawn@yahoo.com) and others */
#include "codeclib.h"
#include "spc/spc_codec.h"
#include "spc/spc_profiler.h"
#include "libspc/spc_codec.h"
#include "libspc/spc_profiler.h"
CODEC_HEADER

View file

@ -1,44 +0,0 @@
# __________ __ ___.
# Open \______ \ ____ ____ | | _\_ |__ _______ ___
# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
# \/ \/ \/ \/ \/
# $Id$
#
INCLUDES=-I$(APPSDIR) -I.. -I. -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
-I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(BUILDDIR)
ifdef APPEXTRA
INCLUDES += $(patsubst %,-I$(APPSDIR)/%,$(subst :, ,$(APPEXTRA)))
endif
SPCOPTS = -O -DROCKBOX
CFLAGS = $(INCLUDES) $(GCCOPTS) $(TARGET_INC) $(SPCOPTS) $(TARGET) \
$(EXTRA_DEFINES) -DMEM=${MEMORYSIZE} $(PROFILE_OPTS) -DCODEC=1
# This sets up 'SRC' based on the files mentioned in SOURCES
include $(TOOLSDIR)/makesrc.inc
SOURCES = $(SRC)
OBJS2 := $(SRC:%.c=$(OBJDIR)/%.o)
OBJS = $(patsubst %.S, $(OBJDIR)/%.o, $(OBJS2))
DEPFILE = $(OBJDIR)/dep-spc
DIRS =
all: $(OUTPUT)
$(OUTPUT): $(OBJS)
$(call PRINTS,AR+RANLIB $(@F))$(AR) ruv $@ $+ >/dev/null 2>&1
$(SILENT)$(RANLIB) $@
include $(TOOLSDIR)/make.inc
clean:
$(call PRINTS,cleaning spc)rm -f $(OBJS) $(OUTPUT) $(DEPFILE)
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPFILE)
endif

View file

@ -1,4 +0,0 @@
spc_cpu.c
spc_dsp.c
spc_emu.c
spc_profiler.c

View file

@ -1,454 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2007-2008 Michael Sevakis (jhMikeS)
* Copyright (C) 2006-2007 Adam Gashlin (hcs)
* Copyright (C) 2004-2007 Shay Green (blargg)
* Copyright (C) 2002 Brad Martin
*
* 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.
*
****************************************************************************/
/* lovingly ripped off from Game_Music_Emu 0.5.2. http://www.slack.net/~ant/ */
/* DSP Based on Brad Martin's OpenSPC DSP emulator */
/* tag reading from sexyspc by John Brawn (John_Brawn@yahoo.com) and others */
#ifndef _SPC_CODEC_H_
#define _SPC_CODEC_H_
/* rather than comment out asserts, just define NDEBUG */
#define NDEBUG
#include <assert.h>
/** Basic configuration options **/
#define SPC_DUAL_CORE 1
#if !defined(SPC_DUAL_CORE) || NUM_CORES == 1
#undef SPC_DUAL_CORE
#define SPC_DUAL_CORE 0
#endif
/* TGB is the only target fast enough for gaussian and realtime BRR decode */
/* echo is almost fast enough but not quite */
#if defined(TOSHIBA_GIGABEAT_F) || defined(TOSHIBA_GIGABEAT_S) ||\
defined(SIMULATOR)
/* Don't cache BRR waves */
#define SPC_BRRCACHE 0
/* Allow gaussian interpolation */
#define SPC_NOINTERP 0
/* Allow echo processing */
#define SPC_NOECHO 0
#elif defined(CPU_COLDFIRE)
/* Cache BRR waves */
#define SPC_BRRCACHE 1
/* Disable gaussian interpolation */
#define SPC_NOINTERP 1
/* Allow echo processing */
#define SPC_NOECHO 0
#elif defined (CPU_PP) && SPC_DUAL_CORE
/* Cache BRR waves */
#define SPC_BRRCACHE 1
/* Disable gaussian interpolation */
#define SPC_NOINTERP 1
/* Allow echo processing */
#define SPC_NOECHO 0
#else
/* Cache BRR waves */
#define SPC_BRRCACHE 1
/* Disable gaussian interpolation */
#define SPC_NOINTERP 1
/* Disable echo processing */
#define SPC_NOECHO 1
#endif
#ifdef CPU_ARM
#if CONFIG_CPU != PP5002
#undef ICODE_ATTR
#define ICODE_ATTR
#undef IDATA_ATTR
#define IDATA_ATTR
#undef ICONST_ATTR
#define ICONST_ATTR
#undef IBSS_ATTR
#define IBSS_ATTR
#endif
#if SPC_DUAL_CORE
#undef SHAREDBSS_ATTR
#define SHAREDBSS_ATTR __attribute__ ((section(".ibss")))
#undef SHAREDDATA_ATTR
#define SHAREDDATA_ATTR __attribute__((section(".idata")))
#endif
#endif
/* Samples per channel per iteration */
#if defined(CPU_PP) && NUM_CORES == 1
#define WAV_CHUNK_SIZE 2048
#else
#define WAV_CHUNK_SIZE 1024
#endif
/**************** Little-endian handling ****************/
static inline unsigned get_le16( void const* p )
{
return ((unsigned char const*) p) [1] * 0x100u +
((unsigned char const*) p) [0];
}
static inline int get_le16s( void const* p )
{
return ((signed char const*) p) [1] * 0x100 +
((unsigned char const*) p) [0];
}
static inline void set_le16( void* p, unsigned n )
{
((unsigned char*) p) [1] = (unsigned char) (n >> 8);
((unsigned char*) p) [0] = (unsigned char) n;
}
#define GET_LE16( addr ) get_le16( addr )
#define SET_LE16( addr, data ) set_le16( addr, data )
#define INT16A( addr ) (*(uint16_t*) (addr))
#define INT16SA( addr ) (*(int16_t*) (addr))
#ifdef ROCKBOX_LITTLE_ENDIAN
#define GET_LE16A( addr ) (*(uint16_t*) (addr))
#define GET_LE16SA( addr ) (*( int16_t*) (addr))
#define SET_LE16A( addr, data ) (void) (*(uint16_t*) (addr) = (data))
#else
#define GET_LE16A( addr ) get_le16 ( addr )
#define GET_LE16SA( addr ) get_le16s( addr )
#define SET_LE16A( addr, data ) set_le16 ( addr, data )
#endif
struct Spc_Emu;
#define THIS struct Spc_Emu* const this
/* The CPU portion (shock!) */
struct cpu_regs_t
{
long pc; /* more than 16 bits to allow overflow detection */
uint8_t a;
uint8_t x;
uint8_t y;
uint8_t status;
uint8_t sp;
};
struct cpu_ram_t
{
union {
uint8_t padding1 [0x100];
uint16_t align;
} padding1 [1];
uint8_t ram [0x10000];
uint8_t padding2 [0x100];
};
#undef RAM
#define RAM ram.ram
extern struct cpu_ram_t ram;
long CPU_run( THIS, long start_time ) ICODE_ATTR;
void CPU_Init( THIS );
/* The DSP portion (awe!) */
enum { VOICE_COUNT = 8 };
enum { REGISTER_COUNT = 128 };
struct raw_voice_t
{
int8_t volume [2];
uint8_t rate [2];
uint8_t waveform;
uint8_t adsr [2]; /* envelope rates for attack, decay, and sustain */
uint8_t gain; /* envelope gain (if not using ADSR) */
int8_t envx; /* current envelope level */
int8_t outx; /* current sample */
int8_t unused [6];
};
struct globals_t
{
int8_t unused1 [12];
int8_t volume_0; /* 0C Main Volume Left (-.7) */
int8_t echo_feedback; /* 0D Echo Feedback (-.7) */
int8_t unused2 [14];
int8_t volume_1; /* 1C Main Volume Right (-.7) */
int8_t unused3 [15];
int8_t echo_volume_0; /* 2C Echo Volume Left (-.7) */
uint8_t pitch_mods; /* 2D Pitch Modulation on/off for each voice */
int8_t unused4 [14];
int8_t echo_volume_1; /* 3C Echo Volume Right (-.7) */
uint8_t noise_enables; /* 3D Noise output on/off for each voice */
int8_t unused5 [14];
uint8_t key_ons; /* 4C Key On for each voice */
uint8_t echo_ons; /* 4D Echo on/off for each voice */
int8_t unused6 [14];
uint8_t key_offs; /* 5C key off for each voice
(instantiates release mode) */
uint8_t wave_page; /* 5D source directory (wave table offsets) */
int8_t unused7 [14];
uint8_t flags; /* 6C flags and noise freq */
uint8_t echo_page; /* 6D */
int8_t unused8 [14];
uint8_t wave_ended; /* 7C */
uint8_t echo_delay; /* 7D ms >> 4 */
char unused9 [2];
};
enum state_t
{ /* -1, 0, +1 allows more efficient if statements */
state_decay = -1,
state_sustain = 0,
state_attack = +1,
state_release = 2
};
struct cache_entry_t
{
int16_t const* samples;
unsigned end; /* past-the-end position */
unsigned loop; /* number of samples in loop */
unsigned start_addr;
};
enum { BRR_BLOCK_SIZE = 16 };
enum { BRR_CACHE_SIZE = 0x20000 + 32} ;
struct voice_t
{
#if SPC_BRRCACHE
int16_t const* samples;
long wave_end;
int wave_loop;
#else
int16_t samples [3 + BRR_BLOCK_SIZE + 1];
int block_header; /* header byte from current block */
#endif
uint8_t const* addr;
short volume [2];
long position;/* position in samples buffer, with 12-bit fraction */
short envx;
short env_mode;
short env_timer;
short key_on_delay;
};
#if SPC_BRRCACHE
/* a little extra for samples that go past end */
extern int16_t BRRcache [BRR_CACHE_SIZE];
#endif
enum { FIR_BUF_HALF = 8 };
#if defined(CPU_COLDFIRE)
/* global because of the large aligment requirement for hardware masking -
* L-R interleaved 16-bit samples for easy loading and mac.w use.
*/
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))
};
#elif defined (CPU_ARM)
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))
};
#endif /* CPU_* */
struct Spc_Dsp
{
union
{
struct raw_voice_t voice [VOICE_COUNT];
uint8_t reg [REGISTER_COUNT];
struct globals_t g;
int16_t align;
} r;
unsigned echo_pos;
int keys_down;
int noise_count;
uint16_t noise; /* also read as int16_t */
#if defined(CPU_COLDFIRE)
/* circularly hardware masked address */
int32_t *fir_ptr;
/* wrapped address just behind current position -
allows mac.w to increment and mask fir_ptr */
int32_t *last_fir_ptr;
/* copy of echo FIR constants as int16_t for use with mac.w */
int16_t fir_coeff [VOICE_COUNT];
#elif defined (CPU_ARM)
/* fir_buf [i + 8] == fir_buf [i], to avoid wrap checking in FIR code */
int32_t *fir_ptr;
/* copy of echo FIR constants as int32_t, for faster access */
int32_t fir_coeff [VOICE_COUNT];
#else
/* fir_buf [i + 8] == fir_buf [i], to avoid wrap checking in FIR code */
int fir_pos; /* (0 to 7) */
int fir_buf [FIR_BUF_HALF * 2] [2];
/* copy of echo FIR constants as int, for faster access */
int fir_coeff [VOICE_COUNT];
#endif
struct voice_t voice_state [VOICE_COUNT];
#if SPC_BRRCACHE
uint8_t oldsize;
struct cache_entry_t wave_entry [256];
struct cache_entry_t wave_entry_old [256];
#endif
};
struct src_dir
{
char start [2];
char loop [2];
};
void DSP_run_( struct Spc_Dsp* this, long count, int32_t* out_buf ) ICODE_ATTR;
void DSP_reset( struct Spc_Dsp* this );
static inline void DSP_run( struct Spc_Dsp* this, long count, int32_t* out )
{
/* Should we just fill the buffer with silence? Flags won't be cleared */
/* during this run so it seems it should keep resetting every sample. */
if ( this->r.g.flags & 0x80 )
DSP_reset( this );
DSP_run_( this, count, out );
}
/**************** SPC emulator ****************/
/* 1.024 MHz clock / 32000 samples per second */
enum { CLOCKS_PER_SAMPLE = 32 };
enum { EXTRA_CLOCKS = CLOCKS_PER_SAMPLE / 2 };
/* using this disables timer (since this will always be in the future) */
enum { TIMER_DISABLED_TIME = 127 };
enum { ROM_SIZE = 64 };
enum { ROM_ADDR = 0xFFC0 };
enum { TIMER_COUNT = 3 };
struct Timer
{
long next_tick;
int period;
int count;
int shift;
int enabled;
int counter;
};
void Timer_run_( struct Timer* t, long time ) ICODE_ATTR;
static inline void Timer_run( struct Timer* t, long time )
{
if ( time >= t->next_tick )
Timer_run_( t, time );
}
struct Spc_Emu
{
uint8_t cycle_table [0x100];
struct cpu_regs_t r;
int32_t* sample_buf;
long next_dsp;
int rom_enabled;
int extra_cycles;
struct Timer timer [TIMER_COUNT];
/* large objects at end */
struct Spc_Dsp dsp;
uint8_t extra_ram [ROM_SIZE];
uint8_t boot_rom [ROM_SIZE];
};
enum { SPC_FILE_SIZE = 0x10180 };
struct spc_file_t
{
char signature [27];
char unused [10];
uint8_t pc [2];
uint8_t a;
uint8_t x;
uint8_t y;
uint8_t status;
uint8_t sp;
char unused2 [212];
uint8_t ram [0x10000];
uint8_t dsp [128];
uint8_t ipl_rom [128];
};
void SPC_Init( THIS );
int SPC_load_spc( THIS, const void* data, long size );
/**************** DSP interaction ****************/
void DSP_write( struct Spc_Dsp* this, int i, int data ) ICODE_ATTR;
static inline int DSP_read( struct Spc_Dsp* this, int i )
{
assert( (unsigned) i < REGISTER_COUNT );
return this->r.reg [i];
}
void SPC_run_dsp_( THIS, long time ) ICODE_ATTR;
static inline void SPC_run_dsp( THIS, long time )
{
if ( time >= this->next_dsp )
SPC_run_dsp_( this, time );
}
int SPC_read( THIS, unsigned addr, long const time ) ICODE_ATTR;
void SPC_write( THIS, unsigned addr, int data, long const time ) ICODE_ATTR;
/**************** Sample generation ****************/
int SPC_play( THIS, long count, int32_t* out ) ICODE_ATTR;
#endif /* _SPC_CODEC_H_ */

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,384 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2006-2007 Adam Gashlin (hcs)
* Copyright (C) 2004-2007 Shay Green (blargg)
* Copyright (C) 2002 Brad Martin
*
* 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.
*
****************************************************************************/
#include "codec.h"
#include "codecs.h"
#include "spc_codec.h"
#include "spc_profiler.h"
/* lovingly ripped off from Game_Music_Emu 0.5.2. http://www.slack.net/~ant/ */
/* DSP Based on Brad Martin's OpenSPC DSP emulator */
/* tag reading from sexyspc by John Brawn (John_Brawn@yahoo.com) and others */
struct cpu_ram_t ram CACHEALIGN_ATTR;
/**************** Timers ****************/
void Timer_run_( struct Timer* t, long time )
{
/* when disabled, next_tick should always be in the future */
assert( t->enabled );
int elapsed = ((time - t->next_tick) >> t->shift) + 1;
t->next_tick += elapsed << t->shift;
elapsed += t->count;
if ( elapsed >= t->period ) /* avoid unnecessary division */
{
int n = elapsed / t->period;
elapsed -= n * t->period;
t->counter = (t->counter + n) & 15;
}
t->count = elapsed;
}
/**************** SPC emulator ****************/
/* 1.024 MHz clock / 32000 samples per second */
static void SPC_enable_rom( THIS, int enable )
{
if ( this->rom_enabled != enable )
{
this->rom_enabled = enable;
ci->memcpy( RAM + ROM_ADDR, (enable ? this->boot_rom : this->extra_ram), ROM_SIZE );
/* TODO: ROM can still get overwritten when DSP writes to echo buffer */
}
}
void SPC_Init( THIS )
{
this->timer [0].shift = 4 + 3; /* 8 kHz */
this->timer [1].shift = 4 + 3; /* 8 kHz */
this->timer [2].shift = 4; /* 8 kHz */
/* Put STOP instruction around memory to catch PC underflow/overflow. */
ci->memset( ram.padding1, 0xFF, sizeof ram.padding1 );
ci->memset( ram.padding2, 0xFF, sizeof ram.padding2 );
/* A few tracks read from the last four bytes of IPL ROM */
this->boot_rom [sizeof this->boot_rom - 2] = 0xC0;
this->boot_rom [sizeof this->boot_rom - 1] = 0xFF;
ci->memset( this->boot_rom, 0, sizeof this->boot_rom - 2 );
/* Have DSP in a defined state in case EMU is run and hasn't loaded
* a program yet */
DSP_reset(&this->dsp);
}
static void SPC_load_state( THIS, struct cpu_regs_t const* cpu_state,
const void* new_ram, const void* dsp_state )
{
ci->memcpy(&(this->r),cpu_state,sizeof this->r);
/* ram */
ci->memcpy( RAM, new_ram, sizeof RAM );
ci->memcpy( this->extra_ram, RAM + ROM_ADDR, sizeof this->extra_ram );
/* boot rom (have to force enable_rom() to update it) */
this->rom_enabled = !(RAM [0xF1] & 0x80);
SPC_enable_rom( this, !this->rom_enabled );
/* dsp */
/* some SPCs rely on DSP immediately generating one sample */
this->extra_cycles = 32;
DSP_reset( &this->dsp );
int i;
for ( i = 0; i < REGISTER_COUNT; i++ )
DSP_write( &this->dsp, i, ((uint8_t const*) dsp_state) [i] );
/* timers */
for ( i = 0; i < TIMER_COUNT; i++ )
{
struct Timer* t = &this->timer [i];
t->next_tick = -EXTRA_CLOCKS;
t->enabled = (RAM [0xF1] >> i) & 1;
if ( !t->enabled )
t->next_tick = TIMER_DISABLED_TIME;
t->count = 0;
t->counter = RAM [0xFD + i] & 15;
int p = RAM [0xFA + i];
if ( !p )
p = 0x100;
t->period = p;
}
/* Handle registers which already give 0 when read by
setting RAM and not changing it.
Put STOP instruction in registers which can be read,
to catch attempted execution. */
RAM [0xF0] = 0;
RAM [0xF1] = 0;
RAM [0xF3] = 0xFF;
RAM [0xFA] = 0;
RAM [0xFB] = 0;
RAM [0xFC] = 0;
RAM [0xFD] = 0xFF;
RAM [0xFE] = 0xFF;
RAM [0xFF] = 0xFF;
}
static void clear_echo( THIS )
{
if ( !(DSP_read( &this->dsp, 0x6C ) & 0x20) )
{
unsigned addr = 0x100 * DSP_read( &this->dsp, 0x6D );
size_t size = 0x800 * DSP_read( &this->dsp, 0x7D );
size_t max_size = sizeof RAM - addr;
if ( size > max_size )
size = sizeof RAM - addr;
ci->memset( RAM + addr, 0xFF, size );
}
}
int SPC_load_spc( THIS, const void* data, long size )
{
struct spc_file_t const* spc = (struct spc_file_t const*) data;
struct cpu_regs_t regs;
if ( size < SPC_FILE_SIZE )
return -1;
if ( ci->memcmp( spc->signature, "SNES-SPC700 Sound File Data", 27 ) != 0 )
return -1;
regs.pc = spc->pc [1] * 0x100 + spc->pc [0];
regs.a = spc->a;
regs.x = spc->x;
regs.y = spc->y;
regs.status = spc->status;
regs.sp = spc->sp;
if ( (unsigned long) size >= sizeof *spc )
ci->memcpy( this->boot_rom, spc->ipl_rom, sizeof this->boot_rom );
SPC_load_state( this, &regs, spc->ram, spc->dsp );
clear_echo(this);
return 0;
}
/**************** DSP interaction ****************/
void SPC_run_dsp_( THIS, long time )
{
/* divide by CLOCKS_PER_SAMPLE */
int count = ((time - this->next_dsp) >> 5) + 1;
int32_t* buf = this->sample_buf;
this->sample_buf = buf + count;
this->next_dsp += count * CLOCKS_PER_SAMPLE;
DSP_run( &this->dsp, count, buf );
}
int SPC_read( THIS, unsigned addr, long const time )
{
int result = RAM [addr];
if ( ((unsigned) (addr - 0xF0)) < 0x10 )
{
assert( 0xF0 <= addr && addr <= 0xFF );
/* counters */
int i = addr - 0xFD;
if ( i >= 0 )
{
struct Timer* t = &this->timer [i];
Timer_run( t, time );
result = t->counter;
t->counter = 0;
}
/* dsp */
else if ( addr == 0xF3 )
{
SPC_run_dsp( this, time );
result = DSP_read( &this->dsp, RAM [0xF2] & 0x7F );
}
}
return result;
}
void SPC_write( THIS, unsigned addr, int data, long const time )
{
/* first page is very common */
if ( addr < 0xF0 )
{
RAM [addr] = (uint8_t) data;
}
else switch ( addr )
{
/* RAM */
default:
if ( addr < ROM_ADDR )
{
RAM [addr] = (uint8_t) data;
}
else
{
this->extra_ram [addr - ROM_ADDR] = (uint8_t) data;
if ( !this->rom_enabled )
RAM [addr] = (uint8_t) data;
}
break;
/* DSP */
/*case 0xF2:*/ /* mapped to RAM */
case 0xF3: {
SPC_run_dsp( this, time );
int reg = RAM [0xF2];
if ( reg < REGISTER_COUNT ) {
DSP_write( &this->dsp, reg, data );
}
else {
/*dprintf( "DSP write to $%02X\n", (int) reg ); */
}
break;
}
case 0xF0: /* Test register */
/*dprintf( "Wrote $%02X to $F0\n", (int) data ); */
break;
/* Config */
case 0xF1:
{
int i;
/* timers */
for ( i = 0; i < TIMER_COUNT; i++ )
{
struct Timer * t = this->timer+i;
if ( !(data & (1 << i)) )
{
t->enabled = 0;
t->next_tick = TIMER_DISABLED_TIME;
}
else if ( !t->enabled )
{
/* just enabled */
t->enabled = 1;
t->counter = 0;
t->count = 0;
t->next_tick = time;
}
}
/* port clears */
if ( data & 0x10 )
{
RAM [0xF4] = 0;
RAM [0xF5] = 0;
}
if ( data & 0x20 )
{
RAM [0xF6] = 0;
RAM [0xF7] = 0;
}
SPC_enable_rom( this, (data & 0x80) != 0 );
break;
}
/* Ports */
case 0xF4:
case 0xF5:
case 0xF6:
case 0xF7:
/* to do: handle output ports */
break;
/* verified on SNES that these are read/write (RAM) */
/*case 0xF8: */
/*case 0xF9: */
/* Timers */
case 0xFA:
case 0xFB:
case 0xFC: {
int i = addr - 0xFA;
struct Timer* t = &this->timer [i];
if ( (t->period & 0xFF) != data )
{
Timer_run( t, time );
this->timer[i].period = data ? data : 0x100;
}
break;
}
/* Counters (cleared on write) */
case 0xFD:
case 0xFE:
case 0xFF:
/*dprintf( "Wrote to counter $%02X\n", (int) addr ); */
this->timer [addr - 0xFD].counter = 0;
break;
}
}
/**************** Sample generation ****************/
int SPC_play( THIS, long count, int32_t* out )
{
int i;
assert( count % 2 == 0 ); /* output is always in pairs of samples */
long start_time = -(count >> 1) * CLOCKS_PER_SAMPLE - EXTRA_CLOCKS;
/* DSP output is made on-the-fly when DSP registers are read or written */
this->sample_buf = out;
this->next_dsp = start_time + CLOCKS_PER_SAMPLE;
/* Localize timer next_tick times and run them to the present to prevent
a running but ignored timer's next_tick from getting too far behind
and overflowing. */
for ( i = 0; i < TIMER_COUNT; i++ )
{
struct Timer* t = &this->timer [i];
if ( t->enabled )
{
t->next_tick += start_time + EXTRA_CLOCKS;
Timer_run( t, start_time );
}
}
/* Run from start_time to 0, pre-advancing by extra cycles from last run */
this->extra_cycles = CPU_run( this, start_time + this->extra_cycles ) +
EXTRA_CLOCKS;
if ( this->extra_cycles < 0 )
{
/*dprintf( "Unhandled instruction $%02X, pc = $%04X\n",
(int) CPU_read( r.pc ), (unsigned) r.pc ); */
return -1;
}
/* Catch DSP up to present */
#if 0
ENTER_TIMER(cpu);
#endif
SPC_run_dsp( this, -EXTRA_CLOCKS );
#if 0
EXIT_TIMER(cpu);
#endif
assert( this->next_dsp == CLOCKS_PER_SAMPLE - EXTRA_CLOCKS );
assert( this->sample_buf - out == count );
return 0;
}

View file

@ -1,66 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2006-2007 Adam Gashlin (hcs)
*
* 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.
*
****************************************************************************/
/* lovingly ripped off from Game_Music_Emu 0.5.2. http://www.slack.net/~ant/ */
/* DSP Based on Brad Martin's OpenSPC DSP emulator */
/* tag reading from sexyspc by John Brawn (John_Brawn@yahoo.com) and others */
#if defined(SPC_PROFILE) && defined(USEC_TIMER)
#include "codec.h"
#include "spc_codec.h"
#define SPC_DEFINE_PROFILER_TIMERS
#include "spc_profiler.h"
void reset_profile_timers(void)
{
RESET_TIMER(total);
RESET_TIMER(render);
#if 0
RESET_TIMER(cpu);
RESET_TIMER(dsp);
RESET_TIMER(dsp_pregen);
RESET_TIMER(dsp_gen);
RESET_TIMER(dsp_mix);
#endif
}
void print_timers(char * path)
{
int logfd = ci->open("/spclog.txt",O_WRONLY|O_CREAT|O_APPEND);
ci->fdprintf(logfd,"%s:\t",path);
ci->fdprintf(logfd,"%10ld total\t",READ_TIMER(total));
PRINT_TIMER_PCT(render,total,"render");
#if 0
PRINT_TIMER_PCT(cpu,total,"CPU");
PRINT_TIMER_PCT(dsp,total,"DSP");
ci->fdprintf(logfd,"(");
PRINT_TIMER_PCT(dsp_pregen,dsp,"pregen");
PRINT_TIMER_PCT(dsp_gen,dsp,"gen");
PRINT_TIMER_PCT(dsp_mix,dsp,"mix");
#endif
ci->fdprintf(logfd,"\n");
ci->close(logfd);
logfd=-1;
}
#endif /* #if defined(SPC_PROFILE) && defined(USEC_TIMER) */

View file

@ -1,72 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2006-2007 Adam Gashlin (hcs)
*
* 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.
*
****************************************************************************/
/* a fun simple elapsed time profiler */
#ifndef _SPC_PROFILER_H_
#define _SPC_PROFILER_H_
#if defined(SPC_PROFILE) && defined(USEC_TIMER)
#ifdef SPC_DEFINE_PROFILER_TIMERS
#define CREATE_TIMER(name) uint32_t spc_timer_##name##_start,\
spc_timer_##name##_total
#else
#define CREATE_TIMER(name) extern uint32_t spc_timer_##name##_start,\
spc_timer_##name##_total
#endif
#define ENTER_TIMER(name) spc_timer_##name##_start=USEC_TIMER
#define EXIT_TIMER(name) spc_timer_##name##_total+=\
(USEC_TIMER-spc_timer_##name##_start)
#define READ_TIMER(name) (spc_timer_##name##_total)
#define RESET_TIMER(name) spc_timer_##name##_total=0
#define PRINT_TIMER_PCT(bname,tname,nstr) ci->fdprintf( \
logfd,"%10ld ",READ_TIMER(bname));\
ci->fdprintf(logfd,"(%3d%%) " nstr "\t",\
((uint64_t)READ_TIMER(bname))*100/READ_TIMER(tname))
CREATE_TIMER(total);
CREATE_TIMER(render);
#if 0
CREATE_TIMER(cpu);
CREATE_TIMER(dsp);
CREATE_TIMER(dsp_pregen);
CREATE_TIMER(dsp_gen);
CREATE_TIMER(dsp_mix);
#endif
void reset_profile_timers(void);
void print_timers(char * path);
#else
#define CREATE_TIMER(name)
#define ENTER_TIMER(name)
#define EXIT_TIMER(name)
#define READ_TIMER(name)
#define RESET_TIMER(name)
#define print_timers(path)
#define reset_profile_timers()
#endif
#endif /* _SPC_PROFILER_H_ */

View file

@ -20,8 +20,8 @@
****************************************************************************/
#include "codeclib.h"
#include "Tremor/ivorbisfile.h"
#include "Tremor/ogg.h"
#include "libtremor/ivorbisfile.h"
#include "libtremor/ogg.h"
CODEC_HEADER

View file

@ -18,7 +18,7 @@ ifdef APPEXTRA
endif
ifdef SOFTWARECODECS
CODECLIBS = -lmad -la52 -lffmpegFLAC -lTremor -lwavpack -lmusepack
CODECLIBS = -lmad -la52 -lffmpegFLAC -ltremor -lwavpack -lmusepack
endif
# Set up the bitmap libraries