LMMS
Loading...
Searching...
No Matches
Kss_Scc_Apu.h
Go to the documentation of this file.
1// Konami SCC sound chip emulator
2
3// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
4#ifndef KSS_SCC_APU_H
5#define KSS_SCC_APU_H
6
7#include "blargg_common.h"
8#include "Blip_Buffer.h"
9#include <string.h>
10
11class Scc_Apu {
12public:
13 // Set buffer to generate all sound into, or disable sound if NULL
14 void output( Blip_Buffer* );
15
16 // Reset sound chip
17 void reset();
18
19 // Write to register at specified time
20 enum { reg_count = 0x90 };
21 void write( blip_time_t time, int reg, int data );
22
23 // Run sound to specified time, end current time frame, then start a new
24 // time frame at time 0. Time frames have no effect on emulation and each
25 // can be whatever length is convenient.
27
28// Additional features
29
30 // Set sound output of specific oscillator to buffer, where index is
31 // 0 to 4. If buffer is NULL, the specified oscillator is muted.
32 enum { osc_count = 5 };
33 void osc_output( int index, Blip_Buffer* );
34
35 // Set overall volume (default is 1.0)
36 void volume( double );
37
38 // Set treble equalization (see documentation)
39 void treble_eq( blip_eq_t const& );
40
41public:
42 Scc_Apu();
43private:
44 enum { amp_range = 0x8000 };
45 struct osc_t
46 {
47 int delay;
48 int phase;
51 };
54 unsigned char regs [reg_count];
56
57 void run_until( blip_time_t );
58};
59
60inline void Scc_Apu::volume( double v ) { synth.volume( 0.43 / osc_count / amp_range * v ); }
61
62inline void Scc_Apu::treble_eq( blip_eq_t const& eq ) { synth.treble_eq( eq ); }
63
64inline void Scc_Apu::osc_output( int index, Blip_Buffer* b )
65{
66 assert( (unsigned) index < osc_count );
67 oscs [index].output = b;
68}
69
70inline void Scc_Apu::write( blip_time_t time, int addr, int data )
71{
72 assert( (unsigned) addr < reg_count );
73 run_until( time );
74 regs [addr] = data;
75}
76
77inline void Scc_Apu::end_frame( blip_time_t end_time )
78{
79 if ( end_time > last_time )
80 run_until( end_time );
81 last_time -= end_time;
82 assert( last_time >= 0 );
83}
84
85inline void Scc_Apu::output( Blip_Buffer* buf )
86{
87 for ( int i = 0; i < osc_count; i++ )
88 oscs [i].output = buf;
89}
90
92{
93 output( 0 );
94}
95
96inline void Scc_Apu::reset()
97{
98 last_time = 0;
99
100 for ( int i = 0; i < osc_count; i++ )
101 memset( &oscs [i], 0, offsetof (osc_t,output) );
102
103 memset( regs, 0, sizeof regs );
104}
105
106#endif
blip_long blip_time_t
Definition Blip_Buffer.h:17
assert(0)
Definition Blip_Buffer.h:23
Definition Blip_Buffer.h:191
unsigned char regs[reg_count]
Definition Kss_Scc_Apu.h:54
void treble_eq(blip_eq_t const &)
Definition Kss_Scc_Apu.h:62
Scc_Apu()
Definition Kss_Scc_Apu.h:91
@ osc_count
Definition Kss_Scc_Apu.h:32
void reset()
Definition Kss_Scc_Apu.h:96
osc_t oscs[osc_count]
Definition Kss_Scc_Apu.h:52
void volume(double)
Definition Kss_Scc_Apu.h:60
@ reg_count
Definition Kss_Scc_Apu.h:20
void run_until(blip_time_t)
Definition Kss_Scc_Apu.cpp:24
void write(blip_time_t time, int reg, int data)
Definition Kss_Scc_Apu.h:70
Blip_Synth< blip_med_quality, 1 > synth
Definition Kss_Scc_Apu.h:55
void osc_output(int index, Blip_Buffer *)
Definition Kss_Scc_Apu.h:64
void output(Blip_Buffer *)
Definition Kss_Scc_Apu.h:85
void end_frame(blip_time_t length)
Definition Kss_Scc_Apu.h:77
@ amp_range
Definition Kss_Scc_Apu.h:44
blip_time_t last_time
Definition Kss_Scc_Apu.h:53
Definition Blip_Buffer.h:239
unsigned v[N_MAX]
Definition inflate.c:1584
register unsigned i
Definition inflate.c:1575
JSAMPIMAGE data
Definition jpeglib.h:945
#define offsetof(TYPE, MEMBER)
Definition list.h:42
png_uint_32 length
Definition png.c:2247
Definition Kss_Scc_Apu.h:46
int delay
Definition Kss_Scc_Apu.h:47
Blip_Buffer * output
Definition Kss_Scc_Apu.h:50
int last_amp
Definition Kss_Scc_Apu.h:49
int phase
Definition Kss_Scc_Apu.h:48
Definition tap_eq.c:71
b
Definition crypt.c:628