[Csnd] Realtime Instrument Generation?
Date | 2011-02-24 02:35 |
From | Jack Senechal |
Subject | [Csnd] Realtime Instrument Generation? |
Hello all, I've got a question about the Csound API. I'm going to be helping to build a synth platform for realtime audio generation. We're enthusiastic about using Csound as the underlying synth framework because of the rich library of opcodes, the low latency, etc. What I'm wondering is how to go about building Csound into our C++ application. Ideally, we would not use any orchestra files but would generate the instruments on the fly in realtime. Is this possible with the C or C++ API, and where would I go to learn more?
So far, I've followed tutorials to compile the basic example app, which is essentially the command line csound utility. I've also dug around in the API docs and the source code a bit, but I haven't yet been able to determine yet how I'd generate instruments on the fly. The API examples I've found all use orchestra files, and call the compile() method to instantiate the instruments from the files and arguments listed in the argv array. I guess I'm looking for something lower level than that.
I've also seen examples of realtime score generation using the CsoundAC API, however I'm not sure if the same can be done with orchestras/instruments. The primary reason for wanting to do realtime instrument generation is so that we can have an interface that will let the user add and remove instruments on the fly, and tweak all aspects of them, without an interruption in the sound output.
Thanks in advance for any advice! Best Regards, Jack Senechal |
Date | 2011-02-24 03:29 |
From | Michael Gogins |
Subject | Re: [Csnd] Realtime Instrument Generation? |
Currently, it is not possible to compile a Csound instrument definition and insert it into a running orchestra. This is, however, a goal of the Csound developers. It is of course possible to build instrument definitions as text in memory, to store both orchestras and scores in memory, to stop and start Csoud programmatically, and so on. Therefore, it is possible to do something like this, and it can be done pretty quickly: Edit an instrument definition while Csound is playing. Replace an old instrument definition in the orchestra with the new definition, or add it to the orchestra. Record at what time in the score Csound is playing. Stop Csound. Quickly recompile the orchestra. Restart Csound. Seek in the score to the point in time at which it was stopped. This can all be done pretty quickly, and indeed I have followed this procedure numerous times in CsoundVST, but there is of course still a brief halt to sound output. Hope this helps, Mike On Wed, Feb 23, 2011 at 9:35 PM, Jack Senechal |
Date | 2011-02-24 04:34 |
From | Jack Senechal |
Subject | Re: [Csnd] Realtime Instrument Generation? |
Michael, thanks for the quick answer! That's very helpful. I think I'll be able to work with that. And if I'm understanding correctly, I'll still be able to alter the input variables of the opcodes in realtime without interrupting the sound output... it would just interrupt the sound if I need to add or remove opcodes or change the structure of the instruments.
Do you have any examples I could refer to that would show the operation you described--adding/altering an instrument, stopping csound, recompiling the orchestra, and restarting it? I haven't yet found the appropriate functions for all of that in my perusals of the API...
Thanks! Jack
On Wed, Feb 23, 2011 at 7:29 PM, Michael Gogins <michael.gogins@gmail.com> wrote: Currently, it is not possible to compile a Csound instrument |
Date | 2011-02-24 05:04 |
From | Steven Yi |
Subject | Re: [Csnd] Realtime Instrument Generation? |
To note, I believe one should--from C++ and C--be able to assemble instruments and manipulate the CSOUND* 's instrument chain. At that point though, the code for doing that would have to do essentially everything that the csound parser/compiler is doing: allocating blocks of memory to use as variables, assembling a linked list of opcodes, etc. It'd be a good bit of work as there isn't an API for this. On Wed, Feb 23, 2011 at 10:29 PM, Michael Gogins |
Date | 2011-02-24 07:35 |
From | Francois PINOT |
Subject | Re: [Csnd] Realtime Instrument Generation? |
A C/C++ app using the Csound API should be able to start two different instances of Csound. So you could start a firts instance of Csound, and while it is playing, you could edit and modify the instruments that this first instance is running. When the modifications are done, a second instance of Csound could be started with the new versions of the instruments, thus avoiding a sound interruption. Francois 2011/2/24 Steven Yi <stevenyi@gmail.com> To note, I believe one should--from C++ and C--be able to assemble |
Date | 2011-02-24 07:52 |
From | Jack Senechal |
Subject | Re: [Csnd] Realtime Instrument Generation? |
Ah, now that's interesting! I wonder how "seamless" one could get the transition. On Wed, Feb 23, 2011 at 11:35 PM, Francois PINOT <fggpinot@gmail.com> wrote: A C/C++ app using the Csound API should be able to start two different instances of Csound. So you could start a firts instance of Csound, and while it is playing, you could edit and modify the instruments that this first instance is running. When the modifications are done, a second instance of Csound could be started with the new versions of the instruments, thus avoiding a sound interruption. |
Date | 2011-02-24 08:21 |
From | Victor Lazzarini |
Subject | Re: [Csnd] Realtime Instrument Generation? |
Provided that your instruments endings are rounded-off nicely, it's as seamless as you like. Victor On 24 Feb 2011, at 07:52, Jack Senechal wrote: Ah, now that's interesting! I wonder how "seamless" one could get the transition. |
Date | 2011-02-24 08:31 |
From | Oeyvind Brandtsegg |
Subject | Re: [Csnd] Realtime Instrument Generation? |
I guess that you could also do crossfading between Csound instances if you collect the audio out from Csound in the C++ application. This way you would not even have to wait for any active notes to finish before switching. There could be a potential problem if your application does live sampling, as the live sampled sudio from the old Csound instance would have to be transferred to the new instance. As far as I know, there is no way for several Csound instances to share memory. A solution could be hacked where the old instance dumps the audio memory and the new one records it. best Oeyvind 2011/2/24 Victor Lazzarini |
Date | 2011-02-24 09:24 |
From | Victor Lazzarini |
Subject | Re: [Csnd] Realtime Instrument Generation? |
They can share memory alright, because you can access the other instance's function tables and channels, for instance. Victor On 24 Feb 2011, at 08:31, Oeyvind Brandtsegg wrote: > I guess that you could also do crossfading between Csound instances if > you collect the audio out from Csound in the C++ application. This way > you would not even have to wait for any active notes to finish before > switching. There could be a potential problem if your application does > live sampling, as the live sampled sudio from the old Csound instance > would have to be transferred to the new instance. As far as I know, > there is no way for several Csound instances to share memory. A > solution could be hacked where the old instance dumps the audio memory > and the new one records it. > best > Oeyvind > > 2011/2/24 Victor Lazzarini |
Date | 2011-02-24 10:34 |
From | Michael Gogins |
Subject | Re: [Csnd] Realtime Instrument Generation? |
The CppSound class can store orcs and access them by instrument instance. This is the C++ or python api. On Feb 24, 2011 4:25 AM, "Victor Lazzarini" <Victor.Lazzarini@nuim.ie> wrote:
> They can share memory alright, because you can access the other > instance's function tables and channels, > for instance. > > Victor > > On 24 Feb 2011, at 08:31, Oeyvind Brandtsegg wrote: > >> I guess that you could also do crossfading between Csound instances if >> you collect the audio out from Csound in the C++ application. This way >> you would not even have to wait for any active notes to finish before >> switching. There could be a potential problem if your application does >> live sampling, as the live sampled sudio from the old Csound instance >> would have to be transferred to the new instance. As far as I know, >> there is no way for several Csound instances to share memory. A >> solution could be hacked where the old instance dumps the audio memory >> and the new one records it. >> best >> Oeyvind >> >> 2011/2/24 Victor Lazzarini <Victor.Lazzarini@nuim.ie>: >>> Provided that your instruments endings are rounded-off nicely, it's >>> as >>> seamless as you like. >>> Victor >>> On 24 Feb 2011, at 07:52, Jack Senechal wrote: >>> >>> Ah, now that's interesting! I wonder how "seamless" one could get the >>> transition. >>> >>> On Wed, Feb 23, 2011 at 11:35 PM, Francois PINOT >>> <fggpinot@gmail.com> wrote: >>>> >>>> A C/C++ app using the Csound API should be able to start two >>>> different >>>> instances of Csound. So you could start a firts instance of >>>> Csound, and >>>> while it is playing, you could edit and modify the instruments >>>> that this >>>> first instance is running. When the modifications are done, a second >>>> instance of Csound could be started with the new versions of the >>>> instruments, thus avoiding a sound interruption. >>>> >>>> Francois >>>> >>>> >>>> 2011/2/24 Steven Yi <stevenyi@gmail.com> >>>>> >>>>> To note, I believe one should--from C++ and C--be able to assemble >>>>> instruments and manipulate the CSOUND* 's instrument chain. At >>>>> that >>>>> point though, the code for doing that would have to do essentially >>>>> everything that the csound parser/compiler is doing: allocating >>>>> blocks >>>>> of memory to use as variables, assembling a linked list of opcodes, >>>>> etc. It'd be a good bit of work as there isn't an API for this. >>>>> >>>>> >>>>> On Wed, Feb 23, 2011 at 10:29 PM, Michael Gogins >>>>> <michael.gogins@gmail.com> wrote: >>>>>> Currently, it is not possible to compile a Csound instrument >>>>>> definition and insert it into a running orchestra. This is, >>>>>> however, a >>>>>> goal of the Csound developers. >>>>>> >>>>>> It is of course possible to build instrument definitions as text >>>>>> in >>>>>> memory, to store both orchestras and scores in memory, to stop and >>>>>> start Csoud programmatically, and so on. Therefore, it is >>>>>> possible to >>>>>> do something like this, and it can be done pretty quickly: >>>>>> >>>>>> Edit an instrument definition while Csound is playing. >>>>>> >>>>>> Replace an old instrument definition in the orchestra with the new >>>>>> definition, or add it to the orchestra. >>>>>> >>>>>> Record at what time in the score Csound is playing. >>>>>> >>>>>> Stop Csound. >>>>>> >>>>>> Quickly recompile the orchestra. >>>>>> >>>>>> Restart Csound. >>>>>> >>>>>> Seek in the score to the point in time at which it was stopped. >>>>>> >>>>>> This can all be done pretty quickly, and indeed I have followed >>>>>> this >>>>>> procedure numerous times in CsoundVST, but there is of course >>>>>> still a >>>>>> brief halt to sound output. >>>>>> >>>>>> Hope this helps, >>>>>> Mike >>>>>> >>>>>> On Wed, Feb 23, 2011 at 9:35 PM, Jack Senechal <jacksenechal@gmail.com >>>>>> > >>>>>> wrote: >>>>>>> Hello all, >>>>>>> I've got a question about the Csound API. I'm going to be >>>>>>> helping to >>>>>>> build >>>>>>> a synth platform for realtime audio generation. We're >>>>>>> enthusiastic >>>>>>> about >>>>>>> using Csound as the underlying synth framework because of the >>>>>>> rich library >>>>>>> of opcodes, the low latency, etc. What I'm wondering is how to >>>>>>> go >>>>>>> about building Csound into our C++ application. Ideally, we >>>>>>> would not >>>>>>> use >>>>>>> any orchestra files but would generate the instruments on the >>>>>>> fly in >>>>>>> realtime. Is this possible with the C or C++ API, and where >>>>>>> would I >>>>>>> go to >>>>>>> learn more? >>>>>>> So far, I've followed tutorials to compile the basic example app, >>>>>>> which is >>>>>>> essentially the command line csound utility. I've also dug >>>>>>> around in >>>>>>> the >>>>>>> API docs and the source code a bit, but I haven't yet been able >>>>>>> to >>>>>>> determine >>>>>>> yet how I'd generate instruments on the fly. The API examples >>>>>>> I've >>>>>>> found >>>>>>> all use orchestra files, and call the compile() method to >>>>>>> instantiate >>>>>>> the >>>>>>> instruments from the files and arguments listed in the argv >>>>>>> array. I >>>>>>> guess >>>>>>> I'm looking for something lower level than that. >>>>>>> I've also seen examples of realtime score generation using the >>>>>>> CsoundAC API, >>>>>>> however I'm not sure if the same can be done with >>>>>>> orchestras/instruments. >>>>>>> The primary reason for wanting to do realtime instrument >>>>>>> generation is >>>>>>> so >>>>>>> that we can have an interface that will let the user add and >>>>>>> remove >>>>>>> instruments on the fly, and tweak all aspects of them, without an >>>>>>> interruption in the sound output. >>>>>>> Thanks in advance for any advice! >>>>>>> Best Regards, >>>>>>> Jack Senechal >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Michael Gogins >>>>>> Irreducible Productions >>>>>> http://www.michael-gogins.com >>>>>> Michael dot Gogins at gmail dot com >>>>>> >>>>>> >>>>>> 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" >>>>> >>>> >>> >>> >>> >> >> >> 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" > |
Date | 2011-02-24 11:59 |
From | Oeyvind Brandtsegg |
Subject | Re: [Csnd] Realtime Instrument Generation? |
Yes, I forgot about that, good :-) But still, consider this scenario: You live sample something in instance 1, then you edit an instrument, so you start a second instance, still reading the live sampled data from instance 1, then you want to edit an instrument definition again, so you want to stop instance 1 to update the orchestra, then you need to transfer the live sampled data out of instance 1 or it will be lost. Unless I have missed something (entirely possible :-). best Oeyvind 2011/2/24 Victor Lazzarini |
Date | 2011-02-24 12:28 |
From | Victor Lazzarini |
Subject | Re: [Csnd] Realtime Instrument Generation? |
Start a third instance? Victor On 24 Feb 2011, at 11:59, Oeyvind Brandtsegg wrote: > Yes, I forgot about that, good :-) > But still, consider this scenario: > > You live sample something in instance 1, > then you edit an instrument, so you start a second instance, > still reading the live sampled data from instance 1, > then you want to edit an instrument definition again, > so you want to stop instance 1 to update the orchestra, > then you need to transfer the live sampled data out of instance 1 or > it will be lost. > Unless I have missed something (entirely possible :-). > > best > Oeyvind > > 2011/2/24 Victor Lazzarini |
Date | 2011-02-24 16:31 |
From | Andres Cabrera |
Subject | Re: [Csnd] Realtime Instrument Generation? |
Hi, I think this approach was taken by Ounk, but it will become unwieldy if you require a very versatile system. That's why Olivier ended up writing his own synthesis audio engine for python. However if you don't need a great flexibility, this will certainly be a good approach. Cheers, Andres On Thu, Feb 24, 2011 at 12:28 PM, Victor Lazzarini |