mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 00:31:34 +11:00
Allow for volume control
This commit is contained in:
parent
c81d73f8d5
commit
3c0d881a45
|
@ -30,6 +30,7 @@ pub struct SoundChannel {
|
|||
should_loop: bool,
|
||||
|
||||
playback_speed: Num<usize, 8>,
|
||||
volume: Num<i16, 4>, // between 0 and 1
|
||||
|
||||
panning: Num<i16, 4>, // between -1 and 1
|
||||
is_done: bool,
|
||||
|
@ -47,6 +48,7 @@ impl SoundChannel {
|
|||
panning: 0.into(),
|
||||
is_done: false,
|
||||
priority: SoundPriority::Low,
|
||||
volume: 1.into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,6 +61,7 @@ impl SoundChannel {
|
|||
panning: 0.into(),
|
||||
is_done: false,
|
||||
priority: SoundPriority::High,
|
||||
volume: 1.into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,4 +82,12 @@ impl SoundChannel {
|
|||
self.panning = panning;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn volume<'a>(&'a mut self, volume: Num<i16, 4>) -> &'a mut Self {
|
||||
assert!(volume <= Num::new(1), "volume must be <= 1");
|
||||
assert!(volume >= Num::new(0), "volume must be >= 0");
|
||||
|
||||
self.volume = volume;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,8 +117,8 @@ impl MixerBuffer {
|
|||
continue;
|
||||
}
|
||||
|
||||
let right_amount = (channel.panning + 1) / 2;
|
||||
let left_amount = -right_amount + 1;
|
||||
let right_amount = ((channel.panning + 1) / 2) * channel.volume;
|
||||
let left_amount = (-right_amount + 1) * channel.volume;
|
||||
|
||||
if channel.pos + channel.playback_speed * SOUND_BUFFER_SIZE >= channel.data.len().into()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue