In a Resources folder inside the folder of the sample folder we load through the package manager. The advantage of Resources folder is that we can create as many of them as we need.
CsoundUnity examples
Yeah, I was just doing that now but wonāt have time to finish it. It would be easiest I think to create a CsoundUnity method like:
public void CreateFunctionTable(AudioClip clip, int tableNumber)
{
string createTableInstrument = String.Format(@"
schedule 9999, 0, 0
instr 9999
i1 ftgen {0}, 0, {1}, -2, 0, {1}, 0
endif",
tableNumber, file.length*AudioSettings.outputSampleRate);
CompiledOrc(createTableInstrument);
//wait some moments and then call:
CopyTableIn(tableNumber, clip.getData());
}
Then users would only have to ensure that they start any instruments that use these tables a little after they create the tables.
Perfect!
Iāll add this along the utility method to retrieve the samples of a clip as a MYFLT array.
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!