Yes, but I added this basically to test if the FileWatcher was working. Then adding the button to save was a matter of seconds. It is just a fast way to read and edit the csd directly in Unity.
CsoundUnity Package (UPM) development
Good idea. Yes, itās cool, letās keep it
I tried a simple command line application to test csoundGet0dbfs() and it works fine. We must be doing something wrongā¦
[edit] we should probably add --realtime
when compiling Csound? Seems like itās something that should always be on?
Itās because we are overriding 0dbfs. No need to do that anymore. I think we scale all Csound samples by zerbdfs
right?
Iām almost sure it doesnāt work also if itās not override by SetParams. But I could be wrong. Great if itās working.
We are now scaling everything by 0dbfs but we are not scaling the AudioChannels, we are getting the samples with
public MYFLT[] GetAudioChannel(string name)
do you think we should scale also this?
We scale them here:
switch (AudioChannelsSetting)
{
case AudioChannels.MONO:
samples[i + channel] = (float)(namedAudioChannelData[0][sampleIndex] / zerodbfs);
break;
case AudioChannels.STEREO:
samples[i + channel] = (float)(namedAudioChannelData[(int)channel][sampleIndex] / zerodbfs);
break;
}
That should be fine. So if someone does send a sample with amp 32000, it will get scaled accordingly right?
Btw, I just pushed the 0dbfs thingā¦
Fine, I just looked at the CsoundUnity part, instead of looking at the child
But maybe is more correct to have it scaled on the CsoundUnity part? the user could want to obtain the AudioChannel for other computations (see visuals), maybe itās better having all normalised?
Good point. I think youāre right
I have another point ā¢
We should find an easy way to load samples, the table thing is great, but I am having some difficulties using that table because itās not recognized as stereo by the table reading opcodes, so I have to calculate the reading speed and position multiplying the table length by the channels.
Also, the table is not accepting long files (Iāll tell the max value), and this is a limitation.
Now a Start method of a user script could be like this:
IEnumerator Start()
{
csound = GetComponent<CsoundUnity>();
if (!csound)
Debug.LogWarning("Csound not found?");
while (!csound.IsInitialized)
{
yield return null; //waiting for initialization
}
// this gets the samples from the AudioClip field
var samples = CsoundUnity.GetSamples(source.name, CsoundUnity.SamplesOrigin.Resources);
// this creates the table with those raw samples (no info about channels)
csound.CreateTable(100, samples);
}
and this is great.
On the Csound part I have to do something like this:
instr 2
ifn = p5
ilen = ftlen(ifn)
itrns = nchnls ; no transposition
itrns *= i(gkspeed)
ilps = int(p4 * sr * nchnls) % ilen ;start
idursam = p3 * sr * nchnls ;duration in samples
ilpe = int(ilps + idursam) % ilen ;end
imode = 1 ; loops forward
istrt = ilps
;lphasor provides index into f1
alphs lphasor itrns, ilps, ilpe, imode, istrt
atab table alphs, ifn
aenv linseg 0, p3/10, p6, (p3 * 4 / 5), p6, p3 / 10, 0
atab *= aenv
outs atab, atab
endin
which is fine as well, but for example loscilx http://www.csounds.com/manual/html/loscilx.html isnāt working with the table, telling that the table has no channels. Lots of opcodes that read audio files can produce multiple audio vars based on channels. And lots of code should be adapted.
Also pitch shifting is not available, or I couldnāt find an easy way without having lots of noise.
What do you think?
What can we do to produce tables with channels? I didnāt find anything in the docs.
As far as I know, none of the table reading opcodes will read in in stereo. But I see your point. However, I donāt know of any way to dynamically create a GEN01 table from data. I could write a new opcode for this? But it would be best to find a native solution. Let me ask on the Csound slack channel. Steven Yi is usually pretty quick to reply, and he is aware of what weāre atā¦
loscilx ā Read multi-channel sampled sound from a table.
Description
Read sampled sound (up to 16 channels) from a table, with optional sustain and release looping.
I never used it, but it seems good!
Should work with GEN01
Greetings to Steven!
Before I ask Steven, couldnāt we do this ourselves, without using loscilx
?
Letās say we use the first index of our table to denote the number of channels. After that we write our interleaved data from Unity to the table. Our instrument reads the first index of the table to get the number of channels and then after that parses the data accordingly, outputting channels data for each channel?
It would need to wrapped up as a UDO, but we can dynamically add the UDO to the orchestra when we compile Csound?
Yes great!
What would be the max duration of the file?
To be honest, the easy way already exists: put the AudioClip in the AudioSource, enable ProcessClipAudio, and in Csound:
ainL, ainR inch 1, 2
But this gives no control on fine audio playback
I think tables have a fixed upper limit, but Iām not sure what it is.
True. But to build samples and things like that itās not so useful. I think this way should work. I will take a look at it when I get a chance. Probably tomorrow morning.
Ok no hurry, Iām just having fun creating an example about Granular Synthesis
Here is a test:
A stereo file of 2 mins would be 10584000 samples.
When I try to load with create table I obtain maximum 6008184 samples, which is about 68 seconds.
Strange. Iāll check with the Csound devsā¦
Maybe thereās some error with the ftgen code I use to create it (using negative GEN2)
The table is created and then the samples are overwritten by CopyTableIn
Can you try with another GEN routine? Say GEN07?
Just tried with this code:
public int CreateTableInstrument(int tableNumber, int tableLength/*, int nChannels*/)
{
string createTableInstrument = String.Format(@"gisampletable{0} ftgen {0}, 0, {1}, -7, 0, 0", tableNumber, -tableLength /** AudioSettings.outputSampleRate*/);
// Debug.Log("orc to create table: \n" + createTableInstrument);
return CompileOrc(createTableInstrument);
}
in the logs I have:
ftable 100: 6008184 points, scalemax 0.000
printing table length:
[2.000000] new instr 2 instance ilen 6008184, P2 2.000000, P3 0.100000, P4 2.000000, P5 100.000000, P6 1.000000
Edit, I think itās my problem, let me investigate
PS Thatās the length I pass to the function