Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 LuisCRSousa · Feb 18, 2016 at 04:30 PM · audiotimeline

Get Audio TimeLine

Hello!

I am trying to get the audio timeline of a music playing on a game.

In Editor, when i select the audio, it shows on the inspector the timeline. There are anyway to get this as an image for example, with code?

alt text

sem-nome.png (115.2 kB)
Comment
Add comment · Show 2
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 Nerevar · Feb 18, 2016 at 04:49 PM 0
Share

IT should be something like : AudioSource.timeSamples / AudioSource.clip.samples

Then to implement an UI looking like the inspector there are bit more lines of code involved.

avatar image LuisCRSousa Nerevar · Feb 18, 2016 at 06:09 PM 0
Share

Thanks, but that is not what i want.

I just discover the answer. I posted below.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by LuisCRSousa · Feb 18, 2016 at 06:06 PM

I did it.

Sharing my raw code. A function that receives an audioclip and return a sprite with the timeline.

I apply also an low pass filter to better results.

One sample returned image:

alt text

     public static Sprite getMusicTimeline(AudioClip audioClip)
     {
         float[] dataClip;
         Texture2D texture;
         int[] dataFinal;
 
         dataClip = new float[audioClip.samples];
         audioClip.GetData(dataClip, 0);
 
         texture = new Texture2D(500, 400, TextureFormat.ARGB32, false);
 
         dataFinal = new int[texture.width];
 
         for (int x = 0; x < texture.width; x++)
         {
             int indexData = (int)Functions.mapTruncate(x, 0, texture.width, 0, dataClip.Length - 1);
 
             int valueOnImage = (int)(Functions.mapTruncate(dataClip[indexData], 0, 1f, 0, texture.height / 2 - 1));
 
             dataFinal[x] = valueOnImage;
         }
 
         for (int i = 4; i < dataFinal.Length - 4; ++i)
             dataFinal[i] = (dataFinal[i - 4] + dataFinal[i - 3] + dataFinal[i - 2] + dataFinal[i - 1] + dataFinal[i] + dataFinal[i + 1] + dataFinal[i + 2] + dataFinal[i + 3] + +dataFinal[i + 4]) / 5;
 
         for (int x = 0; x < texture.width; x++)
         {
 
             for (int y = texture.height / 2 - 1; y < dataFinal[x] + texture.height / 2 - 1; y++)
                 texture.SetPixel(x, y, Color.white);
             for (int y = dataFinal[x] + texture.height / 2 - 1; y < texture.height; y++)
                 texture.SetPixel(x, y, Color.clear);
 
             for (int y = texture.height / 2 - 1; y > texture.height / 2 - 1 - dataFinal[x]; y--)
                 texture.SetPixel(x, y, Color.white);
             for (int y = texture.height / 2 - 1 - dataFinal[x]; y >= 0; y--)
                 texture.SetPixel(x, y, Color.clear);
         }
 
         texture.Apply();
 
         Rect rec = new Rect(0, 0, texture.width, texture.height);
 
         return Sprite.Create(texture, rec, new Vector2(0.5f, 0.5f), 100);
     }



sem-nome.png (9.6 kB)
Comment
Add comment · Show 2 · Share
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 Jay2645 · Mar 08, 2016 at 07:31 AM 0
Share

What does Functions.mapTruncate do?

avatar image tanoshimi Jay2645 · Mar 08, 2016 at 07:43 AM 0
Share

At a guess, it remaps values from one arbitrary range to another, while clamping the values. Something like:

  public static class Functions {
  
 public static float mapTruncate (this float value, float from1, float to1, float from2, float to2) {
     return $$anonymous$$athf.Clamp((value - from1) / (to1 - from1) * (to2 - from2) + from2, from2, to2);
 }
    
 }

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

38 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 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

Animate Audio Source Pitch/Speed in Timeline 0 Answers

Control game elements with Timeline 0 Answers

Timeline and Audiosource not synced? 0 Answers

Audio desync in Timeline while in play mode 1 Answer

sound (audio) makes noise only in timeline 2 Answers


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