Quantcast

PlayBuf negative rate

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

PlayBuf negative rate

Andrea Valle
Dear, 

I had already noticed this. Looks like negative rate is broken in PlayBuf.

On my machine (OS X with SC 3.8) this works

{PlayBuf.ar(1, b,1)}.play

This does not

{PlayBuf.ar(1, b,-1)}.play

(b is a buffer)


Thanks

Best

-a-




--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - StudiUm
Università degli Studi di Torino
--> http://www.cirma.unito.it/andrea/
--> http://www.fonurgia.unito.it/andrea/
--> http://www.flickr.com/photos/vanderaalle/sets/
--> http://vimeo.com/vanderaalle
--> [hidden email]
--------------------------------------------------

"This is a very complicated case, Maude. You know, a lotta ins, a lotta outs, a lotta what-have-yous." 
(Jeffrey 'The Dude' Lebowski)

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PlayBuf negative rate

Donald Craig
Hi,

If you set loop to 1, it will play. The default values are startPos at 0 and no loop,
so with a negative rate, the 'play head' is already at the end. if you want no loop,
then you need to set startPos to the end of your buffer.

Don

On Wed, May 10, 2017 at 8:20 AM, <[hidden email]> wrote:
Dear, 

I had already noticed this. Looks like negative rate is broken in PlayBuf.

On my machine (OS X with SC 3.8) this works

{PlayBuf.ar(1, b,1)}.play

This does not

{PlayBuf.ar(1, b,-1)}.play

(b is a buffer)


Thanks

Best

-a-




--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - StudiUm
Università degli Studi di Torino
--> http://www.cirma.unito.it/andrea/
--> http://www.fonurgia.unito.it/andrea/
--> http://www.flickr.com/photos/vanderaalle/sets/
--> http://vimeo.com/vanderaalle
--> [hidden email]
--------------------------------------------------

"This is a very complicated case, Maude. You know, a lotta ins, a lotta outs, a lotta what-have-yous." 
(Jeffrey 'The Dude' Lebowski)


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PlayBuf negative rate

Stefano_Catena
Hi,

it doesn't work for me neither on 3.8!
I had to use this workaround with the following synthdef

SynthDef(\buf, {
arg buf, out = 0, rate = 1, amp = 1, dur = (BufFrames.kr(buf)/BufSampleRate.kr(buf))/rate.abs, atk = 0.1, rel = 0.1;
var env;
env = EnvGen.kr(Env.new([0.01, 1, 1, 0.01], [atk, 1-(atk+rel), rel], \exp), timeScale: dur, doneAction:2);
Out.ar(out, PlayBuf.ar(1, buf, rate, loop:1)*env*amp);
}).add;

This way it works for me with the rate = -1

Best,
Stefano

On Wed, May 10, 2017 at 11:57 AM, Donald Craig <[hidden email]> wrote:
Hi,

If you set loop to 1, it will play. The default values are startPos at 0 and no loop,
so with a negative rate, the 'play head' is already at the end. if you want no loop,
then you need to set startPos to the end of your buffer.

Don

On Wed, May 10, 2017 at 8:20 AM, <[hidden email]> wrote:
Dear, 

I had already noticed this. Looks like negative rate is broken in PlayBuf.

On my machine (OS X with SC 3.8) this works

{PlayBuf.ar(1, b,1)}.play

This does not

{PlayBuf.ar(1, b,-1)}.play

(b is a buffer)


Thanks

Best

-a-




--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - StudiUm
Università degli Studi di Torino
--> http://www.cirma.unito.it/andrea/
--> http://www.fonurgia.unito.it/andrea/
--> http://www.flickr.com/photos/vanderaalle/sets/
--> http://vimeo.com/vanderaalle
--> [hidden email]
--------------------------------------------------

"This is a very complicated case, Maude. You know, a lotta ins, a lotta outs, a lotta what-have-yous." 
(Jeffrey 'The Dude' Lebowski)



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PlayBuf negative rate

Andrea Valle
In reply to this post by Donald Craig
Thanks Donald

Is this an intended behaviour?
I don’t think this was needed “before” (when?) 
Maybe I’m wrong, in any case it is not mentioned in the help file

Best


-a-


--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - StudiUm
Università degli Studi di Torino
--> http://www.cirma.unito.it/andrea/
--> http://www.fonurgia.unito.it/andrea/
--> http://www.flickr.com/photos/vanderaalle/sets/
--> http://vimeo.com/vanderaalle
--> [hidden email]
--------------------------------------------------

"This is a very complicated case, Maude. You know, a lotta ins, a lotta outs, a lotta what-have-yous." 
(Jeffrey 'The Dude' Lebowski)

On 10 May 2017, at 17:57, Donald Craig <[hidden email]> wrote:

Hi,

If you set loop to 1, it will play. The default values are startPos at 0 and no loop,
so with a negative rate, the 'play head' is already at the end. if you want no loop,
then you need to set startPos to the end of your buffer.

Don

On Wed, May 10, 2017 at 8:20 AM, <[hidden email]> wrote:
Dear, 

I had already noticed this. Looks like negative rate is broken in PlayBuf.

On my machine (OS X with SC 3.8) this works

{PlayBuf.ar(1, b,1)}.play

This does not

{PlayBuf.ar(1, b,-1)}.play

(b is a buffer)


Thanks

Best

-a-




--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - StudiUm
Università degli Studi di Torino
--> http://www.cirma.unito.it/andrea/
--> http://www.fonurgia.unito.it/andrea/
--> http://www.flickr.com/photos/vanderaalle/sets/
--> http://vimeo.com/vanderaalle
--> [hidden email]
--------------------------------------------------

"This is a very complicated case, Maude. You know, a lotta ins, a lotta outs, a lotta what-have-yous." 
(Jeffrey 'The Dude' Lebowski)



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PlayBuf negative rate

Josh Parmenter
I’m pretty sure this has always been the behavior. I remember having to make note of it when I taught SC.
Best,
Josh

On May 10, 2017, at 9:18 AM, [hidden email] wrote:

Thanks Donald

Is this an intended behaviour?
I don’t think this was needed “before” (when?) 
Maybe I’m wrong, in any case it is not mentioned in the help file

Best


-a-


--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - StudiUm
Università degli Studi di Torino
--> http://www.cirma.unito.it/andrea/
--> http://www.fonurgia.unito.it/andrea/
--> http://www.flickr.com/photos/vanderaalle/sets/
--> http://vimeo.com/vanderaalle
--> [hidden email]
--------------------------------------------------

"This is a very complicated case, Maude. You know, a lotta ins, a lotta outs, a lotta what-have-yous." 
(Jeffrey 'The Dude' Lebowski)

On 10 May 2017, at 17:57, Donald Craig <[hidden email]> wrote:

Hi,

If you set loop to 1, it will play. The default values are startPos at 0 and no loop,
so with a negative rate, the 'play head' is already at the end. if you want no loop,
then you need to set startPos to the end of your buffer.

Don

On Wed, May 10, 2017 at 8:20 AM, <[hidden email]> wrote:
Dear, 

I had already noticed this. Looks like negative rate is broken in PlayBuf.

On my machine (OS X with SC 3.8) this works

{PlayBuf.ar(1, b,1)}.play

This does not

{PlayBuf.ar(1, b,-1)}.play

(b is a buffer)


Thanks

Best

-a-




--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - StudiUm
Università degli Studi di Torino
--> http://www.cirma.unito.it/andrea/
--> http://www.fonurgia.unito.it/andrea/
--> http://www.flickr.com/photos/vanderaalle/sets/
--> http://vimeo.com/vanderaalle
--> [hidden email]
--------------------------------------------------

"This is a very complicated case, Maude. You know, a lotta ins, a lotta outs, a lotta what-have-yous." 
(Jeffrey 'The Dude' Lebowski)




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PlayBuf negative rate

Andrea Valle
Well, if you remember it, I trust you for sure.
Seems really bizarre on my side, I was pretty sure of the contrary, I have use  PlayBuf so many times in all these years and never encountered the situation (as it is not specified in the help file)


Best

-a-



--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - StudiUm
Università degli Studi di Torino
--> http://www.cirma.unito.it/andrea/
--> http://www.fonurgia.unito.it/andrea/
--> http://www.flickr.com/photos/vanderaalle/sets/
--> http://vimeo.com/vanderaalle
--> [hidden email]
--------------------------------------------------

"This is a very complicated case, Maude. You know, a lotta ins, a lotta outs, a lotta what-have-yous." 
(Jeffrey 'The Dude' Lebowski)

On 10 May 2017, at 18:20, [hidden email] wrote:

I’m pretty sure this has always been the behavior. I remember having to make note of it when I taught SC.
Best,
Josh

On May 10, 2017, at 9:18 AM, [hidden email] wrote:

Thanks Donald

Is this an intended behaviour?
I don’t think this was needed “before” (when?) 
Maybe I’m wrong, in any case it is not mentioned in the help file

Best


-a-


--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - StudiUm
Università degli Studi di Torino
--> http://www.cirma.unito.it/andrea/
--> http://www.fonurgia.unito.it/andrea/
--> http://www.flickr.com/photos/vanderaalle/sets/
--> http://vimeo.com/vanderaalle
--> [hidden email]
--------------------------------------------------

"This is a very complicated case, Maude. You know, a lotta ins, a lotta outs, a lotta what-have-yous." 
(Jeffrey 'The Dude' Lebowski)

On 10 May 2017, at 17:57, Donald Craig <[hidden email]> wrote:

Hi,

If you set loop to 1, it will play. The default values are startPos at 0 and no loop,
so with a negative rate, the 'play head' is already at the end. if you want no loop,
then you need to set startPos to the end of your buffer.

Don

On Wed, May 10, 2017 at 8:20 AM, <[hidden email]> wrote:
Dear, 

I had already noticed this. Looks like negative rate is broken in PlayBuf.

On my machine (OS X with SC 3.8) this works

{PlayBuf.ar(1, b,1)}.play

This does not

{PlayBuf.ar(1, b,-1)}.play

(b is a buffer)


Thanks

Best

-a-




--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - StudiUm
Università degli Studi di Torino
--> http://www.cirma.unito.it/andrea/
--> http://www.fonurgia.unito.it/andrea/
--> http://www.flickr.com/photos/vanderaalle/sets/
--> http://vimeo.com/vanderaalle
--> [hidden email]
--------------------------------------------------

"This is a very complicated case, Maude. You know, a lotta ins, a lotta outs, a lotta what-have-yous." 
(Jeffrey 'The Dude' Lebowski)





Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PlayBuf negative rate

Russell J
This behavior actually seems intuitive to me: as Donald pointed out, going backward from first frame of buffer leaves nothing to play.  His suggestion about starting from the last frame looks like this and works as you probably expect (without looping):

{ PlayBuf.ar(2, b, -1, startPos: b.numFrames-1) }.play;

Note that numFrames-1 is the last frame since first frame is numbered 0.  But just using numFrames without the minus one also works, due to the forgiving design of the ugen :)

Just for reference if anyone is learning from this thread: doneAction=2 immediately frees the Synth upon reaching the last frame of the buffer, so nothing will play if you try to start on that frame. You can start from the second to last frame in that case:

{ PlayBuf.ar(2, b, -1, startPos: b.numFrames-2, doneAction: 2) }.play;

Eli Fieldsteel addresses this in his lovely YouTube tutorial on Buffers.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PlayBuf negative rate

Russell J
p.s. Stefano's example uses the same idea in a more robust way, but thought posting some simpler code might make the point clearer about starting from end of file.  His code works even if the buffer is changed while the synth is playing.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PlayBuf negative rate

Stefano_Catena
Hi,

from an academic point of view I will agree on the idea that the reversed buffer must be read starting from the last-1 frame: anyway I feel that from the user perspective this behaviour should be automatised similarly in the way I did. 

Best,
Stefano

On Thu, May 11, 2017 at 8:50 AM, <[hidden email]> wrote:
p.s. Stefano's example uses the same idea in a more robust way, but thought
posting some simpler code might make the point clearer about starting from
end of file.  His code works even if the buffer is changed while the synth
is playing.



--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/PlayBuf-negative-rate-tp7632235p7632256.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PlayBuf negative rate

Russell J
Yes, totally agree that your version is superior for real-world use.  :)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PlayBuf negative rate

ddw_music
In reply to this post by Andrea Valle
Andrea Valle wrote
Well, if you remember it, I trust you for sure.
Seems really bizarre on my side, I was pretty sure of the contrary, I have use  PlayBuf so many times in all these years and never encountered the situation (as it is not specified in the help file)
Git remembers. When in doubt, use the source.

The question here is whether the default value of PlayBuf's startPos argument automatically flipped to the end of the buffer for a negative rate. That means checking the PlayBuf class definition. (I'm quite sure it would be wrong for the PlayBuf plug-in to override floating-point inputs.)

https://github.com/supercollider/supercollider/blame/master/SCClassLibrary/Common/Audio/BufIO.sc

"Blame" shows the latest commit responsible for every line of code. PlayBuf is at the top of this file, and I see:

```
PlayBuf add doneAction 9 years ago
        *ar { arg numChannels, bufnum=0, rate=1.0, trigger=1.0, startPos=0.0, loop = 0.0, doneAction=0;
```

So, for at least the last nine years, the default startPos was a plain and simple 0. We can also click on the commit link and see what changed (startPos=0.0 is the same):

```
- *ar { arg numChannels, bufnum=0, rate=1.0, trigger=1.0, startPos=0.0, loop = 0.0;
- ^this.multiNew('audio', numChannels, bufnum, rate, trigger, startPos, loop)
+ *ar { arg numChannels, bufnum=0, rate=1.0, trigger=1.0, startPos=0.0, loop = 0.0, doneAction=0;
+ ^this.multiNew('audio', numChannels, bufnum, rate, trigger, startPos, loop, doneAction)
```

Further, to switch startPos based on rate, it's not as simple as you think. You would need something like this (and even this wouldn't work, because 'rate' is commonly a number, not a UGen, so it doesn't respond to methodSelectorForRate):

```
arg ........., startPos, ...;
startPos ?? {
        startPos = Select.perform(rate.methodSelectorForRate, rate < 0, [0, BufFrames.kr(bufnum)])
};
```

... and I'm quite certain that, if somebody had written this in the past, and then somebody else removed it, there would be a git trail.

So, no, it was never like this. You always had to set the startPos manually, to play backward.

RussellJ wrote
Just for reference if anyone is learning from this thread: doneAction=2 immediately frees the Synth upon reaching the last frame of the buffer, so nothing will play if you try to start on that frame.
Confirmed: that is a bona fide bug.

b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");

// stops after 1 sample!
a = { PlayBuf.ar(1, b, rate: -1, startPos: BufFrames.ir(b) - 1, doneAction: 2).dup }.play;

I don't see where unit->mDone is set in the source code, but clearly, that part of the code assumes a positive rate.

Anyway, now there's https://github.com/supercollider/supercollider/issues/2875 .

hjh
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PlayBuf negative rate

Peter P.-2
* [hidden email] <[hidden email]> [2017-05-12 05:03]:
[...]
> So, no, it was never like this. You always had to set the startPos manually,
> to play backward.
I think it would be good if the help file could mention this as I
stumbled over it in the past as well.

while we are at it, it would furthermore be nice if the help file for
BufDur could mention what unit the reported duration is in (namely
seconds and not samples nor miiliseconds). What is the correct way to
ask for such modifications? Would one file a bug report marked as wish?

P

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PlayBuf negative rate

ddw_music
Peter P.-2 wrote
I think it would be good if the help file could mention this as I
stumbled over it in the past as well.

while we are at it, it would furthermore be nice if the help file for
BufDur could mention what unit the reported duration is in (namely
seconds and not samples nor miiliseconds). What is the correct way to
ask for such modifications? Would one file a bug report marked as wish?
A bug report is a good way -- we'll tag it for the help system.

There are all kinds of details that are... erm... loosely treated in the help files (if not outright ignored). IMO method documentation should generally mention the expected types of every input and the expected return type... but more often than not, it reads like, "Do something sort of like the example and you'll get back a something-or-other, whose class we won't bother to name, which has characteristics that we may or may not spell out, in which case you'd better hope you guessed the right principle."

But, writing comprehensive, clear and uncluttered documentation is extremely hard, and programmers are often bad at writing documentation, and we have no dedicated help authors. So there it is... the best approach is to submit big reports or, perhaps better, check out the git repository, make the changes yourself, and submit pull requests ;)

hhh
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: PlayBuf negative rate

alln4tural-list
In reply to this post by Andrea Valle
Who's this "hhh" imposter, I say
He's acting all informative and helpful like our own hjh, but I'll not be fooled.



--
https://soundcloud.com/all-n4tural _______________________________________________ sc-users mailing list info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx archive: http://www.listarc.bham.ac.uk/marchives/sc-users/ search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Loading...