Skip to content

Commit

Permalink
fix: ranges & db value
Browse files Browse the repository at this point in the history
  • Loading branch information
fcastrovilli committed Apr 6, 2024
1 parent 7fb7ff1 commit d387a88
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/lib/colors.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
import type { voiceType } from './types';
export let voice: voiceType;
let valueInDb: number = -Infinity;
$: {
valueInDb = 20 * Math.log10(value);
valueInDb = Math.max(valueInDb, -3);
}
let osc: Tone.Oscillator | undefined = undefined;
// let touchStart: number = 0;
let value: number = -100;
Expand All @@ -25,18 +19,21 @@
<button
on:touchstart={(e) => {
// touchStart = e.changedTouches[0].clientX;
if (osc) osc.start();
if (osc) {
osc.start();
osc.volume.value = -100;
}
}}
on:touchmove={(e) => {
const touch = e.changedTouches[0];

const touchX = touch.clientX;
const screenCenter = window.innerWidth / 2;
value = Math.min(
Math.max(Math.round(((touchX - screenCenter) / screenCenter) * 50 - 60), -100),
Math.max(Math.round(((touchX - screenCenter) / screenCenter) * 50 - 80), -100),
0
);
if (osc) osc.volume.linearRampTo(value, 0.1);
if (osc) osc.volume.linearRampTo(value, 0.3);
}}
class="flex justify-center items-center"
>
Expand Down

0 comments on commit d387a88

Please sign in to comment.