Skip to content

p5.sound's midiToFreq() allows microtonality (decimal MIDI notes) #7455

Open
@thrly

Description

@thrly

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

1.11.1

Web browser and version

Firefox 133.0.3

Operating system

Windows 11

Steps to reproduce this

Steps:

  1. Decimal numbers in midiToFreq() return microtonal values, because they're not rounded first.
  2. This is actually a pretty cool feature, and allows some creative possibilites (microtonal music!), but it might be unexpected for some because the reference implies the value should be an integer MIDI note number:

General MIDI treats notes as integers where middle C is 60, C# is 61, D is 62 etc. Useful for generating musical frequencies with oscillators.

Rather than 'fix' this, adding a note to the reference description along the lines of 'Decimal values return microtonal frequencies.' Might clarify that those values won't be rounded to equal temperament tuning, but keep a pretty cool, if unexpected, feature?

Snippet:

  console.log(midiToFreq(60)); // returns 261.6255653005986 (Hz) = C4
  console.log(midiToFreq(60.5)); // returns 269.2917795270241 = C4 quarter-sharp!
  console.log(midiToFreq(61)); // returns 277.1826309768721 = C#4

I'd be happy to add this note to the reference if it's accepted.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions