Csound Csound-dev Csound-tekno Search About

[Csnd] Changing the output file dynamically

Date2020-04-06 09:04
Fromsjakops
Subject[Csnd] Changing the output file dynamically
Dear all,

I'm having trouble changing my output file during a performance - is that
not possible?

In the following I was expecting two output files each with one sounding
note "rec0001.wav" and "rec0002.wav" - but I get both notes in one file,
"rec0000.wav".



-o dac



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

gkrecord init 0
alwayson "master"
connect 2, "masterin", "master", "in"

instr 1
gkrecord init p4
endin

instr 2
asig oscil 0.5, p4, 1
outleta "masterin", asig
endin

instr master
ain inleta "in"
outs ain, ain
if (gkrecord != 0) then
Sfile sprintfk "rec%04d.wav", gkrecord
fout Sfile, 18, ain, ain
endif
endin



f 1 0 16384 10 1
i 2 0 0.5 400
i 1 1 0 1
i 2 1 0.5 500
i 1 2 0 2
i 2 2 0.5 600
e





--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2020-04-06 09:28
FromRory Walsh
SubjectRe: [Csnd] Changing the output file dynamically
It is possible. I suspect the problem here is that you can't change the file name passed to fout at k-rate. Try re-initing the output instrument if gkrecord changes. 

On Mon, 6 Apr 2020 at 09:04, sjakops <sorenkj@gmail.com> wrote:
Dear all,

I'm having trouble changing my output file during a performance - is that
not possible?

In the following I was expecting two output files each with one sounding
note "rec0001.wav" and "rec0002.wav" - but I get both notes in one file,
"rec0000.wav".

<CsoundSynthesizer>
<CsOptions>
-o dac
</CsOptions>
<CsInstruments>

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

gkrecord init 0
alwayson "master"
connect 2, "masterin", "master", "in"

instr 1
gkrecord init p4
endin

instr 2
asig oscil 0.5, p4, 1
outleta "masterin", asig
endin

instr master
ain inleta "in"
outs ain, ain
if (gkrecord != 0) then
Sfile sprintfk "rec%04d.wav", gkrecord
fout Sfile, 18, ain, ain
endif
endin

</CsInstruments>
<CsScore>
f 1 0 16384 10 1
i 2 0 0.5 400
i 1 1 0 1
i 2 1 0.5 500
i 1 2 0 2
i 2 2 0.5 600
e
</CsScore>
</CsoundSynthesizer>



--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2020-04-06 10:13
Fromsjakops
SubjectRe: [Csnd] Changing the output file dynamically
Thanks Rory, that works!

Now I just have an issue with 'bypassing' the fout statement before a file
is supplied - in the following, if I replace "rec0.wav" with "" (empty
string) I get an 'invalid file name' error.

Is it possible to conditionally 'bypass' fout?




-o dac



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

gSfile init "rec0.wav"
alwayson "master"
connect 2, "masterin", "master", "in"

instr 1
gSfile init p4
endin

instr 2
asig oscil 0.5, p4, 1
outleta "masterin", asig
endin

instr master
init:
Sfile = gSfile
ain inleta "in"
outs ain, ain
kcomp strcmpk Sfile, gSfile
if (kcomp != 0) then
  reinit init
endif
kcomp strcmpk Sfile, ""
if (kcomp != 0) then
  fout Sfile, 18, ain, ain
endif
endin



f 1 0 16384 10 1
i 2 0 0.5 400
i 1 1 0 "rec1.wav"
i 2 1 0.5 500
i 1 2 0 "rec2.wav"
i 2 2 0.5 600
e





--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2020-04-06 10:17
FromRory Walsh
SubjectRe: [Csnd] Changing the output file dynamically
You can't pass an empty string to fout. Can't you simply use a variable to hold the bypass state, and then wrap the fout code in a conditional test? 

On Mon, 6 Apr 2020 at 10:13, sjakops <sorenkj@gmail.com> wrote:
Thanks Rory, that works!

Now I just have an issue with 'bypassing' the fout statement before a file
is supplied - in the following, if I replace "rec0.wav" with "" (empty
string) I get an 'invalid file name' error.

Is it possible to conditionally 'bypass' fout?


<CsoundSynthesizer>
<CsOptions>
-o dac
</CsOptions>
<CsInstruments>

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

gSfile init "rec0.wav"
alwayson "master"
connect 2, "masterin", "master", "in"

instr 1
gSfile init p4
endin

instr 2
asig oscil 0.5, p4, 1
outleta "masterin", asig
endin

instr master
init:
Sfile = gSfile
ain inleta "in"
outs ain, ain
kcomp strcmpk Sfile, gSfile
if (kcomp != 0) then
  reinit init
endif
kcomp strcmpk Sfile, ""
if (kcomp != 0) then
  fout Sfile, 18, ain, ain
endif
endin

</CsInstruments>
<CsScore>
f 1 0 16384 10 1
i 2 0 0.5 400
i 1 1 0 "rec1.wav"
i 2 1 0.5 500
i 1 2 0 "rec2.wav"
i 2 2 0.5 600
e
</CsScore>
</CsoundSynthesizer>



--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2020-04-06 12:47
Fromsjakops
SubjectRe: [Csnd] Changing the output file dynamically
I actually already have a conditional if-test around the fout code, but it
seems that it is being called even if the condition is false.. is it that
the if-calculation is only performed at k-rate and fout is somehow called
(with the empty string) before the first k-rate calculation..?



--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2020-04-06 15:15
FromRory Walsh
SubjectRe: [Csnd] Changing the output file dynamically
I would put fout into a unique instrument, and simply start and stop it as needed. I think putting it in an instrument and that is always on limits your control. 

On Mon, 6 Apr 2020 at 12:47, sjakops <sorenkj@gmail.com> wrote:
I actually already have a conditional if-test around the fout code, but it
seems that it is being called even if the condition is false.. is it that
the if-calculation is only performed at k-rate and fout is somehow called
(with the empty string) before the first k-rate calculation..?



--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2020-04-06 15:42
Fromjoachim heintz
SubjectRe: [Csnd] Changing the output file dynamically
this was my thought, too.  you could perhaps start it directly from your 
instr 1 (if p4>0).
and you could use the monitor opcode in the recording instrument to get 
the main output.

if you like, post again, and we cann suggest improvements.

	joachim



On 06/04/2020 16:15, Rory Walsh wrote:
> I would put fout into a unique instrument, and simply start and stop it 
> as needed. I think putting it in an instrument and that is always on 
> limits your control.
> 
> On Mon, 6 Apr 2020 at 12:47, sjakops  > wrote:
> 
>     I actually already have a conditional if-test around the fout code,
>     but it
>     seems that it is being called even if the condition is false.. is it
>     that
>     the if-calculation is only performed at k-rate and fout is somehow
>     called
>     (with the empty string) before the first k-rate calculation..?
> 
> 
> 
>     --
>     Sent from:
>     http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html
> 
>     Csound mailing list
>     Csound@listserv.heanet.ie 
>     https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>     Send bugs reports to
>     https://github.com/csound/csound/issues
>     Discussions of bugs and features can be posted here
> 
> Csound mailing list Csound@listserv.heanet.ie 
>  
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to 
> https://github.com/csound/csound/issues Discussions of bugs and features 
> can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2020-04-06 22:12
Fromsjakops
SubjectRe: [Csnd] Changing the output file dynamically
Good idea - that's a much 'cleaner' solution:) Thanks, Søren



--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here