Skip to content

Commit 58e8c4f

Browse files
committed
Fix volume calculation
ryohey/signal#419
1 parent 556e8ae commit 58e8c4f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/src/processor/SynthProcessorCore.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class SynthProcessorCore {
9595
for (const sample of samples) {
9696
const oscillator = new WavetableOscillator(sample, this.sampleRate)
9797

98-
const volume = velocity / 0x80
98+
const volume = velocity / 127
9999
oscillator.noteOn(pitch, volume)
100100

101101
if (state.oscillators[pitch] === undefined) {
@@ -151,12 +151,12 @@ export class SynthProcessorCore {
151151

152152
setMainVolume(channel: number, value: number) {
153153
const state = this.getChannelState(channel)
154-
state.volume = value / 0x80
154+
state.volume = value / 127
155155
}
156156

157157
expression(channel: number, value: number) {
158158
const state = this.getChannelState(channel)
159-
state.expression = value / 0x80
159+
state.expression = value / 127
160160
}
161161

162162
allSoundsOff(channel: number) {
@@ -210,7 +210,7 @@ export class SynthProcessorCore {
210210

211211
modulation(channel: number, value: number) {
212212
const state = this.getChannelState(channel)
213-
state.modulation = value / 0x80
213+
state.modulation = value / 127
214214
}
215215

216216
resetChannel(channel: number) {

lib/src/processor/WavetableOscillator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class WavetableOscillator {
6464

6565
const speed =
6666
(this.baseSpeed * this.speed * this.sample.sampleRate) / this.sampleRate
67-
const volume = this.velocity * this.volume * this.sample.volume
67+
const volume = (this.velocity * this.volume) ** 2 * this.sample.volume
6868

6969
// zero to pi/2
7070
const panTheta =

0 commit comments

Comments
 (0)