[chuck-users] playing SndBuf backward

Perry Cook prc at cs.princeton.edu
Wed Feb 12 17:04:13 EST 2020


It is playing backward from 0, to 0, so it does nothing.  You have to set .pos
to .samples() (point to the end, so it can play backward).

In the example, you’d need to advance time to let it play forward:

mySndBuf.samples() :: samp => now; // you’d hear it play forward

then set rate to -1, then advance time again to hear it backward.

PRC

Looking at our book, I see that you didn’t copy all the lines.  You’ve
got to advance time to hear anything in ChucK.  

// 4.3 Playing sounds in reverse
// by ChucK Programmer 4102, yluJ #A

SndBuf mySound => dac;

me.dir()+"/audio/hihat_04.wav" => mySound.read; #1

mySound.samples() => int numSamples; #2

// play sound once forward
0 => mySound.pos;
numSamples :: samp => now; #3

// and once backward
numSamples => mySound.pos; #4
-1.0 => mySound.rate; #5
numSamples :: samp => now;


> On Feb 12, 2020, at 1:30 PM, chuck-users-request at lists.cs.princeton.edu wrote:
> 
> Send chuck-users mailing list submissions to
> 	chuck-users at lists.cs.princeton.edu
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> 	https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
> or, via email, send a message with subject or body 'help' to
> 	chuck-users-request at lists.cs.princeton.edu
> 
> You can reach the person managing the list at
> 	chuck-users-owner at lists.cs.princeton.edu
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of chuck-users digest..."
> 
> 
> Today's Topics:
> 
>   1. Re: playing SndBuf backward (Perry Cook)
>   2. Error in book "Programming for Musicians and digital artists
>      by Ge Wang" ? (herman verbaeten)
>   3. playing SndBuf backward (herman verbaeten)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Wed, 12 Feb 2020 12:58:36 -0800
> From: Perry Cook <prc at cs.princeton.edu>
> To: chuck-users at lists.cs.princeton.edu
> Subject: Re: [chuck-users] playing SndBuf backward
> Message-ID: <6DBAE4AC-7E7E-413D-8059-8CB929B9AC78 at cs.princeton.edu>
> Content-Type: text/plain; charset=utf-8
> 
> You can set the .pos to wherever you like, and set the .rate to a negative number.  The sample will happily play backward to zero and stick there (unless you have .loop set).
> 
> PRC
> 
> Sent from my iPad
> 
>> On Feb 12, 2020, at 9:00 AM, chuck-users-request at lists.cs.princeton.edu wrote:
>> 
>> ?Send chuck-users mailing list submissions to
>>   chuck-users at lists.cs.princeton.edu
>> 
>> To subscribe or unsubscribe via the World Wide Web, visit
>>   https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>> or, via email, send a message with subject or body 'help' to
>>   chuck-users-request at lists.cs.princeton.edu
>> 
>> You can reach the person managing the list at
>>   chuck-users-owner at lists.cs.princeton.edu
>> 
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of chuck-users digest..."
>> 
>> 
>> Today's Topics:
>> 
>>  1. Re: => now (herman verbaeten)
>> 
>> ----------------------------------------------------------------------
>> 
>> Message: 1
>> Date: Tue, 11 Feb 2020 18:11:09 +0000
>> From: herman verbaeten <hverb54 at hotmail.com>
>> To: ChucK Users Mailing List <chuck-users at lists.cs.princeton.edu>
>> Subject: Re: [chuck-users] => now
>> Message-ID:
>>   <AM0PR08MB389035F6190B1D2C897C097BA5180 at AM0PR08MB3890.eurprd08.prod.outlook.com>
>> 
>> Content-Type: text/plain; charset="iso-8859-1"
>> 
>> Thanks again Mario,
>> 
>> I have another question:
>> Can you recommend a procedure to address individual samples of a wave-file you read into the SndBuf.
>> I discovered a way to play a part of a wave file starting at a certain point using ".pos".
>> I also wonder if there's a way to play it backwards (reverse).
>> 
>> Cheers,
>> 
>> herman
>> 
>> 
>> 
>> _______________________________
> 
> 
> 
> 
> ------------------------------
> 
> Message: 2
> Date: Wed, 12 Feb 2020 21:15:51 +0000
> From: herman verbaeten <hverb54 at hotmail.com>
> To: chuck mailing list <chuck-users at lists.cs.princeton.edu>
> Subject: [chuck-users] Error in book "Programming for Musicians and
> 	digital artists by Ge Wang" ?
> Message-ID:
> 	<AM0PR08MB38900B846EE7C57D44869411A51B0 at AM0PR08MB3890.eurprd08.prod.outlook.com>
> 	
> Content-Type: text/plain; charset="iso-8859-1"
> 
> Hi,
> 
> I was looking in your book and copied listing 4.3 " Playing a sound file backward"
> But it didn't work. Hopefully i did everything correctly. It did perform the first (forward) part but during the reverse part i heard nothing. Can you please help me....
> 
> Kind regards,
> 
> Herman
> 
> 
> // copy Listing 4.3 Playing a sound file backward
> // from Programming for Musicians and digital artists by Ge Wang
> 
> me.sourceDir() + "sample.wav" => string filename;
> if( me.args() ) me.arg(0) => filename;
> 
> // the patch
> SndBuf mySound => dac;
> 
> // load the file in buf
> filename => mySound.read;
> 
> mySound.samples() => int numSamples;
> 
> 0 => mySound.pos;                  // this was ok
> numSamples::samp => now;
> 
> numSamples => mySound.pos;     // This was not heard. Athough the program stayed in VM.
> -1.0 => mySound.rate;
> numSamples::samp => now;
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20200212/622aecd2/attachment-0001.html>
> 
> ------------------------------
> 
> Message: 3
> Date: Wed, 12 Feb 2020 21:29:59 +0000
> From: herman verbaeten <hverb54 at hotmail.com>
> To: ChucK Users Mailing List <chuck-users at lists.cs.princeton.edu>
> Subject: [chuck-users] playing SndBuf backward
> Message-ID:
> 	<AM0PR08MB3890357CDD692F4A42A2BC9DA51B0 at AM0PR08MB3890.eurprd08.prod.outlook.com>
> 	
> Content-Type: text/plain; charset="utf-8"
> 
> 
> Sorry PRC it doesn't work: When i set "buf.rate" to 1.0 and  "buf.pos"  to 0,  it does but not the other way around....
> 
> 
> me.sourceDir() + "aeiou.wav" => string filename;
> if( me.args() ) me.arg(0) => filename;
> 
> SndBuf buf => dac;
> 
> filename => buf.read;
> 
> buf.length() => dur totalelengte;
> buf.samples() => int samples;
> 
> samples => buf.pos;
> -1.0 => buf.rate;
> 
> samples::ms => now;
> 
> ________________________________
> Van: chuck-users-bounces at lists.cs.princeton.edu <chuck-users-bounces at lists.cs.princeton.edu> namens Perry Cook <prc at cs.princeton.edu>
> Verzonden: woensdag 12 februari 2020 20:58
> Aan: chuck-users at lists.cs.princeton.edu <chuck-users at lists.cs.princeton.edu>
> Onderwerp: Re: [chuck-users] playing SndBuf backward
> 
> You can set the .pos to wherever you like, and set the .rate to a negative number.  The sample will happily play backward to zero and stick there (unless you have .loop set).
> 
> PRC
> 
> Sent from my iPad
> 
>> On Feb 12, 2020, at 9:00 AM, chuck-users-request at lists.cs.princeton.edu wrote:
>> 
>> ?Send chuck-users mailing list submissions to
>>   chuck-users at lists.cs.princeton.edu
>> 
>> To subscribe or unsubscribe via the World Wide Web, visit
>>   https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>> or, via email, send a message with subject or body 'help' to
>>   chuck-users-request at lists.cs.princeton.edu
>> 
>> You can reach the person managing the list at
>>   chuck-users-owner at lists.cs.princeton.edu
>> 
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of chuck-users digest..."
>> 
>> 
>> Today's Topics:
>> 
>>  1. Re: => now (herman verbaeten)
>> 
>> ----------------------------------------------------------------------
>> 
>> Message: 1
>> Date: Tue, 11 Feb 2020 18:11:09 +0000
>> From: herman verbaeten <hverb54 at hotmail.com>
>> To: ChucK Users Mailing List <chuck-users at lists.cs.princeton.edu>
>> Subject: Re: [chuck-users] => now
>> Message-ID:
>>   <AM0PR08MB389035F6190B1D2C897C097BA5180 at AM0PR08MB3890.eurprd08.prod.outlook.com>
>> 
>> Content-Type: text/plain; charset="iso-8859-1"
>> 
>> Thanks again Mario,
>> 
>> I have another question:
>> Can you recommend a procedure to address individual samples of a wave-file you read into the SndBuf.
>> I discovered a way to play a part of a wave file starting at a certain point using ".pos".
>> I also wonder if there's a way to play it backwards (reverse).
>> 
>> Cheers,
>> 
>> herman
>> 
>> 
>> 
>> _______________________________
> 
> 
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20200212/b97a132a/attachment.html>
> 
> ------------------------------
> 
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
> 
> 
> End of chuck-users Digest, Vol 174, Issue 14
> ********************************************



More information about the chuck-users mailing list