Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FluidSynth (via jzz-synth-fluid) stops playing after about 300-400 notes on Rpi, more on Mac #95

Open
donundeen opened this issue Jun 20, 2024 · 0 comments

Comments

@donundeen
Copy link

[Note: I posted this issue on the jzz-fluid-synth repo, but it's the only issue there, so maybe this is the more appropriate place to post it? https://github.com/jazz-soft/JZZ-synth-Fluid/issues/1 ]

Hi,
I'm running this library with fluidsynth on both an RPi and a Mac.

I'm struggling with the fact that after some number of notes, the synth stops playing, but doesn't give any error messages.

on an RPI, it stop between 300 and 400 notes.
on my Mac, it stops between 2000 and 3000 notes

Also of note is that the system doesn't fail with any error.

Below is some code the reproduces the error for me:



var JZZ = require('jzz');
require('jzz-synth-fluid')(JZZ);

let env = "mac"; // or "rpi"

let soundfont = './soundfonts/GeneralUserGS/GeneralUserGS.sf2'
let fluidpath = '/usr/bin/fluidsynth';
let arg_a = "pulseaudio";
let args = ["a", arg_a];
if(env == "mac"){
    fluidpath = '/opt/homebrew/bin/fluidsynth';
    soundfont = '/Users/donundeen/Documents/htdocs/icanmusicprojects/server/soundfonts/GeneralUserGS/GeneralUserGS.sf2'
    arg_a = "coreaudio";
    args = ["a", arg_a];
}

let numnotes = 100; // make this number larger for more notes at once (a cluster of notes)
let interval = 100; // how often (in milliseconds) to play each "cluster"
let synth = JZZ.synth.Fluid({ path: fluidpath, 
                sf: soundfont,
                args: args }).or(function(){console.log("some problem starting!")});

setInterval(function(){
    play_notes(numnotes);   
}, interval);

let global_count = 0;
function play_notes(numnotes){
    console.log("playnotes");
    let i = 0;
    while(i < numnotes){
        global_count++;
        console.log(global_count+ "********************************************** " + global_count);
        let note = Math.floor(Math.random() * 127);
        let velocity = Math.floor(Math.random() * 70)+ 50;
        let voice = Math.floor(Math.random() * 100);
        let duration = Math.floor(Math.random() * 200) + 25;
        let channel = Math.floor(Math.random() * 10);
        makenote(channel, voice, note, velocity, duration );
        i++;
    }
}

function makenote(channel, instrument, pitch, velocity, duration){
    console.log("playing note "+ channel + ", " + pitch +","+velocity+","+duration);
    synth.program(channel, instrument)
    .noteOn(channel, pitch, velocity)
    .wait(duration)
    .noteOff(channel,pitch).or(function(msg){
        console.log("some problem! " + msg); // this never is printed
    });
}

I've found that if I count notes, and re-create the synth object before I hit the limit, it will continue to play. But it kill all playing note and creates a pause, which musically isn't great.

I've also noticed that if i DON'T call the .program line, eg


function makenote(channel, instrument, pitch, velocity, duration){
    console.log("playing note "+ channel + ", " + pitch +","+velocity+","+duration);
    synth
    //.program(channel, instrument)
    .noteOn(channel, pitch, velocity)
    .wait(duration)
    .noteOff(channel,pitch).or(function(msg){
        console.log("some problem! " + msg); // this never is printed
    });
}

Then I get about 700 notes on the RPi intead of 400.

If anyone has ideas on what a solution might be, or how to get more insight into how see what's goign on underneath the hood, that would be amazing, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant