Hi, Just to follow up on this, I was using audio files with a different sample rate and that was obviously causing trouble. When dealing with stereo files, both in SndBuf and SndBuf2 samples are accessed in frames: ``` buffer[0] = sample 0 left channel buffer[1] = sample 0 right channel buffer[2] = sample 1 left channel ... ``` The only thing that could be a bit misleading is that .samples() doesn't return the actual number of samples, but number of samples per channel. Looking at the source code (ugen_xxx.cpp - row 770) I found the documentation for .samples() says: "Total number of sample in frames in the file" Thus what .samples() returns is technically correct, but I'm wondering couldn't this be a bit confusing? Maybe not and I should have just checked that out. Might be one for the SndBuf example. Cheers, Mario On 16/06/2021 17:03, Dana Batali wrote:
Hi Mario , I’m not at my computer right now, but wonder if you’ve tried SndBuf2?
On Wed, Jun 16, 2021 at 8:57 AM mario buoninfante
mailto:mario.buoninfante@gmail.com> wrote: Hi,
I'm working on an algorithm that requires accessing samples from a stereo file and am using SndBuf to achieve that. I was expecting that to work so that samples were returned in "frames", for example:
'''
buffer.valueAt(0) = sample 0 on left channel
buffer.valueAt(1) = sample 0 on right channel
buffer.valueAt(2) = sample 1 on left channel
buffer.valueAt(3) = sample 1 on right channel
...
'''
but that doesn't seem to be the case.
Also SndBuf.samples() always returns the same amount of samples, regardless the file being mono or stereo (the size matches the time in msec, so it seems that reports the size of a single channel).
I also played around with .channel(n), but I get the same set of samples regardless the channel number used.
Then I just now found out that basically the channels seem to be stored (or at least accessed) sequentially. Let's say you have a stereo file containing 1024 samples (512 per channel), you get:
samples 0-511 = left channel
samples 512-1023 = right channel
I was wondering if my assumption is correct, but also if this is intentional.
Cheers,
Mario
-- musician, QA engineer http://mbuoninfante.tumblr.com/ http://mbuoninfante.tumblr.com/ https://vimeo.com/creativecodingsalerno https://vimeo.com/creativecodingsalerno https://github.com/mariobuoninfante https://github.com/mariobuoninfante
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu mailto:chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-- musician, QA engineer http://mbuoninfante.tumblr.com/ https://vimeo.com/creativecodingsalerno https://github.com/mariobuoninfante