Search Unity

Audio Record audio from AudioListener

Discussion in 'Audio & Video' started by JossVicore, Apr 30, 2019.

  1. JossVicore

    JossVicore

    Joined:
    Feb 28, 2019
    Posts:
    3
    Hello,
    I am quite new programming in Unity C # and I am trying to make a music creation app for android in which there are several buttons with assigned sounds. What I'm trying to do is, in the scene of those buttons, record everything the AudioListener is listening to, and once a track is recorded, add it to new recordings.

    But as much as I look for it, I can not find how to record those sounds.

    Would there be any way to record everything that these different buttons sounds and then put it back to record again?

    I would be very grateful if someone could give me at least a hint of what I could use in the script to be able to do this function.

    Thank you.
     
  2. Docaroo

    Docaroo

    Joined:
    Nov 7, 2017
    Posts:
    82
  3. JossVicore

    JossVicore

    Joined:
    Feb 28, 2019
    Posts:
    3
    Hello, thanks for the answer.
    Right now I have managed to record the AudioListener, but I have a script with a fade out that makes all the AudioSources put at volume 0 and I'm not looking for that. Could someone tell me what's wrong?


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class AudioFadeOut : MonoBehaviour
    5. {
    6.  
    7.     public static IEnumerator FadeOut(AudioSource audioSource, float FadeTime)
    8.     {
    9.         float startVolume = audioSource.volume;
    10.  
    11.         while (audioSource.volume > 0)
    12.         {
    13.             audioSource.volume -= startVolume * Time.deltaTime / FadeTime;
    14.  
    15.             yield return null;
    16.         }
    17.  
    18.         audioSource.Stop();
    19.         audioSource.volume = startVolume;
    20.     }
    21.  
    22. }
    EDIT.

    I found the problem. How can I make OnTouchUp have the exact variable of the AudioSource in OnTouchDown to be able to do the fade out?

    Code (CSharp):
    1.     private AudioSource[] sonido;
    2.  
    3.    void OnTouchDown()
    4.     {
    5.         if (instrumento == "Piano")
    6.         {
    7.             FindObjectOfType<PianoAudioManager>().Play("PianoGmaj1G");    
    8.         }
    9.  
    10.    void OnTouchUp()
    11.     {
    12.         /*sonido = FindObjectsOfType(typeof(AudioSource)) as AudioSource[];
    13.         foreach (AudioSource audioS in sonido)
    14.         {
    15.  
    16.             StartCoroutine(AudioFadeOut.FadeOut(audioS, 0.02f));
    17.  
    18.             //audioS.Stop();
    19.         }*/

    If someone could help me, I would be very grateful.
    Thank you
     
    Last edited: May 16, 2019