Csound Csound-dev Csound-tekno Search About

[Csnd] CScound and C

Date2010-01-29 04:02
Fromseiya
Subject[Csnd] CScound and C
Hello all,

I've actually been a part of the mailing list for a few months,... but have
not said anything. 

I am emailing you all tonight to ask a question, but let me take this time
to briefly introduce myself as well. I am one of Dr. Richard Boulanger's
students at Berklee, and have been studying CSound for a few months now. 

I just started to learn C programming, and the question I have tonight is
using C and CSound together.

I've written the following code to test a certain function (it has a few
memos):

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

#include 
int	i;
float	amp,note;

int main()
{
	
// the part directly below is the "parameter input" part:
	printf("Amplitude?: ");
	scanf("%f", &);
	printf("\nPitch?: ");
	scanf("%f", ¬e);


// after a couple of things are typed in, I need  and 
// and everything in between printed out and saved as
// a .csd file... and if possible, run, all of this in one process. 
// come to think of it, it doesn't need to print. How else could I get it to
run?
		
	printf("\n");
	printf("\n");
	printf("sr = 44100\n");
	printf("ksmps = 4410\n");
	printf("kr = 10\n");
	printf("nchnls = 1\n");
	printf("instr 1\n");
	printf("a1	oscil %f, cpspch(%f), 1\n", amp,note);//parameters entered go
here. 
	printf("out a1\n");
	printf("endin\n");
	printf("\n");
	printf("\n");
	printf("f1 0 4096 10 	1\n");
	printf("i1 0 3\n");
	printf("\n");
	printf("\n");

	
	printf("Enter 1 to start: ");
	scanf("%d", &i);

	switch (i)
	{
	case 1:
	system ("./simplec >> simplec.csd & csound -odac simplec.csd"); //I was
trying to get this code to make a .csd file
									// but when it does, the parameters entered are gone.
	break;
	}	

	return 0;
}

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

The memos within the code describes my problem pretty well. I'm trying to
find a way to enter the amplitude, and the pitch, of a 3 second sine wave,
and output the data as a .csd file and run it. 
But when I do this the parameter's that I've just put in go away and 0 is
used for both the amplitude and the pitch. What can I do so that everytime I
run the program I can put in new parameters, and create a new .csd file with
those parameters?

I'm only a couple days into C and may be getting too far ahead of myself. I
was trying things with fopen () and fwrite() but gave up after a few hours
of producing only errors. 

I would greatly appreciate it if someone could point me in the right
direction!!

Hope to hear from you soon, and hopefully you'll hear a lot more from me
soon, too.

Seiya Matsumiya

Date2010-01-29 10:50
FromVictor Lazzarini
Subject[Csnd] Re: CScound and C
There are two problems here:

1. all printf() calls are redirected to the file, so there is no way  
to be interactive.
2. The system() call expects your program to exist already, but it has  
not been compiled yet.

Solutions
1. find another way of either writing to file and then you can be  
interactive; find another way of obtaining the values when the program  
is run (command-line arguments?)
2. split this into two programs, if you still want to use indirection.  
Otherwise just run csound with the file you created.

Victor


On 29 Jan 2010, at 04:02, seiya wrote:

>
> Hello all,
>
> I've actually been a part of the mailing list for a few months,...  
> but have
> not said anything.
>
> I am emailing you all tonight to ask a question, but let me take  
> this time
> to briefly introduce myself as well. I am one of Dr. Richard  
> Boulanger's
> students at Berklee, and have been studying CSound for a few months  
> now.
>
> I just started to learn C programming, and the question I have  
> tonight is
> using C and CSound together.
>
> I've written the following code to test a certain function (it has a  
> few
> memos):
>
> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 
> \\\\\\\\\\\\\\\
>
> #include 
> int	i;
> float	amp,note;
>
> int main()
> {
> 	
> // the part directly below is the "parameter input" part:
> 	printf("Amplitude?: ");
> 	scanf("%f", &);
> 	printf("\nPitch?: ");
> 	scanf("%f", ¬e);
>
>
> // after a couple of things are typed in, I need   
> and
> // and everything in between printed out and  
> saved as
> // a .csd file... and if possible, run, all of this in one process.
> // come to think of it, it doesn't need to print. How else could I  
> get it to
> run?
> 		
> 	printf("\n");
> 	printf("\n");
> 	printf("sr = 44100\n");
> 	printf("ksmps = 4410\n");
> 	printf("kr = 10\n");
> 	printf("nchnls = 1\n");
> 	printf("instr 1\n");
> 	printf("a1	oscil %f, cpspch(%f), 1\n", amp,note);//parameters  
> entered go
> here.
> 	printf("out a1\n");
> 	printf("endin\n");
> 	printf("\n");
> 	printf("\n");
> 	printf("f1 0 4096 10 	1\n");
> 	printf("i1 0 3\n");
> 	printf("\n");
> 	printf("\n");
>
> 	
> 	printf("Enter 1 to start: ");
> 	scanf("%d", &i);
>
> 	switch (i)
> 	{
> 	case 1:
> 	system ("./simplec >> simplec.csd & csound -odac simplec.csd"); //I  
> was
> trying to get this code to make a .csd file
> 									// but when it does, the parameters entered are gone.
> 	break;
> 	}	
>
> 	return 0;
> }
>
> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 
> \\\
>
> The memos within the code describes my problem pretty well. I'm  
> trying to
> find a way to enter the amplitude, and the pitch, of a 3 second sine  
> wave,
> and output the data as a .csd file and run it.
> But when I do this the parameter's that I've just put in go away and  
> 0 is
> used for both the amplitude and the pitch. What can I do so that  
> everytime I
> run the program I can put in new parameters, and create a new .csd  
> file with
> those parameters?
>
> I'm only a couple days into C and may be getting too far ahead of  
> myself. I
> was trying things with fopen () and fwrite() but gave up after a few  
> hours
> of producing only errors.
>
> I would greatly appreciate it if someone could point me in the right
> direction!!
>
> Hope to hear from you soon, and hopefully you'll hear a lot more  
> from me
> soon, too.
>
> Seiya Matsumiya
>
> -- 
> View this message in context: http://old.nabble.com/CScound-and-C-tp27366747p27366747.html
> Sent from the Csound - General mailing list archive at Nabble.com.
>
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body  
> "unsubscribe csound"



Send bugs reports to this list.
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2010-01-29 17:32
Fromforrest cahoon
Subject[Csnd] Re: CScound and C
This is easy enough to fix --

declare a filehandle in your declarations like so

FILE *fh;

before your printf statements that write the csd, put

fh = fopen("out.csd", "w");

and then change the printf statements to fprint statements like this:

fprintf(fh, "");

after you're done writing out, close the file with

fclose(fh);

Then you don't have to try to pipe the output of the program into the
file (which doesn't work because it's prompting, and even if it didn't
having a program call itself with no stop condition will result in
infinite recursion).


But why are you trying to write this in C?  If what you're trying to
code is this simple, you should really use a scripting language.  It
seems the CSound community makes extensive use of Python, making it an
obvious choice.

I'm not conversant in python myself; maybe someone else on the list
could post a python version of this code?

Forrest


On Thu, Jan 28, 2010 at 10:02 PM, seiya  wrote:
>
> Hello all,
>
> I've actually been a part of the mailing list for a few months,... but have
> not said anything.
>
> I am emailing you all tonight to ask a question, but let me take this time
> to briefly introduce myself as well. I am one of Dr. Richard Boulanger's
> students at Berklee, and have been studying CSound for a few months now.
>
> I just started to learn C programming, and the question I have tonight is
> using C and CSound together.
>
> I've written the following code to test a certain function (it has a few
> memos):
>
> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
>
> #include 
> int     i;
> float   amp,note;
>
> int main()
> {
>
> // the part directly below is the "parameter input" part:
>        printf("Amplitude?: ");
>        scanf("%f", &);
>        printf("\nPitch?: ");
>        scanf("%f", ¬e);
>
>
> // after a couple of things are typed in, I need  and
> // and everything in between printed out and saved as
> // a .csd file... and if possible, run, all of this in one process.
> // come to think of it, it doesn't need to print. How else could I get it to
> run?
>
>        printf("\n");
>        printf("\n");
>        printf("sr = 44100\n");
>        printf("ksmps = 4410\n");
>        printf("kr = 10\n");
>        printf("nchnls = 1\n");
>        printf("instr 1\n");
>        printf("a1      oscil %f, cpspch(%f), 1\n", amp,note);//parameters entered go
> here.
>        printf("out a1\n");
>        printf("endin\n");
>        printf("\n");
>        printf("\n");
>        printf("f1 0 4096 10    1\n");
>        printf("i1 0 3\n");
>        printf("\n");
>        printf("\n");
>
>
>        printf("Enter 1 to start: ");
>        scanf("%d", &i);
>
>        switch (i)
>        {
>        case 1:
>        system ("./simplec >> simplec.csd & csound -odac simplec.csd"); //I was
> trying to get this code to make a .csd file
>                                                                        // but when it does, the parameters entered are gone.
>        break;
>        }
>
>        return 0;
> }
>
> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
>
> The memos within the code describes my problem pretty well. I'm trying to
> find a way to enter the amplitude, and the pitch, of a 3 second sine wave,
> and output the data as a .csd file and run it.
> But when I do this the parameter's that I've just put in go away and 0 is
> used for both the amplitude and the pitch. What can I do so that everytime I
> run the program I can put in new parameters, and create a new .csd file with
> those parameters?
>
> I'm only a couple days into C and may be getting too far ahead of myself. I
> was trying things with fopen () and fwrite() but gave up after a few hours
> of producing only errors.
>
> I would greatly appreciate it if someone could point me in the right
> direction!!
>
> Hope to hear from you soon, and hopefully you'll hear a lot more from me
> soon, too.
>
> Seiya Matsumiya
>
> --
> View this message in context: http://old.nabble.com/CScound-and-C-tp27366747p27366747.html
> Sent from the Csound - General mailing list archive at Nabble.com.
>
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>


Send bugs reports to this list.
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2010-01-29 23:21
FromSeiya Matsumiya
Subject[Csnd] Re: Re: CScound and C
Thanks for your responses!

Forrest, thanks for the detailed explanation. I had the C programming  
class today and as it turns out, my question was what we covered.

I would like to look into Python in the future... but the reason why  
I'm doing it in C is because I'm studying it now, and I just wanted to  
figure out a way to do it : )

Thanks again.

Seiya




On Jan 29, 2010, at 12:32 PM, forrest cahoon wrote:

> This is easy enough to fix --
>
> declare a filehandle in your declarations like so
>
> FILE *fh;
>
> before your printf statements that write the csd, put
>
> fh = fopen("out.csd", "w");
>
> and then change the printf statements to fprint statements like this:
>
> fprintf(fh, "");
>
> after you're done writing out, close the file with
>
> fclose(fh);
>
> Then you don't have to try to pipe the output of the program into the
> file (which doesn't work because it's prompting, and even if it didn't
> having a program call itself with no stop condition will result in
> infinite recursion).
>
>
> But why are you trying to write this in C?  If what you're trying to
> code is this simple, you should really use a scripting language.  It
> seems the CSound community makes extensive use of Python, making it an
> obvious choice.
>
> I'm not conversant in python myself; maybe someone else on the list
> could post a python version of this code?
>
> Forrest
>
>
> On Thu, Jan 28, 2010 at 10:02 PM, seiya   
> wrote:
>>
>> Hello all,
>>
>> I've actually been a part of the mailing list for a few months,...  
>> but have
>> not said anything.
>>
>> I am emailing you all tonight to ask a question, but let me take  
>> this time
>> to briefly introduce myself as well. I am one of Dr. Richard  
>> Boulanger's
>> students at Berklee, and have been studying CSound for a few months  
>> now.
>>
>> I just started to learn C programming, and the question I have  
>> tonight is
>> using C and CSound together.
>>
>> I've written the following code to test a certain function (it has  
>> a few
>> memos):
>>
>> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 
>> \\\\\\\\\\\\\\\\
>>
>> #include 
>> int     i;
>> float   amp,note;
>>
>> int main()
>> {
>>
>> // the part directly below is the "parameter input" part:
>>        printf("Amplitude?: ");
>>        scanf("%f", &);
>>        printf("\nPitch?: ");
>>        scanf("%f", ¬e);
>>
>>
>> // after a couple of things are typed in, I need  
>>  and
>> // and everything in between printed out and  
>> saved as
>> // a .csd file... and if possible, run, all of this in one process.
>> // come to think of it, it doesn't need to print. How else could I  
>> get it to
>> run?
>>
>>        printf("\n");
>>        printf("\n");
>>        printf("sr = 44100\n");
>>        printf("ksmps = 4410\n");
>>        printf("kr = 10\n");
>>        printf("nchnls = 1\n");
>>        printf("instr 1\n");
>>        printf("a1      oscil %f, cpspch(%f), 1\n", amp,note);// 
>> parameters entered go
>> here.
>>        printf("out a1\n");
>>        printf("endin\n");
>>        printf("\n");
>>        printf("\n");
>>        printf("f1 0 4096 10    1\n");
>>        printf("i1 0 3\n");
>>        printf("\n");
>>        printf("\n");
>>
>>
>>        printf("Enter 1 to start: ");
>>        scanf("%d", &i);
>>
>>        switch (i)
>>        {
>>        case 1:
>>        system ("./simplec >> simplec.csd & csound -odac  
>> simplec.csd"); //I was
>> trying to get this code to make a .csd file
>>                                                                        // but 
>>  when it does, the parameters entered are gone.
>>        break;
>>        }
>>
>>        return 0;
>> }
>>
>> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 
>> \\\\
>>
>> The memos within the code describes my problem pretty well. I'm  
>> trying to
>> find a way to enter the amplitude, and the pitch, of a 3 second  
>> sine wave,
>> and output the data as a .csd file and run it.
>> But when I do this the parameter's that I've just put in go away  
>> and 0 is
>> used for both the amplitude and the pitch. What can I do so that  
>> everytime I
>> run the program I can put in new parameters, and create a new .csd  
>> file with
>> those parameters?
>>
>> I'm only a couple days into C and may be getting too far ahead of  
>> myself. I
>> was trying things with fopen () and fwrite() but gave up after a  
>> few hours
>> of producing only errors.
>>
>> I would greatly appreciate it if someone could point me in the right
>> direction!!
>>
>> Hope to hear from you soon, and hopefully you'll hear a lot more  
>> from me
>> soon, too.
>>
>> Seiya Matsumiya
>>
>> --
>> View this message in context: http://old.nabble.com/CScound-and-C-tp27366747p27366747.html
>> Sent from the Csound - General mailing list archive at Nabble.com.
>>
>>
>>
>> Send bugs reports to this list.
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body  
>> "unsubscribe csound"
>>
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body  
> "unsubscribe csound"



Send bugs reports to this list.
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2010-01-30 13:11
FromRory Walsh
Subject[Csnd] Re: Re: Re: CScound and C
You might also want to look into using teh Csound API which is written
in C. You can find some info about here:
http://www.csounds.com/articles/RoryWalsh_CsoundAPI.pdf

Rory.


On 29 January 2010 23:21, Seiya Matsumiya  wrote:
> Thanks for your responses!
>
> Forrest, thanks for the detailed explanation. I had the C programming class
> today and as it turns out, my question was what we covered.
>
> I would like to look into Python in the future... but the reason why I'm
> doing it in C is because I'm studying it now, and I just wanted to figure
> out a way to do it : )
>
> Thanks again.
>
> Seiya
>
>
>
>
> On Jan 29, 2010, at 12:32 PM, forrest cahoon wrote:
>
>> This is easy enough to fix --
>>
>> declare a filehandle in your declarations like so
>>
>> FILE *fh;
>>
>> before your printf statements that write the csd, put
>>
>> fh = fopen("out.csd", "w");
>>
>> and then change the printf statements to fprint statements like this:
>>
>> fprintf(fh, "");
>>
>> after you're done writing out, close the file with
>>
>> fclose(fh);
>>
>> Then you don't have to try to pipe the output of the program into the
>> file (which doesn't work because it's prompting, and even if it didn't
>> having a program call itself with no stop condition will result in
>> infinite recursion).
>>
>>
>> But why are you trying to write this in C?  If what you're trying to
>> code is this simple, you should really use a scripting language.  It
>> seems the CSound community makes extensive use of Python, making it an
>> obvious choice.
>>
>> I'm not conversant in python myself; maybe someone else on the list
>> could post a python version of this code?
>>
>> Forrest
>>
>>
>> On Thu, Jan 28, 2010 at 10:02 PM, seiya  wrote:
>>>
>>> Hello all,
>>>
>>> I've actually been a part of the mailing list for a few months,... but
>>> have
>>> not said anything.
>>>
>>> I am emailing you all tonight to ask a question, but let me take this
>>> time
>>> to briefly introduce myself as well. I am one of Dr. Richard Boulanger's
>>> students at Berklee, and have been studying CSound for a few months now.
>>>
>>> I just started to learn C programming, and the question I have tonight is
>>> using C and CSound together.
>>>
>>> I've written the following code to test a certain function (it has a few
>>> memos):
>>>
>>>
>>> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
>>>
>>> #include 
>>> int     i;
>>> float   amp,note;
>>>
>>> int main()
>>> {
>>>
>>> // the part directly below is the "parameter input" part:
>>>       printf("Amplitude?: ");
>>>       scanf("%f", &);
>>>       printf("\nPitch?: ");
>>>       scanf("%f", ¬e);
>>>
>>>
>>> // after a couple of things are typed in, I need  and
>>> // and everything in between printed out and saved as
>>> // a .csd file... and if possible, run, all of this in one process.
>>> // come to think of it, it doesn't need to print. How else could I get it
>>> to
>>> run?
>>>
>>>       printf("\n");
>>>       printf("\n");
>>>       printf("sr = 44100\n");
>>>       printf("ksmps = 4410\n");
>>>       printf("kr = 10\n");
>>>       printf("nchnls = 1\n");
>>>       printf("instr 1\n");
>>>       printf("a1      oscil %f, cpspch(%f), 1\n", amp,note);//parameters
>>> entered go
>>> here.
>>>       printf("out a1\n");
>>>       printf("endin\n");
>>>       printf("\n");
>>>       printf("\n");
>>>       printf("f1 0 4096 10    1\n");
>>>       printf("i1 0 3\n");
>>>       printf("\n");
>>>       printf("\n");
>>>
>>>
>>>       printf("Enter 1 to start: ");
>>>       scanf("%d", &i);
>>>
>>>       switch (i)
>>>       {
>>>       case 1:
>>>       system ("./simplec >> simplec.csd & csound -odac simplec.csd"); //I
>>> was
>>> trying to get this code to make a .csd file
>>>                                                                       //
>>> but when it does, the parameters entered are gone.
>>>       break;
>>>       }
>>>
>>>       return 0;
>>> }
>>>
>>> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
>>>
>>> The memos within the code describes my problem pretty well. I'm trying to
>>> find a way to enter the amplitude, and the pitch, of a 3 second sine
>>> wave,
>>> and output the data as a .csd file and run it.
>>> But when I do this the parameter's that I've just put in go away and 0 is
>>> used for both the amplitude and the pitch. What can I do so that
>>> everytime I
>>> run the program I can put in new parameters, and create a new .csd file
>>> with
>>> those parameters?
>>>
>>> I'm only a couple days into C and may be getting too far ahead of myself.
>>> I
>>> was trying things with fopen () and fwrite() but gave up after a few
>>> hours
>>> of producing only errors.
>>>
>>> I would greatly appreciate it if someone could point me in the right
>>> direction!!
>>>
>>> Hope to hear from you soon, and hopefully you'll hear a lot more from me
>>> soon, too.
>>>
>>> Seiya Matsumiya
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/CScound-and-C-tp27366747p27366747.html
>>> Sent from the Csound - General mailing list archive at Nabble.com.
>>>
>>>
>>>
>>> Send bugs reports to this list.
>>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
>>> csound"
>>>
>>
>>
>> Send bugs reports to this list.
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
>> csound"
>
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> csound"
>


Send bugs reports to this list.
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"