Skip to content

Commit

Permalink
Cleanup and slim down the public API surface
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex committed Dec 29, 2024
1 parent d7469ea commit c13e923
Show file tree
Hide file tree
Showing 20 changed files with 569 additions and 760 deletions.
64 changes: 16 additions & 48 deletions oxisynth-chorus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ const INTERPOLATION_SAMPLES: usize = 5;

#[derive(Clone)]
pub struct Chorus {
active: bool,

type_0: ChorusMode,
new_type: ChorusMode,
depth_ms: f32,
Expand All @@ -41,10 +39,8 @@ pub struct Chorus {
}

impl Chorus {
pub fn new(sample_rate: f32, active: bool) -> Self {
pub fn new(sample_rate: f32) -> Self {
let mut chorus = Self {
active,

type_0: ChorusMode::Sine,
new_type: ChorusMode::Sine,
depth_ms: 0f32,
Expand Down Expand Up @@ -88,7 +84,7 @@ impl Chorus {

fn init(&mut self) {
self.chorusbuf.fill(0.0);
self.set_chorus(&Default::default());
self.set_params(&Default::default());
self.update();
}

Expand Down Expand Up @@ -263,7 +259,9 @@ pub enum ChorusMode {

#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ChorusParams {
/// Chorus nr
pub nr: u32,
/// Chorus level
pub level: f32,
/// Speed in Hz
pub speed: f32,
Expand All @@ -286,23 +284,13 @@ impl Default for ChorusParams {
}

impl Chorus {
/// Turn on/off the built-in chorus unit
pub fn set_active(&mut self, on: bool) {
self.active = on;
}

/// Check if Chorus is on/off
pub fn active(&self) -> bool {
self.active
}

/// Set the current chorus nr
fn set_nr(&mut self, nr: u32) {
self.new_number_blocks = nr;
}

/// Query the current chorus nr
pub fn nr(&self) -> u32 {
fn nr(&self) -> u32 {
self.number_blocks
}

Expand All @@ -312,7 +300,7 @@ impl Chorus {
}

/// Query the current chorus level
pub fn level(&self) -> f32 {
fn level(&self) -> f32 {
self.level
}

Expand All @@ -322,7 +310,7 @@ impl Chorus {
}

/// Query the current chorus speed (Hz)
pub fn speed_hz(&self) -> f32 {
fn speed_hz(&self) -> f32 {
self.speed_hz
}

Expand All @@ -332,7 +320,7 @@ impl Chorus {
}

/// Query the current chorus depth (mS)
pub fn depth_ms(&self) -> f32 {
fn depth_ms(&self) -> f32 {
self.depth_ms
}

Expand All @@ -342,46 +330,26 @@ impl Chorus {
}

/// Query the current chorus mode
pub fn mode(&self) -> ChorusMode {
fn mode(&self) -> ChorusMode {
self.type_0
}
}

impl Chorus {
// Set up the chorus. It should be turned on with Chorus::set_active().
// If faulty parameters are given, all new settings are discarded.
// Keep in mind, that the needed CPU time is proportional to `nr`.
pub fn set_chorus(&mut self, params: &ChorusParams) {
self.set_chorus_params(
params.nr,
params.level,
params.speed,
params.depth,
params.mode,
);
}

/// Set up the chorus. It should be turned on with Chorus::set_active().
/// If faulty parameters are given, all new settings are discarded.
/// Keep in mind, that the needed CPU time is proportional to `nr`.
pub fn set_chorus_params(
&mut self,
nr: u32,
level: f32,
speed: f32,
depth_ms: f32,
type_0: ChorusMode,
) {
self.set_nr(nr);
self.set_level(level);
self.set_speed_hz(speed);
self.set_depth_ms(depth_ms);
self.set_mode(type_0);
pub fn set_params(&mut self, params: &ChorusParams) {
self.set_nr(params.nr);
self.set_level(params.level);
self.set_speed_hz(params.speed);
self.set_depth_ms(params.depth);
self.set_mode(params.mode);
self.update();
}

/// Query the current chorus params
pub fn get_chorus(&self) -> ChorusParams {
pub fn params(&self) -> ChorusParams {
ChorusParams {
nr: self.nr(),
level: self.level(),
Expand Down
53 changes: 22 additions & 31 deletions oxisynth-reverb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ struct LRPair<T> {

#[derive(Clone)]
pub struct Reverb {
active: bool,

roomsize: f32,
damp: f32,
wet: f32,
Expand All @@ -118,11 +116,15 @@ pub struct Reverb {
allpass: [LRPair<AllPass>; 4],
}

impl Default for Reverb {
fn default() -> Self {
Self::new()
}
}

impl Reverb {
pub fn new(active: bool) -> Self {
pub fn new() -> Self {
let mut rev = Self {
active,

roomsize: 0.5 * 0.28 + 0.7,
damp: 0.2 * 1.0,
wet: 1.0 * 3.0,
Expand Down Expand Up @@ -183,7 +185,7 @@ impl Reverb {
},
],
};
rev.set_reverb(&Default::default());
rev.set_params(&Default::default());
rev
}

Expand Down Expand Up @@ -311,9 +313,13 @@ impl Reverb {

#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ReverbParams {
/// Reverb room size
pub roomsize: f32,
/// Reverb dumping
pub damp: f32,
/// Reverb width
pub width: f32,
/// Reverb level
pub level: f32,
}

Expand All @@ -329,23 +335,13 @@ impl Default for ReverbParams {
}

impl Reverb {
/// Turn on/off the built-in Reverb unit
pub fn set_active(&mut self, on: bool) {
self.active = on;
}

/// Check if Reverb is on/off
pub fn active(&self) -> bool {
self.active
}

/// Set the current reverb room size
fn set_room_size(&mut self, value: f32) {
self.roomsize = value * 0.28 + 0.7;
}

/// Query the current reverb room size
pub fn room_size(&self) -> f32 {
fn room_size(&self) -> f32 {
(self.roomsize - 0.7) / 0.28
}

Expand All @@ -355,7 +351,7 @@ impl Reverb {
}

/// Query the current reverb dumping
pub fn damp(&self) -> f32 {
fn damp(&self) -> f32 {
self.damp / 1.0
}

Expand All @@ -366,7 +362,7 @@ impl Reverb {
}

/// Query the current reverb level
pub fn level(&self) -> f32 {
fn level(&self) -> f32 {
self.wet / 3.0
}

Expand All @@ -376,28 +372,23 @@ impl Reverb {
}

/// Query the current reverb width
pub fn width(&self) -> f32 {
fn width(&self) -> f32 {
self.width
}
}

impl Reverb {
/// Set the parameters for the built-in reverb unit
pub fn set_reverb(&mut self, params: &ReverbParams) {
self.set_reverb_params(params.roomsize, params.damp, params.width, params.level);
}

/// Set the parameters for the built-in reverb unit
pub fn set_reverb_params(&mut self, roomsize: f32, damping: f32, width: f32, level: f32) {
self.set_room_size(roomsize);
self.set_damp(damping);
self.set_width(width);
self.set_level(level);
pub fn set_params(&mut self, params: &ReverbParams) {
self.set_room_size(params.roomsize);
self.set_damp(params.damp);
self.set_width(params.width);
self.set_level(params.level);
self.update();
}

/// Query the current reverb params
pub fn reverb(&self) -> ReverbParams {
pub fn params(&self) -> ReverbParams {
ReverbParams {
roomsize: self.room_size(),
damp: self.damp(),
Expand Down
4 changes: 2 additions & 2 deletions oxisynth/examples/multi_font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ fn synth_sf2() -> Result<(), OxiError> {
let font = SoundFont::load(&mut file).unwrap();
let boom = synth.add_font(font, true);

synth.program_select(0, sin, 0, 0).unwrap();
synth.program_select(1, boom, 0, 0).unwrap();
synth.select_program(0, sin, 0, 0).unwrap();
synth.select_program(1, boom, 0, 0).unwrap();

let mut samples = [0f32; 44100 / 8];

Expand Down
Loading

0 comments on commit c13e923

Please sign in to comment.