mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-12-14 22:31:57 +00:00
040cb17370
# Conflicts: # CMakeLists.txt # libraries/glslang/OGLCompilersDLL/CMakeLists.txt # libraries/glslang/OGLCompilersDLL/InitializeDll.cpp # libraries/glslang/OGLCompilersDLL/InitializeDll.h # libraries/glslang/glslang/CMakeLists.txt # libraries/glslang/glslang/GenericCodeGen/CodeGen.cpp # libraries/glslang/glslang/GenericCodeGen/Link.cpp # libraries/glslang/glslang/Include/BaseTypes.h # libraries/glslang/glslang/Include/Common.h # libraries/glslang/glslang/Include/ConstantUnion.h # libraries/glslang/glslang/Include/InfoSink.h # libraries/glslang/glslang/Include/InitializeGlobals.h # libraries/glslang/glslang/Include/PoolAlloc.h # libraries/glslang/glslang/Include/ResourceLimits.h # libraries/glslang/glslang/Include/ShHandle.h # libraries/glslang/glslang/Include/Types.h # libraries/glslang/glslang/Include/arrays.h # libraries/glslang/glslang/Include/intermediate.h # libraries/glslang/glslang/Include/revision.h # libraries/glslang/glslang/Include/revision.template # libraries/glslang/glslang/MachineIndependent/Constant.cpp # libraries/glslang/glslang/MachineIndependent/InfoSink.cpp # libraries/glslang/glslang/MachineIndependent/Initialize.cpp # libraries/glslang/glslang/MachineIndependent/Initialize.h # libraries/glslang/glslang/MachineIndependent/IntermTraverse.cpp # libraries/glslang/glslang/MachineIndependent/Intermediate.cpp # libraries/glslang/glslang/MachineIndependent/LiveTraverser.h # libraries/glslang/glslang/MachineIndependent/ParseContextBase.cpp # libraries/glslang/glslang/MachineIndependent/ParseHelper.cpp # libraries/glslang/glslang/MachineIndependent/ParseHelper.h # libraries/glslang/glslang/MachineIndependent/PoolAlloc.cpp # libraries/glslang/glslang/MachineIndependent/RemoveTree.cpp # libraries/glslang/glslang/MachineIndependent/RemoveTree.h # libraries/glslang/glslang/MachineIndependent/Scan.cpp # libraries/glslang/glslang/MachineIndependent/Scan.h # libraries/glslang/glslang/MachineIndependent/ScanContext.h # libraries/glslang/glslang/MachineIndependent/ShaderLang.cpp # libraries/glslang/glslang/MachineIndependent/SymbolTable.cpp # libraries/glslang/glslang/MachineIndependent/SymbolTable.h # libraries/glslang/glslang/MachineIndependent/Versions.cpp # libraries/glslang/glslang/MachineIndependent/Versions.h # libraries/glslang/glslang/MachineIndependent/attribute.cpp # libraries/glslang/glslang/MachineIndependent/attribute.h # libraries/glslang/glslang/MachineIndependent/gl_types.h # libraries/glslang/glslang/MachineIndependent/glslang.y # libraries/glslang/glslang/MachineIndependent/glslang_tab.cpp # libraries/glslang/glslang/MachineIndependent/glslang_tab.cpp.h # libraries/glslang/glslang/MachineIndependent/intermOut.cpp # libraries/glslang/glslang/MachineIndependent/iomapper.cpp # libraries/glslang/glslang/MachineIndependent/iomapper.h # libraries/glslang/glslang/MachineIndependent/limits.cpp # libraries/glslang/glslang/MachineIndependent/linkValidate.cpp # libraries/glslang/glslang/MachineIndependent/localintermediate.h # libraries/glslang/glslang/MachineIndependent/parseConst.cpp # libraries/glslang/glslang/MachineIndependent/parseVersions.h # libraries/glslang/glslang/MachineIndependent/pch.cpp # libraries/glslang/glslang/MachineIndependent/pch.h # libraries/glslang/glslang/MachineIndependent/preprocessor/Pp.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpAtom.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpContext.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpContext.h # libraries/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpTokens.h # libraries/glslang/glslang/MachineIndependent/propagateNoContraction.cpp # libraries/glslang/glslang/MachineIndependent/propagateNoContraction.h # libraries/glslang/glslang/MachineIndependent/reflection.cpp # libraries/glslang/glslang/MachineIndependent/reflection.h # libraries/glslang/glslang/OSDependent/Unix/CMakeLists.txt # libraries/glslang/glslang/OSDependent/Unix/ossource.cpp # libraries/glslang/glslang/OSDependent/Windows/CMakeLists.txt # libraries/glslang/glslang/OSDependent/Windows/main.cpp # libraries/glslang/glslang/OSDependent/Windows/ossource.cpp # libraries/glslang/glslang/OSDependent/osinclude.h # libraries/glslang/glslang/Public/ShaderLang.h # libraries/glslang/glslang/updateGrammar # libraries/glslang/spirv/CMakeLists.txt # libraries/glslang/spirv/GLSL.ext.AMD.h # libraries/glslang/spirv/GLSL.ext.EXT.h # libraries/glslang/spirv/GLSL.ext.KHR.h # libraries/glslang/spirv/GLSL.ext.NV.h # libraries/glslang/spirv/GLSL.std.450.h # libraries/glslang/spirv/GlslangToSpv.cpp # libraries/glslang/spirv/GlslangToSpv.h # libraries/glslang/spirv/InReadableOrder.cpp # libraries/glslang/spirv/Logger.cpp # libraries/glslang/spirv/Logger.h # libraries/glslang/spirv/SPVRemapper.cpp # libraries/glslang/spirv/SPVRemapper.h # libraries/glslang/spirv/SpvBuilder.cpp # libraries/glslang/spirv/SpvBuilder.h # libraries/glslang/spirv/SpvPostProcess.cpp # libraries/glslang/spirv/SpvTools.cpp # libraries/glslang/spirv/SpvTools.h # libraries/glslang/spirv/bitutils.h # libraries/glslang/spirv/disassemble.cpp # libraries/glslang/spirv/disassemble.h # libraries/glslang/spirv/doc.cpp # libraries/glslang/spirv/doc.h # libraries/glslang/spirv/hex_float.h # libraries/glslang/spirv/spirv.hpp # libraries/glslang/spirv/spvIR.h # src/CMakeLists.txt
207 lines
5.4 KiB
C++
207 lines
5.4 KiB
C++
// Fast SNES SPC-700 DSP emulator (about 3x speed of accurate one)
|
|
|
|
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
|
#ifndef SPC_DSP_H
|
|
#define SPC_DSP_H
|
|
|
|
#include "blargg_common.h"
|
|
|
|
struct Spc_Dsp {
|
|
public:
|
|
// Setup
|
|
|
|
// Initializes DSP and has it use the 64K RAM provided
|
|
void init( void* ram_64k );
|
|
|
|
// Sets destination for output samples. If out is NULL or out_size is 0,
|
|
// doesn't generate any.
|
|
typedef short sample_t;
|
|
void set_output( sample_t* out, int out_size );
|
|
|
|
// Number of samples written to output since it was last set, always
|
|
// a multiple of 2. Undefined if more samples were generated than
|
|
// output buffer could hold.
|
|
int sample_count() const;
|
|
|
|
// Emulation
|
|
|
|
// Resets DSP to power-on state
|
|
void reset();
|
|
|
|
// Emulates pressing reset switch on SNES
|
|
void soft_reset();
|
|
|
|
// Reads/writes DSP registers. For accuracy, you must first call spc_run_dsp()
|
|
// to catch the DSP up to present.
|
|
int read ( int addr ) const;
|
|
void write( int addr, int data );
|
|
|
|
// Runs DSP for specified number of clocks (~1024000 per second). Every 32 clocks
|
|
// a pair of samples is be generated.
|
|
void run( int clock_count );
|
|
|
|
// Sound control
|
|
|
|
// Mutes voices corresponding to non-zero bits in mask (overrides VxVOL with 0).
|
|
// Reduces emulation accuracy.
|
|
enum { voice_count = 8 };
|
|
void mute_voices( int mask );
|
|
|
|
// If true, prevents channels and global volumes from being phase-negated
|
|
void disable_surround( bool disable = true );
|
|
|
|
// State
|
|
|
|
// Resets DSP and uses supplied values to initialize registers
|
|
enum { register_count = 128 };
|
|
void load( uint8_t const regs [register_count] );
|
|
|
|
// DSP register addresses
|
|
|
|
// Global registers
|
|
enum {
|
|
r_mvoll = 0x0C, r_mvolr = 0x1C,
|
|
r_evoll = 0x2C, r_evolr = 0x3C,
|
|
r_kon = 0x4C, r_koff = 0x5C,
|
|
r_flg = 0x6C, r_endx = 0x7C,
|
|
r_efb = 0x0D, r_pmon = 0x2D,
|
|
r_non = 0x3D, r_eon = 0x4D,
|
|
r_dir = 0x5D, r_esa = 0x6D,
|
|
r_edl = 0x7D,
|
|
r_fir = 0x0F // 8 coefficients at 0x0F, 0x1F ... 0x7F
|
|
};
|
|
|
|
// Voice registers
|
|
enum {
|
|
v_voll = 0x00, v_volr = 0x01,
|
|
v_pitchl = 0x02, v_pitchh = 0x03,
|
|
v_srcn = 0x04, v_adsr0 = 0x05,
|
|
v_adsr1 = 0x06, v_gain = 0x07,
|
|
v_envx = 0x08, v_outx = 0x09
|
|
};
|
|
|
|
public:
|
|
enum { extra_size = 16 };
|
|
sample_t* extra() { return m.extra; }
|
|
sample_t const* out_pos() const { return m.out; }
|
|
public:
|
|
BLARGG_DISABLE_NOTHROW
|
|
|
|
enum { echo_hist_size = 8 };
|
|
|
|
enum env_mode_t { env_release, env_attack, env_decay, env_sustain };
|
|
enum { brr_buf_size = 12 };
|
|
struct voice_t
|
|
{
|
|
int buf [brr_buf_size*2];// decoded samples (twice the size to simplify wrap handling)
|
|
int* buf_pos; // place in buffer where next samples will be decoded
|
|
int interp_pos; // relative fractional position in sample (0x1000 = 1.0)
|
|
int brr_addr; // address of current BRR block
|
|
int brr_offset; // current decoding offset in BRR block
|
|
int kon_delay; // KON delay/current setup phase
|
|
env_mode_t env_mode;
|
|
int env; // current envelope level
|
|
int hidden_env; // used by GAIN mode 7, very obscure quirk
|
|
int volume [2]; // copy of volume from DSP registers, with surround disabled
|
|
int enabled; // -1 if enabled, 0 if muted
|
|
};
|
|
private:
|
|
struct state_t
|
|
{
|
|
uint8_t regs [register_count];
|
|
|
|
// Echo history keeps most recent 8 samples (twice the size to simplify wrap handling)
|
|
int echo_hist [echo_hist_size * 2] [2];
|
|
int (*echo_hist_pos) [2]; // &echo_hist [0 to 7]
|
|
|
|
int every_other_sample; // toggles every sample
|
|
int kon; // KON value when last checked
|
|
int noise;
|
|
int echo_offset; // offset from ESA in echo buffer
|
|
int echo_length; // number of bytes that echo_offset will stop at
|
|
int phase; // next clock cycle to run (0-31)
|
|
unsigned counters [4];
|
|
|
|
int new_kon;
|
|
int t_koff;
|
|
|
|
voice_t voices [voice_count];
|
|
|
|
unsigned* counter_select [32];
|
|
|
|
// non-emulation state
|
|
uint8_t* ram; // 64K shared RAM between DSP and SMP
|
|
int mute_mask;
|
|
int surround_threshold;
|
|
sample_t* out;
|
|
sample_t* out_end;
|
|
sample_t* out_begin;
|
|
sample_t extra [extra_size];
|
|
};
|
|
state_t m;
|
|
|
|
void init_counter();
|
|
void run_counter( int );
|
|
void soft_reset_common();
|
|
void write_outline( int addr, int data );
|
|
void update_voice_vol( int addr );
|
|
};
|
|
|
|
#include <assert.h>
|
|
|
|
inline int Spc_Dsp::sample_count() const { return m.out - m.out_begin; }
|
|
|
|
inline int Spc_Dsp::read( int addr ) const
|
|
{
|
|
assert( (unsigned) addr < register_count );
|
|
return m.regs [addr];
|
|
}
|
|
|
|
inline void Spc_Dsp::update_voice_vol( int addr )
|
|
{
|
|
int l = (int8_t) m.regs [addr + v_voll];
|
|
int r = (int8_t) m.regs [addr + v_volr];
|
|
|
|
if ( l * r < m.surround_threshold )
|
|
{
|
|
// signs differ, so negate those that are negative
|
|
l ^= l >> 7;
|
|
r ^= r >> 7;
|
|
}
|
|
|
|
voice_t& v = m.voices [addr >> 4];
|
|
int enabled = v.enabled;
|
|
v.volume [0] = l & enabled;
|
|
v.volume [1] = r & enabled;
|
|
}
|
|
|
|
inline void Spc_Dsp::write( int addr, int data )
|
|
{
|
|
assert( (unsigned) addr < register_count );
|
|
|
|
m.regs [addr] = (uint8_t) data;
|
|
int low = addr & 0x0F;
|
|
if ( low < 0x2 ) // voice volumes
|
|
{
|
|
update_voice_vol( low ^ addr );
|
|
}
|
|
else if ( low == 0xC )
|
|
{
|
|
if ( addr == r_kon )
|
|
m.new_kon = (uint8_t) data;
|
|
|
|
if ( addr == r_endx ) // always cleared, regardless of data written
|
|
m.regs [r_endx] = 0;
|
|
}
|
|
}
|
|
|
|
inline void Spc_Dsp::disable_surround( bool disable )
|
|
{
|
|
m.surround_threshold = disable ? 0 : -0x4000;
|
|
}
|
|
|
|
#define SPC_NO_COPY_STATE_FUNCS 1
|
|
|
|
#define SPC_LESS_ACCURATE 1
|
|
|
|
#endif
|