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.
You can do this on individual AudioSources using OnAudioFilterRead() but for the AudioListener output you need to use AudioListener.GetOutputData as per here:
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?
using UnityEngine;
using System.Collections;
public class AudioFadeOut : MonoBehaviour
{
public static IEnumerator FadeOut(AudioSource audioSource, float FadeTime)
{
float startVolume = audioSource.volume;
while (audioSource.volume > 0)
{
audioSource.volume -= startVolume * Time.deltaTime / FadeTime;
yield return null;
}
audioSource.Stop();
audioSource.volume = startVolume;
}
}
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?
private AudioSource[] sonido;
void OnTouchDown()
{
if (instrumento == "Piano")
{
FindObjectOfType<PianoAudioManager>().Play("PianoGmaj1G");
}
void OnTouchUp()
{
/*sonido = FindObjectsOfType(typeof(AudioSource)) as AudioSource[];
foreach (AudioSource audioS in sonido)
{
StartCoroutine(AudioFadeOut.FadeOut(audioS, 0.02f));
//audioS.Stop();
}*/
If someone could help me, I would be very grateful.
Thank you