From 7373138e3da6b5581788a85da6bb03b1dce2c322 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Fri, 21 Jul 2023 17:46:45 +0200 Subject: [PATCH] improve pitch page --- website/src/components/PitchSlider.jsx | 216 +++++++++++++++++++++++++ website/src/config.ts | 3 + website/src/pages/understand/pitch.mdx | 59 ++++--- 3 files changed, 248 insertions(+), 30 deletions(-) create mode 100644 website/src/components/PitchSlider.jsx diff --git a/website/src/components/PitchSlider.jsx b/website/src/components/PitchSlider.jsx new file mode 100644 index 00000000..4ab961d4 --- /dev/null +++ b/website/src/components/PitchSlider.jsx @@ -0,0 +1,216 @@ +import useEvent from '@strudel.cycles/react/src/hooks/useEvent.mjs'; +import useFrame from '@strudel.cycles/react/src/hooks/useFrame.mjs'; +import { getAudioContext } from '@strudel.cycles/webaudio'; +import { useState, useRef, useEffect } from 'react'; + +let Button = (props) => + )} + {animatable && ( + + )} + {buttons.map((f, i) => ( + + ))} + + + ); +} diff --git a/website/src/config.ts b/website/src/config.ts index d65c54fc..64971466 100644 --- a/website/src/config.ts +++ b/website/src/config.ts @@ -89,6 +89,9 @@ export const SIDEBAR: Sidebar = { { text: 'Accumulation', link: 'learn/accumulation' }, { text: 'Tonal Functions', link: 'learn/tonal' }, ], + Understand: [ + { text: 'Pitch', link: 'understand/pitch' }, + ], Development: [ { text: 'REPL', link: 'technical-manual/repl' }, { text: 'Sounds', link: 'technical-manual/sounds' }, diff --git a/website/src/pages/understand/pitch.mdx b/website/src/pages/understand/pitch.mdx index ef4294dd..7f49a2ab 100644 --- a/website/src/pages/understand/pitch.mdx +++ b/website/src/pages/understand/pitch.mdx @@ -8,64 +8,63 @@ import { PitchSlider } from '../../components/PitchSlider'; # Understanding Pitch -Let's learn how pitch works! But first, let's experience pitch in its rawest form: +Let's learn how pitch works! The slider below controls the frequency of an oscillator, producing a pitch: - +{/* */} + + - Drag the slider to hear a pitch - Move the slider to change the pitch -- Observe how the number on the right changes +- Observe how the Hz number changes -The number on the right is the **frequency** of the pitch you're hearing. +The Hz number is the frequency of the pitch you're hearing. The higher the frequency, the higher the pitch and vice versa. A pitch occurs whenever something is vibrating / oscillating at a frequency, in this case it's your speaker. The unit **Hz** describes how many times that oscillation happens per second. Our eyes are too slow to actually see the oscillation on the speaker, but we can [see it in slow motion](https://www.youtube.com/watch?v=CDMBWw7OuJQ&t=5s). -## Pitch Perception +## Frequency vs Pitch Perception -Maybe you have already noticed that the pitch slider is "lopsided". To make that more obvious, let's automate the slider! -Below are 2 buttons for automation, try them out: +Maybe you have already noticed that the frequency slider is "lopsided", +meaning the pitch changes more in the left region and less in the right region. +To make that more obvious, let's add a pitch slider +that controls the frequency on a different scale: - + -There are 2 different colored lines: +Try out the buttons above to sweep through the frequency range in 2 different ways: -- blue: the frequency value -- yellow: the pitch value or how you perceive the frequency - -Depending on the type of sweep, the lines behave differently: - -- Frequency Sweep: frequency is linear , pitch is logarithmic -- Pitch Sweep: frequency is exponential , pitch is linear +- Frequency Sweep: frequency rises linear , pitch rises logarithmic +- Pitch Sweep: frequency rises exponential , pitch rises linear Don't be scared of these mathematical terms: - "logarithmic" is just a fancy way of saying "it starts fast and slows down" - "exponential" is just a fancy way of saying "it starts slow and gets faster" -## A Pitch Slider +Most of the time, we might want to control pitch in a way that matches our perception, +which is what the pitch slider does. -Most of the time, we might want to control pitch in a way that matches our perception. -Now that we know that frequency in Hz does not match our perception, -let's make the slider exponential (and yellow): +## From Hz to Semitones - - -- Do you see how the slider is now linked to the yellow line? -- Try out the buttons again and compare it to the frequency slider above - -## A unit for Pitch - -Let's try to find a linear unit for pitch, as frequency won't cut it. +Because Hz does not match our perception, let's try to find a unit for pitch that matches. To approach that unit of pitch, let's look at how frequency behaves when it is doubled: - + +- Use the now stepped pitch slider above - Can you hear how these pitches seem related to each other? - +In mathematical terms, the frequency of button `n` would be `50Hz * 2^n` (n starting from 0). +We could already use that `n` as a pitch unit! So a value of 0 would relate to a certain base frequency (50Hz), +and each whole number step would be an additional doubling of 2. +In musical terms, a pitch with double the frequency of another is an `octave` higher. + +Because octaves are pretty far apart, octaves are typically divided into 12 equal parts: + + ## Definition