WebMSX icon indicating copy to clipboard operation
WebMSX copied to clipboard

Why is CHANNEL_VOLUME_CURVE_POWER = 30?

Open leo-hydraulic opened this issue 1 year ago • 9 comments

This is more just a question than a bug, but there was no "Discussion" section in the project. Maybe add comments as a fix?

I was wondering where did the value of 30 come from in modeling the volume curve for the PSG: https://github.com/ppeccin/WebMSX/blob/master/src/main/msx/audio/PSGAudio.js#L292

I notice it's a simple exponential formula, was just wondering why choose 30 as the base. I tried tracking previous commits, and the value used to be 16, and changed to 30 without comments. I wonder, is this just an aesthetic change because it "sounds good", or is that taken from a datasheet, or oscilloscope measurements, etc?

I've been doing a few experiments with MSX audio myself, and I've been taking WebMSX as a source of information and inspiration. Great project, and thanks!

leo-hydraulic avatar Dec 31 '23 14:12 leo-hydraulic

It is a bug!

Webmsx plays terribly psg samples, until now I though it was caused by the fact that it's a javascript-based emulator. However its because of a incorrect volume-table being used.

function createVolumeCurve() { for (var v = 0; v < 16; v++) volumeCurve[v] = (Math.pow(CHANNEL_VOLUME_CURVE_POWER, v / 15) - 1) / (CHANNEL_VOLUME_CURVE_POWER - 1) * CHANNEL_MAX_VOLUME; }

When the code is changed into (below).... the psg samples are being played correctly!

function createVolumeCurve() { for (var v = 1; v < 16; v++) volumeCurve[v] = Math.pow(2, -(15-v)/2) * CHANNEL_MAX_VOLUME; }

more info: https://map.grauw.nl/articles/psg_sample.php

example video (error and fixed): https://github.com/ppeccin/WebMSX/assets/19953254/95d99242-d132-465b-bd0a-8f58e4ecd897

inchl avatar Jan 22 '24 16:01 inchl

Hi!

Hum... That's interesting... I will do some testing and fix that for the next release! Thanks for the report and the solution! :-)

Can you point me to the games or software you were using when you detected the problem?

Paulo

On Mon, Jan 22, 2024 at 1:10 PM Stephan Smetsers @.***> wrote:

It is a bug!

Webmsx plays terribly psg samples, until now I though it was caused by the fact that it's a javascript-based emulator. However its because of a incorrect volume-table being used.

function createVolumeCurve() { for (var v = 0; v < 16; v++) volumeCurve[v] = (Math.pow(CHANNEL_VOLUME_CURVE_POWER, v / 15) - 1) / (CHANNEL_VOLUME_CURVE_POWER - 1) * CHANNEL_MAX_VOLUME; }

When the code is changed into (below).... the psg samples are being played correctly!

function createVolumeCurve() { for (var v = 1; v < 16; v++) volumeCurve[v] = Math.pow(2, -(15-v)/2) * CHANNEL_MAX_VOLUME; }

more info: https://map.grauw.nl/articles/psg_sample.php

https://github.com/ppeccin/WebMSX/assets/19953254/95d99242-d132-465b-bd0a-8f58e4ecd897

— Reply to this email directly, view it on GitHub https://github.com/ppeccin/WebMSX/issues/102#issuecomment-1904330852, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFOLIDU37XLMRRWISNSZTTYP2FPPAVCNFSM6AAAAABBIJRO7KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBUGMZTAOBVGI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

ppeccin avatar Jan 23 '24 20:01 ppeccin

Hi Stephan,

I applied your changes to the createVolumeCurve() and tried https://nopmsx.nl/wp-content/uploads/2023/10/KingsValleyEnhanced9811ASCII16.zip, but that doesn't seem to sound fully correct still (compared to OpenMSX) ?

Am I doing something wrong perhaps or is there still some difference in emulation that possibly needs to be addressed ?

NullPointerReference avatar Mar 13 '24 11:03 NullPointerReference

Will check later this day. I fixed the sound by correcting the volumes (using the browser debugger) in the appropriate variables used by the replay routine of webmsx. Not sure if the function mentioned is the correct place to calculate the correct volumes. I tried to fix the filehunter website by providing them with a fixed function, but that also did not solve the problem. Anyway... I will look into this later this day and get back to you!

inchl avatar Mar 13 '24 12:03 inchl

Might be this: In javascript arrays are not initliazed... So manually setting volumeCurve[0] = 0 is required (for loops starts at 1). Index 0 cannot be calculated with the formula. Must be 0!

inchl avatar Mar 13 '24 13:03 inchl

I tested with index 0 explicitly set to 0 too, as I noticed it to ('empty'); it didn't help (much) :)

NullPointerReference avatar Mar 13 '24 13:03 NullPointerReference

Haha... Try changing the closure variables during playback / during a running webmsx.... Setting all 16 as they should be... Then it works!

inchl avatar Mar 13 '24 13:03 inchl

@ppeccin: @inchl, @TFHFony and I tested the (by @inchl) proposed curve - with the additional 'volumeCurve[0] = 0' - extensively and also put it on file-hunter.com for 'public' testing for about a month. We think it solves this audio-emulation issue and has no further negative impact. The complete snipplet is as follows, no additional changes outside mentioned code required.

function createVolumeCurve() { volumeCurve[0] = 0; for (let v = 1; v < 16; v++) volumeCurve[v] = Math.pow(2, -(15-v)/2) * CHANNEL_MAX_VOLUME; }

NullPointerReference avatar Apr 22 '24 14:04 NullPointerReference