Exemplo n.º 1
0
    void CreateCubeButton(int index, Vector2 rotation, float depth)
    {
        GameObject cubeButton = Instantiate(cubeButtonPrefab, Vector3.zero, Quaternion.identity) as GameObject;

        cubeButton.transform.localPosition = new Vector3(Mathf.Sin(rotation.x * (Mathf.PI * 2) / 360) * depth, 0, Mathf.Cos(rotation.x * (Mathf.PI * 2) / 360) * depth);
        cubeButton.transform.rotation      = Quaternion.Euler(new Vector3(rotation.y, rotation.x, 0));


        //   cubeButton.GetComponent<Renderer>().material = Instantiate(material) as Material;
        cubeButton.GetComponent <Renderer>().material.color = buttonSettings[index].normalColor;
        cubeButton.GetComponent <Button>().onClick.AddListener(() =>
        {
            onGameButtonClick(index);
        });

        cubeButtons.Add(cubeButton);

        {
            float length    = 2f;
            float frequency = 0.0001f * ((float)index + 1f);

            AnimationCurve volumeCurve    = new AnimationCurve(new Keyframe(0f, 1f, 0f, -1f), new Keyframe(length, 0f, -1f, 0f));
            AnimationCurve frequencyCurve = new AnimationCurve(new Keyframe(0f, frequency, 0f, 0f), new Keyframe(length, frequency, 0f, 0f));

            LeanAudioOptions audioOptions = LeanAudio.options();
            audioOptions.setWaveSine();
            audioOptions.setFrequency(44100);


            AudioClip audioClip = LeanAudio.createAudio(volumeCurve, frequencyCurve, audioOptions);
            cubeButton.GetComponent <AudioSource>().clip = audioClip;
        }
    }
Exemplo n.º 2
0
 static public int get_waveNoiseInfluence(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         LeanAudioOptions self = (LeanAudioOptions)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.waveNoiseInfluence);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Exemplo n.º 3
0
	/**
	* Create dynamic audio from a set of Animation Curves and other options.
	* 
	* @method createAudio
	* @param {AnimationCurve} volumeCurve:AnimationCurve describing the shape of the audios volume (from 0-1). The length of the audio is dicated by the end value here.
	* @param {AnimationCurve} frequencyCurve:AnimationCurve describing the width of the oscillations between the sound waves in seconds. Large numbers mean a lower note, while higher numbers mean a tighter frequency and therefor a higher note. Values are usually between 0.01 and 0.000001 (or smaller)
	* @param {LeanAudioOptions} options:LeanAudioOptions You can pass any other values in here like vibrato or the frequency you would like the sound to be encoded at. See <a href="LeanAudioOptions.html">LeanAudioOptions</a> for more details.
	* @return {AudioClip} AudioClip of the procedurally generated audio
	* @example
	* AnimationCurve volumeCurve = new AnimationCurve( new Keyframe(0f, 1f, 0f, -1f), new Keyframe(1f, 0f, -1f, 0f));<br>
	* AnimationCurve frequencyCurve = new AnimationCurve( new Keyframe(0f, 0.003f, 0f, 0f), new Keyframe(1f, 0.003f, 0f, 0f));<br>
	* AudioClip audioClip = LeanAudio.createAudio(volumeCurve, frequencyCurve, LeanAudio.options().setVibrato( new Vector3[]{ new Vector3(0.32f,0f,0f)} ));<br>
	*/
	public static AudioClip createAudio( AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options = null ){
		if(options==null)
			options = new LeanAudioOptions();
		
		float[] generatedWavePts = createAudioWave( volume, frequency, options);
		return createAudioFromWave( generatedWavePts, options );
	}
Exemplo n.º 4
0
    static int createAudioStream(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                UnityEngine.AnimationCurve arg0 = (UnityEngine.AnimationCurve)ToLua.CheckObject <UnityEngine.AnimationCurve>(L, 1);
                UnityEngine.AnimationCurve arg1 = (UnityEngine.AnimationCurve)ToLua.CheckObject <UnityEngine.AnimationCurve>(L, 2);
                LeanAudioStream            o    = LeanAudio.createAudioStream(arg0, arg1);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 3)
            {
                UnityEngine.AnimationCurve arg0 = (UnityEngine.AnimationCurve)ToLua.CheckObject <UnityEngine.AnimationCurve>(L, 1);
                UnityEngine.AnimationCurve arg1 = (UnityEngine.AnimationCurve)ToLua.CheckObject <UnityEngine.AnimationCurve>(L, 2);
                LeanAudioOptions           arg2 = (LeanAudioOptions)ToLua.CheckObject <LeanAudioOptions>(L, 3);
                LeanAudioStream            o    = LeanAudio.createAudioStream(arg0, arg1, arg2);
                ToLua.PushObject(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: LeanAudio.createAudioStream"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Exemplo n.º 5
0
    private static AudioClip createAudioFromWave(int waveLength, LeanAudioOptions options)
    {
        float time = longList[waveLength - 2];

        float[] audioArr = new float[(int)(options.frequencyRate * time)];

        int   waveIter        = 0;
        float subWaveDiff     = longList[waveIter];
        float subWaveTimeLast = 0f;
        float subWaveTime     = longList[waveIter];
        float waveHeight      = longList[waveIter + 1];

        for (int i = 0; i < audioArr.Length; i++)
        {
            float passedTime = (float)i / (float)options.frequencyRate;
            if (passedTime > longList[waveIter])
            {
                subWaveTimeLast = longList[waveIter];
                waveIter       += 2;
                subWaveDiff     = longList[waveIter] - longList[waveIter - 2];
                waveHeight      = longList[waveIter + 1];
                // Debug.Log("passed wave i:"+i);
            }
            subWaveTime = passedTime - subWaveTimeLast;
            float ratioElapsed = subWaveTime / subWaveDiff;

            float value = Mathf.Sin(ratioElapsed * Mathf.PI);
            //if(i<25)
            //	Debug.Log("passedTime:"+passedTime+" value:"+value+" ratioElapsed:"+ratioElapsed+" subWaveTime:"+subWaveTime+" subWaveDiff:"+subWaveDiff);

            value *= waveHeight;

            audioArr[i] = value;
            // Debug.Log("pt:"+pt+" i:"+i+" val:"+audioArr[i]+" len:"+audioArr.Length);
        }


        int lengthSamples = audioArr.Length;

                #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
        bool      is3dSound = false;
        AudioClip audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, is3dSound, false);
                #else
        AudioClip audioClip = null;
        if (options.useSetData)
        {
            audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, false, null, OnAudioSetPosition);
            audioClip.SetData(audioArr, 0);
        }
        else
        {
            options.stream = new LeanAudioStream(audioArr);
            Debug.Log("len:" + audioArr.Length + " lengthSamples:" + lengthSamples + " freqRate:" + options.frequencyRate);
            audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, false, options.stream.OnAudioRead, options.stream.OnAudioSetPosition);
            options.stream.audioClip = audioClip;
        }
                #endif

        return(audioClip);
    }
Exemplo n.º 6
0
 static public int set_waveStyle(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         LeanAudioOptions self = (LeanAudioOptions)checkSelf(l);
         LeanAudioOptions.LeanAudioWaveStyle v;
         v = (LeanAudioOptions.LeanAudioWaveStyle)LuaDLL.luaL_checkinteger(l, 2);
         self.waveStyle = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Exemplo n.º 7
0
 static public int constructor(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         LeanAudioOptions o;
         o = new LeanAudioOptions();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Exemplo n.º 8
0
 static public int setVibrato(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         LeanAudioOptions      self = (LeanAudioOptions)checkSelf(l);
         UnityEngine.Vector3[] a1;
         checkArray(l, 2, out a1);
         var ret = self.setVibrato(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Exemplo n.º 9
0
 static public int set_stream(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         LeanAudioOptions self = (LeanAudioOptions)checkSelf(l);
         LeanAudioStream  v;
         checkType(l, 2, out v);
         self.stream = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Exemplo n.º 10
0
	/**
	* Create dynamic audio from a set of Animation Curves and other options.
	* 
	* @method createAudio
	* @param {AnimationCurve} volumeCurve:AnimationCurve describing the shape of the audios volume (from 0-1). The length of the audio is dicated by the end value here.
	* @param {AnimationCurve} frequencyCurve:AnimationCurve describing the width of the oscillations between the sound waves in seconds. Large numbers mean a lower note, while higher numbers mean a tighter frequency and therefor a higher note. Values are usually between 0.01 and 0.000001 (or smaller)
	* @param {LeanAudioOptions} options:LeanAudioOptions You can pass any other values in here like vibrato or the frequency you would like the sound to be encoded at. See <a href="LeanAudioOptions.html">LeanAudioOptions</a> for more details.
	* @return {AudioClip} AudioClip of the procedurally generated audio
	* @example
	* AnimationCurve volumeCurve = new AnimationCurve( new Keyframe(0f, 1f, 0f, -1f), new Keyframe(1f, 0f, -1f, 0f));<br>
	* AnimationCurve frequencyCurve = new AnimationCurve( new Keyframe(0f, 0.003f, 0f, 0f), new Keyframe(1f, 0.003f, 0f, 0f));<br>
	* AudioClip audioClip = LeanAudio.createAudio(volumeCurve, frequencyCurve, LeanAudio.options().setVibrato( new Vector3[]{ new Vector3(0.32f,0f,0f)} ));<br>
	*/
	public static AudioClip createAudio( AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options = null ){
		if(options==null)
			options = new LeanAudioOptions();
		
		int generatedWavePtsLength = createAudioWave( volume, frequency, options);
		// Debug.Log("generatedWavePtsLength:"+generatedWavePtsLength);
		return createAudioFromWave( generatedWavePtsLength, options );
	}
Exemplo n.º 11
0
 public static AudioClip createAudio(AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options = null)
 {
     if (options == null)
     {
         options = new LeanAudioOptions();
     }
     return(createAudioFromWave(createAudioWave(volume, frequency, options), options));
 }
Exemplo n.º 12
0
 public static LeanAudioStream createAudioStream(AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options = null)
 {
     if (options == null)
     {
         options = new LeanAudioOptions();
     }
     options.useSetData = false;
     createAudioFromWave(createAudioWave(volume, frequency, options), options);
     return(options.stream);
 }
Exemplo n.º 13
0
    /**
     * Create dynamic audio from a set of Animation Curves and other options.
     *
     * @method createAudio
     * @param {AnimationCurve} volumeCurve:AnimationCurve describing the shape of the audios volume (from 0-1). The length of the audio is dicated by the end value here.
     * @param {AnimationCurve} frequencyCurve:AnimationCurve describing the width of the oscillations between the sound waves in seconds. Large numbers mean a lower note, while higher numbers mean a tighter frequency and therefor a higher note. Values are usually between 0.01 and 0.000001 (or smaller)
     * @param {LeanAudioOptions} options:LeanAudioOptions You can pass any other values in here like vibrato or the frequency you would like the sound to be encoded at. See <a href="LeanAudioOptions.html">LeanAudioOptions</a> for more details.
     * @return {AudioClip} AudioClip of the procedurally generated audio
     * @example
     * AnimationCurve volumeCurve = new AnimationCurve( new Keyframe(0f, 1f, 0f, -1f), new Keyframe(1f, 0f, -1f, 0f));<br>
     * AnimationCurve frequencyCurve = new AnimationCurve( new Keyframe(0f, 0.003f, 0f, 0f), new Keyframe(1f, 0.003f, 0f, 0f));<br>
     * AudioClip audioClip = LeanAudio.createAudio(volumeCurve, frequencyCurve, LeanAudio.options().setVibrato( new Vector3[]{ new Vector3(0.32f,0f,0f)} ));<br>
     */
    public static AudioClip createAudio(AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options = null)
    {
        if (options == null)
        {
            options = new LeanAudioOptions();
        }

        float[] generatedWavePts = createAudioWave(volume, frequency, options);
        return(createAudioFromWave(generatedWavePts, options));
    }
Exemplo n.º 14
0
	public static LeanAudioStream createAudioStream( AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options = null ){
		if(options==null)
			options = new LeanAudioOptions();

		options.useSetData = false;

		int generatedWavePtsLength = createAudioWave( volume, frequency, options);
		createAudioFromWave( generatedWavePtsLength, options );

		return options.stream;
	}
Exemplo n.º 15
0
 static public int get_stream(IntPtr l)
 {
     try {
         LeanAudioOptions self = (LeanAudioOptions)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.stream);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 16
0
 static public int get_waveNoiseInfluence(IntPtr l)
 {
     try {
         LeanAudioOptions self = (LeanAudioOptions)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.waveNoiseInfluence);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 17
0
 static public int get_waveStyle(IntPtr l)
 {
     try {
         LeanAudioOptions self = (LeanAudioOptions)checkSelf(l);
         pushValue(l, true);
         pushEnum(l, (int)self.waveStyle);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 18
0
    /**
     * Create dynamic audio from a set of Animation Curves and other options.
     *
     * @method createAudio
     * @param {AnimationCurve} volumeCurve:AnimationCurve describing the shape of the audios volume (from 0-1). The length of the audio is dicated by the end value here.
     * @param {AnimationCurve} frequencyCurve:AnimationCurve describing the width of the oscillations between the sound waves in seconds. Large numbers mean a lower note, while higher numbers mean a tighter frequency and therefor a higher note. Values are usually between 0.01 and 0.000001 (or smaller)
     * @param {LeanAudioOptions} options:LeanAudioOptions You can pass any other values in here like vibrato or the frequency you would like the sound to be encoded at. See <a href="LeanAudioOptions.html">LeanAudioOptions</a> for more details.
     * @return {AudioClip} AudioClip of the procedurally generated audio
     * @example
     * AnimationCurve volumeCurve = new AnimationCurve( new Keyframe(0f, 1f, 0f, -1f), new Keyframe(1f, 0f, -1f, 0f));<br>
     * AnimationCurve frequencyCurve = new AnimationCurve( new Keyframe(0f, 0.003f, 0f, 0f), new Keyframe(1f, 0.003f, 0f, 0f));<br>
     * AudioClip audioClip = LeanAudio.createAudio(volumeCurve, frequencyCurve, LeanAudio.options().setVibrato( new Vector3[]{ new Vector3(0.32f,0f,0f)} ));<br>
     */

    public static AudioClip createAudio(AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options = null)
    {
        if (options == null)
        {
            options = new LeanAudioOptions();
        }

        int generatedWavePtsLength = createAudioWave(volume, frequency, options);

        // Debug.Log("generatedWavePtsLength:"+generatedWavePtsLength);
        return(createAudioFromWave(generatedWavePtsLength, options));
    }
Exemplo n.º 19
0
 static public int setWaveSawtooth(IntPtr l)
 {
     try {
         LeanAudioOptions self = (LeanAudioOptions)checkSelf(l);
         var ret = self.setWaveSawtooth();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 20
0
 static public int constructor(IntPtr l)
 {
     try {
         LeanAudioOptions o;
         o = new LeanAudioOptions();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 21
0
 static int options(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 0);
         LeanAudioOptions o = LeanAudio.options();
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemplo n.º 22
0
 static public int set_modulation(IntPtr l)
 {
     try {
         LeanAudioOptions      self = (LeanAudioOptions)checkSelf(l);
         UnityEngine.Vector3[] v;
         checkArray(l, 2, out v);
         self.modulation = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 23
0
 static public int set_stream(IntPtr l)
 {
     try {
         LeanAudioOptions self = (LeanAudioOptions)checkSelf(l);
         LeanAudioStream  v;
         checkType(l, 2, out v);
         self.stream = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 24
0
 static public int set_frequencyRate(IntPtr l)
 {
     try {
         LeanAudioOptions self = (LeanAudioOptions)checkSelf(l);
         System.Int32     v;
         checkType(l, 2, out v);
         self.frequencyRate = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 25
0
 static public int set_waveStyle(IntPtr l)
 {
     try {
         LeanAudioOptions self = (LeanAudioOptions)checkSelf(l);
         LeanAudioOptions.LeanAudioWaveStyle v;
         checkEnum(l, 2, out v);
         self.waveStyle = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 26
0
 static public int set_waveNoiseInfluence(IntPtr l)
 {
     try {
         LeanAudioOptions self = (LeanAudioOptions)checkSelf(l);
         System.Single    v;
         checkType(l, 2, out v);
         self.waveNoiseInfluence = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 27
0
 static public int set_useSetData(IntPtr l)
 {
     try {
         LeanAudioOptions self = (LeanAudioOptions)checkSelf(l);
         System.Boolean   v;
         checkType(l, 2, out v);
         self.useSetData = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 28
0
 static public int setWaveStyle(IntPtr l)
 {
     try {
         LeanAudioOptions self = (LeanAudioOptions)checkSelf(l);
         LeanAudioOptions.LeanAudioWaveStyle a1;
         checkEnum(l, 2, out a1);
         var ret = self.setWaveStyle(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 29
0
 static public int setWaveNoiseInfluence(IntPtr l)
 {
     try {
         LeanAudioOptions self = (LeanAudioOptions)checkSelf(l);
         System.Single    a1;
         checkType(l, 2, out a1);
         var ret = self.setWaveNoiseInfluence(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 30
0
 static public int setFrequency(IntPtr l)
 {
     try {
         LeanAudioOptions self = (LeanAudioOptions)checkSelf(l);
         System.Int32     a1;
         checkType(l, 2, out a1);
         var ret = self.setFrequency(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 31
0
 static public int setVibrato(IntPtr l)
 {
     try {
         LeanAudioOptions      self = (LeanAudioOptions)checkSelf(l);
         UnityEngine.Vector3[] a1;
         checkArray(l, 2, out a1);
         var ret = self.setVibrato(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 32
0
    private static AudioClip createAudioFromWave(float[] wave, LeanAudioOptions options)
    {
        float time = wave[wave.Length - 2];

        float[] audioArr = new float[(int)(options.frequencyRate * time)];

        int   waveIter        = 0;
        float subWaveDiff     = wave[waveIter];
        float subWaveTimeLast = 0f;
        float subWaveTime     = wave[waveIter];
        float waveHeight      = wave[waveIter + 1];

        for (int i = 0; i < audioArr.Length; i++)
        {
            float passedTime = (float)i / (float)options.frequencyRate;
            if (passedTime > wave[waveIter])
            {
                subWaveTimeLast = wave[waveIter];
                waveIter       += 2;
                subWaveDiff     = wave[waveIter] - wave[waveIter - 2];
                waveHeight      = wave[waveIter + 1];
                // Debug.Log("passed wave i:"+i);
            }
            subWaveTime = passedTime - subWaveTimeLast;
            float ratioElapsed = subWaveTime / subWaveDiff;

            float value = Mathf.Sin(ratioElapsed * Mathf.PI);
            //if(i<25)
            //	Debug.Log("passedTime:"+passedTime+" value:"+value+" ratioElapsed:"+ratioElapsed+" subWaveTime:"+subWaveTime+" subWaveDiff:"+subWaveDiff);

            value *= waveHeight;

            audioArr[i] = value;
            // Debug.Log("pt:"+pt+" i:"+i+" val:"+audioArr[i]+" len:"+audioArr.Length);
        }

        int lengthSamples = audioArr.Length;

                #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5 && !UNITY_4_6
        AudioClip audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, false);
                #else
        bool      is3dSound = false;
        AudioClip audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, is3dSound, false);
                #endif
        audioClip.SetData(audioArr, 0);

        return(audioClip);
    }
Exemplo n.º 33
0
 static int createAudio(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         UnityEngine.AnimationCurve arg0 = (UnityEngine.AnimationCurve)ToLua.CheckObject(L, 1, typeof(UnityEngine.AnimationCurve));
         UnityEngine.AnimationCurve arg1 = (UnityEngine.AnimationCurve)ToLua.CheckObject(L, 2, typeof(UnityEngine.AnimationCurve));
         LeanAudioOptions           arg2 = (LeanAudioOptions)ToLua.CheckObject(L, 3, typeof(LeanAudioOptions));
         UnityEngine.AudioClip      o    = LeanAudio.createAudio(arg0, arg1, arg2);
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemplo n.º 34
0
	private static AudioClip createAudioFromWave( float[] wave, LeanAudioOptions options ){
		float time = wave[ wave.Length - 2 ];
		float[] audioArr = new float[ (int)(options.frequencyRate*time) ];

		int waveIter = 0;
		float subWaveDiff = wave[waveIter];
		float subWaveTimeLast = 0f;
		float subWaveTime = wave[waveIter];
		float waveHeight = wave[waveIter+1];
		for(int i = 0; i < audioArr.Length; i++){
			float passedTime = (float)i / (float)options.frequencyRate;
			if(passedTime > wave[waveIter] ){
				subWaveTimeLast = wave[waveIter];
				waveIter += 2;
				subWaveDiff = wave[waveIter] - wave[waveIter-2];
				waveHeight = wave[waveIter+1];
				// Debug.Log("passed wave i:"+i);
			}
			subWaveTime = passedTime - subWaveTimeLast;
			float ratioElapsed = subWaveTime / subWaveDiff;

			float value = Mathf.Sin( ratioElapsed * Mathf.PI );
			//if(i<25)
			//	Debug.Log("passedTime:"+passedTime+" value:"+value+" ratioElapsed:"+ratioElapsed+" subWaveTime:"+subWaveTime+" subWaveDiff:"+subWaveDiff);
			
			value *= waveHeight;

			audioArr[i] = value;
			// Debug.Log("pt:"+pt+" i:"+i+" val:"+audioArr[i]+" len:"+audioArr.Length);
		}

		int lengthSamples = audioArr.Length;
		#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2 && !UNITY_4_3 && !UNITY_4_5 && !UNITY_4_6
		AudioClip audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, false);
		#else
		bool is3dSound = false;
		AudioClip audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, is3dSound, false);
		#endif
		audioClip.SetData(audioArr, 0);

		return audioClip;
	}
Exemplo n.º 35
0
	private static float[] createAudioWave( AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options ){
		float time = volume[ volume.length - 1 ].time;
		List<float> list = new List<float>();
		generatedWaveDistances = new List<float>();
		// float[] vibratoValues = new float[ vibrato.Length ];
		float passed = 0f;
		for(int i = 0; i < PROCESSING_ITERATIONS_MAX; i++){
			float f = frequency.Evaluate(passed);
			if(f<MIN_FREQEUNCY_PERIOD)
				f = MIN_FREQEUNCY_PERIOD;
			float height = volume.Evaluate(passed + 0.5f*f);
			if(options.vibrato!=null){
				for(int j=0; j<options.vibrato.Length; j++){
					float peakMulti = Mathf.Abs( Mathf.Sin( 1.5708f + passed * (1f/options.vibrato[j][0]) * Mathf.PI ) );
					float diff = (1f-options.vibrato[j][1]);
					peakMulti = options.vibrato[j][1] + diff*peakMulti;
					height *= peakMulti;
				}	
			}
			// Debug.Log("i:"+i+" f:"+f+" passed:"+passed+" height:"+height+" time:"+time);
			if(passed + 0.5f*f>=time)
				break;

			generatedWaveDistances.Add( f );
			passed += f;

			list.Add( passed );
			list.Add( i%2==0 ? -height : height );
			if(i>=PROCESSING_ITERATIONS_MAX-1){
				Debug.LogError("LeanAudio has reached it's processing cap. To avoid this error increase the number of iterations ex: LeanAudio.PROCESSING_ITERATIONS_MAX = "+(PROCESSING_ITERATIONS_MAX*2));
			}
		}

		float[] wave = new float[ list.Count ];
		for(int i = 0; i < wave.Length; i++){
			wave[i] = list[i];
		}
		return wave;
	}
Exemplo n.º 36
0
    private static float[] createAudioWave( AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options )
    {
        float time = volume[ volume.length - 1 ].time;
        List<float> list = new List<float>();
        // float[] vibratoValues = new float[ vibrato.Length ];
        float passed = 0f;
        for(int i = 0; i < 1000; i++){
            float f = frequency.Evaluate(passed);
            if(f<MIN_FREQEUNCY_PERIOD)
                f = MIN_FREQEUNCY_PERIOD;
            float height = volume.Evaluate(passed + 0.5f*f);
            if(options.vibrato!=null){
                for(int j=0; j<options.vibrato.Length; j++){
                    float peakMulti = Mathf.Abs( Mathf.Sin( 1.5708f + passed * (1f/options.vibrato[j][0]) * Mathf.PI ) );
                    float diff = (1f-options.vibrato[j][1]);
                    peakMulti = options.vibrato[j][1] + diff*peakMulti;
                    height *= peakMulti;
                }
            }
            // Debug.Log("i:"+i+" f:"+f+" passed:"+passed+" height:"+height+" time:"+time);
            if(passed + 0.5f*f>=time)
                break;

            passed += f;

            list.Add( passed );
            list.Add( i%2==0 ? -height : height );
        }

        float[] wave = new float[ list.Count ];
        for(int i = 0; i < wave.Length; i++){
            wave[i] = list[i];
        }
        return wave;
    }
Exemplo n.º 37
0
    private static AudioClip createAudioFromWave( int waveLength, LeanAudioOptions options )
    {
        float time = longList[ waveLength - 2 ];
        float[] audioArr = new float[ (int)(options.frequencyRate*time) ];

        int waveIter = 0;
        float subWaveDiff = longList[waveIter];
        float subWaveTimeLast = 0f;
        float subWaveTime = longList[waveIter];
        float waveHeight = longList[waveIter+1];
        for(int i = 0; i < audioArr.Length; i++){
            float passedTime = (float)i / (float)options.frequencyRate;
            if(passedTime > longList[waveIter] ){
                subWaveTimeLast = longList[waveIter];
                waveIter += 2;
                subWaveDiff = longList[waveIter] - longList[waveIter-2];
                waveHeight = longList[waveIter+1];
                // Debug.Log("passed wave i:"+i);
            }
            subWaveTime = passedTime - subWaveTimeLast;
            float ratioElapsed = subWaveTime / subWaveDiff;

            float value = Mathf.Sin( ratioElapsed * Mathf.PI );

            if(options.waveStyle==LeanAudioOptions.LeanAudioWaveStyle.Square){
                if(value>0f)
                    value = 1f;
                if(value<0f)
                    value = -1f;
            }else if(options.waveStyle==LeanAudioOptions.LeanAudioWaveStyle.Sawtooth){
                float sign = value > 0f ? 1f : -1f;
                if(ratioElapsed<0.5f){
                    value = (ratioElapsed*2f)*sign;
                }else{ // 0.5f - 1f
                    value = (1f - ratioElapsed)*2f*sign;
                }
            }else if(options.waveStyle==LeanAudioOptions.LeanAudioWaveStyle.Noise){
                float peakMulti = (1f-options.waveNoiseInfluence) + Mathf.PerlinNoise(0f, passedTime * options.waveNoiseScale ) * options.waveNoiseInfluence;

                /*if(i<25){
                    Debug.Log("passedTime:"+passedTime+" peakMulti:"+peakMulti+" infl:"+options.waveNoiseInfluence);
                }*/

                value *= peakMulti;
            }

            //if(i<25)
            //	Debug.Log("passedTime:"+passedTime+" value:"+value+" ratioElapsed:"+ratioElapsed+" subWaveTime:"+subWaveTime+" subWaveDiff:"+subWaveDiff);

            value *= waveHeight;

            if(options.modulation!=null){
                for(int k=0; k<options.modulation.Length; k++){
                    float peakMulti = Mathf.Abs( Mathf.Sin( 1.5708f + passedTime * (1f/options.modulation[k][0]) * Mathf.PI ) );
                    float diff = (1f-options.modulation[k][1]);
                    peakMulti = options.modulation[k][1] + diff*peakMulti;
                    // if(k<10){
                        // Debug.Log("k:"+k+" peakMulti:"+peakMulti+" value:"+value+" after:"+(value*peakMulti));
                    // }
                    value *= peakMulti;
                }
            }

            audioArr[i] = value;
            // Debug.Log("pt:"+pt+" i:"+i+" val:"+audioArr[i]+" len:"+audioArr.Length);
        }

        int lengthSamples = audioArr.Length;

        #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
        bool is3dSound = false;
        AudioClip audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, is3dSound, false);
        #else
        AudioClip audioClip = null;
        if(options.useSetData){
            audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, false, null, OnAudioSetPosition);
            audioClip.SetData(audioArr, 0);
        }else{
            options.stream = new LeanAudioStream(audioArr);
            // Debug.Log("len:"+audioArr.Length+" lengthSamples:"+lengthSamples+" freqRate:"+options.frequencyRate);
            audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, false, options.stream.OnAudioRead, options.stream.OnAudioSetPosition);
            options.stream.audioClip = audioClip;
        }

        #endif

        return audioClip;
    }
Exemplo n.º 38
0
	private static AudioClip createAudioFromWave( int waveLength, LeanAudioOptions options ){
		float time = longList[ waveLength - 2 ];
		float[] audioArr = new float[ (int)(options.frequencyRate*time) ];

		int waveIter = 0;
		float subWaveDiff = longList[waveIter];
		float subWaveTimeLast = 0f;
		float subWaveTime = longList[waveIter];
		float waveHeight = longList[waveIter+1];
		for(int i = 0; i < audioArr.Length; i++){
			float passedTime = (float)i / (float)options.frequencyRate;
			if(passedTime > longList[waveIter] ){
				subWaveTimeLast = longList[waveIter];
				waveIter += 2;
				subWaveDiff = longList[waveIter] - longList[waveIter-2];
				waveHeight = longList[waveIter+1];
				// Debug.Log("passed wave i:"+i);
			}
			subWaveTime = passedTime - subWaveTimeLast;
			float ratioElapsed = subWaveTime / subWaveDiff;

			float value = Mathf.Sin( ratioElapsed * Mathf.PI );
			//if(i<25)
			//	Debug.Log("passedTime:"+passedTime+" value:"+value+" ratioElapsed:"+ratioElapsed+" subWaveTime:"+subWaveTime+" subWaveDiff:"+subWaveDiff);
			
			value *= waveHeight;

			audioArr[i] = value;
			// Debug.Log("pt:"+pt+" i:"+i+" val:"+audioArr[i]+" len:"+audioArr.Length);
		}

		
		int lengthSamples = audioArr.Length;
		
		#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
		bool is3dSound = false;
		AudioClip audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, is3dSound, false);
		#else
		AudioClip audioClip = null;
		if(options.useSetData){
			audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, false, null, OnAudioSetPosition);
			audioClip.SetData(audioArr, 0);
		}else{
			options.stream = new LeanAudioStream(audioArr);
			Debug.Log("len:"+audioArr.Length+" lengthSamples:"+lengthSamples+" freqRate:"+options.frequencyRate);
			audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, options.frequencyRate, false, options.stream.OnAudioRead, options.stream.OnAudioSetPosition);
			options.stream.audioClip = audioClip;
		}
		
		#endif

		return audioClip;
	}