mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
Improve accuracy of the panning and volume until the last second
This commit is contained in:
parent
d233a2539c
commit
a4df095031
|
@ -229,9 +229,9 @@ pub struct SoundChannel {
|
||||||
restart_point: Num<u32, 8>,
|
restart_point: Num<u32, 8>,
|
||||||
|
|
||||||
playback_speed: Num<u32, 8>,
|
playback_speed: Num<u32, 8>,
|
||||||
volume: Num<i16, 4>, // between 0 and 1
|
volume: Num<i16, 8>, // between 0 and 1
|
||||||
|
|
||||||
panning: Num<i16, 4>, // between -1 and 1
|
panning: Num<i16, 8>, // between -1 and 1
|
||||||
is_done: bool,
|
is_done: bool,
|
||||||
|
|
||||||
is_stereo: bool,
|
is_stereo: bool,
|
||||||
|
@ -366,7 +366,7 @@ impl SoundChannel {
|
||||||
/// Defaults to 0 (meaning equal on left and right) and doesn't affect stereo
|
/// Defaults to 0 (meaning equal on left and right) and doesn't affect stereo
|
||||||
/// sounds.
|
/// sounds.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn panning(&mut self, panning: impl Into<Num<i16, 4>>) -> &mut Self {
|
pub fn panning(&mut self, panning: impl Into<Num<i16, 8>>) -> &mut Self {
|
||||||
let panning = panning.into();
|
let panning = panning.into();
|
||||||
|
|
||||||
debug_assert!(panning >= Num::new(-1), "panning value must be >= -1");
|
debug_assert!(panning >= Num::new(-1), "panning value must be >= -1");
|
||||||
|
@ -381,7 +381,7 @@ impl SoundChannel {
|
||||||
///
|
///
|
||||||
/// Must be a value >= 0 and defaults to 1.
|
/// Must be a value >= 0 and defaults to 1.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn volume(&mut self, volume: impl Into<Num<i16, 4>>) -> &mut Self {
|
pub fn volume(&mut self, volume: impl Into<Num<i16, 8>>) -> &mut Self {
|
||||||
let volume = volume.into();
|
let volume = volume.into();
|
||||||
|
|
||||||
assert!(volume >= Num::new(0), "volume must be >= 0");
|
assert!(volume >= Num::new(0), "volume must be >= 0");
|
||||||
|
|
|
@ -449,14 +449,14 @@ impl MixerBuffer {
|
||||||
agb_rs__mixer_add_stereo_first(
|
agb_rs__mixer_add_stereo_first(
|
||||||
channel.data.as_ptr().add(channel.pos.floor() as usize),
|
channel.data.as_ptr().add(channel.pos.floor() as usize),
|
||||||
working_buffer.as_mut_ptr(),
|
working_buffer.as_mut_ptr(),
|
||||||
channel.volume,
|
channel.volume.change_base(),
|
||||||
self.frequency.buffer_size(),
|
self.frequency.buffer_size(),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
agb_rs__mixer_add_stereo(
|
agb_rs__mixer_add_stereo(
|
||||||
channel.data.as_ptr().add(channel.pos.floor() as usize),
|
channel.data.as_ptr().add(channel.pos.floor() as usize),
|
||||||
working_buffer.as_mut_ptr(),
|
working_buffer.as_mut_ptr(),
|
||||||
channel.volume,
|
channel.volume.change_base(),
|
||||||
self.frequency.buffer_size(),
|
self.frequency.buffer_size(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -475,6 +475,9 @@ impl MixerBuffer {
|
||||||
let right_amount = ((channel.panning + 1) / 2) * channel.volume;
|
let right_amount = ((channel.panning + 1) / 2) * channel.volume;
|
||||||
let left_amount = ((-channel.panning + 1) / 2) * channel.volume;
|
let left_amount = ((-channel.panning + 1) / 2) * channel.volume;
|
||||||
|
|
||||||
|
let right_amount: Num<i16, 4> = right_amount.change_base();
|
||||||
|
let left_amount: Num<i16, 4> = left_amount.change_base();
|
||||||
|
|
||||||
let channel_len = Num::<u32, 8>::new(channel.data.len() as u32);
|
let channel_len = Num::<u32, 8>::new(channel.data.len() as u32);
|
||||||
let mut playback_speed = channel.playback_speed;
|
let mut playback_speed = channel.playback_speed;
|
||||||
|
|
||||||
|
|
|
@ -256,7 +256,7 @@ impl TrackerChannel {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
PatternEffect::Panning(panning) => {
|
PatternEffect::Panning(panning) => {
|
||||||
channel.panning(*panning);
|
channel.panning(panning.change_base());
|
||||||
}
|
}
|
||||||
PatternEffect::Volume(volume) => {
|
PatternEffect::Volume(volume) => {
|
||||||
channel.volume(volume.change_base());
|
channel.volume(volume.change_base());
|
||||||
|
|
Loading…
Reference in a new issue