resid-rs icon indicating copy to clipboard operation
resid-rs copied to clipboard

sampler bug?

Open sbechet opened this issue 2 years ago • 2 comments

Hello,

To begin, thank you very much for your work! It's a very nice peace of rust code.

I played and wrote some code here using resid-rs.

It seems i found a sampler bug when playing soundfx number : 13, 14 and 16 (all others working):

thread 'main' panicked at 'attempt to subtract with overflow', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/resid-rs-1.1.1/src/envelope.rs:313:25
stack backtrace:
   0: rust_begin_unwind
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/panicking.rs:142:14
   2: core::panicking::panic
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/panicking.rs:48:5
   3: resid::envelope::EnvelopeGenerator::clock_delta
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/resid-rs-1.1.1/src/envelope.rs:313:25
   4: resid::synth::Synth::clock_delta
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/resid-rs-1.1.1/src/synth.rs:95:13
   5: resid::sampler::Sampler::clock_fast
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/resid-rs-1.1.1/src/sampler.rs:150:13
   6: resid::sampler::Sampler::clock
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/resid-rs-1.1.1/src/sampler.rs:126:37
   7: resid::sid::Sid::sample
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/resid-rs-1.1.1/src/sid.rs:160:9
   8: robrs::rhplayer::RhPlayer::sample
             at ./src/rhplayer.rs:617:5
   9: robrs::main
             at ./src/main.rs:61:41
  10: core::ops::function::FnOnce::call_once
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Can you help? Thank you.

sbechet avatar Oct 13 '22 15:10 sbechet

Ok, I have extracted SID registers: voice: (u16, u16, u8, u8, u8) = (freq, pw, cr,ad,sr) [ voice1, voice2, voice3 ]

just after i call sample() fn.

=>

debuging resid-rs: Some( [ (32896, 32896, 128, 128, 128), (32896, 32896, 128, 128, 128), (32896, 32896, 128, 128, 128)] ) thread 'main' panicked at 'attempt to subtract with overflow', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/resid-rs-1.1.1/src/envelope.rs:313:25 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

sbechet avatar Oct 14 '22 17:10 sbechet

Can self.envelope_counter be lesser than 0?

                    State::Release => {
                        // The envelope counter can flip from 0x00 to 0xff by changing state to
                        // attack, then to release. The envelope counter will then continue
                        // counting down in the release state.
                        // This has been verified by sampling ENV3.
                        // NB! The operation below requires two's complement integer.
                        self.envelope_counter -= 1;
                    }

sbechet avatar Oct 14 '22 17:10 sbechet