Skip to content

Commit c4d058d

Browse files
committed
Embed SoundUnit in SGU
1 parent e35549c commit c4d058d

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/chips/sgu1.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,15 @@ void sgu1_init(sgu1_t* sgu, const sgu1_desc_t* desc) {
3434
sgu->sample_counter = sgu->sample_period;
3535
sgu->sample_mag = desc->magnitude;
3636
// sgu->sample_accum_count[0] = sgu->sample_accum_count[1] = 1.0f;
37-
sgu->su = new SoundUnit();
3837
sgu->tick_period = (desc->tick_hz * SGU1_FIXEDPOINT_SCALE) / (CHIP_CLOCK / CHIP_DIVIDER);
3938
sgu->tick_counter = sgu->tick_period;
40-
SoundUnit_Init(sgu->su, 65536, false);
39+
SoundUnit_Init(&sgu->su, 65536, false);
4140
sgu->resampler = speex_resampler_init(SGU1_AUDIO_CHANNELS, CHIP_CLOCK / CHIP_DIVIDER, sgu->sound_hz, 10, nullptr);
4241
}
4342

4443
void sgu1_reset(sgu1_t* sgu) {
4544
CHIPS_ASSERT(sgu);
46-
SoundUnit_Reset(sgu->su);
45+
SoundUnit_Reset(&sgu->su);
4746
memset(sgu->reg, 0, sizeof(sgu->reg));
4847
sgu->tick_counter = sgu->tick_period;
4948
sgu->sample_counter = sgu->sample_period;
@@ -59,14 +58,14 @@ static uint64_t _sgu1_tick(sgu1_t* sgu, uint64_t pins) {
5958
if (sgu->tick_counter <= 0) {
6059
sgu->tick_counter += sgu->tick_period;
6160
short l, r;
62-
SoundUnit_NextSample(sgu->su, &l, &r);
61+
SoundUnit_NextSample(&sgu->su, &l, &r);
6362
float in[2] = { ((float)l / 32767.0f), ((float)r / 32767.0f) };
6463
spx_uint32_t in_len = 1; // 1 stereo frame
6564
spx_uint32_t out_len = 1; // room for 1 stereo frame
6665
speex_resampler_process_interleaved_float(sgu->resampler, in, &in_len, sgu->sample, &out_len);
6766

6867
for (int i = 0; i < SGU1_NUM_CHANNELS; i++) {
69-
sgu->voice[i].sample_buffer[sgu->voice[i].sample_pos++] = (float)SoundUnit_GetSample(sgu->su, i);
68+
sgu->voice[i].sample_buffer[sgu->voice[i].sample_pos++] = (float)SoundUnit_GetSample(&sgu->su, i);
7069
if (sgu->voice[i].sample_pos >= SGU1_AUDIO_SAMPLES) {
7170
sgu->voice[i].sample_pos = 0;
7271
}
@@ -98,7 +97,7 @@ uint8_t sgu1_reg_read(sgu1_t* sgu, uint8_t reg) {
9897
}
9998
else {
10099
uint8_t chan = _sgu1_selected_channel(sgu);
101-
data = ((unsigned char*)sgu->su->chan)[chan << 5 | (reg & (SGU1_NUM_CHANNEL_REGS - 1))];
100+
data = ((unsigned char*)sgu->su.chan)[chan << 5 | (reg & (SGU1_NUM_CHANNEL_REGS - 1))];
102101
}
103102
return data;
104103
}
@@ -111,7 +110,7 @@ void sgu1_reg_write(sgu1_t* sgu, uint8_t reg, uint8_t data) {
111110
}
112111
else {
113112
uint8_t chan = _sgu1_selected_channel(sgu);
114-
((unsigned char*)sgu->su->chan)[chan << 5 | (reg & (SGU1_NUM_CHANNEL_REGS - 1))] = data;
113+
((unsigned char*)sgu->su.chan)[chan << 5 | (reg & (SGU1_NUM_CHANNEL_REGS - 1))] = data;
115114
}
116115
}
117116

src/chips/sgu1.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ typedef struct {
179179
typedef struct {
180180
int sound_hz;
181181
// sound unit instance
182-
SoundUnit* su;
182+
SoundUnit su;
183183
uint8_t reg[32];
184184
int tick_period;
185185
int tick_counter;

src/ui/ui_sgu1.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static void ui_util_s8(int8_t val) {
4040

4141
static void _ui_sgu1_draw_state(ui_sgu1_t* win) {
4242
sgu1_t* sgu = win->sgu;
43-
SoundUnit* su = static_cast<SoundUnit*>(sgu->su);
43+
SoundUnit* su = &sgu->su;
4444
const float cw0 = 158.0f;
4545
const float cw = 62.0f;
4646
const float h = ImGui::GetTextLineHeight();

0 commit comments

Comments
 (0)