Skip to content

Commit

Permalink
fixed #271
Browse files Browse the repository at this point in the history
  • Loading branch information
ellvix committed Nov 14, 2023
1 parent 55e5ba5 commit 45ff9dc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/js/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ class Audio {
/**
* Plays a tone based on the current chart type and position.
*/
playTone() {
playTone(params = null) {
let currentDuration = constants.duration;
let volume = constants.vol;
if (params != null) {
if (params.volScale != null) {
volume = params.volScale * constants.vol;
}
}

let rawPanning = 0;
let rawFreq = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/js/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class Constants {
MAX_FREQUENCY = 1000;
MIN_FREQUENCY = 200;
NULL_FREQUENCY = 100;
combinedVolMin = 0.25; // volume for min amplitude combined tones
combinedVolMax = 1.25; // volume for max amplitude combined tones

// autoplay speed
MAX_SPEED = 500;
Expand Down
13 changes: 12 additions & 1 deletion src/js/segmented.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,20 @@ class Segmented {
);
} else {
// sonifMode == 'same', so we play all at once

// adjust these volumes by amplitude, min 50% max 125%
let volMin = Math.min(...this.plotData[position.x][position.y]);
let volMax = Math.max(...this.plotData[position.x][position.y]);
for (let i = 0; i < this.plotData[position.x][position.y].length; i++) {
position.z = i;
audio.playTone();
let vol = audio.SlideBetween(
this.plotData[position.x][position.y][i],
volMin,
volMax,
constants.combinedVolMin,
constants.combinedVolMax
);
audio.playTone({ volScale: vol });
}
}
} else {
Expand Down

0 comments on commit 45ff9dc

Please sign in to comment.