Skip to content

Commit

Permalink
Improvements maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
spessasus committed Sep 21, 2023
1 parent d99ccee commit a61eba5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 20 deletions.
10 changes: 4 additions & 6 deletions src/spessasynth_lib/synthetizer/buffer_voice/midi_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import {Voice} from "./voice.js";
import {Preset} from "../../soundfont/chunk/presets.js";
import { consoleColors } from '../../utils/other.js'
import { midiControllers } from '../../midi_parser/midi_message.js'
import { DEFAULT_GAIN } from '../synthetizer.js'

const CHANNEL_LOUDNESS = 0.5;


const dataEntryStates = {
Idle: 0,
RPCoarse: 1,
Expand Down Expand Up @@ -57,12 +55,12 @@ export class MidiChannel {
gain: CHANNEL_LOUDNESS
});


// note -> panner -> gain -> out
// \-> chorus -> delay -/
this.panner.connect(this.gainController);
this.gainController.connect(this.outputNode);


this.chorusController = new GainNode(this.ctx, {
gain: 0
});
Expand Down Expand Up @@ -233,7 +231,7 @@ export class MidiChannel {

setExpression(val)
{
val = Math.min(1, val);
//val = Math.min(1, val);
this.channelExpression = val;
this.updateGain();
}
Expand Down Expand Up @@ -370,8 +368,8 @@ export class MidiChannel {
{
if(this.vibrato.delay === 0 && this.vibrato.rate === 0 && this.vibrato.depth === 0)
{
this.vibrato.depth = 30;
this.vibrato.rate = 6;
this.vibrato.depth = 50;
this.vibrato.rate = 8;
this.vibrato.delay = 0.6;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ export class SynthesisModel
{
/**
* Creates a new instance of a single sample
* @param synthesisOptions {GeneratorTranslator}
* @param sampleAndGenerators {SampleAndGenerators}
* @param midiNote {number}
* @param outputNode {AudioNode}
* @param tuningRatio {number}
* @param velocity {number}
* @param vibratoDepth {number} in cents
*/
constructor(synthesisOptions, outputNode, tuningRatio, velocity, vibratoDepth) {
constructor(sampleAndGenerators, midiNote, outputNode, tuningRatio, velocity, vibratoDepth) {
const synthesisOptions = new GeneratorTranslator(sampleAndGenerators, midiNote, velocity);
const context = outputNode.context;
const sample = synthesisOptions.sample;
const offsets = synthesisOptions.getAddressOffsets();
Expand Down Expand Up @@ -232,7 +234,7 @@ export class SynthesisModel
// filter too
if(this.lowpassFilter) {
this.lowpassFilter.frequency.setValueAtTime(this.lowpassFilter.frequency.value, this.now);
this.lowpassFilter.frequency.linearRampToValueAtTime(this.filEnv.endHz, this.now + this.filEnv.releaseTime);
this.lowpassFilter.frequency.exponentialRampToValueAtTime(this.filEnv.endHz, this.now + this.filEnv.releaseTime);
}

if(!this.wavetableOscillator.loop)
Expand Down
4 changes: 2 additions & 2 deletions src/spessasynth_lib/synthetizer/buffer_voice/voice.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Preset} from "../../soundfont/chunk/presets.js";
import {GeneratorTranslator} from "./generator_translator.js";
import { SynthesisModel } from './synthesis_model.js'

export class Voice
Expand Down Expand Up @@ -48,7 +47,8 @@ export class Voice
*/
this.sampleNodes = samples.map(samAndGen => {
const sm = new SynthesisModel(
new GeneratorTranslator(samAndGen, midiNote, targetVelocity),
samAndGen,
midiNote,
node,
this.tuningRatio,
this.velocity,
Expand Down
9 changes: 1 addition & 8 deletions src/spessasynth_lib/synthetizer/synthetizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,12 @@ export class Synthetizer {
*/
this.system = "gm2";

/**
* @type {WorkletChannel[]}
*/
this.midiChannels = [];

this.defaultPreset = this.soundFont.getPreset(0, 0);
this.percussionPreset = this.soundFont.getPreset(128, 0);

// create 16 channels
for (let j = 0; j < 16; j++) {
// default to the first preset
this.midiChannels[j] = new MidiChannel(this.volumeController, this.defaultPreset, j + 1, false);
}
this.midiChannels = [...Array(16).keys()].map(j => new MidiChannel(this.volumeController, this.defaultPreset, j + 1, false));

// change percussion channel to the percussion preset
this.midiChannels[DEFAULT_PERCUSSION].percussionChannel = true;
Expand Down
2 changes: 1 addition & 1 deletion src/website/ui/synthesizer_ui/synthetizer_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export class SynthetizerUI
const expression = new Meter(this.channelColors[channelNumber],
"Expression: ",
0,
127,
256,
true,
val => {
this.synth.controllerChange(channelNumber, midiControllers.expressionController, val);
Expand Down

0 comments on commit a61eba5

Please sign in to comment.