[Csnd] Mixing channels from different csound instances
Date | 2013-11-24 07:07 |
From | imaia |
Subject | [Csnd] Mixing channels from different csound instances |
I'm working real-time project involving multiple audio channels. I have multiple instances of csound(an instance per channel). I decided to not use threads from csound lib, instead I manage threads by hand, using cpu affinity API. Now I need to mix channels from different csound instances. It seems that opcodes like MixerSend, MixerReceive are not appropriate for my case. Could someone give me a hand? Thanks. -- View this message in context: http://csound.1045644.n5.nabble.com/Mixing-channels-from-different-csound-instances-tp5730035.html Sent from the Csound - General mailing list archive at Nabble.com. |
Date | 2013-11-25 15:18 |
From | Steven Yi |
Subject | Re: [Csnd] Mixing channels from different csound instances |
Could you clarify if you are using one thread per csound? I think to make things sync up for mixing, it'd be best to run the csound instances together read the outputs from some instances then write that as the inputs to another csound instance (could use channels or use SPIN and SPOUT to read from the audio ins/outs for the Csound instance). On Sun, Nov 24, 2013 at 2:07 AM, imaia |
Date | 2013-11-25 21:21 |
From | imaia |
Subject | [Csnd] Re: Mixing channels from different csound instances |
I'm using one thread per csound instance. But I'm using my own pthreads instead of csound's thread API. What you mean when you say ' run the csound instances together' ? On multiple threads in the same process? That's my case. So, If I use either SPIN/SPOUT or channels, the things will be synchronized? Thanks. -- View this message in context: http://csound.1045644.n5.nabble.com/Mixing-channels-from-different-csound-instances-tp5730035p5730181.html Sent from the Csound - General mailing list archive at Nabble.com. |
Date | 2013-11-27 17:24 |
From | |
Subject | Re: [Csnd] Re: Mixing channels from different csound instances |
Well the design for your work seems to necessitate things not being in sync. As it is now, is each thread/csound pair running completely separately and all writing to soundcard? I was going to go through a number of different strategies here but there are just too many variations. Maybe better, could you explain the desired behavior/design you were thinking about? I.e. each tread renders one block and delivers via message passing to a mixing thread/csound, etc. I'm using one thread per csound instance. But I'm using my own pthreads
instead of csound's thread API. What you mean when you say ' run the csound instances together' ? On multiple threads in the same process? That's my case. So, If I use either SPIN/SPOUT or channels, the things will be synchronized? Thanks. -- View this message in context: http://csound.1045644.n5.nabble.com/Mixing-channels-from-different-csound-instances-tp5730035p5730181.html Sent from the Csound - General mailing list archive at Nabble.com. Send bugs reports to the Sourceforge bug trackers csound6: https://sourceforge.net/p/csound/tickets/ csound5: https://sourceforge.net/p/csound/bugs/ Discussions of bugs and features can be posted here To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound" |
Date | 2013-11-28 06:42 |
From | imaia |
Subject | [Csnd] Re: Mixing channels from different csound instances |
The behavior I want is the same found in mixing equipment. Multiple independent I/O channels, each one with a chain o effects. The system has multiple output cards. In some circumstances, channels need to be mixed in a single output card. I'm asking myself whether I need sync to mix audio channels. I don't know the answer yet. I found in cs6 API : csound{Get/Set}AudioChannel that could be used to communicate cs instances. It's synchronized through spinlocks. In this case I could use chnget, chnset in .cds files. I'm in a good direction? -- View this message in context: http://csound.1045644.n5.nabble.com/Mixing-channels-from-different-csound-instances-tp5730035p5730277.html Sent from the Csound - General mailing list archive at Nabble.com. |
Date | 2013-11-28 11:38 |
From | Justin Smith |
Subject | Re: [Csnd] Re: Mixing channels from different csound instances |
You could prioritize the csound instances staying in sync with one another, by having a "master thread" that calls performKsmps on every instance after mixing their channels from the outside as appropriate. You could prioritize the csound instances staying in sync with their sound cards by having each csound instance in its own thread, sharing channel data. As far as I can tell, either synchronization with each sound card, or synchronization between the csound instances, will be fragile unless there is a common clock keeping the sound cards synced to one another. With low CPU load and short performance duration, you may not notice an issue. With a long enough performance time or a high enough CPU load, you will most definitely see one of these fall out of sync (csounds or soundcards), depending on your design.
On Wed, Nov 27, 2013 at 10:42 PM, imaia <ismapsa@gmail.com> wrote: The behavior I want is the same found in mixing equipment. |
Date | 2013-11-28 14:29 |
From | Oeyvind Brandtsegg |
Subject | Re: [Csnd] Re: Mixing channels from different csound instances |
>From this description it seems it might be a good idea to just use one instance of Csound, as you have have as many inputs and outputs as you like in one instance. If you communicate with several different soundcards, you could make an aggregate device by conneting all hardware to jack and then let csound read/write to jack. Each channel could have independent processing and/or you could route flexible between channels according to needs (e.g. common aux send). If you need to split processing load onto several CPU cores, this should be possible with the recent multicore support within one Csound instance, and if your channels are indeed separate (not too much sending back and forth between channels) the multicore facilities should do a reasonably good job of automatically distributing the load on the available CPUs. Hope I did not misunderstand you use case(?), but perhaps you do not need to split into several instances. best Oeyvind 2013/11/28 imaia |
Date | 2013-11-29 20:26 |
From | imaia |
Subject | [Csnd] Re: Mixing channels from different csound instances |
Thanks for the replies. I will try a single csound instance and csound's multicore implementation. My question is about the load balancing and speedup in csound's multicore. How csound decides what's is a good load in one instance? In Top/threadsafe.c , I can see "CsoundLockMutex" which makes the calling thread sleep. I think it would be better use spinlocks instead of mutex. -- View this message in context: http://csound.1045644.n5.nabble.com/Mixing-channels-from-different-csound-instances-tp5730035p5730344.html Sent from the Csound - General mailing list archive at Nabble.com. |
Date | 2013-11-30 22:38 |
From | Steven Yi |
Subject | Re: [Csnd] Re: Mixing channels from different csound instances |
We do use spin locks in a number of places in the codebase, probably more than actual locks now. (Look for csoundSpinLock and csoundSpinUnLock). The multi-core implementation is mostly held within the Engine/cs_par_* files. I haven't looked through the multicore implementation in depth, but as far as I understand, it uses a SAT solver to figure out dependency of nodes upon each other, splits up work by instrument instance, respects Csound's natural instrument ordering, and uses some cost analysis to figure out if it's worth splitting up the work or just to go ahead and do it. John would be able to better explain (and correct me if I've gotten it wrong!). On Fri, Nov 29, 2013 at 3:26 PM, imaia |
Date | 2013-12-02 01:06 |
From | imaia |
Subject | [Csnd] Re: Mixing channels from different csound instances |
Thanks for the explanations Steven, I can't figure out how many threads csound creates to control performance of one instance. It's something the API user can control? It would be nice to limit the number of threads and CPU affinity of these threads. I say that because it's important in real-time performance a CPU dedicated to I/O and interrupts events while the other on audio processing. -- View this message in context: http://csound.1045644.n5.nabble.com/Mixing-channels-from-different-csound-instances-tp5730035p5730431.html Sent from the Csound - General mailing list archive at Nabble.com. |
Date | 2013-12-02 01:24 |
From | Steven Yi |
Subject | Re: [Csnd] Re: Mixing channels from different csound instances |
You can control the number of threads with -j # where # is number of threads (or can use --num-threads). Those should work with csoundSetOption. As for affinity, I think it isn't used because it is isn't supported on all platforms. I suppose it could be enabled depending on OS. Victor or John would know more about that area of code. On Sun, Dec 1, 2013 at 8:06 PM, imaia |
Date | 2013-12-02 04:04 |
From | imaia |
Subject | [Csnd] Re: Mixing channels from different csound instances |
Ah thanks! It seems good the "--num-threads" option. I will use csoundSetOption in my code. The only remaining question is how to route several channels from a single csound instances to different soundcards? -- View this message in context: http://csound.1045644.n5.nabble.com/Mixing-channels-from-different-csound-instances-tp5730035p5730437.html Sent from the Csound - General mailing list archive at Nabble.com. |
Date | 2013-12-02 04:18 |
From | Steven Yi |
Subject | Re: [Csnd] Re: Mixing channels from different csound instances |
The only way I see for doing that would be to disable csound's hardware IO and to handle it yourself. You can do that with calling csoundSetHostImplementedIO to disable csound from trying to open hardware devices. From there, you could do your own hardware device opening, running of csound, and splitting of audio from the csound spout to the various hardware devices. On Sun, Dec 1, 2013 at 11:04 PM, imaia |
Date | 2013-12-02 07:29 |
From | Oeyvind Brandtsegg |
Subject | Re: [Csnd] Re: Mixing channels from different csound instances |
Or you could create an aggregate device, combining several hardware devices into what looks like one device for Csound. On OSX it can be done in the system audio setup, under windows with ASIO4ALL, under Linux I'm not sure yet (must be possible). I did say earlier that you could do this in jack, but it seems I was wrong about tha, as jack only can relate to one hardware device at a time (someone correct me if I'm wrong) Oeyvind 2013/12/2 Steven Yi |
Date | 2013-12-02 08:57 |
From | Anders Genell |
Subject | Re: [Csnd] Re: Mixing channels from different csound instances |
Just to chime in: An aggregate device can be done with alsa on Linux by creating a "multi" virtual device in your .asoundrc config file. Regards, Anders 2 dec 2013 kl. 08:29 skrev Oeyvind Brandtsegg |
Date | 2013-12-02 09:12 |
From | Victor Lazzarini |
Subject | Re: [Csnd] Mixing channels from different csound instances |
These are for API calls and they should be OK. Spinlocks are used in other places, here I think mutexes are better suited. Victor On 29 Nov 2013, at 20:26, imaia |