@@ -35,7 +35,7 @@ void sgu1_init(sgu1_t* sgu, const sgu1_desc_t* desc) {
3535 sgu->sample_period = (desc->tick_hz * SGU1_FIXEDPOINT_SCALE ) / desc->sound_hz ;
3636 sgu->sample_counter = sgu->sample_period ;
3737 sgu->sample_mag = desc->magnitude ;
38- sgu->sample_accum_count = 1 .0f ;
38+ sgu->sample_accum_count [ 0 ] = sgu-> sample_accum_count [ 1 ] = 1 .0f ;
3939 sgu->su = new SoundUnit ();
4040 sgu->tick_period = (desc->tick_hz * SGU1_FIXEDPOINT_SCALE ) / (CHIP_CLOCK / CHIP_DIVIDER );
4141 sgu->tick_counter = sgu->tick_period ;
@@ -48,9 +48,9 @@ void sgu1_reset(sgu1_t* sgu) {
4848 memset (sgu->reg , 0 , sizeof (sgu->reg ));
4949 sgu->tick_counter = sgu->tick_period ;
5050 sgu->sample_counter = sgu->sample_period ;
51- sgu->sample = 0 .0f ;
52- sgu->sample_accum = 0 .0f ;
53- sgu->sample_accum_count = 1 .0f ;
51+ sgu->sample [ 0 ] = sgu-> sample [ 1 ] = 0 .0f ;
52+ sgu->sample_accum [ 0 ] = sgu-> sample_accum [ 1 ] = 0 .0f ;
53+ sgu->sample_accum_count [ 0 ] = sgu-> sample_accum_count [ 1 ] = 1 .0f ;
5454 sgu->pins = 0 ;
5555}
5656
@@ -62,9 +62,10 @@ static uint64_t _sgu1_tick(sgu1_t* sgu, uint64_t pins) {
6262 sgu->tick_counter += sgu->tick_period ;
6363 short l, r;
6464 SGU_SU ->NextSample (&l, &r);
65- int sample = ((int )l + (int )r) >> 1 ;
66- sgu->sample_accum += ((float )sample / 32767 .0f );
67- sgu->sample_accum_count += 1 .0f ;
65+ sgu->sample_accum [0 ] += ((float )l / 32767 .0f );
66+ sgu->sample_accum_count [0 ] += 1 .0f ;
67+ sgu->sample_accum [1 ] += ((float )r / 32767 .0f );
68+ sgu->sample_accum_count [1 ] += 1 .0f ;
6869
6970 for (int i = 0 ; i < SGU1_NUM_CHANNELS ; i++) {
7071 sgu->voice [i].sample_buffer [sgu->voice [i].sample_pos ++] = (float )SGU_SU ->GetSample (i);
@@ -78,10 +79,12 @@ static uint64_t _sgu1_tick(sgu1_t* sgu, uint64_t pins) {
7879 sgu->sample_counter -= SGU1_FIXEDPOINT_SCALE ;
7980 if (sgu->sample_counter <= 0 ) {
8081 sgu->sample_counter += sgu->sample_period ;
81- float s = sgu->sample_accum / sgu->sample_accum_count ;
82- sgu->sample = sgu->sample_mag * s;
83- sgu->sample_accum = 0 .0f ;
84- sgu->sample_accum_count = 0 .0f ;
82+ float l = sgu->sample_accum [0 ] / sgu->sample_accum_count [0 ];
83+ sgu->sample [0 ] = sgu->sample_mag * l;
84+ float r = sgu->sample_accum [1 ] / sgu->sample_accum_count [1 ];
85+ sgu->sample [1 ] = sgu->sample_mag * r;
86+ sgu->sample_accum [0 ] = sgu->sample_accum [1 ] = 0 .0f ;
87+ sgu->sample_accum_count [0 ] = sgu->sample_accum_count [1 ] = 0 .0f ;
8588 pins |= SGU1_SAMPLE ;
8689 }
8790 else {
0 commit comments