# Processing Audio with inch opcode

**URL:** <https://forum.cabbageaudio.com/t/processing-audio-with-inch-opcode/576>\
**Category:** Csound for Games\
**Created:** [11 June 2017 18:53 UTC](https://forum.cabbageaudio.com/t/processing-audio-with-inch-opcode/576 "2017-06-11T18:53:40Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lukas](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/l/e9a140/32.png) [@Lukas](https://forum.cabbageaudio.com/u/Lukas)\
**Post date:** [11 June 2017 18:53 UTC](https://forum.cabbageaudio.com/t/processing-audio-with-inch-opcode/576/1 "2017-06-11T18:53:40Z")

</div>

Hello,

I’m a beginner to Csound and audio programming, I’m building a synthesizer and audio DSP simulator with Unity, I saw the post on this page: about using “[Processing Audio](http://forum.cabbageaudio.com/t/csoundunity-for-beat-matching/553/2)” toggle to send audio buffer with ‘inch’ opcode in CsoundUnity, I actually tried by my self but still don’t really know how to make it works.

So can you explain more detail about how to process and send audio clip using “ProcessAudio” toggle from Audio source to Csound with “inch”? More specifically, what function in C# should I use to send the audio buffers (or I don’t even need a C# script)? How do I set up the channels with “inch” in order to receive audio from Unity? What flags should I use in Csound and what does the Csound codes looks like? Thanks!

---

<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:** [12 June 2017 11:10 UTC](https://forum.cabbageaudio.com/t/processing-audio-with-inch-opcode/576/2 "2017-06-12T11:10:30Z")

</div>

There seems to be an issue with this at the moment, I’ll take a look.

I might have mentioned this on another thread, but I rarely ever found the need to process audio clips in this way. I usually just load the audio directly into Csound using a table, or the [diskin2](https://csound.github.io/docs/manual/diskin2.html). For example, the following instrument will load a file called pianoSample.wav from the Assets/Audio folder and start playing it back.

```
<Cabbage>
form caption("Test"), size(300, 200)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -m0d
</CsOptions>
<CsInstruments>
sr = 44100 
ksmps = 32
nchnls = 2
0dbfs	=	1 

instr 1
SPath chnget "AudioPath"
SFilename sprintf "%s/pianoSample.wav", SPath
a1, a2 diskin2 SFilename, 1, 0, 1
outs a1, a2
endin

</CsInstruments>
<CsScore>
i1 0 [3600*12]
</CsScore>
</CsoundSynthesizer>

```

I’ll need to fix the issue with ‘Process Clip’ before you can access mic input.

---

<div class="post-metadata">

**Author:** ![Lukas](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/l/e9a140/32.png) [@Lukas](https://forum.cabbageaudio.com/u/Lukas)\
**Post date:** [12 June 2017 13:21 UTC](https://forum.cabbageaudio.com/t/processing-audio-with-inch-opcode/576/3 "2017-06-12T13:21:07Z")

</div>

Cool, let me know when you fix the issue, thanks!

---

<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:** [12 June 2017 19:54 UTC](https://forum.cabbageaudio.com/t/processing-audio-with-inch-opcode/576/4 "2017-06-12T19:54:21Z")

</div>

I found the issue and I’m currently working on a fix. I have two possible options. I know which one is best, I’m just not sure how to do it 😏  
…yet..

---

<div class="post-metadata">

**Author:** ![Lukas](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/l/e9a140/32.png) [@Lukas](https://forum.cabbageaudio.com/u/Lukas)\
**Post date:** [12 June 2017 20:02 UTC](https://forum.cabbageaudio.com/t/processing-audio-with-inch-opcode/576/5 "2017-06-12T20:02:54Z")

</div>

No problem:joy:

---

<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:** [15 June 2017 12:08 UTC](https://forum.cabbageaudio.com/t/processing-audio-with-inch-opcode/576/6 "2017-06-15T12:08:54Z")

</div>

I have a fix for this, but I won’t be able to prepare an OSX version till tomorrow. I’ll also try to work out how we can process audio from the microphone.

---

<div class="post-metadata">

**Author:** ![Lukas](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/l/e9a140/32.png) [@Lukas](https://forum.cabbageaudio.com/u/Lukas)\
**Post date:** [18 June 2017 17:51 UTC](https://forum.cabbageaudio.com/t/processing-audio-with-inch-opcode/576/7 "2017-06-18T17:51:33Z")

</div>

Thanks! It only works for Windows now? How can I update my CsoundUnity to the fixed version?

---

<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:** [18 June 2017 18:19 UTC](https://forum.cabbageaudio.com/t/processing-audio-with-inch-opcode/576/8 "2017-06-18T18:19:08Z")

</div>

I@m still having a s;ight issue. I’ll take another swipe at it tomorrow. I’ll let you know when I get it done. Thanks for your patience 😉

---

<div class="post-metadata">

**Author:** ![Lukas](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/l/e9a140/32.png) [@Lukas](https://forum.cabbageaudio.com/u/Lukas)\
**Post date:** [18 June 2017 18:28 UTC](https://forum.cabbageaudio.com/t/processing-audio-with-inch-opcode/576/9 "2017-06-18T18:28:56Z")

</div>

No problem:)

---

<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:** [19 June 2017 11:36 UTC](https://forum.cabbageaudio.com/t/processing-audio-with-inch-opcode/576/10 "2017-06-19T11:36:23Z")

</div>

Can you try this one?

> **[Dropbox](https://www.dropbox.com/s/pnxtlm5l17srgq6/CsoundUnityOSX.unitypackage?dl=0)**

It doesn’t contain any samples scenes, but does ships with a native plugin that should enable processing of AudioClips. I hope to remove the need for that compiled plugin in the future, but for now it’s easiest. Processing microphone input works now too, but you have to first fill the AudioSource associated with the CsoundUnity component with input from your microphone. Here’s is a little code that should do the trick.

```
private CsoundUnity csound;
private AudioSource audio;
// Use this for initialization
void Start()
{
    csound = GetComponent<CsoundUnity>();
    audio = csound.GetComponent<AudioSource>();
    audio.clip = Microphone.Start(null, true, 10, 44100);
    audio.loop = true; // Set the AudioClip to loop
    while (!(Microphone.GetPosition("USB Audio CODEC") > 0)) { } // Wait until the recording has started
    audio.Play(); // Play the audio source!
}

// Update is called once per frame
void Update()
{

} 

```

You could simply attach it to a script and then to the GameObject that has the CsoundUnity component attached. Note that you will need to find the name of your own microphone. Mine happens to be _USB Audio CODEC_. Yours will most likely be different. Let me know how you get on.

---

<div class="post-metadata">

**Author:** ![Lukas](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/l/e9a140/32.png) [@Lukas](https://forum.cabbageaudio.com/u/Lukas)\
**Post date:** [20 June 2017 22:21 UTC](https://forum.cabbageaudio.com/t/processing-audio-with-inch-opcode/576/11 "2017-06-20T22:21:18Z")

</div>

Nice! Thank you, I’ll try on my Mac and let you know, did you also updated the CsoundUnity PC package for this?

---

<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:** [21 June 2017 00:02 UTC](https://forum.cabbageaudio.com/t/processing-audio-with-inch-opcode/576/12 "2017-06-21T00:02:24Z")

</div>

What’s the idea behind your work? Are you trying to process live vocals? I’m interested to hear more about how you are going to use this 😉

---

<div class="post-metadata">

**Author:** ![Lukas](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/l/e9a140/32.png) [@Lukas](https://forum.cabbageaudio.com/u/Lukas)\
**Post date:** [21 June 2017 21:38 UTC](https://forum.cabbageaudio.com/t/processing-audio-with-inch-opcode/576/13 "2017-06-21T21:38:39Z")

</div>

Not really about processing live vocals but the audio clip, haha. I’m trying to build a VR project and add some cool sound FX, since VR is not supported very well on a Mac so I’m working on the project with a PC haha. I’ll show you something once I finish the prototype:)

---

<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:** [21 June 2017 22:02 UTC](https://forum.cabbageaudio.com/t/processing-audio-with-inch-opcode/576/14 "2017-06-21T22:02:40Z")

</div>

Sounds interesting. Are you planning to use the hrtf opcodes? Hector Centeno created this Android app with them afaik:  
[https://play.google.com/store/apps/details?id=net.hcenteno.ambiexplorer](https://play.google.com/store/apps/details?id=net.hcenteno.ambiexplorer)  
There is also a game that uses them but I can’t think of it right now. I’ll ask the person who mentioned it to me. I’ve never used them myself but from what I hear, they are very well implemented.

---

<div class="post-metadata">

**Author:** ![Lukas](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/l/e9a140/32.png) [@Lukas](https://forum.cabbageaudio.com/u/Lukas)\
**Post date:** [22 June 2017 04:39 UTC](https://forum.cabbageaudio.com/t/processing-audio-with-inch-opcode/576/15 "2017-06-22T04:39:51Z")

</div>

Interesting! Let me check them out. Thanks!

btw, did you also modified and recopiled some shared library codes? seems after I used the new package in my PC with copying the dll files and got some errors says CsoundUnityNativePlugin.dll is missing.

---

<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:** [22 June 2017 09:25 UTC](https://forum.cabbageaudio.com/t/processing-audio-with-inch-opcode/576/16 "2017-06-22T09:25:15Z")

</div>

I’ve just updated the releases. You can find the latest packages [here](https://github.com/rorywalsh/CsoundUnity/releases). From now on I’m putting the demos scenes into a separate package which you can also find on that page. Let me know if it works Ok.
