Csound Csound-dev Csound-tekno Search About

[Csnd] Not quite understanding csounds loop function

Date2011-11-17 13:48
FromOle Adrian Heggli
Subject[Csnd] Not quite understanding csounds loop function
AttachmentsLooptest1.csd  
Hi,


I'm new to this list, and will start off by asking for help with the
loop functionality in csound. My goal is to create a script that will
process files with opcodes with randomized parameters. Everything
works well, apart from that my code will only actually write the audio
file the second to last iteration of the for-loop. I guess this might
have something to do with me not quite understanding the subleties of
the csound score. Any help would be appriciated.

What is considered good practise on this mailing list? Attaching
files, or pasting code into the email? I wil do both for good measure.


Ole Adrian Heggli
MA student, SARC
Queen's University Belfast


-start code-





;-o ;fout.wav
-W ;;;




sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

instr 1 ; Creates score-events the length of the file being processed.
	; Should be noted that I've tried this with an oscil-opcode in the
	; looping instrument, and get the same results. So, there might be a
	; flaw in this instrument, but I believe there is another flaw that
	; is causing the main problems.


ilength filelen "tilpros.wav"
        event_i "i", 2, 0, ilength

endin

instr 2

iindex = 1

loopStart:


aInL diskin "tilpros.wav", 1	; Read the file to be processed
aInR = aInL
aTestL,aTestR freeverb aInL, aInR, 0.7, 0.2 ; Processing

SName sprintf "test%02d.wav", iindex ; Creates a string with changing
name for each iteration


fout SName,2,aTestL,aTestR 	; Writes audio to disk, will only work the
last iteration of the loop.
				; Actually it only works the "last iteration -1" of the loop

iindex = iindex + 1

if (iindex < 5) igoto loopStart


endin





;f1 0 16384 10 1
i 1 0 1
i 2 0 length





-end code-

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-11-17 14:05
FromØyvind Brandtsegg
Subjectre: [Csnd] Not quite understanding csounds loop function
Hello Ole

I haven't looked too hard at the details, but one problem is that you loop at i-rate, but the file writing occurs at k-rate.
So at init time, you rewrite the contents of SName a few times (not creating new instances),
and when the k-rate processing starts it will use the last version of SName.

Perhaps you could look at the udo RecursiveDiskin for inspiration
http://www.csounds.com/udo/displayOpcode.php?opcode_id=8
Or perhaps it could be done with a macro. I guess using an udo would be more elegant.
 

Oeyvind Brandtsegg
Professor of Music Technology
NTNU
7491 Trondheim
Norway

________________________________________
Fra: Ole Adrian Heggli [oleheggli@gmail.com]
Sendt: 17. november 2011 14:48
Til: csound@lists.bath.ac.uk
Emne: [Csnd] Not quite understanding csounds loop function

Hi,


I'm new to this list, and will start off by asking for help with the
loop functionality in csound. My goal is to create a script that will
process files with opcodes with randomized parameters. Everything
works well, apart from that my code will only actually write the audio
file the second to last iteration of the for-loop. I guess this might
have something to do with me not quite understanding the subleties of
the csound score. Any help would be appriciated.

What is considered good practise on this mailing list? Attaching
files, or pasting code into the email? I wil do both for good measure.


Ole Adrian Heggli
MA student, SARC
Queen's University Belfast


-start code-





;-o ;fout.wav
-W ;;;




sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

instr 1 ; Creates score-events the length of the file being processed.
        ; Should be noted that I've tried this with an oscil-opcode in the
        ; looping instrument, and get the same results. So, there might be a
        ; flaw in this instrument, but I believe there is another flaw that
        ; is causing the main problems.


ilength filelen "tilpros.wav"
        event_i "i", 2, 0, ilength

endin

instr 2

iindex = 1

loopStart:


aInL diskin "tilpros.wav", 1    ; Read the file to be processed
aInR = aInL
aTestL,aTestR freeverb aInL, aInR, 0.7, 0.2 ; Processing

SName sprintf "test%02d.wav", iindex ; Creates a string with changing
name for each iteration


fout SName,2,aTestL,aTestR      ; Writes audio to disk, will only work the
last iteration of the loop.
                                ; Actually it only works the "last iteration -1" of the loop

iindex = iindex + 1

if (iindex < 5) igoto loopStart


endin





;f1 0 16384 10 1
i 1 0 1
i 2 0 length





-end code-

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-11-17 14:12
FromVictor Lazzarini
SubjectRe: [Csnd] Not quite understanding csounds loop function
Hi Ole,

this is because somewhere the audio signal is being overwritten before being put to the file.
Generally speaking, you will not want to loop over audio signals like this. There are two ways 
to do what you want:

1) the simplest way is to have instr 1 spawn many instances of instr 2 (with no loops, just the
audio generation opcodes) use 'out' or 'outs' etc, to  write the signal to the main output buffer
(which will contain the mix of all instruments). Then use the option  -o  to write the 
mixed output (instead of say -o dac) to a file.

If you still want to use fout, place this in a different instrument (higher number) and then
use a global variable (as a bus) or a bus channel (chnget/set etc) to send the signal from instr 2 
to it

2) Use a recursive UDO to implement a loop. More complex conceptually.

Victor

On 17 Nov 2011, at 13:48, Ole Adrian Heggli wrote:

> Hi,
> 
> 
> I'm new to this list, and will start off by asking for help with the
> loop functionality in csound. My goal is to create a script that will
> process files with opcodes with randomized parameters. Everything
> works well, apart from that my code will only actually write the audio
> file the second to last iteration of the for-loop. I guess this might
> have something to do with me not quite understanding the subleties of
> the csound score. Any help would be appriciated.
> 
> What is considered good practise on this mailing list? Attaching
> files, or pasting code into the email? I wil do both for good measure.
> 
> 
> Ole Adrian Heggli
> MA student, SARC
> Queen's University Belfast
> 
> 
> -start code-
> 
> 
> 
> 
> 
> ;-o ;fout.wav
> -W ;;;
> 
> 
> 
> 
> sr = 44100
> ksmps = 32
> nchnls = 2
> 0dbfs  = 1
> 
> instr 1 ; Creates score-events the length of the file being processed.
> 	; Should be noted that I've tried this with an oscil-opcode in the
> 	; looping instrument, and get the same results. So, there might be a
> 	; flaw in this instrument, but I believe there is another flaw that
> 	; is causing the main problems.
> 
> 
> ilength filelen "tilpros.wav"
>        event_i "i", 2, 0, ilength
> 
> endin
> 
> instr 2
> 
> iindex = 1
> 
> loopStart:
> 
> 
> aInL diskin "tilpros.wav", 1	; Read the file to be processed
> aInR = aInL
> aTestL,aTestR freeverb aInL, aInR, 0.7, 0.2 ; Processing
> 
> SName sprintf "test%02d.wav", iindex ; Creates a string with changing
> name for each iteration
> 
> 
> fout SName,2,aTestL,aTestR 	; Writes audio to disk, will only work the
> last iteration of the loop.
> 				; Actually it only works the "last iteration -1" of the loop
> 
> iindex = iindex + 1
> 
> if (iindex < 5) igoto loopStart
> 
> 
> endin
> 
> 
> 
> 
> 
> ;f1 0 16384 10 1
> i 1 0 1
> i 2 0 length
> 
> 
> 
> 
> 
> -end code-
> 
> 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





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-11-18 18:23
FromOle Adrian Heggli
SubjectRe: [Csnd] Not quite understanding csounds loop function
Hi,

Thanks for the quick replies. I will look into both possible
solutions. I also came across this article (1), which seems to
offering a solution to my basic problem, batch processing.

(1) http://www.csounds.com/journal/issue7/commandLineFXProcessing.html


Ole Adrian Heggli
MA student, SARC
 Queen's University Belfast



2011/11/17 Victor Lazzarini :
> Hi Ole,
>
> this is because somewhere the audio signal is being overwritten before being put to the file.
> Generally speaking, you will not want to loop over audio signals like this. There are two ways
> to do what you want:
>
> 1) the simplest way is to have instr 1 spawn many instances of instr 2 (with no loops, just the
> audio generation opcodes) use 'out' or 'outs' etc, to  write the signal to the main output buffer
> (which will contain the mix of all instruments). Then use the option  -o  to write the
> mixed output (instead of say -o dac) to a file.
>
> If you still want to use fout, place this in a different instrument (higher number) and then
> use a global variable (as a bus) or a bus channel (chnget/set etc) to send the signal from instr 2
> to it
>
> 2) Use a recursive UDO to implement a loop. More complex conceptually.
>
> Victor
>
> On 17 Nov 2011, at 13:48, Ole Adrian Heggli wrote:
>
>> Hi,
>>
>>
>> I'm new to this list, and will start off by asking for help with the
>> loop functionality in csound. My goal is to create a script that will
>> process files with opcodes with randomized parameters. Everything
>> works well, apart from that my code will only actually write the audio
>> file the second to last iteration of the for-loop. I guess this might
>> have something to do with me not quite understanding the subleties of
>> the csound score. Any help would be appriciated.
>>
>> What is considered good practise on this mailing list? Attaching
>> files, or pasting code into the email? I wil do both for good measure.
>>
>>
>> Ole Adrian Heggli
>> MA student, SARC
>> Queen's University Belfast
>>
>>
>> -start code-
>>
>> 
>>
>>
>> 
>> ;-o ;fout.wav
>> -W ;;;
>> 
>>
>>
>> 
>> sr = 44100
>> ksmps = 32
>> nchnls = 2
>> 0dbfs  = 1
>>
>> instr 1 ; Creates score-events the length of the file being processed.
>>       ; Should be noted that I've tried this with an oscil-opcode in the
>>       ; looping instrument, and get the same results. So, there might be a
>>       ; flaw in this instrument, but I believe there is another flaw that
>>       ; is causing the main problems.
>>
>>
>> ilength filelen "tilpros.wav"
>>        event_i "i", 2, 0, ilength
>>
>> endin
>>
>> instr 2
>>
>> iindex = 1
>>
>> loopStart:
>>
>>
>> aInL diskin "tilpros.wav", 1  ; Read the file to be processed
>> aInR = aInL
>> aTestL,aTestR freeverb aInL, aInR, 0.7, 0.2 ; Processing
>>
>> SName sprintf "test%02d.wav", iindex ; Creates a string with changing
>> name for each iteration
>>
>>
>> fout SName,2,aTestL,aTestR    ; Writes audio to disk, will only work the
>> last iteration of the loop.
>>                               ; Actually it only works the "last iteration -1" of the loop
>>
>> iindex = iindex + 1
>>
>> if (iindex < 5) igoto loopStart
>>
>>
>> endin
>>
>> 
>>
>>
>> 
>> ;f1 0 16384 10 1
>> i 1 0 1
>> i 2 0 length
>> 
>>
>>
>> 
>>
>> -end code-
>>
>> 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
>
>
>
>
>
> 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"