Csound Csound-dev Csound-tekno Search About

[Csnd] Setting loop points in file with phasor index

Date2013-02-12 02:46
FromAndrew Ikenberry
Subject[Csnd] Setting loop points in file with phasor index
Hello Csounders!

I am trying to create a csd that will allow me to dynamically change the start and end points of a loop reading through an audio file. 
I currently have an audio file written to a table and am accessing the table with table3. The index to the table is generated by phasor. 
I also have a slider that is controlling the speed of playback. What I am trying to do is have two sliders that control loop start and loop end points.
I tried to do this by rescaling the signal from phasor but the only thing that changes is the pitch and not the looping points. Is there a way to scale phasor 
to only read a section of the file according to my start and end points? My code is pasted below. Thanks in advance!!!!!!!!!!!!!!!!!

Best,

Andrew





; isize = file length in seconds


; Loop start

kloopstart chnget "kloopstart"

kloopstart scale kloopstart, isize, 0


; Loop end

kloopend chnget "kloopend"

kloopend scale kloopend, isize, 0.01


; Speed of playback

kspeed chnget "kspeed"

kspeed scale kspeed, 2, -2


ksize = kloopend-kloopstart


; Runs fine stright through entire file

;kphase = (1/isize)*kspeed


; Doesn't run correctly

kphase = (1/ksize)*kspeed


aline phasor kphase


asig table3 aline, 1, 1


out asig


Date2013-02-12 12:01
FromRory Walsh
SubjectRe: [Csnd] Setting loop points in file with phasor index
I just covered this topic with my students. Here's the csd file we
came up with, although you'll need to change a few i-rate variables to
k-rates. You'll note that the phasor frequency is dependent on how
much of the table we are reading. Without this it would play back at
the incorrect speed resulting in unwanted changes to the frequency
which I believe it what was happening in your case although I haven't
studied the code.



-odac


0dbfs=1


instr 1
iStart=p4
iEnd=p5
iDirection=p6
iFn=1
iMode=1
iRange=iEnd-iStart

aIndex phasor iDirection/((ftlen(1)*iRange)/sr)
aOutput tab (aIndex*iRange)+iStart,iFn,iMode
out aOutput
endin



f1 0 0 1 "Guitar1.wav" 0 4 1
;p4 = start point (0-1)
;p5 = end point (0-1)
;p6 = playback directions, -1(backwards), or +1(forwards)
i1 0 3           .5    1     1



Date2013-02-12 23:32
FromAndrew Ikenberry
SubjectRe: [Csnd] Setting loop points in file with phasor index
Thanks Rory! This helped immensely.

-Andrew

On Tue, Feb 12, 2013 at 7:01 AM, Rory Walsh <rorywalsh@ear.ie> wrote:
I just covered this topic with my students. Here's the csd file we
came up with, although you'll need to change a few i-rate variables to
k-rates. You'll note that the phasor frequency is dependent on how
much of the table we are reading. Without this it would play back at
the incorrect speed resulting in unwanted changes to the frequency
which I believe it what was happening in your case although I haven't
studied the code.

<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
0dbfs=1


instr 1
iStart=p4
iEnd=p5
iDirection=p6
iFn=1
iMode=1
iRange=iEnd-iStart

aIndex phasor iDirection/((ftlen(1)*iRange)/sr)
aOutput tab (aIndex*iRange)+iStart,iFn,iMode
out aOutput
endin

</CsInstruments>
<CsScore>
f1 0 0 1 "Guitar1.wav" 0 4 1
;p4 = start point (0-1)
;p5 = end point (0-1)
;p6 = playback directions, -1(backwards), or +1(forwards)
i1 0 3           .5    1     1
</CsScore>
</CsoundSynthesizer>


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"