Csound Csound-dev Csound-tekno Search About

[Csnd] transport controls with diskin2

Date2011-12-29 00:54
FromThomas Hass
Subject[Csnd] transport controls with diskin2
Hi everyone,

This is my first post to the list, but I've been loving Csound ever since Dr. B introduced it to me last year at Berklee.  

I'm trying to develop some additional transport controls to work with diskin2 based off the example, SF_Play_from_HD_2.csd.  The main problem that I'm encountering is that this csd keeps track of the current position in a file based off a clock.  This approach doesn't account for the user changing the pitch of the file (which also alters the rate at which the file is read).  So if the user presses play, raises the pitch, pauses, then resumes, the file starts at a position prior to where it should.  I'm also having problems implementing a seek functionality for the same reasons.  Does anyone have any examples of a file player with more transport controls?

Any help would be much appreciated.

-Thomas

Date2011-12-29 09:37
FromVictor Lazzarini
SubjectRe: [Csnd] transport controls with diskin2
Would it not be as simple as multiplying the start time by the pitch transposition and check for bounds/wraparound?


On 29 Dec 2011, at 00:54, Thomas Hass wrote:

Hi everyone,

This is my first post to the list, but I've been loving Csound ever since Dr. B introduced it to me last year at Berklee.  

I'm trying to develop some additional transport controls to work with diskin2 based off the example, SF_Play_from_HD_2.csd.  The main problem that I'm encountering is that this csd keeps track of the current position in a file based off a clock.  This approach doesn't account for the user changing the pitch of the file (which also alters the rate at which the file is read).  So if the user presses play, raises the pitch, pauses, then resumes, the file starts at a position prior to where it should.  I'm also having problems implementing a seek functionality for the same reasons.  Does anyone have any examples of a file player with more transport controls?

Any help would be much appreciated.

-Thomas

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie




Date2011-12-29 14:14
FromTito Latini
SubjectRe: [Csnd] transport controls with diskin2
AttachmentsNone  

Date2011-12-29 21:17
FromThomas Hass
SubjectRe: [Csnd] transport controls with diskin2
The problem with multiplying the start time by the pitch transposition is that the user is able to change the pitch while the file is playing.  So I don't think this approach will accurately track the location in the file if the user messes with the pitch during playback.  I was hoping that there was another opcode related to diskin2 that returned the current read position in a file.  If no such opcode exists, it would be awesome if one could be developed.  Maybe the current position could be returned via one of the arguments.

Thanks for the great example Tito.  However, I have to keep my memory footprint pretty low in the context that I'm using Csound in and would like to avoid loading entire audio files into ftables.

Thanks,
Thomas

On Thu, Dec 29, 2011 at 6:14 AM, Tito Latini <tito.01beta@gmail.com> wrote:
I have written a simple sound player that uses the `table3' opcode
controlled by OSC messages.

In this example I send the OSC messages from my linux console.

# some alias
alias cs_play='oscsend localhost 57112 /play i'
alias cs_speed='oscsend localhost 57112 /speed f'
alias cs_pos='oscsend localhost 57112 /position f'

# start csound in another console
nohup xterm -e csound test.csd >/dev/null &

cs_play 1       # start
cs_speed 1.5    # set the speed; 1=normal
cs_speed 0.75
cs_pos 45       # set the position in seconds
cs_pos 99
cs_play 0       # pause
cs_play 1       # resume
cs_speed 2
cs_pos 0
cs_pos 148
cs_play 0
cs_speed 0.3
cs_play 1
cs_play 0

# finish
pkill csound
unalias cs_play cs_speed cs_pos


<CsoundSynthesizer>
<CsOptions>
-d -m0 -odac
</CsOptions>
<CsInstruments>
sr     = 44100
ksmps  = 64
nchnls = 2
0dbfs  = 1

zakinit   1, 1
gihandle  OSCinit 57112

gapha     init 0
gkspeed   init 1
gkplaying init 0
gidur     = 151   ; duration of the loop (sec)

instr 1
 isamps    = gidur*sr
 gkplaying = 1
 kphs      zkr 1
 iphs      = p4
ptr:
 gapha phasor gkspeed/gidur, iphs
 rireturn
 if (kphs != 0) then
phase:
   iphs = i(kphs) - 1
   rireturn
   reinit phase
   reinit ptr
 endif
 andx = gapha * isamps
 al table3 andx, 1
 ar table3 andx, 2
 out  al, ar
 zkcl 0, 1
endin

instr 2 ; control
 kstatus  init 0
 ksval    init 0
 kpval    init 0
nxtmsg:
 kplay  OSClisten gihandle, "/play",     "i", kstatus
 kspeed OSClisten gihandle, "/speed",    "f", ksval
 kpos   OSClisten gihandle, "/position", "f", kpval

 if (kplay == 0) goto position
 if (kstatus == 1) then
   if (gkplaying != 0) kgoto nxtmsg
   kpha downsamp gapha
   event "i", 1, 0, 36000, kpha
 else
   turnoff2 1,0,0
   gkplaying = 0
 endif
position:
 if (kpos == 0) goto speed
 zkw kpval/gidur + 1, 1
speed:
 if (kspeed == 0) goto ex
 gkspeed = ksval
 kgoto nxtmsg
ex:
endin
</CsInstruments>
<CsScore>
f1 0 8388608 1 "stornello.wav" 0 0 1
f2 0 8388608 1 "stornello.wav" 0 0 2
i2 0 36000
e
</CsScore>
</CsoundSynthesizer>

tito

On Wed, Dec 28, 2011 at 04:54:13PM -0800, Thomas Hass wrote:
> Hi everyone,
>
> This is my first post to the list, but I've been loving Csound ever since
> Dr. B introduced it to me last year at Berklee.
>
> I'm trying to develop some additional transport controls to work with
> diskin2 based off the example, SF_Play_from_HD_2.csd.  The main problem
> that I'm encountering is that this csd keeps track of the current position
> in a file based off a clock.  This approach doesn't account for the user
> changing the pitch of the file (which also alters the rate at which the
> file is read).  So if the user presses play, raises the pitch, pauses, then
> resumes, the file starts at a position prior to where it should.  I'm also
> having problems implementing a seek functionality for the same reasons.
>  Does anyone have any examples of a file player with more transport
> controls?
>
> Any help would be much appreciated.
>
> -Thomas
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>


Send bugs reports to the Sourceforge bug tracker
           https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"



Date2011-12-29 21:32
FromVictor Lazzarini
SubjectRe: [Csnd] transport controls with diskin2
I think you can always keep track of the pos if you scale its increment along with the changes in pitch. So when the pitch is 2, instead of incrementing by 1 control cycle (or whatever), increment it by 2 and so on.

Victor
On 29 Dec 2011, at 21:17, Thomas Hass wrote:

The problem with multiplying the start time by the pitch transposition is that the user is able to change the pitch while the file is playing.  So I don't think this approach will accurately track the location in the file if the user messes with the pitch during playback.  I was hoping that there was another opcode related to diskin2 that returned the current read position in a file.  If no such opcode exists, it would be awesome if one could be developed.  Maybe the current position could be returned via one of the arguments.

Thanks for the great example Tito.  However, I have to keep my memory footprint pretty low in the context that I'm using Csound in and would like to avoid loading entire audio files into ftables.

Thanks,
Thomas

On Thu, Dec 29, 2011 at 6:14 AM, Tito Latini <tito.01beta@gmail.com> wrote:
I have written a simple sound player that uses the `table3' opcode
controlled by OSC messages.

In this example I send the OSC messages from my linux console.

# some alias
alias cs_play='oscsend localhost 57112 /play i'
alias cs_speed='oscsend localhost 57112 /speed f'
alias cs_pos='oscsend localhost 57112 /position f'

# start csound in another console
nohup xterm -e csound test.csd >/dev/null &

cs_play 1       # start
cs_speed 1.5    # set the speed; 1=normal
cs_speed 0.75
cs_pos 45       # set the position in seconds
cs_pos 99
cs_play 0       # pause
cs_play 1       # resume
cs_speed 2
cs_pos 0
cs_pos 148
cs_play 0
cs_speed 0.3
cs_play 1
cs_play 0

# finish
pkill csound
unalias cs_play cs_speed cs_pos


<CsoundSynthesizer>
<CsOptions>
-d -m0 -odac
</CsOptions>
<CsInstruments>
sr     = 44100
ksmps  = 64
nchnls = 2
0dbfs  = 1

zakinit   1, 1
gihandle  OSCinit 57112

gapha     init 0
gkspeed   init 1
gkplaying init 0
gidur     = 151   ; duration of the loop (sec)

instr 1
 isamps    = gidur*sr
 gkplaying = 1
 kphs      zkr 1
 iphs      = p4
ptr:
 gapha phasor gkspeed/gidur, iphs
 rireturn
 if (kphs != 0) then
phase:
   iphs = i(kphs) - 1
   rireturn
   reinit phase
   reinit ptr
 endif
 andx = gapha * isamps
 al table3 andx, 1
 ar table3 andx, 2
 out  al, ar
 zkcl 0, 1
endin

instr 2 ; control
 kstatus  init 0
 ksval    init 0
 kpval    init 0
nxtmsg:
 kplay  OSClisten gihandle, "/play",     "i", kstatus
 kspeed OSClisten gihandle, "/speed",    "f", ksval
 kpos   OSClisten gihandle, "/position", "f", kpval

 if (kplay == 0) goto position
 if (kstatus == 1) then
   if (gkplaying != 0) kgoto nxtmsg
   kpha downsamp gapha
   event "i", 1, 0, 36000, kpha
 else
   turnoff2 1,0,0
   gkplaying = 0
 endif
position:
 if (kpos == 0) goto speed
 zkw kpval/gidur + 1, 1
speed:
 if (kspeed == 0) goto ex
 gkspeed = ksval
 kgoto nxtmsg
ex:
endin
</CsInstruments>
<CsScore>
f1 0 8388608 1 "stornello.wav" 0 0 1
f2 0 8388608 1 "stornello.wav" 0 0 2
i2 0 36000
e
</CsScore>
</CsoundSynthesizer>

tito

On Wed, Dec 28, 2011 at 04:54:13PM -0800, Thomas Hass wrote:
> Hi everyone,
>
> This is my first post to the list, but I've been loving Csound ever since
> Dr. B introduced it to me last year at Berklee.
>
> I'm trying to develop some additional transport controls to work with
> diskin2 based off the example, SF_Play_from_HD_2.csd.  The main problem
> that I'm encountering is that this csd keeps track of the current position
> in a file based off a clock.  This approach doesn't account for the user
> changing the pitch of the file (which also alters the rate at which the
> file is read).  So if the user presses play, raises the pitch, pauses, then
> resumes, the file starts at a position prior to where it should.  I'm also
> having problems implementing a seek functionality for the same reasons.
>  Does anyone have any examples of a file player with more transport
> controls?
>
> Any help would be much appreciated.
>
> -Thomas
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>


Send bugs reports to the Sourceforge bug tracker
           https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"



Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie




Date2011-12-29 23:42
FromIain McCurdy
SubjectRE: [Csnd] transport controls with diskin2
You could use a krate phasor to mirror the time location of playback by diskin. e.g.

Sfile = "Soundfile.wav"
ilen filelen Sfile  ;length of sound file in seconds
kpos  phasor gkspeed/ilen
kpos  = kpos * ilen ;position of playback in seconds
printk 2,kptr  
a1,a2 diskin2 Sfile,gkspeed,0,1


Maybe this is what you are looking for...
Iain


Date: Thu, 29 Dec 2011 13:17:21 -0800
From: thass@berklee.edu
To: csound@lists.bath.ac.uk
Subject: Re: [Csnd] transport controls with diskin2

The problem with multiplying the start time by the pitch transposition is that the user is able to change the pitch while the file is playing.  So I don't think this approach will accurately track the location in the file if the user messes with the pitch during playback.  I was hoping that there was another opcode related to diskin2 that returned the current read position in a file.  If no such opcode exists, it would be awesome if one could be developed.  Maybe the current position could be returned via one of the arguments.

Thanks for the great example Tito.  However, I have to keep my memory footprint pretty low in the context that I'm using Csound in and would like to avoid loading entire audio files into ftables.

Thanks,
Thomas

On Thu, Dec 29, 2011 at 6:14 AM, Tito Latini <tito.01beta@gmail.com> wrote:
I have written a simple sound player that uses the `table3' opcode
controlled by OSC messages.

In this example I send the OSC messages from my linux console.

# some alias
alias cs_play='oscsend localhost 57112 /play i'
alias cs_speed='oscsend localhost 57112 /speed f'
alias cs_pos='oscsend localhost 57112 /position f'

# start csound in another console
nohup xterm -e csound test.csd >/dev/null &

cs_play 1       # start
cs_speed 1.5    # set the speed; 1=normal
cs_speed 0.75
cs_pos 45       # set the position in seconds
cs_pos 99
cs_play 0       # pause
cs_play 1       # resume
cs_speed 2
cs_pos 0
cs_pos 148
cs_play 0
cs_speed 0.3
cs_play 1
cs_play 0

# finish
pkill csound
unalias cs_play cs_speed cs_pos


<CsoundSynthesizer>
<CsOptions>
-d -m0 -odac
</CsOptions>
<CsInstruments>
sr     = 44100
ksmps  = 64
nchnls = 2
0dbfs  = 1

zakinit   1, 1
gihandle  OSCinit 57112

gapha     init 0
gkspeed   init 1
gkplaying init 0
gidur     = 151   ; duration of the loop (sec)

instr 1
 isamps    = gidur*sr
 gkplaying = 1
 kphs      zkr 1
 iphs      = p4
ptr:
 gapha phasor gkspeed/gidur, iphs
 rireturn
 if (kphs != 0) then
phase:
   iphs = i(kphs) - 1
   rireturn
   reinit phase
   reinit ptr
 endif
 andx = gapha * isamps
 al table3 andx, 1
 ar table3 andx, 2
 out  al, ar
 zkcl 0, 1
endin

instr 2 ; control
 kstatus  init 0
 ksval    init 0
 kpval    init 0
nxtmsg:
 kplay  OSClisten gihandle, "/play",     "i", kstatus
 kspeed OSClisten gihandle, "/speed",    "f", ksval
 kpos   OSClisten gihandle, "/position", "f", kpval

 if (kplay == 0) goto position
 if (kstatus == 1) then
   if (gkplaying != 0) kgoto nxtmsg
   kpha downsamp gapha
   event "i", 1, 0, 36000, kpha
 else
   turnoff2 1,0,0
   gkplaying = 0
 endif
position:
 if (kpos == 0) goto speed
 zkw kpval/gidur + 1, 1
speed:
 if (kspeed == 0) goto ex
 gkspeed = ksval
 kgoto nxtmsg
ex:
endin
</CsInstruments>
<CsScore>
f1 0 8388608 1 "stornello.wav" 0 0 1
f2 0 8388608 1 "stornello.wav" 0 0 2
i2 0 36000
e
</CsScore>
</CsoundSynthesizer>

tito

On Wed, Dec 28, 2011 at 04:54:13PM -0800, Thomas Hass wrote:
> Hi everyone,
>
> This is my first post to the list, but I've been loving Csound ever since
> Dr. B introduced it to me last year at Berklee.
>
> I'm trying to develop some additional transport controls to work with
> diskin2 based off the example, SF_Play_from_HD_2.csd.  The main problem
> that I'm encountering is that this csd keeps track of the current position
> in a file based off a clock.  This approach doesn't account for the user
> changing the pitch of the file (which also alters the rate at which the
> file is read).  So if the user presses play, raises the pitch, pauses, then
> resumes, the file starts at a position prior to where it should.  I'm also
> having problems implementing a seek functionality for the same reasons.
>  Does anyone have any examples of a file player with more transport
> controls?
>
> Any help would be much appreciated.
>
> -Thomas
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>


Send bugs reports to the Sourceforge bug tracker
           https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"



Date2011-12-30 02:15
FromThomas Hass
SubjectRe: [Csnd] transport controls with diskin2
Like Victor said, it turned out to be as simple as changing this line in instrument 10:

gktimi10k = gktimi10k + 1


to:


gktimi10k = gktimi10k + kpitch


Thanks for the help.


-Thomas


On Thu, Dec 29, 2011 at 3:42 PM, Iain McCurdy <i_mccurdy@hotmail.com> wrote:
You could use a krate phasor to mirror the time location of playback by diskin. e.g.

Sfile = "Soundfile.wav"
ilen filelen Sfile  ;length of sound file in seconds
kpos  phasor gkspeed/ilen
kpos  = kpos * ilen ;position of playback in seconds
printk 2,kptr  
a1,a2 diskin2 Sfile,gkspeed,0,1


Maybe this is what you are looking for...
Iain


Date: Thu, 29 Dec 2011 13:17:21 -0800
From: thass@berklee.edu
To: csound@lists.bath.ac.uk
Subject: Re: [Csnd] transport controls with diskin2


The problem with multiplying the start time by the pitch transposition is that the user is able to change the pitch while the file is playing.  So I don't think this approach will accurately track the location in the file if the user messes with the pitch during playback.  I was hoping that there was another opcode related to diskin2 that returned the current read position in a file.  If no such opcode exists, it would be awesome if one could be developed.  Maybe the current position could be returned via one of the arguments.

Thanks for the great example Tito.  However, I have to keep my memory footprint pretty low in the context that I'm using Csound in and would like to avoid loading entire audio files into ftables.

Thanks,
Thomas

On Thu, Dec 29, 2011 at 6:14 AM, Tito Latini <tito.01beta@gmail.com> wrote:
I have written a simple sound player that uses the `table3' opcode
controlled by OSC messages.

In this example I send the OSC messages from my linux console.

# some alias
alias cs_play='oscsend localhost 57112 /play i'
alias cs_speed='oscsend localhost 57112 /speed f'
alias cs_pos='oscsend localhost 57112 /position f'

# start csound in another console
nohup xterm -e csound test.csd >/dev/null &

cs_play 1       # start
cs_speed 1.5    # set the speed; 1=normal
cs_speed 0.75
cs_pos 45       # set the position in seconds
cs_pos 99
cs_play 0       # pause
cs_play 1       # resume
cs_speed 2
cs_pos 0
cs_pos 148
cs_play 0
cs_speed 0.3
cs_play 1
cs_play 0

# finish
pkill csound
unalias cs_play cs_speed cs_pos


<CsoundSynthesizer>
<CsOptions>
-d -m0 -odac
</CsOptions>
<CsInstruments>
sr     = 44100
ksmps  = 64
nchnls = 2
0dbfs  = 1

zakinit   1, 1
gihandle  OSCinit 57112

gapha     init 0
gkspeed   init 1
gkplaying init 0
gidur     = 151   ; duration of the loop (sec)

instr 1
 isamps    = gidur*sr
 gkplaying = 1
 kphs      zkr 1
 iphs      = p4
ptr:
 gapha phasor gkspeed/gidur, iphs
 rireturn
 if (kphs != 0) then
phase:
   iphs = i(kphs) - 1
   rireturn
   reinit phase
   reinit ptr
 endif
 andx = gapha * isamps
 al table3 andx, 1
 ar table3 andx, 2
 out  al, ar
 zkcl 0, 1
endin

instr 2 ; control
 kstatus  init 0
 ksval    init 0
 kpval    init 0
nxtmsg:
 kplay  OSClisten gihandle, "/play",     "i", kstatus
 kspeed OSClisten gihandle, "/speed",    "f", ksval
 kpos   OSClisten gihandle, "/position", "f", kpval

 if (kplay == 0) goto position
 if (kstatus == 1) then
   if (gkplaying != 0) kgoto nxtmsg
   kpha downsamp gapha
   event "i", 1, 0, 36000, kpha
 else
   turnoff2 1,0,0
   gkplaying = 0
 endif
position:
 if (kpos == 0) goto speed
 zkw kpval/gidur + 1, 1
speed:
 if (kspeed == 0) goto ex
 gkspeed = ksval
 kgoto nxtmsg
ex:
endin
</CsInstruments>
<CsScore>
f1 0 8388608 1 "stornello.wav" 0 0 1
f2 0 8388608 1 "stornello.wav" 0 0 2
i2 0 36000
e
</CsScore>
</CsoundSynthesizer>

tito

On Wed, Dec 28, 2011 at 04:54:13PM -0800, Thomas Hass wrote:
> Hi everyone,
>
> This is my first post to the list, but I've been loving Csound ever since
> Dr. B introduced it to me last year at Berklee.
>
> I'm trying to develop some additional transport controls to work with
> diskin2 based off the example, SF_Play_from_HD_2.csd.  The main problem
> that I'm encountering is that this csd keeps track of the current position
> in a file based off a clock.  This approach doesn't account for the user
> changing the pitch of the file (which also alters the rate at which the
> file is read).  So if the user presses play, raises the pitch, pauses, then
> resumes, the file starts at a position prior to where it should.  I'm also
> having problems implementing a seek functionality for the same reasons.
>  Does anyone have any examples of a file player with more transport
> controls?
>
> Any help would be much appreciated.
>
> -Thomas
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>


Send bugs reports to the Sourceforge bug tracker
           https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"