[CM] misbehavior in functions to shift and stretch regions

David O'Toole deeteeoh1138 at gmail.com
Wed Aug 28 08:39:57 PDT 2019


I have these functions which work fine in snd 18.1 but produce errors
in snd 19.6 ... SHIFT-REGION uses EXPSRC to return a pitch-shifted
version of the region you give it. STRETCH-REGION uses EXPANDN to
return a time-stretched version of the region it gets.  Both functions
below (and their corresponding error messages in snd 19.6) are below.
The whole batch file is at
https://gitlab.com/dto/mosaic-el/blob/master/mosaic.scm and this just
needs a suitable input filename toward the bottom of the file if you
want to try debugging it. (Give it a minute or two of music.)

I would greatly appreciate any insight or suggestions you might be
able to provide, as I would like to continue developing this code in
the latest Snd and get more involved. This "mosaic.scm" is part of a
library of functions to specify rearrangements of beats and melodies
in ways inspired by vaporwave and/or "chopped and screwed" music. The
basic operating procedure of mosaic.scm is inspired by "soundmosaic"
although I haven't implemented the analysis/matching portion yet. But
in the meantime I'm getting some interesting rhythms :)

Here is SHIFT-REGION:

(define* (shift-region region factor)
  (let ((new-region '())
(new-sound (new-sound :channels 2 :srate 44100 :file (snd-tempnam))))
    (insert-region region 0 new-sound #f)
    (map-channel (expsrc factor) 0 (framples region) new-sound 0)
    (map-channel (expsrc factor) 0 (framples region) new-sound 1)
    (set! new-region (make-region 0 (framples region) new-sound #t))
    (close-sound new-sound)
    new-region))

---------------OUTPUT FROM SHIFT-REGION in snd 19.6--------
----snippets removed---
(shift-region #<region 0> 0.66) -> #<region 254>
(shift-region #<region 4> 0.66) -> #<region 255>
(shift-region #<region 8> 0.66) -> attempt to apply a free cell <free
cell! type: free-cell? (0), opt_op: 0, flags: #x0> to (#<region 8>
0.66) in <free cell! type: free-cell? (0), opt_op: 0, flags: #x0>?
-----------------------------------------------------------

Now here is STRETCH-REGION.

(define* (stretch-region region factor)
  (let* ((new-region '())
(temp-1 (snd-tempnam))
(temp-2 (snd-tempnam))
(new-sound (new-sound :channels 2 :srate 44100 :file temp-2))
(len (floor (* factor (framples region)))))
    (save-region region temp-1)
    (with-sound (:output temp-2)
(expandn 0 (* factor (samples->seconds (framples region)))
temp-1
0.6
:expand factor
:ramp 0.2
:seglen (* 0.7 *mosaic-slice-size*)
:hop (* 0.1 *mosaic-slice-size*)
:amp-env '(0 1 100 1)))
    (save-sound new-sound)
    (select-sound new-sound)
    (set! new-region (make-region 0 (- len 1) new-sound #t))
    (close-sound new-sound)
    new-region))

------OUTPUT FROM STRETCH-REGION in snd 19.6
----snippets removed----
>(stretch-region #<region 0> 2) -> #<region 254>
>(stretch-region #<region 4> 2) -> attempt to apply a real 0.0 to (#<region 4> 2) in 0.0?
----------------------------------
On another occasion (different ordering of events), it produced this:
----------------------------------------------------
(stretch-region #<region 4> 2) -> attempt to apply a slot (variable
binding) 'vol 0.6000000000000001 to (#<region 4> 2) in 'vol
0.6000000000000001?

Also even in snd 18.1 there are problems. Apparently if you shift and
then stretch the same region, it segfaults. How can I get a proper
backtrace?

Thank you.


More information about the Cmdist mailing list