Perfect!
I’ll add this along the utility method to retrieve the samples of a clip as a MYFLT array.
CsoundUnity examples
Great. I’ve no called compileOrc()
from CsoundUnity but I think this would the cleanest way, although it will end up running an instrument that users will not have declared…?
Yes I’ll add the CompileOrc method too.
Could schedule be called outside an instrument?
Yeah, it can be called like I have it in the rough example I sent. Easier than sending a score event…
Ok just pulled the update, later I’m going to test it in the Sequencer scene!
Now that I have values inside the tables, and they have raw samples data, what opcode to use to read all audio channels accordingly?
Should we pass an argument to CsoundUnity.CreateTable method specifying the number of channels of the samples?
So maybe it’s better to create one or more tables based on the channel numbers, or is it ok to store raw data like I am doing now?
Because I didn’t find how to read data from the tables I created.
Tried with loscil3 but it says:
stereo loscil cannot read from mono ftable
I created the table with GEN02 with orc like this (I thought there was no reason to use an instrument since ftgen works also in global space):
gisampletable900 ftgen 900, 0, -165375, -2, 0, 0
this is the csound code to play a sample, I just changed yours
instr PlaySample
a1, a2 loscil3 1.0, 1, giTable[p4]
outs a1*.1, a2*.1
endin
EDIT:
I forgot:
giTable reads a float with the table number to read from:
giTable[0] chnget "sampletable900"
and I set a table and a channel for every AudioClip I have in Sequencer inspector:
var tn = 900 + count;
var res = csoundUnity.CreateTable(tn, samples);
csoundUnity.SetChannel($"sampletable{tn}", tn);
so when count is 0 tn is 900
EDIT of the EDIT:
I swear I read all this thread: Reading speed of a GEN table but there’s no mention about a table filled externally. I can’t use GEN01!
Any table reading opcode should work once the vales are in the table?
I’ll need to double check this. loscil uses GEN01, and I’m not sure we can create a gen01 as we don’t have a file nam to use. We may just have to create a table for each channel in our sound file?
I actually don’t think it makes any difference which gen02 routine we use as we just overwrite the data anyway. One thing we need to check is that non power of2 sized tables are allowed…
I won’t get a chance to look into this till later, or most likely tomorrow at some point
Yes but I suppose I should do some computation to retrieve the single channels, if multichannel
That seems the easiest way to do this.
True!
Yes this is allowed setting the value of the samples as a negative number
from: http://write.flossmanuals.net/csound/d-function-tables/
size : the size of the function table. A little care is required: in the early days of Csound only power-of-two sizes were possible for function tables (2, 4, 8, 16, …); nowadays almost all GEN Routines accepts other sizes, but these non-power-of-two sizes must be declared as negative numbers!
I’ll try to do my best for a couple of hours, then I’ll be busy until next tuesday.
We already did a lot, no hurry!
No problem. Thanks again for all the work you’ve done with this. Don’t forget to drop in every now and then in case I have a list of questions for you
For sure, this is forum has become my favourite reading!
And it’s a pleasure working with you on CsoundUnity, something I wanted to do since I discovered it!
I have lots of projects in mind that will use it!
I did it with the perfect example I found here:
http://www.csounds.com/manual/html/nsamp.html
I’ll push the updated Sequencer example in some minutes
Edit: done!
(maybe needs some polish with levels and playback duration of the sample)
Let me know!
nsamp
. That’s a new one one me. I’d have used ftlen but I see there are subtle differences between then. I hope to get a chance today to look at this.
I guess there are loads of updates we could make, but at some point we will ruin the simplicity of the demo? I had hoped to add a first person shooter mechanism so there is an element of play. It is a game engine after all
Hi @rorywalsh, @giovannibedetti, I’m just finishing up the mechanics for my little example and about to move onto the CSound implementation. I’m trying to use the JM_Sub synth by Karamel (which is awesome btw) but noticed it reads in HZ instead of MIDI notes which seems odd as it does work when using my midi controller in cabbage. What’s the best way to edit the instr to register midi notes?
There are various converters in csound between midi and frequency, have a look at http://www.csounds.com/manual/html/midinoteoncps.html
Or
http://www.csounds.com/manual/html/cpsmidi.html
But in general, there would be no problem in passing a frequency as a parameter of the score.
I cannot look at the csd now (I am travelling with train) but if you could explain what kind of problem you have I’ll try to help if I can!
I can take a look later if @giovannibedetti can’t help you, sorry but I’m not at home either and am writing on my phone…
That’s great, I’ll take a look at those docs.
I’d prefer to use MIDI notes because the game I’m making will select notes mathematically, and it will make things a lot easier if I can stick to a 12 int octave.
I’ve got the score event set to instrument 1 and get the correct sound result, but I’m having to send it the note in frequency. So basically I just want to be able to send “i1 0 1 60 1” instead of “i1 0 1 261.6 1”.
It should be a matter of adding the conversion from midi note to cps to p4
at line 902, 903, 905 and 906.
Sorry but I cannot help more than this now, maybe tomorrow I’ll find some time!
If you post the .csd file you are using I can update it later to work with midi notes. Or is it the same one @Karamel1 posted to the list here? That was a very nice synth!
Hey, sorry for the slow reply. Yeah it was that one he posted here! New synth for Cabbage 2
I’ll give @giovannibedetti’s tip a shot now.
JM_sub.csd (67.2 KB)
This one swaps out cps values for MIDI note numbers. Note that it will also run in Cabbage with the keyboard because I swapped:
--midi-key-cps=4
in the CsOptions
section with:
--midi-key=4
Let me know how it goes