Code Monkey home page Code Monkey logo

Comments (5)

danigb avatar danigb commented on May 30, 2024 1

It was a bug. Should be fixed in latest version.

from smplr.

danigb avatar danigb commented on May 30, 2024

Hi, this is a sampler based instrument, so you can only pitch the sounds by altering the speed (aka: detune). The only option is to calculate the detune for each note. The idea is to convert a frequency to midi (with decimals) and then select the integer part to choose the note and the float part to detune.

Given this freqToMidi function (taken from tonal):

function freqToMidi(freq: number): number {
  const v = (12 * (Math.log(freq) - Math.log(440)) / Math.log(2) + 69;
  return Math.round(v * 100) / 100;
}

If you want to play a sample a 360Hz then:

freqToMidi(360); => 65.53
instrument.start({ note: 65, detune: 53 });

Hope it helps

from smplr.

alexshenker avatar alexshenker commented on May 30, 2024

Hi, this is a sampler based instrument, so you can only pitch the sounds by altering the speed (aka: detune). The only option is to calculate the detune for each note. The idea is to convert a frequency to midi (with decimals) and then select the integer part to choose the note and the float part to detune.

Given this freqToMidi function (taken from tonal):

function freqToMidi(freq: number): number {
  const v = (12 * (Math.log(freq) - Math.log(440)) / Math.log(2) + 69;
  return Math.round(v * 100) / 100;
}

If you want to play a sample a 360Hz then:

freqToMidi(360); => 65.53
instrument.start({ note: 65, detune: 53 });

Hope it helps

This was helpful, thank you

from smplr.

alexshenker avatar alexshenker commented on May 30, 2024

@danigb I do have a followup question,
Playback works in terms of instrument.start. Any known reason why the detune property wouldn't affect the tone?
I tried it when first setting up the instrument via new Soundfont, and I tried changing it when calling instrument.start(), however the pitch remains the same.
Any ideas?

Thank you

from smplr.

alexshenker avatar alexshenker commented on May 30, 2024

It was a bug. Should be fixed in latest version.

@danigb , It is fixed when using it in instrument.start({ detune: ...}), however, using detune in

new Soundfont(audioCtx, { detune: ...})

Doesn't have an effect it seems.

from smplr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.