[CM] make-sampler vs. open

2023-12-08 Thread James Hearon
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-boun...@ccrma.stanford.edu  on 
behalf of cmdist-requ...@ccrma.stanford.edu 
Sent: Thursday, December 7, 2023 10:00 AM
To: cmdist@ccrma.Stanford.EDU 
Subject: Cmdist Digest, Vol 187, Issue 1

Send Cmdist mailing list submissions to
cmdist@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-requ...@ccrma.stanford.edu

You can reach the person managing the list at
cmdist-ow...@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 +
From: James Hearon 
To: "cmdist@ccrma.Stanford.EDU" 
Subject: [CM] make-sampler vs. open
Message-ID:



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@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist


End of Cmdist Digest, Vol 187, Issue 1
**
___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist


Re: [CM] make-sampler vs. open

2023-12-07 Thread bil

I'd need to see you sampler code to see what the problem
is, but this sequence works:

;; write a square-wave to test.snd
(with-sound (:output "test.snd" :to-snd #f)
  (let ((g (make-square-wave 440.0)))
(do ((i 0 (+ i 1)))
((= i 44100))
  (outa i (square-wave g)

;; read it using a sampler
(let* ((snd (open-sound "test.snd"))
   (sampler (make-sampler 0 snd 0)))
  (with-sound (:output "test1.snd")
(do ((i 0 (+ i 1)))
((= i 44100))
  (outa i (read-sample sampler)

;; filter it using fft-filtering
(let* ((len (mus-sound-framples "test1.snd"))
   (fsize (expt 2 (ceiling (log len 2
   (rdata (make-float-vector fsize))
   (idata (make-float-vector fsize)))
  (file->array "test1.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 "test2.snd"
   (float-vector-scale! rdata (/ 1.0 fsize))
   len
   44100 ;(srate "oboe.snd")
   1)

  (open-sound "test2.snd"))

load this into snd and you should see the 3 files.  If they
appear to be all ones, move the graph slider to show a
smaller portion of the file.  File:Open is probably
showing only a small portion of the file in its initial
window -- I think the variable that sets that is initial-dur
which defaults to .1 seconds.


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


[CM] make-sampler vs. open

2023-12-07 Thread James Hearon
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
___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist