byulparan / cl-collider

A SuperCollider client for CommonLisp
Other
218 stars 23 forks source link

`buffer-get-to-list` error: Invalid range requested #108

Closed TatriX closed 3 years ago

TatriX commented 3 years ago

Hi! Consider the following code:

(defconstant +sample-rate+ (parse-integer (uiop:run-program "jack_samplerate" :output :string))) ; 48000
(defvar *b* (buffer-alloc (* 1 +sample-rate+)))
(buffer-fill *b* :sine (list 1))
(buffer-write *b* "/tmp/foo.wav") ; works fine, Audacity shows nice sine wave
(buffer-get-to-list *b*)

buffer-get-to-list gives me the following error:

Invalid range requested (START (48000) must be greater than END (48000)).
   [Condition of type SIMPLE-ERROR]

Restarts:
 0: [CONTINUE] Retry assertion with new values for CL-COLLIDER::START, CL-COLLIDER::END.
 1: [RETRY] Retry SLY interactive evaluation request.
 2: [*ABORT] Return to SLY's top level.
 3: [ABORT] abort thread (#<THREAD "slynk-worker" RUNNING {1006FCF503}>)

Backtrace:
 0: (SB-KERNEL:ASSERT-ERROR (> CL-COLLIDER::END CL-COLLIDER::START) 2 CL-COLLIDER::END 48000 CL-COLLIDER::START 48000 (CL-COLLIDER::START CL-COLLIDER::END) "Invalid range requested (START (~a) must be gre..
 1: (BUFFER-GETN #<CL-COLLIDER::BUFFER :server #<CL-COLLIDER::EXTERNAL-SERVER cl-collider-0.0.0.0:4444> :bufnum 0 :frames 48000 :channels 1 :samplerate 48000.0 :path NIL> 48000 48000 NIL)
 2: (BUFFER-GET-TO-LIST #<CL-COLLIDER::BUFFER :server #<CL-COLLIDER::EXTERNAL-SERVER cl-collider-0.0.0.0:4444> :bufnum 0 :frames 48000 :channels 1 :samplerate 48000.0 :path NIL> :START 0 :END NIL)
 3: (SB-INT:SIMPLE-EVAL-IN-LEXENV (BUFFER-GET-TO-LIST *B*) #<NULL-LEXENV>)
 4: (EVAL (BUFFER-GET-TO-LIST *B*))
 5: ((LAMBDA NIL :IN SLYNK:INTERACTIVE-EVAL))
 --more--

@defaultxr it seems like a +1 error?

TatriX commented 3 years ago

Replacing :upto with :below in https://github.com/byulparan/cl-collider/blob/4f7544ecd0ff4ab5901756d2cf853530fe1328d7/buffer.lisp#L186 seems to fix it.

defaultxr commented 3 years ago

Oops, thanks for finding that; another bug I introduced with the recent changes, and yes it looks like your fix is correct. I'll submit a PR with the correction shortly.