Csound Csound-dev Csound-tekno Search About

[Cs-dev] csound events delayed when added through API

Date2015-08-16 17:30
FromPeter Burgess
Subject[Cs-dev] csound events delayed when added through API
AttachmentsNone  None  
Hello again! Sorry to keep going on and on at you guys about my problems :D but I'm on the home straight with my project, but I'm facing one potentially big problem!

You're probably already getting familiar with what I'm trying to do, but essentially I'm using C++ API to create score events in Csound. My current approach involves a score generator in C++, then sending csound->ReadScore messages to an instance of csound running in a performance thread.

I wanted to see if I could get c++ to automatically send a set of score events periodically, and so I've tried a few systems to achieve this. The current one involves a Csound instrument periodically sending a message on a software bus that activates a c++ score generation function. I've set this up a number of ways, to try and maximise the chance of getting accurate playback, but so far I am having no success. the system works for the first 2 sets of score events, and then with every new score event, there is a bigger and bigger gap between playbacks (they should play uninterrupted from one to the next).

I cout << each of my score events so I can check that they are send accurately, and in a timely fashion, and they are. I have read back through my console output many times and checked the start times of each event, and can see that the event messages are definitely sent correctly, but the playback of the events is running behind. I can only guess this means that csound itself is delaying the playback of the events I've sent.

I wondered if I was sending too much data for it to process as quickly as I needed it to, as I am sending a kick line, a snare line and a hat line all separately, which is probably about 30-50 events per section, so I removed the snare and hat score gens to see if that helped. I think the gaps are slightly smaller. I have tried swiching from csound->ReadScore to perfThread->InputMessage in the hope that using the perfThread might help, and it makes no notable difference. I have also tried slowing the tempo down from 120bpm to 40bpm (that is my c++ variable tempo that is used to calculate event times) to see if that helps csound to keep up, and there are still gaps, though maybe not as large as before.

Interestingly, if I vastly increase the length of each score section, the timing is vastly improved, despite the fact I'm generating and sending well more score events!

So my theory is that this is a problem with score message processing. Is it possible that csound is struggling to keep up? And if so, is there anything I can do about it? I'm half temped to try and rewrite it entirely in csound to see if that helps...

I'm partially wondering if there's a better sample player opcode I can use. I've scoured the manual for a really lightweight sampler playback opcode, one that does nothing but play the sample in real time. The closest I've found is loscil using gen 1 with my sample loaded. This works fine, but it loscil still takes arguments like pitch. Is there anything even lighterweight than this?

It's probably worth mentioning that I'm not using the greatest laptop: 2.4Ghz intel core i3, 3.7GB RAM and with no extra soundcard, I would have thought this should be enough to handle what I'm doing though. I've managed to make some pretty excessive tracks in FLStudio with multiple SynthMaker synths running before.

Sorry for the essay! Cheers to anyone with the patience to read all this :D

Pete

Date2015-08-16 17:40
Fromjpff
SubjectRe: [Cs-dev] csound events delayed when added through API
Just a silly thought; what value of p2 are you sending?

On Sun, 16 Aug 2015, Peter Burgess wrote:

> Hello again! Sorry to keep going on and on at you guys about my problems :D
> but I'm on the home straight with my project, but I'm facing one potentially
> big problem!
> 
> You're probably already getting familiar with what I'm trying to do, but
> essentially I'm using C++ API to create score events in Csound. My current
> approach involves a score generator in C++, then sending csound->ReadScore
> messages to an instance of csound running in a performance thread.
> 
> I wanted to see if I could get c++ to automatically send a set of score events
> periodically, and so I've tried a few systems to achieve this. The current one
> involves a Csound instrument periodically sending a message on a software bus
> that activates a c++ score generation function. I've set this up a number of
> ways, to try and maximise the chance of getting accurate playback, but so far
> I am having no success. the system works for the first 2 sets of score events,
> and then with every new score event, there is a bigger and bigger gap between
> playbacks (they should play uninterrupted from one to the next).
> 
> I cout << each of my score events so I can check that they are send
> accurately, and in a timely fashion, and they are. I have read back through my
> console output many times and checked the start times of each event, and can
> see that the event messages are definitely sent correctly, but the playback of
> the events is running behind. I can only guess this means that csound itself
> is delaying the playback of the events I've sent.
> 
> I wondered if I was sending too much data for it to process as quickly as I
> needed it to, as I am sending a kick line, a snare line and a hat line all
> separately, which is probably about 30-50 events per section, so I removed the
> snare and hat score gens to see if that helped. I think the gaps are slightly
> smaller. I have tried swiching from csound->ReadScore to
> perfThread->InputMessage in the hope that using the perfThread might help, and
> it makes no notable difference. I have also tried slowing the tempo down from
> 120bpm to 40bpm (that is my c++ variable tempo that is used to calculate event
> times) to see if that helps csound to keep up, and there are still gaps,
> though maybe not as large as before.
> 
> Interestingly, if I vastly increase the length of each score section, the
> timing is vastly improved, despite the fact I'm generating and sending well
> more score events!
> 
> So my theory is that this is a problem with score message processing. Is it
> possible that csound is struggling to keep up? And if so, is there anything I
> can do about it? I'm half temped to try and rewrite it entirely in csound to
> see if that helps...
> 
> I'm partially wondering if there's a better sample player opcode I can use.
> I've scoured the manual for a really lightweight sampler playback opcode, one
> that does nothing but play the sample in real time. The closest I've found is
> loscil using gen 1 with my sample loaded. This works fine, but it loscil still
> takes arguments like pitch. Is there anything even lighterweight than this?
> 
> It's probably worth mentioning that I'm not using the greatest laptop: 2.4Ghz
> intel core i3, 3.7GB RAM and with no extra soundcard, I would have thought
> this should be enough to handle what I'm doing though. I've managed to make
> some pretty excessive tracks in FLStudio with multiple SynthMaker synths
> running before.
> 
> Sorry for the essay! Cheers to anyone with the patience to read all this :D
> 
> Pete
> 
>

------------------------------------------------------------------------------
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2015-08-16 18:00
FromPeter Burgess
SubjectRe: [Cs-dev] csound events delayed when added through API
AttachmentsNone  None  
the p2 value for my beats or for the special instrument that sends the bus message?

in the case of the beats, I have vigirously checked the p2 figures generated and they are correct, and don't sync up with the rtevent printouts from csound.

in the case of the special bus message instrument, i have tried many start times to see if it makes a difference. Innitially it was happening 1 section of music prior to the first start time for the score generation that was triggered (if that makes sense?). Now I have 4, positioned at 0, 0.1, 0.2, and 0.3, which trigger the 2nd, 3rd, 4th and 5th sections of music (as the first is already generated without a trigger)

On Sun, Aug 16, 2015 at 5:40 PM, jpff <jpff@codemist.co.uk> wrote:
Just a silly thought; what value of p2 are you sending?

On Sun, 16 Aug 2015, Peter Burgess wrote:

> Hello again! Sorry to keep going on and on at you guys about my problems :D
> but I'm on the home straight with my project, but I'm facing one potentially
> big problem!
>
> You're probably already getting familiar with what I'm trying to do, but
> essentially I'm using C++ API to create score events in Csound. My current
> approach involves a score generator in C++, then sending csound->ReadScore
> messages to an instance of csound running in a performance thread.
>
> I wanted to see if I could get c++ to automatically send a set of score events
> periodically, and so I've tried a few systems to achieve this. The current one
> involves a Csound instrument periodically sending a message on a software bus
> that activates a c++ score generation function. I've set this up a number of
> ways, to try and maximise the chance of getting accurate playback, but so far
> I am having no success. the system works for the first 2 sets of score events,
> and then with every new score event, there is a bigger and bigger gap between
> playbacks (they should play uninterrupted from one to the next).
>
> I cout << each of my score events so I can check that they are send
> accurately, and in a timely fashion, and they are. I have read back through my
> console output many times and checked the start times of each event, and can
> see that the event messages are definitely sent correctly, but the playback of
> the events is running behind. I can only guess this means that csound itself
> is delaying the playback of the events I've sent.
>
> I wondered if I was sending too much data for it to process as quickly as I
> needed it to, as I am sending a kick line, a snare line and a hat line all
> separately, which is probably about 30-50 events per section, so I removed the
> snare and hat score gens to see if that helped. I think the gaps are slightly
> smaller. I have tried swiching from csound->ReadScore to
> perfThread->InputMessage in the hope that using the perfThread might help, and
> it makes no notable difference. I have also tried slowing the tempo down from
> 120bpm to 40bpm (that is my c++ variable tempo that is used to calculate event
> times) to see if that helps csound to keep up, and there are still gaps,
> though maybe not as large as before.
>
> Interestingly, if I vastly increase the length of each score section, the
> timing is vastly improved, despite the fact I'm generating and sending well
> more score events!
>
> So my theory is that this is a problem with score message processing. Is it
> possible that csound is struggling to keep up? And if so, is there anything I
> can do about it? I'm half temped to try and rewrite it entirely in csound to
> see if that helps...
>
> I'm partially wondering if there's a better sample player opcode I can use.
> I've scoured the manual for a really lightweight sampler playback opcode, one
> that does nothing but play the sample in real time. The closest I've found is
> loscil using gen 1 with my sample loaded. This works fine, but it loscil still
> takes arguments like pitch. Is there anything even lighterweight than this?
>
> It's probably worth mentioning that I'm not using the greatest laptop: 2.4Ghz
> intel core i3, 3.7GB RAM and with no extra soundcard, I would have thought
> this should be enough to handle what I'm doing though. I've managed to make
> some pretty excessive tracks in FLStudio with multiple SynthMaker synths
> running before.
>
> Sorry for the essay! Cheers to anyone with the patience to read all this :D
>
> Pete
>
>

------------------------------------------------------------------------------
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel


Date2015-08-16 18:52
FromPeter Burgess
SubjectRe: [Cs-dev] csound events delayed when added through API
AttachmentsNone  None  

Huh... I haven't had a chance to properly test it yet, but I might have found the potential cause.

Would routing audio through the HDMI potentially cause these sorts of problems? My laptops jack socket is busted and I've been using the HDMI port to get sound as a temporary solution. When I routed sound through my laptop speakers a second ago, the problem went away... how embarrassing! Lol

Pete


Date2015-08-17 07:46
FromPeter Burgess
SubjectRe: [Cs-dev] csound events delayed when added through API
AttachmentsNone  None  

It hasn't totally relieved the issue. I've just used Top to check the CPU and memory usage and my program uses 106% of the CPU power!!! Plus 8.5% for pulseaudio, so nearly 115% all together! I'm surprised to see it uses bugger all memory, which is nice, but I wonder if I could shift some of the performance weight onto the memory. Besides generating the scores in advance, are there any tricks that might do that?