Skip to content

Commit

Permalink
play beat in the tracker speed
Browse files Browse the repository at this point in the history
When the tracker was at half speed, the beat still played at full speed.
This is confusing to dance to. Better to only play the relevant beats.
  • Loading branch information
jakmeier committed Sep 5, 2024
1 parent 2658a26 commit 2941b57
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 3 additions & 4 deletions bouncy_frontend/src/lib/components/Audio.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import BackgroundTask from './BackgroundTask.svelte';
import { audioContext, loadAudio, getAudio } from '$lib/stores/Audio';
export let bpm = 120;
export let secondsPerNote = 0.5;
export let isOn = false;
export let voice = false;
let initialized = false;
$: initialized && (isOn ? startAudio() : stopAudio());
$: initialized && bpm && resetAudio();
$: initialized && secondsPerNote && resetAudio();
let countAudioFiles = ['one', 'two', 'three', 'four'];
let andAudioFiles = ['and_0', 'and_1', 'and_2'];
Expand All @@ -24,7 +24,7 @@
let isPlaying = false;
let slowNoteString = ' 1 2 12341234';
let fastNoteString = ' 1 a 2 a 1a2a3a4a1a2a3a4a';
$: noteString = bpm > 109 ? fastNoteString : slowNoteString;
$: noteString = secondsPerNote < 0.55 ? fastNoteString : slowNoteString;
/**
* batches of connected audio nodes that should be disconnected at some point
* @type {AudioBufferSourceNode[][]}
Expand Down Expand Up @@ -145,7 +145,6 @@
function onFrame() {
if (!isPlaying) return;
const secondsPerNote = 30.0 / bpm;
const secondsPerString = noteString.length * secondsPerNote;
while (nextNoteTime < audioContext.currentTime + secondsPerString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
let showReview = false;
let bpm = 132;
let secondsPerNote = 30 / 132;
let useFixedBpm = false;
async function start() {
Expand Down Expand Up @@ -118,6 +119,7 @@
tracker = course.tracker(lessonIndex);
if (tracker) {
tracker.setBpm(bpm);
secondsPerNote = tracker.timeBetweenPoses / 1000;
setContext('tracker', { tracker });
} else {
console.error('could not construct tracker for lesson');
Expand All @@ -128,6 +130,7 @@
function updateBeat() {
if (tracker) {
tracker.setBpm(bpm);
secondsPerNote = tracker.timeBetweenPoses / 1000;
} else {
console.warn('tracker not set');
}
Expand Down Expand Up @@ -236,7 +239,7 @@
</div>
<Audio
{bpm}
{secondsPerNote}
isOn={useFixedBpm && $trackingState !== DetectionState.TrackingDone}
></Audio>
Expand Down

0 comments on commit 2941b57

Please sign in to comment.