Csound Csound-dev Csound-tekno Search About

[Csnd] Re: Re: Re: Re: Re: CSound (Python) API & Output Buffers

Date2008-04-03 21:40
FromMichael Gogins
Subject[Csnd] Re: Re: Re: Re: Re: CSound (Python) API & Output Buffers
OK, it sounds like your current solution should work out best of the current alternatives.

Regards,
Mike

-----Original Message-----
>From: Lilith Bryant 
>Sent: Apr 3, 2008 4:15 PM
>To: csound@lists.bath.ac.uk
>Subject: [Csnd] Re: Re: Re: Re: CSound (Python) API & Output Buffers
>
>correct, there are no score events in the loaded csd.   i'm simply calling 
>csoundScoreEvent for each note at the beginning of each rendering to load up 
>csound with a bunch of future "realtime" events (even though technically this 
>isn't actually technically realtime).   and yes, the only output is now via 
>fout.
>
>i'm running on linux, and i need my solution to be cross platform. 
>
>cheers.
>
>On Friday 04 April 2008 08:46, Michael Gogins wrote:
>> Thanks for the information.
>>
>> Yes, performKsmps produces one spout buffer per kperiod. So if you have
>> ksmps == 1 (kr == sr), this will be way slower than buffer access.
>>
>> Another thought is to use the Lua interface to Csound. If you are working
>> on Windows, there is a just-in-time compiler for Lua that runs considerably
>> faster than Python.
>>
>> I take it, then, that you are sending scores only as real-time events, and
>> that you are sending output only through fout?
>>
>> Regards,
>> Mike
>>
>> -----Original Message-----
>>
>> >From: Lilith Bryant 
>> >Sent: Apr 3, 2008 3:00 PM
>> >To: csound@lists.bath.ac.uk
>> >Subject: [Csnd] Re: Re: CSound (Python) API & Output Buffers
>> >
>> >a) python is most certainly too slow.  even just running a loop of
>> >csoundPerformKsmps is noticably (i.e. 5-10 times) slower than running a
>> > loop of csoundPerformBuffer, even without processing any samples in
>> > python. especially when kr=sr
>> >
>> >b) recompiling the orchestra is slow enough (especially when there are
>> >soundfonts involved) for me to want to avoid it at all costs.  i run
>> > csound sometimes on a 300Mhz celeron laptop.
>> >
>> >c) fout does the trick, thanks for the offer though.
>> >
>> >On Friday 04 April 2008 00:51, Michael Gogins wrote:
>> >> Python probably isn't too slow for this. You don't need the host IO
>> >> calls either. Just get the samples from the spout buffer and stream them
>> >> to your own soundfile. That means calling csoundPerformKsmps do compute
>> >> one spout buffer at a time. There is a Python wrapper for libsndfile in
>> >> the CsoundAC module you can use to write your output. If the Python
>> >> access to spout doesn't work, let me know and I will make it work.
>> >>
>> >> Perhaps more to the point, Csound can recompile the orchestra and
>> >> re-create the soundfile plenty fast -- usually in a few seconds or less.
>> >> Loading soundfonts, samples, or VST plugins slows it down somewhat but
>> >> it is still tolerable (to me, anyway).
>> >>
>> >> Regards,
>> >> Mike
>> >>
>> >> ----- Original Message -----
>> >> From: "Lilith Bryant" 
>> >> To: 
>> >> Sent: Wednesday, April 02, 2008 11:10 PM
>> >> Subject: [Csnd] CSound (Python) API & Output Buffers
>> >>
>> >> >I wonder if I could tap the list here for some advice.
>> >> >
>> >> > I'm writing a score writer front-end in python using the csound API.
>> >> >
>> >> > The big idea with this project, is to be able to quickly change the
>> >> > score and
>> >> > re-render with having csound reload the whole orchestra/csd file for
>> >> > every simple score change.  So i'm simply calling the csoundCompile
>> >> > and all the prequisites once at the beginning of my application (or
>> >> > whenever the user asks to reload the orchestra/csd)
>> >> >
>> >> > Then for each renderering, I call csoundScoreRewind and then
>> >> > csoundScoreEvent
>> >> > for each note.
>> >> >
>> >> > Which works as expected, except the output wav file simply grows with
>> >> > easy pass.  i.e. it  csoundScoreRewind doesn't clear it, like would be
>> >> > useful for
>> >> > this case.
>> >> >
>> >> > Now I can alternatively not use wav file output at all, and use
>> >> > csoundSetHostImplementedAudioIO and manually fish out the samples, and
>> >> > write
>> >> > them to a wav file myself.  But this is python and that hideously
>> >> > slow.
>> >> >
>> >> > So the questions are:
>> >> > 1) Is there a way to restart the wav file output without reloading the
>> >> > orchestra/csd?
>> >> >
>> >> > OR
>> >> >
>> >> > 2) Is there a quick way to fish out the output buffer samples into a
>> >> > python
>> >> > string or array, for writing out to file using the python wav module?
>> >> >
>> >> > The best i have so far is something like:
>> >> >
>> >> > ob=csnd.csoundGetOutputBuffer(self.cs)
>> >> > fa=csnd.floatArray.frompointer(ob)
>> >> > sa=array.Array('h',[0]*buffersize*2)
>> >> > for n in range(buffersize*2):
>> >> > sa[n]=fa[n]*32767
>> >> > wavdata=sa.tostring()
>> >> >
>> >> > which really SUCKS performance-wise (not surprisingly).
>> >> >
>> >> > I don't want to write a C/SWIG function to do just this, since i want
>> >> > to be
>> >> > able to give this to people who aren't up to running compilers.
>> >> >
>> >> >
>> >> > 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"
>
>
>Send bugs reports to this list.
>To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"