LMMS
Loading...
Searching...
No Matches
Ay_Apu.h
Go to the documentation of this file.
1// AY-3-8910 sound chip emulator
2
3// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
4#ifndef AY_APU_H
5#define AY_APU_H
6
7#include "blargg_common.h"
8#include "Blip_Buffer.h"
9
10class Ay_Apu {
11public:
12 // Set buffer to generate all sound into, or disable sound if NULL
13 void output( Blip_Buffer* );
14
15 // Reset sound chip
16 void reset();
17
18 // Write to register at specified time
19 enum { reg_count = 16 };
20 void write( blip_time_t time, int addr, int data );
21
22 // Run sound to specified time, end current time frame, then start a new
23 // time frame at time 0. Time frames have no effect on emulation and each
24 // can be whatever length is convenient.
26
27// Additional features
28
29 // Set sound output of specific oscillator to buffer, where index is
30 // 0, 1, or 2. If buffer is NULL, the specified oscillator is muted.
31 enum { osc_count = 3 };
32 void osc_output( int index, Blip_Buffer* );
33
34 // Set overall volume (default is 1.0)
35 void volume( double );
36
37 // Set treble equalization (see documentation)
38 void treble_eq( blip_eq_t const& );
39
40public:
41 Ay_Apu();
42 typedef unsigned char byte;
43private:
54
55 struct {
57 blargg_ulong lfsr;
59
60 struct {
62 byte const* wave;
63 int pos;
64 byte modes [8] [48]; // values already passed through volume table
65 } env;
66
67 void run_until( blip_time_t );
68 void write_data_( int addr, int data );
69public:
70 enum { amp_range = 255 };
72};
73
74inline void Ay_Apu::volume( double v ) { synth_.volume( 0.7 / osc_count / amp_range * v ); }
75
76inline void Ay_Apu::treble_eq( blip_eq_t const& eq ) { synth_.treble_eq( eq ); }
77
78inline void Ay_Apu::write( blip_time_t time, int addr, int data )
79{
80 run_until( time );
81 write_data_( addr, data );
82}
83
84inline void Ay_Apu::osc_output( int i, Blip_Buffer* buf )
85{
86 assert( (unsigned) i < osc_count );
87 oscs [i].output = buf;
88}
89
90inline void Ay_Apu::output( Blip_Buffer* buf )
91{
92 osc_output( 0, buf );
93 osc_output( 1, buf );
94 osc_output( 2, buf );
95}
96
97inline void Ay_Apu::end_frame( blip_time_t time )
98{
99 if ( time > last_time )
100 run_until( time );
101
102 assert( last_time >= time );
103 last_time -= time;
104}
105
106#endif
int const osc_count
Definition Ay_Emu.cpp:25
blip_long blip_time_t
Definition Blip_Buffer.h:17
assert(0)
blip_time_t last_time
Definition Ay_Apu.h:52
struct Ay_Apu::@233362204247110341175273265363243245272140071216 env
byte regs[reg_count]
Definition Ay_Apu.h:53
@ reg_count
Definition Ay_Apu.h:19
byte modes[8][48]
Definition Ay_Apu.h:64
unsigned char byte
Definition Ay_Apu.h:42
void volume(double)
Definition Ay_Apu.h:74
void end_frame(blip_time_t length)
Definition Ay_Apu.h:97
void output(Blip_Buffer *)
Definition Ay_Apu.h:90
void write_data_(int addr, int data)
Definition Ay_Apu.cpp:120
byte const * wave
Definition Ay_Apu.h:62
int pos
Definition Ay_Apu.h:63
@ amp_range
Definition Ay_Apu.h:70
void osc_output(int index, Blip_Buffer *)
Definition Ay_Apu.h:84
struct Ay_Apu::osc_t oscs[osc_count]
void treble_eq(blip_eq_t const &)
Definition Ay_Apu.h:76
Blip_Synth< blip_good_quality, 1 > synth_
Definition Ay_Apu.h:71
@ osc_count
Definition Ay_Apu.h:31
void run_until(blip_time_t)
Definition Ay_Apu.cpp:164
blargg_ulong lfsr
Definition Ay_Apu.h:57
Ay_Apu()
Definition Ay_Apu.cpp:70
blip_time_t delay
Definition Ay_Apu.h:56
void write(blip_time_t time, int addr, int data)
Definition Ay_Apu.h:78
void reset()
Definition Ay_Apu.cpp:97
Definition Blip_Buffer.h:23
Definition Blip_Buffer.h:191
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
static float noise(float x, float y)
Definition lice_texgen.cpp:149
png_uint_32 length
Definition png.c:2247
Definition Ay_Apu.h:45
short phase
Definition Ay_Apu.h:49
blip_time_t delay
Definition Ay_Apu.h:47
Blip_Buffer * output
Definition Ay_Apu.h:50
short last_amp
Definition Ay_Apu.h:48
blip_time_t period
Definition Ay_Apu.h:46
Definition tap_eq.c:71