-
Notifications
You must be signed in to change notification settings - Fork 220
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
Speakers "squeal" when given values not equal to 0
#1907
Comments
0
CC:T re-encodes audio to DFPWM when sending it from the client to the server. DFPWM uses a single bit per sample, and due to its design, isn't very good at holding a constant value at higher amplitudes. We can use the local dfpwm = require "cc.audio.dfpwm"
local audio = {}
for i = 1, 1024 do audio[i] = -127 end
local resampled = dfpwm.decode(dfpwm.encode(audio))
print(table.concat(resampled, " ", #resampled - 8))
-- -122 -125 -81 -45 -79 -102 -115 -122 -125 This should correspond to your plots in audacity. As mentioned, DFPWM isn't very good at sustaining high amplitudes. That said, I'm a little surprised it fluctuates as much as it does — I'd need to plot some of the encoder internals to see what's going on. |
Oh, I see! Thank you for the explanation. I initially thought that speakers supported "true" PCM audio because of this quote on the
This is partially true, since |
Plotting the various bits of encoder/decoder state, we can see what's going on here: Inside the DFPWM encoder/decoder, "charge" effectively models the output of the decoder (before the low-pass filter and antijerk is applied), while "strength" is used to control the rate at which the charge changes. When we see a sample that differs to the current charge, the strength increases until it reaches the sample, at which point it decreases. Well, that's what's meant to happen. However, what actually happens is that we hit the desired value exactly, and so the strength increases more and more, causing the charge to flail more and more around the target value. I'm not actually sure there's a good fix in the encoder/decoder here. Have documented this for now (7285c32), and have a bit more of a think. |
Minecraft Version
1.20.1
Version
1.111.0
Details
When given samples above or below
0
, the speaker starts playing a really obnoxious, extremely high-pitched noise.I initially spotted this when trying to synthesize sawtooth waves, but I reduced the code to just this:
What I discovered:
0
seem to reduce this noise's volume.0
, it does not appear to be playing at all.-128
or127
, the speaker also seems to be completely silent.Video demonstration of this code (volume warning):
https://github.com/user-attachments/assets/9803764d-65d7-4848-99f0-67138e17eca6
Plot of the squeal, put into Audacity for inspection:
Ditto, but with the script changed to output
126
constantly:The reason why I even spotted this is because the code below, which produces a sawtooth wave, seemed to have very prominent resonance, even though that was never programmed in:
Plot of audio produced in-game:
Below is plot of a sawtooth signal produced at the same frequency (50Hz):
The expected behavior is for speakers to:
The text was updated successfully, but these errors were encountered: