@@ -31,7 +31,7 @@ void PCEFast_PSG::SetVolume(double new_volume)
3131   Blip_Synth_set_volume (&Synth, OutputVolume / 6 , 8192 );
3232}
3333
34- void  PCEFast_PSG::SetChannelUserVolume (int  chnum, uint8  new_volume)
34+ void  PCEFast_PSG::SetChannelUserVolume (int  chnum, int32  new_volume)
3535{
3636    if (chnum >=6  || new_volume > 100 ) return ;  //  check valid args
3737    psg_channel *ch = &channel[chnum];
@@ -41,13 +41,24 @@ void PCEFast_PSG::SetChannelUserVolume(int chnum, uint8 new_volume)
4141void  PCEFast_PSG::UpdateOutput_Norm (const  int32 timestamp, psg_channel *ch)
4242{
4343   int32 samp[2 ];
44+    int  delta0;
45+    int  delta1;   
4446   int  sv = ch->dda ;
4547
4648   samp[0 ] = dbtable[ch->vl [0 ]][sv];
4749   samp[1 ] = dbtable[ch->vl [1 ]][sv];
4850
49-    Blip_Synth_offset (&Synth, timestamp, (samp[0 ] - ch->blip_prev_samp [0 ]) * ch->user_volume  / 100 , sbuf[0 ]);
50-    Blip_Synth_offset (&Synth, timestamp, (samp[1 ] - ch->blip_prev_samp [1 ]) * ch->user_volume  / 100 , sbuf[1 ]);
51+    if (ch->user_volume  < 100 )
52+    {
53+        delta0 = (samp[0 ] - ch->blip_prev_samp [0 ]) * ch->user_volume  / 100 ;
54+        delta1 = (samp[1 ] - ch->blip_prev_samp [1 ]) * ch->user_volume  / 100 ;
55+    } else  {
56+        delta0 = samp[0 ] - ch->blip_prev_samp [0 ];
57+        delta1 = samp[1 ] - ch->blip_prev_samp [1 ];
58+    }
59+     
60+    Blip_Synth_offset (&Synth, timestamp, delta0, sbuf[0 ]);
61+    Blip_Synth_offset (&Synth, timestamp, delta1, sbuf[1 ]);
5162
5263   ch->blip_prev_samp [0 ] = samp[0 ];
5364   ch->blip_prev_samp [1 ] = samp[1 ];
@@ -56,13 +67,24 @@ void PCEFast_PSG::UpdateOutput_Norm(const int32 timestamp, psg_channel *ch)
5667void  PCEFast_PSG::UpdateOutput_Noise (const  int32 timestamp, psg_channel *ch)
5768{
5869   int32 samp[2 ];
70+    int  delta0;
71+    int  delta1;
5972   int  sv = ((ch->lfsr  & 1 ) << 5 ) - (ch->lfsr  & 1 ); // (ch->lfsr & 0x1) ? 0x1F : 0;
6073
6174   samp[0 ] = dbtable[ch->vl [0 ]][sv];
6275   samp[1 ] = dbtable[ch->vl [1 ]][sv];
6376
64-    Blip_Synth_offset (&Synth, timestamp, (samp[0 ] - ch->blip_prev_samp [0 ]) * ch->user_volume  / 100 , sbuf[0 ]);
65-    Blip_Synth_offset (&Synth, timestamp, (samp[1 ] - ch->blip_prev_samp [1 ]) * ch->user_volume  / 100 , sbuf[1 ]);
77+    if (ch->user_volume  < 100 )
78+    {
79+        delta0 = (samp[0 ] - ch->blip_prev_samp [0 ]) * ch->user_volume  / 100 ;
80+        delta1 = (samp[1 ] - ch->blip_prev_samp [1 ]) * ch->user_volume  / 100 ;
81+    } else  {
82+        delta0 = samp[0 ] - ch->blip_prev_samp [0 ];
83+        delta1 = samp[1 ] - ch->blip_prev_samp [1 ];
84+    }
85+     
86+    Blip_Synth_offset (&Synth, timestamp, delta0, sbuf[0 ]);
87+    Blip_Synth_offset (&Synth, timestamp, delta1, sbuf[1 ]);
6688
6789   ch->blip_prev_samp [0 ] = samp[0 ];
6890   ch->blip_prev_samp [1 ] = samp[1 ];
@@ -71,11 +93,22 @@ void PCEFast_PSG::UpdateOutput_Noise(const int32 timestamp, psg_channel *ch)
7193void  PCEFast_PSG::UpdateOutput_Off (const  int32 timestamp, psg_channel *ch)
7294{
7395   int32 samp[2 ];
96+    int  delta0;
97+    int  delta1;
7498
7599   samp[0 ] = samp[1 ] = 0 ;
76100
77-    Blip_Synth_offset (&Synth, timestamp, (samp[0 ] - ch->blip_prev_samp [0 ]) * ch->user_volume  / 100 , sbuf[0 ]);
78-    Blip_Synth_offset (&Synth, timestamp, (samp[1 ] - ch->blip_prev_samp [1 ]) * ch->user_volume  / 100 , sbuf[1 ]);
101+    if (ch->user_volume  < 100 )
102+    {
103+        delta0 = (samp[0 ] - ch->blip_prev_samp [0 ]) * ch->user_volume  / 100 ;
104+        delta1 = (samp[1 ] - ch->blip_prev_samp [1 ]) * ch->user_volume  / 100 ;
105+    } else  {
106+        delta0 = samp[0 ] - ch->blip_prev_samp [0 ];
107+        delta1 = samp[1 ] - ch->blip_prev_samp [1 ];
108+    }
109+     
110+    Blip_Synth_offset (&Synth, timestamp, delta0, sbuf[0 ]);
111+    Blip_Synth_offset (&Synth, timestamp, delta1, sbuf[1 ]);
79112
80113   ch->blip_prev_samp [0 ] = samp[0 ];
81114   ch->blip_prev_samp [1 ] = samp[1 ];
@@ -85,12 +118,23 @@ void PCEFast_PSG::UpdateOutput_Off(const int32 timestamp, psg_channel *ch)
85118void  PCEFast_PSG::UpdateOutput_Accum (const  int32 timestamp, psg_channel *ch)
86119{
87120   int32 samp[2 ];
121+    int  delta0;
122+    int  delta1;
88123
89124   samp[0 ] = ((int32)dbtable_volonly[ch->vl [0 ]] * ((int32)ch->samp_accum  - 496 )) >> (8  + 5 );
90125   samp[1 ] = ((int32)dbtable_volonly[ch->vl [1 ]] * ((int32)ch->samp_accum  - 496 )) >> (8  + 5 );
91126
92-    Blip_Synth_offset (&Synth, timestamp, (samp[0 ] - ch->blip_prev_samp [0 ]) * ch->user_volume  / 100 , sbuf[0 ]);
93-    Blip_Synth_offset (&Synth, timestamp, (samp[1 ] - ch->blip_prev_samp [1 ]) * ch->user_volume  / 100 , sbuf[1 ]);
127+    if (ch->user_volume  < 100 )
128+    {
129+        delta0 = (samp[0 ] - ch->blip_prev_samp [0 ]) * ch->user_volume  / 100 ;
130+        delta1 = (samp[1 ] - ch->blip_prev_samp [1 ]) * ch->user_volume  / 100 ;
131+    } else  {
132+        delta0 = samp[0 ] - ch->blip_prev_samp [0 ];
133+        delta1 = samp[1 ] - ch->blip_prev_samp [1 ];
134+    }
135+     
136+    Blip_Synth_offset (&Synth, timestamp, delta0, sbuf[0 ]);
137+    Blip_Synth_offset (&Synth, timestamp, delta1, sbuf[1 ]);
94138
95139   ch->blip_prev_samp [0 ] = samp[0 ];
96140   ch->blip_prev_samp [1 ] = samp[1 ];
0 commit comments