Cabbage Logo
Back to Cabbage Site

CsoundUnity examples

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!

1 Like

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 :wink:

Thanks Rory, but I think you forgot to attach the edited version. Assuming the CsOptions isn’t the only thing that needs changing.

JM_sub.csd (67.2 KB)

Shoot, sorry about that!

1 Like

This works perfectly!

So, other than the CsOptions, the only changes are from lines 902-908?
From:

	if gkDetuneOn==1 then
		kFreq2 = p4+gkDetune*0.5
		kFreq1 = p4-gkDetune*0.5	
	else 
		kFreq1 =p4
		kFreq2 =p4
	endif

To:

if gkDetuneOn==1 then
        kFreq2 = cpsmidinn(p4)+gkDetune*0.5
        kFreq1 = cpsmidinn(p4)-gkDetune*0.5
	else 
		kFreq1 =cpsmidinn(p4)
		kFreq2 =cpsmidinn(p4)
	endif

Great!
I am very curious to try out your demo!

Me too. Feel free to post a few screencasts of the development stages!

Yeah for sure! I’ll try and get a demo vid here by tonight.

1 Like

Ok here’s a quick screen cap of progress so far. https://www.youtube.com/watch?v=ZFsV3_QgDw8

Got panning mapped left/right as well as a few other parameters when you raise/ lower the sun by holding spacebar.

I’ll probably do a few more additions on it, mostly visual. But let me know if you have any other ideas!

1 Like

This looks and sounds great. Keep them coming!

Very cool! We definitely need examples like that!
The logic is very smart we will reuse it for sure!

Thanks! well, i’m not an expert with coding so some of it may well be approached in a more efficient way. That said, I’d be happy to add it as an example for the package so you can tweak it and flesh out some of the editor interaction. Though you’ll have to guide me through getting it set up properly on the repo.

Actually one addition I’d love to make is some Audio Spectrum reactive particle effects. My previous set-up didn’t allow me to have precision as I could only feed in MIDI data. Though I’d likely have to use something like https://github.com/keijiro/Reaktion. Would this pose an issue for the example package?

Or maybe there’s no need as it doesn’t directly show the capabilities of the package? Just let me know :slight_smile:

I think it’s a good idea to do an example with the Audio Spectrum, but there’s no need for external packages. We can find the spectrum data pretty easily!
https://docs.unity3d.com/ScriptReference/AudioSource.GetSpectrumData.html
I’m thinking of creating a granular-like sequencer with notes represented graphically, like a visual score.
That would be very interesting, but not an easy task!

And on top of that there is no end to the way we can analyse sounds in Csound :wink: