Skip to content

Commit de18ced

Browse files
committed
Add initial channel InterpolationMethod setting
1 parent 99db377 commit de18ced

6 files changed

Lines changed: 55 additions & 39 deletions

File tree

oxisynth/src/core/channel_pool/channel.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,11 @@ use std::sync::Arc;
44
use super::super::soundfont::{Preset, SoundFont};
55

66
use crate::arena::Index;
7+
use crate::core::InterpolationMethod;
78
use crate::midi_event::ControlFunction;
89
use crate::GeneratorType;
910
use crate::Tuning;
1011

11-
// Flags to choose the interpolation method
12-
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
13-
pub enum InterpolationMethod {
14-
/// No interpolation: Fastest, but questionable audio quality
15-
None = 0,
16-
/// Straight-line interpolation: A bit slower, reasonable audio quality
17-
Linear = 1,
18-
/// Fourth-order interpolation: Requires 50% of the whole DSP processing time, good quality (default)
19-
#[default]
20-
FourthOrder = 4,
21-
/// Seventh-order interpolation
22-
SeventhOrder = 7,
23-
}
24-
2512
#[derive(Clone)]
2613
struct CcList([u8; 128]);
2714

@@ -106,7 +93,7 @@ impl Channel {
10693
cc: CcList([0; 128]),
10794
bank_msb: 0,
10895

109-
interp_method: Default::default(),
96+
interp_method: InterpolationMethod::default(),
11097
tuning: None,
11198

11299
nrpn_select: 0,

oxisynth/src/core/channel_pool/mod.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
mod channel;
2-
pub use channel::{Channel, InterpolationMethod};
2+
pub(crate) use channel::Channel;
33

44
use crate::OxiError;
55

6+
use super::InterpolationMethod;
7+
68
pub struct ChannelPool(Vec<Channel>);
79

810
impl ChannelPool {
9-
pub fn new(len: usize) -> Self {
10-
let channels = (0..len).map(Channel::new).collect();
11-
Self(channels)
11+
pub fn new(len: usize, interpolation: InterpolationMethod) -> Self {
12+
Self(
13+
(0..len)
14+
.map(|id| {
15+
let mut ch = Channel::new(id);
16+
ch.set_interp_method(interpolation);
17+
ch
18+
})
19+
.collect(),
20+
)
1221
}
1322

1423
pub fn get(&self, id: usize) -> Result<&Channel, OxiError> {

oxisynth/src/core/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod settings;
77
mod voice_pool;
88

99
mod conv;
10-
pub use channel_pool::InterpolationMethod;
10+
pub use settings::InterpolationMethod;
1111
pub(crate) use settings::Settings;
1212

1313
mod font_bank;
@@ -65,7 +65,7 @@ impl Core {
6565

6666
font_bank: FontBank::new(),
6767

68-
channels: ChannelPool::new(settings.midi_channels as usize),
68+
channels: ChannelPool::new(settings.midi_channels as usize, settings.interpolation),
6969
voices: VoicePool::new(settings.polyphony as usize, settings.sample_rate),
7070

7171
output: OutputBuffer::new(nbuf as usize),

oxisynth/src/core/settings.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
use crate::{RangeError, SettingsError, SynthDescriptor};
22

3+
// Flags to choose the interpolation method
4+
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
5+
pub enum InterpolationMethod {
6+
/// No interpolation: Fastest, but questionable audio quality
7+
None = 0,
8+
/// Straight-line interpolation: A bit slower, reasonable audio quality
9+
Linear = 1,
10+
/// Fourth-order interpolation: Requires 50% of the whole DSP processing time, good quality (default)
11+
#[default]
12+
FourthOrder = 4,
13+
/// Seventh-order interpolation
14+
SeventhOrder = 7,
15+
}
16+
317
pub(crate) struct Settings {
418
pub reverb_active: bool,
519
pub chorus_active: bool,
620
pub drums_channel_active: bool,
721

22+
/// Interpolation method/quality
23+
//
24+
/// Def: FourthOrder
25+
pub interpolation: InterpolationMethod,
26+
827
/// Def: 256
928
/// Min: 1
1029
/// Max: 65535
@@ -122,6 +141,7 @@ impl TryFrom<SynthDescriptor> for Settings {
122141
reverb_active: desc.reverb_active,
123142
chorus_active: desc.chorus_active,
124143
drums_channel_active: desc.drums_channel_active,
144+
interpolation: desc.interpolation,
125145

126146
polyphony,
127147
midi_channels,

oxisynth/src/core/voice_pool/voice/mod.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,23 @@ pub use envelope::EnvelopeStep;
55
use envelope::{Envelope, EnvelopePortion};
66

77
use crate::{
8-
core::{BUFSIZE, BUFSIZE_F32},
8+
core::{
9+
channel_pool::Channel,
10+
conv::{
11+
act2hz, atten2amp, cb2amp, ct2hz, ct2hz_real, pan, tc2sec, tc2sec_attack, tc2sec_delay,
12+
tc2sec_release,
13+
},
14+
soundfont::{
15+
generator::{Generator, GeneratorList, GeneratorType},
16+
modulator::Mod,
17+
Sample,
18+
},
19+
write::FxBuf,
20+
InterpolationMethod, BUFSIZE, BUFSIZE_F32,
21+
},
922
midi_event::ControlFunction,
1023
};
1124

12-
use super::super::{
13-
channel_pool::{Channel, InterpolationMethod},
14-
write::FxBuf,
15-
};
16-
17-
use super::super::soundfont::{
18-
generator::{Generator, GeneratorList, GeneratorType},
19-
modulator::Mod,
20-
Sample,
21-
};
22-
23-
use super::super::conv::{
24-
act2hz, atten2amp, cb2amp, ct2hz, ct2hz_real, pan, tc2sec, tc2sec_attack, tc2sec_delay,
25-
tc2sec_release,
26-
};
27-
2825
use soundfont::raw::{ControllerPalette, GeneralPalette};
2926

3027
type Phase = u64;

oxisynth/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mod midi_event;
1717
mod unsafe_stuff;
1818

1919
pub use api::Tuning;
20-
pub use core::{GeneratorType, Preset, SoundFont};
20+
pub use core::{GeneratorType, InterpolationMethod, Preset, SoundFont};
2121
pub use error::{OxiError, RangeError, SettingsError};
2222
pub use midi_event::MidiEvent;
2323

@@ -34,6 +34,8 @@ pub struct SynthDescriptor {
3434
pub reverb_active: bool,
3535
pub chorus_active: bool,
3636
pub drums_channel_active: bool,
37+
// Interpolation method/quality
38+
pub interpolation: InterpolationMethod,
3739

3840
/// Def: 256
3941
/// Min: 1
@@ -71,6 +73,7 @@ impl Default for SynthDescriptor {
7173
reverb_active: true,
7274
chorus_active: true,
7375
drums_channel_active: true,
76+
interpolation: InterpolationMethod::default(),
7477

7578
polyphony: 256,
7679
midi_channels: 16,

0 commit comments

Comments
 (0)