- Home /
Set audio clip to 3D in script
Hi, I have been breaking my head over this one for a couple of day's now and I can't seem to find a direct answer on the wiki/questions/forums to my problem.
It is about the following piece of code. audio.clip = Microphone.Start(selectedDevice, true, 10, maxFreq);
As you can see it is an audio clip created directly in script. What I need is that this audio clip gets imported as a 3D sound, which can not be done in the editor, since there is not physical clip in my asset folder (because I create it live in my script).
Is there anyway I can set it's audio type manually without using the AssetImporter class (because this would require a datapath to a clip inside the asset folder).
Answer by smoggach · Oct 29, 2014 at 04:36 PM
There's no way to set it directly. As with sprites (and their importer settings) You have to set them via the Create function.
http://docs.unity3d.com/ScriptReference/AudioClip.Create.html
Create a new audio clip with the settings you want, GetData from your microphone recording and SetData on your new audio clip.
Ok thanks, this gives a better insight, I will try a workaround through an editor script. If that fails, I will give your approach a sway.
thx
Unfortunately it does not seem to be possible to use a GetData function from the microphone en then feed it with SetData to an audio clip. After some research it seems that the $$anonymous$$icrophone interface (scripting) only supports 2D audio, which is a shame.
That's pretty lame but not entirely impossible. There are many more ways to get the audio data than just with Unity. If you're still serious I'd look into that, otherwise you're better off just modifying the volume by yourself.
Well I have created my own workaround, Unity creates the 3D effect by changing it's volume, this gave me the idea to calculate the distance between the AudioSource(wich carry's my clip) and the audio listener, this is the algorithm I came up with audio.volume = (sourceVolume/100/(ListenerDistance*VolumeFallOff));
This creates exactly the effect I wanted, without having the hassle of GetData and SetData.
Thx for your support, without your reply I would have never come up with this solution!.
Your answer
Follow this Question
Related Questions
Playing a sound clip from another object 1 Answer
Help with sound clips [C#] 0 Answers
Get audio from device... -1 Answers
Random, 3d sound. 1 Answer
Audio not coming out of speakers 1 Answer