# CsoundUnity for beat matching

**URL:** <https://forum.cabbageaudio.com/t/csoundunity-for-beat-matching/553>\
**Category:** Csound for Games\
**Created:** [27 May 2017 14:33 UTC](https://forum.cabbageaudio.com/t/csoundunity-for-beat-matching/553 "2017-05-27T14:33:44Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [27 May 2017 14:51 UTC](https://forum.cabbageaudio.com/t/csoundunity-for-beat-matching/553/2 "2017-05-27T14:51:37Z")

</div>

First things first, you should download the following [files](https://github.com/rorywalsh/CsoundUnity/tree/master/CsoundUnityScripts) and put them into your CsoundUnityScripts folder. Then we know we are on the same page. Secondly, are you using the same sampling rate in both Unity and Csound?

I probably won’t be able to do much more than offer some suggestions for the rest of the weekend, but once Monday comes around I’ll be able to try out some examples myself and see what’s what.

> [@Tao\_Yao](#):
>
> III. Are there any other opcode that better than temposcal for beat matching?

You could use a combo of other PVS opcodes, but I think you’re on the right track using temposcal…

> [@Tao\_Yao](#):
>
> IV. I have to specify the very specific path of my audio files (songs) as the 5th argument of temposcal, but what is the best way to pass multiple audio files and let the user can choose these songs in game? (by passing the a string path from Unity to Csound? if so, what’s the function name?) And as you can see the 5th argument of temposcal, I even have to specify “/user/…/Desktop/…”, but if player download the game it would be a different path in his computer.

When CsoundUnity loads, it passes a path to a channel called “AudioPath”. If you put all your audio files in an Assets/Audio folder then you can do something like this to get them:

```
SPath chnget "AudioPath"
SAudioFile sprintf "%s/MySOundfiler.wav", SPath

```

Basically you just append your sound file names to the audio path.

> [@Tao\_Yao](#):
>
> V. Can I feed audio signal from Unity to Csound instead? I found this link says there are some functions in CsoundUnity.cs that can do this, but when I opened my CsoundUnity.cs I didn’t found some functions showing in the link. If those functions are removed, can I still feed my songs to Csound?

Yes, in theory although I haven’t tested it in a while. With teh latest source I linked above, there should be a “processAudio” toggle button in the CsoundUnity inspector. If you check this, audio from the currentl audio clip will be piped to Csound. You’ll need to use the `inch` opcode to access the audio from the clip. As in the following if the clip is stereo:

```
aL inch 1
aR inch 2

```

To be honest, I added this feature thinking it would be really useful but ended up never needing to use it as it’s just as easy to load and manage the sound files directly from Csound 😉

---

_[View the full topic](https://forum.cabbageaudio.com/t/csoundunity-for-beat-matching/553)._
