Skip to content

Commit

Permalink
various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilymilovidov committed Sep 26, 2023
1 parent 9606ce0 commit 69a3e27
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 148 deletions.
8 changes: 2 additions & 6 deletions packages/desktopbridge/webaudiobridge.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ export const desktopAudio = async (value, deadline, hapDuration) => {
if (bank && s) {
s = `${bank}_${s}`;
}
let map = getSound(s).data.samples;

if (freq !== undefined && note !== undefined) {
logger('[sampler] hap has note and freq. ignoring note', 'warning');
}
Expand All @@ -86,13 +84,12 @@ export const desktopAudio = async (value, deadline, hapDuration) => {
transpose = midi - 36;
let sampleUrl;
let baseUrl;
if (s === 'sine' || s === 'square' || s === 'saw' || s === 'triangle') {
if (s === 'sine' || s === 'square' || s === 'saw' || s === 'sawtooth' || s === 'triangle') {
sampleUrl = 'none';
} else {
let path;
if (getSound(s).data.baseUrl !== undefined) {
baseUrl = getSound(s).data.baseUrl;
console.log('baseUrl', baseUrl);
if (baseUrl === './piano/') {
path = 'https://strudel.tidalcycles.org/';
} else if (baseUrl === './EmuSP12/') {
Expand All @@ -101,7 +98,7 @@ export const desktopAudio = async (value, deadline, hapDuration) => {
path = '';
}
}

let map = getSound(s).data.samples;
if (Array.isArray(map)) {
sampleUrl =
path !== undefined ? path + map[n % map.length].replace('./', '') : map[n % map.length].replace('./', '');
Expand All @@ -114,7 +111,6 @@ export const desktopAudio = async (value, deadline, hapDuration) => {
(closest, key, j) => (!closest || Math.abs(midiDiff(key)) < Math.abs(midiDiff(closest)) ? key : closest),
null,
);
console.log('closest', closest);
transpose = -midiDiff(closest); // semitones to repitch
sampleUrl =
path !== undefined
Expand Down
149 changes: 29 additions & 120 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ midir = "0.9.1"
tokio = { version = "1.29.0", features = ["full"] }
rosc = "0.10.1"
web-audio-api = { git = "https://github.com/orottier/web-audio-api-rs.git", branch = "main" }
mini-moka = "0.10.2"
reqwest = "0.11.20"
quick_cache = "0.4.0"

[features]
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.
Expand Down
22 changes: 12 additions & 10 deletions src-tauri/src/superdough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,18 @@ pub struct FilterADSR {
pub env: f64,
}


pub fn superdough_sample(message: &WebAudioMessage, context: &mut AudioContext, audio_buffer: AudioBuffer) {
pub fn superdough_sample(
message: &WebAudioMessage,
context: &mut AudioContext,
audio_buffer: AudioBuffer,
) {
let now = context.current_time();
let mut chain: Vec<&dyn AudioNode> = Vec::new();
let compressor = context.create_dynamics_compressor();
compressor.connect(&context.destination());
compressor.threshold().set_value(-50.0);
let delay = context.create_delay(1.);
// Play synth or sample


// Create nodes for sample playback
// let audio_buffer = context.decode_audio_data_sync(file).unwrap();
let audio_buffer_duration = audio_buffer.duration();
let mut src = context.create_buffer_source();
src.set_buffer(audio_buffer);
Expand All @@ -92,15 +91,18 @@ pub fn superdough_sample(message: &WebAudioMessage, context: &mut AudioContext,
}


pub fn superdough_synth(message: &WebAudioMessage, context: &mut AudioContext) {
pub fn superdough_synth(
message: &WebAudioMessage,
context: &mut AudioContext,

) {
let now = context.current_time();
let mut chain: Vec<&dyn AudioNode> = Vec::new();
let compressor = context.create_dynamics_compressor();
compressor.connect(&context.destination());
compressor.threshold().set_value(-50.0);
let env = context.create_gain();
let delay = context.create_delay(1.);
// Play synth or sample

let osc = context.create_oscillator();
// Create nodes for synth playback
Expand Down Expand Up @@ -139,7 +141,6 @@ fn create_delay(message: &WebAudioMessage, context: &mut AudioContext, env: &Gai
delay.connect(&feedback);

let pre_gain = context.create_gain();
// pre_gain.gain().set_value_at_time(0.0, now);
pre_gain.gain().set_value_at_time(message.delay.wet, now + message.delay.delay_time as f64);
pre_gain.connect(&feedback);

Expand Down Expand Up @@ -170,6 +171,7 @@ fn create_osc_type(message: &WebAudioMessage) -> OscillatorType {
"square" => OscillatorType::Square,
"triangle" => OscillatorType::Triangle,
"saw" => OscillatorType::Sawtooth,
"sawtooth" => OscillatorType::Sawtooth,
_ => panic!("Invalid oscillator type"),
}
}
Expand Down Expand Up @@ -295,7 +297,7 @@ fn apply_adsr(
.set_value_at_time(0.0, now)
.linear_ramp_to_value_at_time(message.velocity, now + attack)
.exponential_ramp_to_value_at_time(
sustain * message.velocity,
(sustain + 0.00001) * message.velocity,
now + attack + decay,
)
.set_value_at_time(sustain * message.velocity, now + message.duration)
Expand Down
Loading

0 comments on commit 69a3e27

Please sign in to comment.