[CM] make-sampler vs. open

James Hearon j_hearon at hotmail.com
Fri Dec 8 09:42:01 PST 2023


Hi,
Yes.  Snd's make-square-wave works great.
I took another look at my code and figured out the problem was not reading from make-sampler, but my trying to get the maxval of the sampler's output to see what was going wrong.

I was using (set! maxval (float-vector-max (float-vector-abs! im))) and didn't realize float-vector-abs! was setting all the values to absolute value.  I thought it was just getting the abs value.  So for a square wave that's deadly.

My fault.
Thank you,
Jim

________________________________
From: cmdist-bounces at ccrma.Stanford.EDU <cmdist-bounces at ccrma.Stanford.EDU> on behalf of cmdist-request at ccrma.Stanford.EDU <cmdist-request at ccrma.Stanford.EDU>
Sent: Thursday, December 7, 2023 10:00 AM
To: cmdist at ccrma.Stanford.EDU <cmdist at ccrma.Stanford.EDU>
Subject: Cmdist Digest, Vol 187, Issue 1

Send Cmdist mailing list submissions to
        cmdist at ccrma.stanford.edu

To subscribe or unsubscribe via the World Wide Web, visit
        https://cm-mail.stanford.edu/mailman/listinfo/cmdist
or, via email, send a message with subject or body 'help' to
        cmdist-request at ccrma.stanford.edu

You can reach the person managing the list at
        cmdist-owner at ccrma.stanford.edu

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Cmdist digest..."


Today's Topics:

   1. make-sampler vs. open (James Hearon)


----------------------------------------------------------------------

Message: 1
Date: Thu, 7 Dec 2023 18:12:56 +0000
From: James Hearon <j_hearon at hotmail.com>
To: "cmdist at ccrma.Stanford.EDU" <cmdist at ccrma.Stanford.EDU>
Subject: [CM] make-sampler vs. open
Message-ID:
        <SN7PR07MB9651B77F7DC22E6F046B1521E58BA at SN7PR07MB9651.namprd07.prod.outlook.com>

Content-Type: text/plain; charset="iso-8859-1"

Hi,
I was trying to use make-sampler, but having a problem opening (read-sample) a non-bandlimited square wav effectively.  Snd's Open menu function works fine, but the make-sampler approach gives a max'd out flat line which seems like it might be an aliasing problem? I tried low-pass filtering with make-sample without much success.

Instead I was tweaking this code below from spectrum as an fft filter for file based bandlimiting.  Reason being most of what I was doing is outside the editor, or file-based manipulation before the sound gets opened in the editor.  The result is better than before but I'm still not seeing anything resembling a square wav yet with make-sampler and read-sample.  I also tried some peak limiting on amplitudes, but still no joy.

I'm wondering what might be the difference with Snd's file Open and why it works so well vs. the lower level approach of make-sampler, and read-sample, or what might be a better way to approach those pesky non-bandlimited snds?

(let* ((len (mus-sound-framples "oboe.snd"))
       (fsize (expt 2 (ceiling (log len 2))))
       (rdata (make-float-vector fsize))
       (idata (make-float-vector fsize)))
  (file->array "oboe.snd" 0 0 len rdata)
  (mus-fft rdata idata fsize 1)
  (let ((fsize2 (/ fsize 2))
        (cutoff (round (/ fsize 10))))
    (do ((i cutoff (+ i 1))
         (j (- fsize 1) (- j 1)))
        ((= i fsize2))
      (set! (rdata i) 0.0)
      (set! (idata i) 0.0)
      (set! (rdata j) 0.0)
      (set! (idata j) 0.0)))
  (mus-fft rdata idata fsize -1)
  (array->file "test.snd"
               (float-vector-scale! rdata (/ 1.0 fsize))
               len
               (srate "oboe.snd")
               1)
  (let ((previous-case (find-sound "test.snd")))
    (if (sound? previous-case)
        (close-sound previous-case)))
  (open-sound "test.snd"))

Regards,
Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/pipermail/cmdist/attachments/20231207/c01c70b0/attachment-0001.html>

------------------------------

_______________________________________________
Cmdist mailing list
Cmdist at ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist


End of Cmdist Digest, Vol 187, Issue 1
**************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/pipermail/cmdist/attachments/20231208/9e6d4f4e/attachment.html>


More information about the Cmdist mailing list