fix(apu): implement NR50 volume controls
This commit is contained in:
		
							
								
								
									
										10
									
								
								src/apu.rs
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/apu.rs
									
									
									
									
									
								
							| @@ -154,8 +154,11 @@ impl Apu { | ||||
|                     let ch4_left = self.ctrl.output.ch4_left() as u8 as f32 * ch4_amplitude; | ||||
|                     let ch4_right = self.ctrl.output.ch4_right() as u8 as f32 * ch4_amplitude; | ||||
|  | ||||
|                     let left = (ch1_left + ch2_left + ch3_left + ch4_left) / 4.0; | ||||
|                     let right = (ch1_right + ch2_right + ch3_right + ch4_right) / 4.0; | ||||
|                     let left_mixed = (ch1_left + ch2_left + ch3_left + ch4_left) / 4.0; | ||||
|                     let right_mixed = (ch1_right + ch2_right + ch3_right + ch4_right) / 4.0; | ||||
|  | ||||
|                     let left = (self.ctrl.channel.left_volume() + 1.0) * left_mixed; | ||||
|                     let right = (self.ctrl.channel.right_volume() + 1.0) * right_mixed; | ||||
|  | ||||
|                     prod.push(left) | ||||
|                         .and(prod.push(right)) | ||||
| @@ -742,7 +745,8 @@ impl Channel3 { | ||||
|     } | ||||
|  | ||||
|     fn amplitude(&self) -> f32 { | ||||
|         let dac_input = self.read_sample(self.offset) >> self.volume.shift_count(); | ||||
|         let dac_input = | ||||
|             (self.read_sample(self.offset) >> self.volume.shift_count()) * self.enabled as u8; | ||||
|  | ||||
|         (dac_input as f32 / 7.5) - 1.0 | ||||
|     } | ||||
|   | ||||
| @@ -503,10 +503,20 @@ impl From<SoundOutput> for u8 { | ||||
| bitfield! { | ||||
|     pub struct ChannelControl(u8); | ||||
|     impl Debug; | ||||
|     vin_so2, _: 7; | ||||
|     so2_level, _: 6, 4; | ||||
|     vin_so1, _: 3; | ||||
|     so1_level, _: 2, 0; | ||||
|     vin_left, _: 7; | ||||
|     _left_volume, _: 6, 4; | ||||
|     vin_right, _: 3; | ||||
|     _right_volume, _: 2, 0; | ||||
| } | ||||
|  | ||||
| impl ChannelControl { | ||||
|     pub(crate) fn left_volume(&self) -> f32 { | ||||
|         self._left_volume() as f32 | ||||
|     } | ||||
|  | ||||
|     pub(crate) fn right_volume(&self) -> f32 { | ||||
|         self._right_volume() as f32 | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl Copy for ChannelControl {} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user