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

Sampler or Player? #1182

Open
syfenx opened this issue Apr 22, 2023 · 1 comment
Open

Sampler or Player? #1182

syfenx opened this issue Apr 22, 2023 · 1 comment

Comments

@syfenx
Copy link

syfenx commented Apr 22, 2023

I've basically went through hell and back trying to figure out my issue here, I started with a Sampler connected to a Channel, controlling it via Sequence, animating via Draw (I've used divs, canvas and now svg since I thought this was a graphics issue). The entire time I've used this sampler set up, it works to an extent but fails when a lot of sounds are loaded and sequenced (30-40 sounds for a drum machine).

If I use a Sampler I have access to triggerAttack but if I use a Player I do not? The main issue is that if I load 30-40 Samplers I experience drops/lags/stuttering but If I do the exact same thing with a Player it's so much faster, it doesn't even seem to lag with very high BPM.

What makes a Sampler so much different than a Player when loading so many sounds? Is it possible to use a Sampler but each sound is considered its own track/pattern/fx?

I would greatly appreciate a push in the right direction...

This is what I've got:

export class Track {
  constructor(name, sample_file, patternLength, color, trackIndex) {
    this.trackId = nanoid();
    this.baseDir = "./samples";
    this.patternLength = patternLength;
    this.pattern = [];
    this.blocks = [];
    this.trackColor = color;
    this.trackIndex = trackIndex;
    this.name = name;
    this.sample_file = sample_file;
    this.volume = -3;
    this.pan = 0;

    this.fx = [];

    this.channel = new Tone.Channel(this.volume, this.pan).toDestination();

    this.path = `${this.baseDir}/${this.sample_file}`;
    this.player = new Tone.Player(this.path).connect(this.channel);
    // this.sampler = new Tone.Sampler({
    //   urls: {
    //     C1: `${this.baseDir}/${this.sample_file}`,
    //   },
    // }).connect(this.channel);

    this.createInitialPattern();

    this.seq = new Tone.Sequence((time, item) => {
      this.channel.volume.value = item.velocity;
      if(item.velocity === 1){
        this.player.start(time);
      }
      // console.log(item.velocity);
    }, this.pattern, '16n');

  }

  createInitialPattern() {
    for (let i = 0; i < this.patternLength; i++) {
      let eventItem = { time: `0:0:${i}n`, note: "C1", velocity: 0 };
      this.pattern.push(eventItem);
    }
  }
}
@yishengjiang99
Copy link

Pretty sure you can connect player to an envelope as well. It’s not built in like sampler so it’s an connnected note

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

2 participants