Skip to content

fix(spectroscope): zero-pad fft samples to expected size - #24

Open
dotacow wants to merge 1 commit into
alemidev:devfrom
dotacow:spectroscope-fix
Open

fix(spectroscope): zero-pad fft samples to expected size#24
dotacow wants to merge 1 commit into
alemidev:devfrom
dotacow:spectroscope-fix

Conversation

@dotacow

@dotacow dotacow commented Jul 25, 2026

Copy link
Copy Markdown

First of all, thanks for making this project, it earned a place in my terminal, it is very neat & nice to look at, I also want to learn more about DSP and this is a great output of doing that.

fixes a panic that occurs when not using the PulseAudio backend

I initially ran the program

./target/debug/scope-tui audio # I also tried matching buffer size with -b512,2048, etc.,  didn't seem to help, expected size just kept changing to passed size/2

then when I tabbed my way to the spectroscope view:

o/registry/src/index.crates.io-1949cf8c6b5b557f/rustfft-6.3.0/src/common.rs:19:5:
Provided FFT buffer was too small. Expected len = 2048, got len = 512
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I recreated the panic with gdb running, found the culprit at src/display/spectroscope.rs:163, so I just prefixed it with a check that zero-pads the tmp buffer to match the expected sample size.

I explain my process because I don't know much about the Linux audio stack, so I don't know why the accumulated buffer doesn't match the expected size, but I suspect it may be because PulseAudio protects us from this failure by automatically padding the audio peripheral queue to reach 2048 samples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant