Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TheRobWatling · Sep 11, 2013 at 03:34 PM · audioaudioclipaudio clipping

Audio, GetData not returning Data.

Hi there, So Me and my colleague have been trying to work on some audio code throughout the day trying various work around(s) but to no avail.

We are using the audio.clip = Microphone.Start("", true, 1, 44100); and playing a audio clip through a phone plugged into the Microphone port.

We then check with GetData against the duplicate clips we have in our Unity Project. The problem is GetData never returns anything but 0's and some Epsilon Values from time to time.

Due to this we can't do a comparison of the audio.

does anyone know a solution to this? Thanks

 using UnityEngine;
 using System.Collections;
 
 public class ToneTest : MonoBehaviour {
 
     float[] samples;
     public AudioClip Sine;
     public AudioClip Square;
     public AudioClip Saw;
 
     float[] SineSamples;
     float[] SquareSamples;
     float[] SawSamples;
 
 
     // Use this for initialization
     void Start()
     {
         audio.clip = Microphone.Start("", true, 1, 44100);
 
         samples = new float[100];
         SineSamples = new float[100];
         SquareSamples = new float[100];
         SawSamples = new float[100];
     }
 
     // Update is called once per frame
     void Update()
     {
         if (audio.clip != null)
         {
 
             audio.clip.GetData(samples, 0);
             Sine.GetData(SineSamples, 0);
             Square.GetData(SquareSamples, 0);
             Saw.GetData(SawSamples, 0);
Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tarlius · Sep 11, 2013 at 03:36 PM 0
Share

Watch out for double posts ;)

avatar image Exalia · Sep 11, 2013 at 03:41 PM 0
Share

I used this piece of code to check if GetData was working for me and it was

     public AudioClip $$anonymous$$usic;
 
     void Start() 
     {
         audio.clip = $$anonymous$$usic;
         float[] samples = new float[1000];
         audio.clip.GetData(samples, 0);
         int i = 0;
         while (i < samples.Length) 
         {
             print(samples[i]);
             ++i;
         }
     }

So to me it seems like GetData isn't the problem here but it's how you're getting your audio from your microphone.

Unless I'm misunderstanding something

avatar image Jamora · Sep 11, 2013 at 04:50 PM 0
Share

The AudioClip is declared when you call $$anonymous$$icrophone.Start, but you need to stop recording before the AudioClip's data is set. That is, you will need to use $$anonymous$$icrophone.End(""); before you can play back or access the data of the AudioClip.

avatar image TheRobWatling Jamora · Sep 12, 2013 at 08:08 AM 0
Share

Hi, Thanks for the help. I added a timer to count an amount into the tone and then to end the $$anonymous$$icrophone after around 5 seconds. Unfortunately the SineSample is still empty.

Thanks Rob

avatar image Exalia Jamora · Sep 12, 2013 at 08:19 AM 0
Share

Can you post the code where you call and the method you use for the timer?

Thanks

avatar image TheRobWatling Jamora · Sep 12, 2013 at 08:21 AM 0
Share
     void Update()
     {
         if (audio.clip != null)
         {
             if (!timerEnd)
             {
                 timer += Time.deltaTime;
                 //print(timer);
 
                 if (timer > 5f)
                 {
                     $$anonymous$$icrophone.End("");
                     timerEnd = true;
                 }
             }
             else
 {
 // Rest of the code for the checking is here.
 }
 
avatar image TheRobWatling · Sep 12, 2013 at 08:37 AM 0
Share

We also added this as a test. it still just returned 0's

 using UnityEngine; 
 using System.Collections;
 
 public class TestGetData : $$anonymous$$onoBehaviour {
 
 float[] samples;
  
 // Use this for initialization
 void Start () 
 {
     samples = new float[100];
 }
  
 // Update is called once per frame
 void Update () 
 {
     audio.clip.GetData(samples, 0);
 }

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Truncate audio runtime 0 Answers

play audio from frequency and amplitude file 0 Answers

Is there any way for implementing auto rap type functionality in Unity3d? 1 Answer

Is there a way to create a random Audiosource loop? 2 Answers

Sound creation using WAV. files 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges