[Stk] prototyping in python?

Iain Duncan iainduncanlists at gmail.com
Wed Nov 2 19:27:20 PDT 2011


Nevermind, stupid mistake, apologies. Will check math better next time. =)

iain

On Wed, Nov 2, 2011 at 7:21 PM, Iain Duncan <iainduncanlists at gmail.com>wrote:

> Hi Gary, Antoine, and any lurkers. I'm hoping to do the exact same audio
> gen in an adaptation of the crtsine.cpp example in the stk and with
> Antoine's py example so I can figure out just how much penalty doing it
> python incurs. Unfortunately, I must be missing something, because in the
> cpp example I get silence. If anyone can see my error, or knows why it
> wouldn't work the same way, that would be helpful. Thanks!
>
> Here is the audio gen code from the PyRtAudio examp:
>
> def __call__(self):
>    self.idx += 1
>    # deleted the ascending scale code
>    return 0.5 * cos( 2. * 3.1416 * self.freq * self.idx / SAMPLE_RATE )
>
> And here is my attempt to do it in C++, not getting any sound:
>
> int tick( void *outputBuffer, void *inputBuffer, unsigned int
> nBufferFrames,
> double streamTime, RtAudioStreamStatus status, void *dataPointer )
> {
>     // buffer to fill
>     register StkFloat *samples = (StkFloat *) outputBuffer;
>     int freq = 440;
>
>    // loop through the number of samples we need to fill, filling the
> output buffer
>    // samp_index is a global int counter
>    for ( unsigned int i=0; i<nBufferFrames; i++, samp_index++ ){
>      *samples++ = ( 0.5 * cos( 2.0 * 3.1416 * freq) * samp_index /
> SAMPLE_RATE );
>    }
>
>    return 0;
> }
>
>
>
> On Wed, Nov 2, 2011 at 1:02 PM, Iain Duncan <iainduncanlists at gmail.com>wrote:
>
>> Preliminary tests seem to imply this works really well actually. I'm
>> pleasantly surprised, I was able to put some pointless number crunching in
>> the non-audio thread and spit to the screen, sending my python process up
>> to 30-40% Cpu use and gnome -terminal up to about 50% ( on a quad core chip
>> mind you ) without noticing any underruns. Mind you, I have no idea what
>> the real latency is, I have my buffer set at 64, but dac.getStreamLatency()
>> is reporting 0.00 so I might have to benchmark.
>>
>> Wondering if either of you would happen to have an idea of how I could
>> easily make the audio gen really audio heavy?
>>
>> An ideal benchmark I think would be to get some audio-in, process it, and
>> spit it out, but that may take a while.
>>
>> The gen as is now:
>>
>> 0.5 * cos( 2. * 3.1416 * self.freq * self.idx / SAMPLE_RATE )
>>
>> perhaps making a matrix of a whole bunch of those would do it.
>>
>> thanks
>> Iain
>>
>>
>>
>> On Wed, Nov 2, 2011 at 12:52 PM, Iain Duncan <iainduncanlists at gmail.com>wrote:
>>
>>> Thanks Gary, I got in touch with Antoine and will be helping to extend
>>> that example.
>>>
>>> thanks
>>> iain
>>>
>>> On Wed, Nov 2, 2011 at 10:58 AM, Iain Duncan <iainduncanlists at gmail.com>wrote:
>>>
>>>> Well it works, and it seems to be running ok on my box ( some clicking,
>>>> but the sine sounds clean ).
>>>>
>>>> I noticed the python file has a mixture of spaces and tabs, so it
>>>> opened up looking funny in my editor, I'm converting that. I emailed
>>>> Antoine to see if he's still working on this or what the status is. I'll
>>>> definitely play around with it. I assume none of the other stk stuff has
>>>> been ported given that Python is not really appropriate for real time dsp
>>>> eh?
>>>>
>>>> Looking over my notes I realized I got busy and never tested the
>>>> crtsine example on my firepod for you, I'll get to that to.
>>>>
>>>> thanks
>>>> Iain
>>>>
>>>>  On Wed, Nov 2, 2011 at 7:24 AM, Gary Scavone <gary at ccrma.stanford.edu>wrote:
>>>>
>>>>> Hi Iain,
>>>>>
>>>>> If it helps, there is a python wrapper for RtAudio in the latest
>>>>> release of RtAudio (look in the "contrib/python/" directory).
>>>>>
>>>>> --gary
>>>>>
>>>>> On 2011-11-02, at 12:22 AM, Iain Duncan wrote:
>>>>>
>>>>> > Hi, I'm working on an a project that I intend to do using the STK,
>>>>> but am hoping I can prototype the architecture in python until I've figured
>>>>> out the various components and their responsibilities and dependencies.
>>>>> Does anyone know of any kind of python library ( or method? ) that would
>>>>> let me simulate the way callback based STK apps using RTAudio work? IE I
>>>>> want to have a python master callable that gets called once per audio
>>>>> sample and has a way of sending out it's results.
>>>>> >
>>>>> > I've found a bunch of python audio libs but it doesn't seem like
>>>>> they work that way, maybe I'm missing something?
>>>>> >
>>>>> > thanks!
>>>>> > Iain
>>>>> > _______________________________________________
>>>>> > Stk mailing list
>>>>> > Stk at ccrma.stanford.edu
>>>>> > http://ccrma-mail.stanford.edu/mailman/listinfo/stk
>>>>>
>>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ccrma-mail.stanford.edu/pipermail/stk/attachments/20111102/8103a08a/attachment-0001.html 


More information about the Stk mailing list