Csound Csound-dev Csound-tekno Search About

[Csnd] Re: [Cs-dev] bus opcodes

Date2009-11-27 15:20
Frommichael.gogins@gmail.com
Subject[Csnd] Re: [Cs-dev] bus opcodes
This didn't seem to go through to the list though I sent it last night, 
sending it again and also to the Csound list...

MKG

----- Original Message ----- 
From: 
To: "Developer discussions" 
Sent: Thursday, November 26, 2009 11:16 PM
Subject: Re: [Cs-dev] bus opcodes


>I have mentioned before that Peter Brinkmann's jReality package, written in
> Java, for mathematics visualization and sonification can use Csound to
> attach sounds to visual objects. Here is Peter's source code, which I 
> helped
> him to write, from jReality SVN for sending audio output from Csound to 
> the
> audio backend of jReality. I have heard this code run. I imagine similar
> code would work in Lua, and I may verify that if I have time.
>
> The key lines are as follows, with my comments added:
>
> // SWIG-generated wrapper for an array of MYFLT.
>  spout = new CsoundMYFLTArray();
> // Set the SWIG wrapper for Csound's spout buffer pointer to the MYFLT 
> array
> wrapper. The "Ptr" is a SWIG wrapper for a C MYFLT * pointer.
> // In other words, in SWIG-generated code you never see a truly raw 
> pointer.
> // THIS IS PROBABLY YOUR MISSING STEP, GENTLEMEN.
>  spout.SetPtr(csnd.GetSpout());
> // Create a native host language buffer for sending monophonic audio to 
> the
> backend.
>  cumulativeBuffer = new float[ksmps];
>
> // Call on Csound to synthesize ksmps worth of audio.
> // ANOTHER POSSIBLE "GOTCHA": MUST USE csoundPerformKsmps NOT
> csoundPerformBuffer.
>   csnd.PerformKsmps();
> // Transfer audio, framewise, from the SWIG wrapper for spout to my native
> buffer.
> // I.e., j is the SAMPLE FRAME index.
>   for(int j=0; j // Average N-channel output to my monophonic native buffer.
> // Note that v collects only one sample if nchnls = 1.
>    float v = 0;
>    // I.e., k is the CHANNEL index (and ksmps is the channel "stride" in
> spout).
>    for(int k=j; k     v += spout.GetValue(k);
>    }
>    cumulativeBuffer[j] = v/scale;
>   }
> // Write my native audio buffer to my backend.
>   ringBuffer.write(cumulativeBuffer, 0, ksmps);
>  }
> }
>
> For N-channel final output, instead of
>
> v+= spout.GetValue(k)
>
> you should have
>
> frame[channel] = spout.getValue(k)
>
> In spite of the fact that this works, I will add to the API more direct,
> samplewise access to spout and spin. The above would be more efficient for
> ksmps above a certain size, but I'm not sure what that size would be; I
> expect for low latency (ksmps of 20 or so) samplewise access should be 
> about
> as fast.
>
> I imagine the reason SWIG takes this circuitous route is that, in some
> languages, you can directly index a pointer as though it is an array,
> whereas in other languages pointers do not directly appear. The array
> wrapper makes both kinds of languages act the same way.
>
> Hope this helps,
> Mike
>
> ----- Original Message ----- 
> From: "jhearon" 
> To: 
> Sent: Thursday, November 26, 2009 8:51 PM
> Subject: Re: [Cs-dev] bus opcodes
>
>
>>
>>
>>
>> You may remember that i failed to get the JAVA API to access audio
>> channels last summer, and there still is no explanation
>> ==John ffitch
>>
>> Hi John,
>> This was some old java code posted a long time ago which is supposed to
>> show
>> channel communication to/from a java host using .csnd.jar methods.  I'm 
>> no
>> Java expert but sort of have this working.  Maybe Steven Yi or J.P.
>> Lemoine
>> are better at java.  The code I was working on was mostly using chnget to
>> get a k-value for frequency from the java host using the
>> csoundGetChannelPtr
>> method and passing the java wrapped value of MYFLT **p to csound.
>>
>> //Main.java
>> public class Main {
>>    public static void main(String[] args) {
>>        chntest_thread  c = new chntest_thread();
>>    }
>> }
>> //--------------
>> //chntest_thread.java
>>
>> import csnd.*;
>>
>> public class chntest_thread {
>>    SWIGTYPE_p_void myvoid;
>>    //SWIGTYPE_p_void myvoid = null;//if above gives compiler error
>>    SWIGTYPE_p_CSOUND_ mycsound = csnd.csoundCreate(myvoid);
>>    Csound csound = new Csound();
>>    CsoundMYFLTArray myfltarray = new CsoundMYFLTArray();
>>    CsoundMYFLTArray chn1 = new CsoundMYFLTArray();
>>    CsoundMYFLTArray chn2 = new CsoundMYFLTArray();
>>    CsoundMYFLTArray chn3 = new CsoundMYFLTArray();
>>    CsoundMYFLTArray chn4 = new CsoundMYFLTArray();
>>    CsoundMYFLTArray chn5 = new CsoundMYFLTArray();
>>
>>    chntest_thread() {
>>        run();
>>    }
>>
>>    public void run() {
>>    int err, ksmps, kcnt = 0;
>>    double phs = 0.0, phs_inc;
>>    err = csound.Compile("chnTest.csd");
>>    if (err == 0) {
>>      err |= csnd.csoundGetChannelPtr(mycsound, chn1.GetPtr(), "k_in",
>>                                  csndConstants.CSOUND_CONTROL_CHANNEL
>>                                  | csndConstants.CSOUND_INPUT_CHANNEL);
>>      err |= csnd.csoundGetChannelPtr(mycsound, chn2.GetPtr(), "a_in",
>>                                  csndConstants.CSOUND_AUDIO_CHANNEL
>>                                  | csndConstants.CSOUND_INPUT_CHANNEL);
>>      err |= csnd.csoundGetChannelPtr(mycsound, chn3.GetPtr(), "S_in",
>>                                  csndConstants.CSOUND_STRING_CHANNEL
>>                                  | csndConstants.CSOUND_INPUT_CHANNEL);
>>      err |= csnd.csoundGetChannelPtr(mycsound, chn4.GetPtr(), "k_out",
>>                                  csndConstants.CSOUND_CONTROL_CHANNEL
>>                                  | csndConstants.CSOUND_OUTPUT_CHANNEL);
>>      err |= csnd.csoundGetChannelPtr(mycsound, chn5.GetPtr(), "S_out",
>>                                  csndConstants.CSOUND_STRING_CHANNEL
>>                                  | csndConstants.CSOUND_OUTPUT_CHANNEL);
>>      if (err == 0) {
>>        chn1.SetValue(0, 3.14159265);
>>        chn3.SetStringValue("String Input Value",
>> csound.GetStrVarMaxLen());
>>        phs_inc = 2.0 * 3.14159265 * 440.0 / csound.GetSr();
>>        ksmps = csound.GetKsmps();
>>        do {
>>          for (int i = 0; i < ksmps; i++) {
>>            chn2.SetValue(i, 0.7071 * Math.sin(phs));
>>            phs += phs_inc;
>>          }
>>          err = csound.PerformKsmps();
>>          if (kcnt == 0) {
>>            String s = chn5.GetStringValue();
>>            System.err.printf("Values sent: %g, '%s'\n", chn4.GetValue(0),
>> s);
>>          }
>>          kcnt++;
>>        } while (err == 0);
>>      }
>>    }
>>         csound.Reset();
>>        java.lang.System.exit(1);
>>    } //end run method
>> }//ends chntest_thread
>> //-----------
>> //chnTest.csd
>>
>> 
>> 
>> -s -d -+rtaudio=ALSA -odac:hw:0,0 -b1024 -B16384
>> 
>> 
>> sr =  44100
>> ksmps =  32
>> nchnls =  2
>> 0dbfs =  1
>>        chn_k "k_in", 1
>>        chn_a "a_in", 1
>>        chn_S "S_in", 1
>>        chn_k "k_out", 2
>>        chn_S "S_out", 2
>>
>>        chnset 2.71828, "k_out"
>>        chnset "Output String Value", "S_out"
>>
>>        instr 1
>> ichn1 chnget "k_in"
>> achn2 chnget "a_in"
>> Schn3 chnget "S_in"
>>
>>        printf_i "Values received: %g, '%s'\n", 1, ichn1, Schn3
>>        outs achn2, achn2
>> endin
>>
>> 
>> 
>> i 1 0 2
>> e
>> 
>> 
>>
>> -- 
>> View this message in context:
>> http://old.nabble.com/bus-opcodes-tp26362662p26535852.html
>> Sent from the Csound - Dev mailing list archive at Nabble.com.
>>
>>
>> ------------------------------------------------------------------------------
>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
>> 30-Day
>> trial. Simplify your report design, integration and deployment - and 
>> focus
>> on
>> what you do best, core application coding. Discover what's new with
>> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
>> _______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>
> 


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel