-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I2S sound harsh artifacts #196
Comments
Honestly, can't remember what that was about... I will have a play with your suggestion. I've just corrected an issue with the pwm audio.. the smoothed beeper is signed now but I hadn't updated other parts of the code to reflect it. |
I thought the idea was to scale the volume around virtual centre, so I tried to rewrite it as such:
This also sounds good, but I don't think it's perfectly right. In order to offset everything to zero we need to center each individual component before mixing.
But in practice this doesn't seem to have any benefit compared to the simpler version above, sounds alright though. |
Just tried: |
The simple unsigned version worked well for me too. I'm slightly worried that there's sine if the dynamic range lost somewhere, or if it would flip if AY and beeper play at the same time. PCM5100 expects 2's complement, so it's signed. When sending unsigned data, we must stay within 15 bits or risk some harsh noises when bit 15 becomes 1. Say, if all inputs are -128..127 signed, 4 inputs, max range would be [-4128..4127] = [-512..508]. There's a << 4 so [-8192..8128]. I don't know what the _vol range is. It's probably 0..255 because there's >> 8 after multiplication. So [-8192 * 255..8128 * 255], well within 32-bit integer range. In fact, we're well too low on the scale after shifting >> 8 and could have >> 6, the values will stay in range [-32640..32385]. I'm going to test this later. |
I'm on this branch at the moment... This is working nicely for me:
...which is just a slight optimisation of your earlier simple version. |
That version works but it's very quiet. Could the distortion happen because the beeper is signed in that branch? int32_t is = s - 128; // this is not needed if s is already signed and centered around 0 |
That's what I wondered. I tried taking out the -128 and it did not help... but I am really guessing here... really I should get a log of the numbers being produced! |
...how does this sound...
|
More or less the same, it's fine I guess. Have you tried producing a ramp just to see what kind of range does the DAC take and if it matches the expectations? I'm having a hard time doing that somehow. I thought I'd just count some number and write it to ll/rr, but I'm seeing some garbage on the output. |
Does it glitch about half way? |
Hmm, I wonder if the values are signed...
This works suspiciously well for me. |
The bit where it just jumps about is weird, that really should not happen. Maybe add a delay in your ramp at 0 so we can see where it is. |
I've just realised that my PCM5102 board has a jumper switch for FMT, which has been set to Left-Justified all of this time. This might explain the discrepancies between our results. Do you know how your DAC is configured? |
I'm using a Pimoroni Pico DV Demo Base, which has a 5100A, fmt, fit, demp to gnd, xsmt to vcc (3.3v) |
...and yes, your ramp looks unsigned. |
Sadly, my scope has recently failed on me... but to be fair it was made in 1969. I need to look into a replacement. |
I2S sound with PCM5102 produces harsh and extremely loud noises. I think these 2 lines may be the culprit:
pico-zxspectrum/src/ZxSpectrumAudio.cpp
Lines 288 to 289 in 75f0396
What is the reason for the second term in the expression here? All the inputs and result are unsigned and the expression underflows for a wide range of input values. I'm not sure what should be expected here but it doesn't look right.
I tried removing the second term and everything sounds great without it. However I don't know why it was written that way and perhaps on some devices this is the right thing to do.
Exolon is always a good test, but I can also recommend a dedicated sound test (attached).
AY_YM_TS_test_v02.ZIP
The text was updated successfully, but these errors were encountered: