[Csnd] CSound (Python) API & Output Buffers
Date | 2008-04-03 04:10 |
From | Lilith Bryant |
Subject | [Csnd] CSound (Python) API & Output Buffers |
Attachments | None |
Date | 2008-04-03 05:17 |
From | DavidW |
Subject | [Csnd] Re: CSound (Python) API & Output Buffers |
hi Lilith, Have you looked at using PyAudio? http://people.csail.mit.edu/hubert/pyaudio/docs/ D. On 03/04/2008, at 2:10 PM, Lilith Bryant wrote: > 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. > |
Date | 2008-04-03 06:27 |
From | "Steven Yi" |
Subject | [Csnd] Re: CSound (Python) API & Output Buffers |
Attachments | None |
Date | 2008-04-03 10:38 |
From | Lilith Bryant |
Subject | [Csnd] Re: Re: CSound (Python) API & Output Buffers |
Attachments | None |
Date | 2008-04-03 10:47 |
From | Lilith Bryant |
Subject | [Csnd] Re: Re: CSound (Python) API & Output Buffers |
Attachments | None |
Date | 2008-04-03 11:00 |
From | Lilith Bryant |
Subject | [Csnd] Re: Re: CSound (Python) API & Output Buffers |
Attachments | None |
Date | 2008-04-03 11:03 |
From | Victor Lazzarini |
Subject | [Csnd] Re: Re: Re: CSound (Python) API & Output Buffers |
Why don't you dedicate an instrument to write files using fout? Victor At 10:47 03/04/2008, you wrote: >for my own work, rewinding the score is not a problem. i'm not trying to do >realtime output at all. i just want to render independant chunks of >dynamically created score, without having to reload the orchestra for every >single chunk. > >i don't use the performance thread stuff at all, i simply render (in my own >python thread) by loading up a bunch of notes with csoundScoreEvent, and then >calling csoundPerformBuffer until i have the required amount of output. > >so the structural facilites of csound are currently suitable for me. its >probably more of a python issue that i can't get the output buffer data out >of csound in an efficient form. > >one or two simple C/SWIG functions would solve all my issues. > >On Thursday 03 April 2008 18:27, Steven Yi wrote: > > Hi Lilith, > > > > This brings up some bigger issues but ones worth addressing. > > Currently, as far as I know, there is no indefinite playing mode for > > csound. Something like that might be worth putting in so that the > > main kperf thread will just keep running even if there are no active > > score events. If we do that, then we can introduce a > > "csoundClearScore" method that would wipe all score events. That way, > > you wouldn't need to rewind the score or anything, just keep it going > > and call the csoundScoreEvent. Also, this would allow the possibility > > of indefinite running of csound for things like installations. > > > > I have the feeling this has been discussed before a long while back, > > and that there was some kind of complication due to scoreTime. I > > remember Istvan changing it from an int to a long or something like > > that to make the max score time longer. I can not recall all the > > issues though. > > > > Lilith and everyone: Any thoughts on this? Anyone remember any > > threads regarding this kind of thing? > > > > Thanks, > > steven > > > > On Wed, Apr 2, 2008 at 8:10 PM, Lilith Bryant |
Date | 2008-04-03 11:05 |
From | Victor Lazzarini |
Subject | [Csnd] Re: Re: Re: CSound (Python) API & Output Buffers |
fout is perhaps a solution. Victor At 11:00 03/04/2008, you wrote: >The issue isn't keeping things running, that f trick is what i'm already >doing, the issue is splitting the output file up into chunks. i.e. >render some, play that, render some more, play that., render some more, >play that, etc. all without ending up with a huge .wav file on disk >(that nothing fcloses anyway). i'm going to need C code to do this i >think. if i wrote it, is there any chance of getting a >"csoundGetOutputBufferAsArray" into the mainline? or alternatively >functions in floatArray and doubleArray to return their data as an >array.array. On Thursday 03 April 2008 18:27, Steven Yi wrote: > Hi >Lilith, > > This brings up some bigger issues but ones worth addressing. > >Currently, as far as I know, there is no indefinite playing mode for > >csound. Something like that might be worth putting in so that the > main >kperf thread will just keep running even if there are no active > score >events. If we do that, then we can introduce a > "csoundClearScore" >method that would wipe all score events. That way, > you wouldn't need to >rewind the score or anything, just keep it going > and call the >csoundScoreEvent. Also, this would allow the possibility > of indefinite >running of csound for things like installations. > > I have the feeling >this has been discussed before a long while back, > and that there was >some kind of complication due to scoreTime. I > remember Istvan changing >it from an int to a long or something like > that to make the max score >time longer. I can not recall all the > issues though. > > Lilith and >everyone: Any thoughts on this? Anyone remember any > threads regarding >this kind of thing? > > Thanks, > steven > > On Wed, Apr 2, 2008 at 8:10 >PM, Lilith Bryant |
Date | 2008-04-03 11:11 |
From | Lilith Bryant |
Subject | [Csnd] Re: Re: Re: Re: CSound (Python) API & Output Buffers |
Attachments | None |
Date | 2008-04-03 11:43 |
From | DavidW |
Subject | [Csnd] Re: Re: Re: Re: Re: CSound (Python) API & Output Buffers |
A couple of other ideas which might be useful if you're interested in feedback or other python processing of the audio data: memory-mapped file support http://docs.python.org/lib/module-mmap.html writing to a psuedo file using Using StringIO. See discussion at: http://www.skymind.com/~ocrow/python_string/ David On 03/04/2008, at 9:11 PM, Lilith Bryant wrote: > excellent idea, it works well. downside is that i can't load > unmodified > csd's/orc's directly in. but that's not a biggie. > > On Thursday 03 April 2008 23:03, Victor Lazzarini wrote: >> Why don't you dedicate an instrument to write files using fout? >> Victor >> >> At 10:47 03/04/2008, you wrote: >>> for my own work, rewinding the score is not a problem. i'm not >>> trying to >>> do realtime output at all. i just want to render independant >>> chunks of >>> dynamically created score, without having to reload the orchestra >>> for >>> every single chunk. >>> >>> i don't use the performance thread stuff at all, i simply render >>> (in my >>> own python thread) by loading up a bunch of notes with >>> csoundScoreEvent, >>> and then calling csoundPerformBuffer until i have the required >>> amount of >>> output. >>> >>> so the structural facilites of csound are currently suitable for >>> me. its >>> probably more of a python issue that i can't get the output buffer >>> data >>> out of csound in an efficient form. >>> >>> one or two simple C/SWIG functions would solve all my issues. >>> >>> On Thursday 03 April 2008 18:27, Steven Yi wrote: >>>> Hi Lilith, >>>> >>>> This brings up some bigger issues but ones worth addressing. >>>> Currently, as far as I know, there is no indefinite playing mode >>>> for >>>> csound. Something like that might be worth putting in so that the >>>> main kperf thread will just keep running even if there are no >>>> active >>>> score events. If we do that, then we can introduce a >>>> "csoundClearScore" method that would wipe all score events. That >>>> way, >>>> you wouldn't need to rewind the score or anything, just keep it >>>> going >>>> and call the csoundScoreEvent. Also, this would allow the >>>> possibility >>>> of indefinite running of csound for things like installations. >>>> >>>> I have the feeling this has been discussed before a long while >>>> back, >>>> and that there was some kind of complication due to scoreTime. I >>>> remember Istvan changing it from an int to a long or something like >>>> that to make the max score time longer. I can not recall all the >>>> issues though. >>>> >>>> Lilith and everyone: Any thoughts on this? Anyone remember any >>>> threads regarding this kind of thing? >>>> >>>> Thanks, >>>> steven >>>> >>>> On Wed, Apr 2, 2008 at 8:10 PM, Lilith Bryant |
Date | 2008-04-03 12:09 |
From | Victor Lazzarini |
Subject | [Csnd] Re: Re: Re: Re: Re: CSound (Python) API & Output Buffers |
you can easily write a python script to do that (load unmodified CSDs), perhaps using Michael's CppSound class. Victor At 11:11 03/04/2008, you wrote: >excellent idea, it works well. downside is that i can't load unmodified >csd's/orc's directly in. but that's not a biggie. > >On Thursday 03 April 2008 23:03, Victor Lazzarini wrote: > > Why don't you dedicate an instrument to write files using fout? > > Victor > > > > At 10:47 03/04/2008, you wrote: > > >for my own work, rewinding the score is not a problem. i'm not trying to > > > do realtime output at all. i just want to render independant chunks of > > > dynamically created score, without having to reload the orchestra for > > > every single chunk. > > > > > >i don't use the performance thread stuff at all, i simply render (in my > > > own python thread) by loading up a bunch of notes with csoundScoreEvent, > > > and then calling csoundPerformBuffer until i have the required amount of > > > output. > > > > > >so the structural facilites of csound are currently suitable for me. its > > >probably more of a python issue that i can't get the output buffer data > > > out of csound in an efficient form. > > > > > >one or two simple C/SWIG functions would solve all my issues. > > > > > >On Thursday 03 April 2008 18:27, Steven Yi wrote: > > > > Hi Lilith, > > > > > > > > This brings up some bigger issues but ones worth addressing. > > > > Currently, as far as I know, there is no indefinite playing mode for > > > > csound. Something like that might be worth putting in so that the > > > > main kperf thread will just keep running even if there are no active > > > > score events. If we do that, then we can introduce a > > > > "csoundClearScore" method that would wipe all score events. That way, > > > > you wouldn't need to rewind the score or anything, just keep it going > > > > and call the csoundScoreEvent. Also, this would allow the possibility > > > > of indefinite running of csound for things like installations. > > > > > > > > I have the feeling this has been discussed before a long while back, > > > > and that there was some kind of complication due to scoreTime. I > > > > remember Istvan changing it from an int to a long or something like > > > > that to make the max score time longer. I can not recall all the > > > > issues though. > > > > > > > > Lilith and everyone: Any thoughts on this? Anyone remember any > > > > threads regarding this kind of thing? > > > > > > > > Thanks, > > > > steven > > > > > > > > On Wed, Apr 2, 2008 at 8:10 PM, Lilith Bryant |