csoundAddSpinSample() question...
Date | 2017-06-12 12:30 |
From | Rory Walsh |
Subject | csoundAddSpinSample() question... |
Attachments | GetSpoutExample2.cpp test8.csd |
I'm having some issues using csoundAddSpinSample. It seems to blow up in my face. I may be using it wrong, but the following file and .csd illustrate the problem. I've always used GetSpout/In, but I have to do things on a sample by sample basis in Unity. The csoundGetSpoutSample() method works fine.
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Thanks. |
Date | 2017-06-12 13:45 |
From | Victor Lazzarini |
Subject | Re: csoundAddSpinSample() question... |
I’ve never used it myself. Does the problem go away if you use GetSpin() and a pointer? ======================== Prof. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy, Maynooth University, Maynooth, Co Kildare, Ireland Tel: 00 353 7086936 Fax: 00 353 1 7086952 > On 12 Jun 2017, at 12:30, Rory Walsh |
Date | 2017-06-12 13:49 |
From | Victor Lazzarini |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
Just looked at the implementation: PUBLIC void csoundAddSpinSample(CSOUND *csound, int frame, int channel, MYFLT sample) { int index = (frame * csound->inchnls) + channel; csound->spin[index] += sample; } it appears you would need to clear spin before using it, otherwise it will blow up. (moved this to developers so not too scare any users) ======================== Prof. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy, Maynooth University, Maynooth, Co Kildare, Ireland Tel: 00 353 7086936 Fax: 00 353 1 7086952 > On 12 Jun 2017, at 13:45, Victor Lazzarini |
Date | 2017-06-12 13:54 |
From | Rory Walsh |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
Thanks Victor. Can the csoundAddSpinSample() function be updated to do this automatically, or is there a reason why it needs to be done manually? On 12 June 2017 at 13:49, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote: Just looked at the implementation: |
Date | 2017-06-12 13:59 |
From | Victor Lazzarini |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
I don’t think we can without changing behaviour, it does what it says on the tin. OTOH we could have a csoundReplaceSpinSample(), but isn’t it easier just to get the pointer and write to the buffer directly? ======================== Prof. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy, Maynooth University, Maynooth, Co Kildare, Ireland Tel: 00 353 7086936 Fax: 00 353 1 7086952 > On 12 Jun 2017, at 13:54, Rory Walsh |
Date | 2017-06-12 14:17 |
From | Rory Walsh |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
I don’t think we can without changing behaviour, it does what it says on the tin. OTOH we could have a csoundReplaceSpinSample(), Not when you're trying to move data between the C library and the C# interface. I've not been able to mange pointers between the two. Strings were hairy enough. So the question is, if I don't have access to the spin pointer how am I going to be able to zero it? A csoundReplaceSpinSample() method would be useful, but if I can use what's there already it would be better as I wouldn't have to wait for a new release. What's the recommended way of clearing spin? ======================== |
Date | 2017-06-12 14:24 |
From | Victor Lazzarini |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
Couldn’t you add a simple C file to your build, where you have a single function that does this: #include |
Date | 2017-06-12 14:35 |
From | Rory Walsh |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
I'm loading the Csound .dll directly into Unity using DLLImport(). I then manage each of the functions I need from the library. Are you suggesting writing another dll to look after clearing up spin? On 12 June 2017 at 14:24, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote: Couldn’t you add a simple C file to your build, where you have a single function that does this: |
Date | 2017-06-12 14:39 |
From | Victor Lazzarini |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
yes, that is what I am suggesting. That DLL could potentially just link to the Csound dll (or static lib) and you can import only one lib. In fact, since you are doing that, you could create a customised interface to deal with all the other issues you are having. ======================== Prof. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy, Maynooth University, Maynooth, Co Kildare, Ireland Tel: 00 353 7086936 Fax: 00 353 1 7086952 > On 12 Jun 2017, at 14:35, Rory Walsh |
Date | 2017-06-12 14:46 |
From | Rory Walsh |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
To be honest, this is the only issue I am currently having with it. Strange as it may seem, but Csound and C# actually make very good bedfellows in Unity. Your solution should work, although it seems like a bit of effort. Right now, CsoundUnity exists entirely as a collection of C# scripts. Users don't have to build anything to get going, and it works with the standard Csound installers. I don't even have to build a plugin dll myself. Before I go down that route I better crack open the C# book again and see how the flip I can deal with pointers! On 12 June 2017 at 14:39, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote: yes, that is what I am suggesting. That DLL could potentially just link to the Csound dll (or static lib) and you can import |
Date | 2017-06-14 11:27 |
From | Rory Walsh |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
I've had to down the route you suggested, but I've not been able to get your method to work. Instead I just zero out each sample one by one which works fine: while(csound->PerformKsmps()==0) { for(int i=0;i<csound->GetKsmps();i++) { spin[0] = 0.f; csound->AddSpinSample(i, 0, simpleRamp[sampleCount]); sampleCount=sampleCount==44100 ? 0 : sampleCount+1; } }Trying to clear the entire buffer in one go results in the same problem as before for some reason. Here's what I tried: while(csound->PerformKsmps()==0) { clearSpin(csound); for(int i=0;i<csound->GetKsmps();i++) { csound->AddSpinSample(i, 0, simpleRamp[sampleCount]); sampleCount=sampleCount==44100 ? 0 : sampleCount+1; } } On 12 June 2017 at 14:46, Rory Walsh <rorywalsh@ear.ie> wrote:
|
Date | 2017-06-14 11:42 |
From | Victor Lazzarini |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
It’s probable that my code was wrong. Since you’re doing this, I’d suggest to just get rid of the function call and set spin[i] = simpleRand[i]. If you have access to spin, just use it. ======================== Prof. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy, Maynooth University, Maynooth, Co Kildare, Ireland Tel: 00 353 7086936 Fax: 00 353 1 7086952 > On 14 Jun 2017, at 11:27, Rory Walsh |
Date | 2017-06-14 11:47 |
From | Rory Walsh |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
That's what I'll do. On 14 June 2017 at 11:42, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote: It’s probable that my code was wrong. Since you’re doing this, I’d suggest to just get rid of the function call |
Date | 2017-06-14 14:13 |
From | Rory Walsh |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
In hindsight I can see why this method is called csoundAddSpinSample ;) It would be nice if we can also directly write samples to the intput buffers. A complementary function to csoundGetSpoutSample(...). csoundGetSpinSample(..) maybe? On 14 June 2017 at 11:47, Rory Walsh <rorywalsh@ear.ie> wrote:
|
Date | 2017-06-14 14:19 |
From | Victor Lazzarini |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
That would get the sample, rather than write to it ;) ======================== Prof. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy, Maynooth University, Maynooth, Co Kildare, Ireland Tel: 00 353 7086936 Fax: 00 353 1 7086952 > On 14 Jun 2017, at 14:13, Rory Walsh |
Date | 2017-06-14 14:28 |
From | jpff |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
csoundSetSpiSample ? On Wed, 14 Jun 2017, Victor Lazzarini wrote: > That would get the sample, rather than write to it ;) > ======================== > Prof. Victor Lazzarini > Dean of Arts, Celtic Studies, and Philosophy, > Maynooth University, > Maynooth, Co Kildare, Ireland > Tel: 00 353 7086936 > Fax: 00 353 1 7086952 > >> On 14 Jun 2017, at 14:13, Rory Walsh |
Date | 2017-06-14 14:29 |
From | Victor Lazzarini |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
yep, doing it now ======================== Prof. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy, Maynooth University, Maynooth, Co Kildare, Ireland Tel: 00 353 7086936 Fax: 00 353 1 7086952 > On 14 Jun 2017, at 14:28, jpff |
Date | 2017-06-14 14:31 |
From | Victor Lazzarini |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
In git now /** * Clears the input buffer (spin). */ PUBLIC void csoundClearSpin(CSOUND *); /** * Sets the audio input working buffer (spin) to the indicated sample * this only ever makes sense before calling csoundPerformKsmps(). * The frame and channel must be in bounds relative to ksmps and nchnls. */ PUBLIC void csoundSetSpinSample(CSOUND *csound, int frame, int channel, MYFLT sample); ======================== Prof. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy, Maynooth University, Maynooth, Co Kildare, Ireland Tel: 00 353 7086936 Fax: 00 353 1 7086952 > On 14 Jun 2017, at 14:29, Victor Lazzarini |
Date | 2017-06-14 15:24 |
From | Rory Walsh |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
Thanks Victor. These are definitely useful, and will save me from having to build a .dll for each release. But for now I'll need the .dll. I create a very simple function, but I'm concerned about the cost of calling csoundGetSpin() on each sample? Here's my function: void setCsoundInputSample(void *p, int pos, double sample) { MYFLT *spin = csoundGetSpin((CSOUND*) p); spin[pos] = sample; } If you think it might incur some overhead I would need to embed my instance of Csound into my own dll rather than creating a utility lib of my own. On 14 June 2017 at 14:31, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote: In git now |
Date | 2017-06-14 15:26 |
From | Victor Lazzarini |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
Can’t you pass the MYFLT * to it instead or is it awkward? ======================== Prof. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy, Maynooth University, Maynooth, Co Kildare, Ireland Tel: 00 353 7086936 Fax: 00 353 1 7086952 > On 14 Jun 2017, at 15:24, Rory Walsh |
Date | 2017-06-14 15:32 |
From | Rory Walsh |
Subject | Re: [Csnd-dev] [Csnd] csoundAddSpinSample() question... |
I'll try that. I can get access to it in my interface, but I just can't seem to manipulate it without all sorts of OTT nonsense. But passing it back and forth between the native interface might work. On 14 June 2017 at 15:26, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote: Can’t you pass the MYFLT * to it instead or is it awkward? |