Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
run: bash -c "$(curl https://fireflyzero.com/install.sh)"

- name: Setup MoonBit
uses: hustcer/setup-moonbit@1522f9aef02a8ca0187dfc00a41f5dd6b16750f7 # v1.23
uses: hustcer/setup-moonbit@87e2bdf5cf20d3b6f5c5f266a8a513f503bb5b76 # v1.25

- name: Update MoonBit package registry
run: moon update
Expand Down
44 changes: 22 additions & 22 deletions src/audio/node.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -38,43 +38,43 @@ pub trait Node {
///|
/// Add sine wave oscillator source (`∿`).
impl Node with fn add_sine(self, freq : Hz, phase : Float) -> Sine {
Sine::{ id: @ffi.audio_add_sine(self.id(), freq, phase) }
Sine::{ id: @ffi.audio_add_sine(self.id(), freq, phase), }
}

///|
/// Add square wave oscillator source (`⎍`).
impl Node with fn add_square(self, freq : Hz, phase : Float) -> Square {
Square::{ id: @ffi.audio_add_square(self.id(), freq, phase) }
Square::{ id: @ffi.audio_add_square(self.id(), freq, phase), }
}

///|
/// Add sawtooth wave oscillator source (`╱│`).
impl Node with fn add_sawtooth(self, freq : Hz, phase : Float) -> Sawtooth {
Sawtooth::{ id: @ffi.audio_add_sawtooth(self.id(), freq, phase) }
Sawtooth::{ id: @ffi.audio_add_sawtooth(self.id(), freq, phase), }
}

///|
/// Add triangle wave oscillator source (`╱╲`).
impl Node with fn add_triangle(self, freq : Hz, phase : Float) -> Triangle {
Triangle::{ id: @ffi.audio_add_triangle(self.id(), freq, phase) }
Triangle::{ id: @ffi.audio_add_triangle(self.id(), freq, phase), }
}

///|
/// Add white noise source (amplitude on each tick is random).
impl Node with fn add_noise(self, seed : Int) -> Noise {
Noise::{ id: @ffi.audio_add_noise(self.id(), seed) }
Noise::{ id: @ffi.audio_add_noise(self.id(), seed), }
}

///|
/// Add always stopped source.
impl Node with fn add_empty(self) -> Empty {
Empty::{ id: @ffi.audio_add_empty(self.id()) }
Empty::{ id: @ffi.audio_add_empty(self.id()), }
}

///|
/// Add silent source producing zeros.
impl Node with fn add_zero(self) -> Zero {
Zero::{ id: @ffi.audio_add_zero(self.id()) }
Zero::{ id: @ffi.audio_add_zero(self.id()), }
}

///|
Expand All @@ -94,91 +94,91 @@ impl Node with fn add_file(self, path : @firefly.Utf8View) -> File {
///|
/// Add node simply mixing all inputs.
impl Node with fn add_mix(self) -> Mix {
Mix::{ id: @ffi.audio_add_mix(self.id()) }
Mix::{ id: @ffi.audio_add_mix(self.id()), }
}

///|
/// Add mixer node that stops if any of the sources stops.
impl Node with fn add_all_for_one(self) -> AllForOne {
AllForOne::{ id: @ffi.audio_add_all_for_one(self.id()) }
AllForOne::{ id: @ffi.audio_add_all_for_one(self.id()), }
}

///|
/// Add gain control node.
impl Node with fn add_gain(self, level : Float) -> Gain {
Gain::{ id: @ffi.audio_add_gain(self.id(), level) }
Gain::{ id: @ffi.audio_add_gain(self.id(), level), }
}

///|
/// Add a loop node that resets the input if it stops.
impl Node with fn add_loop(self) -> Loop {
Loop::{ id: @ffi.audio_add_loop(self.id()) }
Loop::{ id: @ffi.audio_add_loop(self.id()), }
}

///|
/// Add a node that plays the inputs one after the other, in the order as they added.
impl Node with fn add_concat(self) -> Concat {
Concat::{ id: @ffi.audio_add_concat(self.id()) }
Concat::{ id: @ffi.audio_add_concat(self.id()), }
}

///|
/// Add node panning the audio to the left (0.), right (1.), or something in between.
impl Node with fn add_pan(self, level : Float) -> Pan {
Pan::{ id: @ffi.audio_add_pan(self.id(), level) }
Pan::{ id: @ffi.audio_add_pan(self.id(), level), }
}

///|
/// Add node that can be muted using modulation.
impl Node with fn add_mute(self) -> Mute {
Mute::{ id: @ffi.audio_add_mute(self.id()) }
Mute::{ id: @ffi.audio_add_mute(self.id()), }
}

///|
/// Add node that can be paused using modulation.
impl Node with fn add_pause(self) -> Pause {
Pause::{ id: @ffi.audio_add_pause(self.id()) }
Pause::{ id: @ffi.audio_add_pause(self.id()), }
}

///|
/// Add node tracking the elapsed playback time.
impl Node with fn add_track_position(self) -> TrackPosition {
TrackPosition::{ id: @ffi.audio_add_track_position(self.id()) }
TrackPosition::{ id: @ffi.audio_add_track_position(self.id()), }
}

///|
/// Add lowpass filter node.
impl Node with fn add_low_pass(self, freq : Hz, q : Float) -> LowPass {
LowPass::{ id: @ffi.audio_add_low_pass(self.id(), freq, q) }
LowPass::{ id: @ffi.audio_add_low_pass(self.id(), freq, q), }
}

///|
/// Add highpass filter node.
impl Node with fn add_high_pass(self, freq : Hz, q : Float) -> HighPass {
HighPass::{ id: @ffi.audio_add_high_pass(self.id(), freq, q) }
HighPass::{ id: @ffi.audio_add_high_pass(self.id(), freq, q), }
}

///|
/// Add node converting stereo to mono by taking the left channel.
impl Node with fn add_take_left(self) -> TakeLeft {
TakeLeft::{ id: @ffi.audio_add_take_left(self.id()) }
TakeLeft::{ id: @ffi.audio_add_take_left(self.id()), }
}

///|
/// Add node converting stereo to mono by taking the right channel.
impl Node with fn add_take_right(self) -> TakeRight {
TakeRight::{ id: @ffi.audio_add_take_right(self.id()) }
TakeRight::{ id: @ffi.audio_add_take_right(self.id()), }
}

///|
/// Add node swapping left and right channels of the stereo input.
impl Node with fn add_swap(self) -> Swap {
Swap::{ id: @ffi.audio_add_swap(self.id()) }
Swap::{ id: @ffi.audio_add_swap(self.id()), }
}

///|
/// Add node clamping the input amplitude. Can be used for hard distortion.
impl Node with fn add_clip(self, low : Float, high : Float) -> Clip {
Clip::{ id: @ffi.audio_add_clip(self.id(), low, high) }
Clip::{ id: @ffi.audio_add_clip(self.id(), low, high), }
}

///|
Expand Down
50 changes: 49 additions & 1 deletion src/audio/nodes.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ pub impl Node for Out with fn id(_self) -> UInt {
return 0
}

///|
pub extend Out with Node::{id}

///|
/// The output audio node. Mixes all inputs and plays them on the device's speaker.
pub let out : Out = Out::{ }
pub let out : Out = Out::{ }

///|
/// A marker for a specific node type. See `Node::add_mix`.
Expand All @@ -21,6 +24,9 @@ pub impl Node for Mix with fn id(self) -> UInt {
return self.id
}

///|
pub extend Mix with Node::{id}

///|
/// A marker for a specific node type. See `Node::add_all_for_one`.
struct AllForOne {
Expand All @@ -32,6 +38,9 @@ pub impl Node for AllForOne with fn id(self) -> UInt {
return self.id
}

///|
pub extend AllForOne with Node::{id}

///|
/// A marker for a specific node type. See `Node::add_gain`.
struct Gain {
Expand All @@ -43,6 +52,9 @@ pub impl Node for Gain with fn id(self) -> UInt {
return self.id
}

///|
pub extend Gain with Node::{id}

///|
/// A marker for a specific node type. See `Node::add_loop`.
struct Loop {
Expand All @@ -54,6 +66,9 @@ pub impl Node for Loop with fn id(self) -> UInt {
return self.id
}

///|
pub extend Loop with Node::{id}

///|
/// A marker for a specific node type. See `Node::add_concat`.
struct Concat {
Expand All @@ -65,6 +80,9 @@ pub impl Node for Concat with fn id(self) -> UInt {
return self.id
}

///|
pub extend Concat with Node::{id}

///|
/// A marker for a specific node type. See `Node::add_pan`.
struct Pan {
Expand All @@ -76,6 +94,9 @@ pub impl Node for Pan with fn id(self) -> UInt {
return self.id
}

///|
pub extend Pan with Node::{id}

///|
/// A marker for a specific node type. See `Node::add_mute`.
struct Mute {
Expand All @@ -87,6 +108,9 @@ pub impl Node for Mute with fn id(self) -> UInt {
return self.id
}

///|
pub extend Mute with Node::{id}

///|
/// A marker for a specific node type. See `Node::add_pause`.
struct Pause {
Expand All @@ -98,6 +122,9 @@ pub impl Node for Pause with fn id(self) -> UInt {
return self.id
}

///|
pub extend Pause with Node::{id}

///|
/// A marker for a specific node type. See `Node::add_track_position`.
struct TrackPosition {
Expand All @@ -109,6 +136,9 @@ pub impl Node for TrackPosition with fn id(self) -> UInt {
return self.id
}

///|
pub extend TrackPosition with Node::{id}

///|
/// A marker for a specific node type. See `Node::add_low_pass`.
struct LowPass {
Expand All @@ -120,6 +150,9 @@ pub impl Node for LowPass with fn id(self) -> UInt {
return self.id
}

///|
pub extend LowPass with Node::{id}

///|
/// A marker for a specific node type. See `Node::add_high_pass`.
struct HighPass {
Expand All @@ -131,6 +164,9 @@ pub impl Node for HighPass with fn id(self) -> UInt {
return self.id
}

///|
pub extend HighPass with Node::{id}

///|
/// A marker for a specific node type. See `Node::add_take_left`.
struct TakeLeft {
Expand All @@ -142,6 +178,9 @@ pub impl Node for TakeLeft with fn id(self) -> UInt {
return self.id
}

///|
pub extend TakeLeft with Node::{id}

///|
/// A marker for a specific node type. See `Node::add_take_right`.
struct TakeRight {
Expand All @@ -153,6 +192,9 @@ pub impl Node for TakeRight with fn id(self) -> UInt {
return self.id
}

///|
pub extend TakeRight with Node::{id}

///|
/// A marker for a specific node type. See `Node::add_swap`.
struct Swap {
Expand All @@ -164,6 +206,9 @@ pub impl Node for Swap with fn id(self) -> UInt {
return self.id
}

///|
pub extend Swap with Node::{id}

///|
/// A marker for a specific node type. See `Node::add_clip`.
struct Clip {
Expand All @@ -175,6 +220,9 @@ pub impl Node for Clip with fn id(self) -> UInt {
return self.id
}

///|
pub extend Clip with Node::{id}

///|
/// Modulate the gain level.
pub fn[Mod : Modulator] Gain::modulate(
Expand Down
Loading