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 /
This question was closed Mar 16, 2015 at 07:14 PM by KnightRiderGuy for the following reason:

Duplicate Question

avatar image
1
Question by KnightRiderGuy · Mar 06, 2015 at 01:15 AM · audiorenderingui imagedatarender texture

Render Audio Waveform to UI Image

Is it possible to render an Audio waveform to a UI image in the same way that this script does? I tried making changes to this one to get it to work with a UI image but I am not having much luck.

UPDATE: I still have had no luck in searching for how to get this to work on either a UI image or UI Raw image, I suspect it is the Raw image that it needs to work on in much the same way as the webcam works with a Raw image.... but so far no luck with figuring out this waveform to display.

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 //[RequireComponent(typeof(AudioSource))]
 //[RequireComponent(typeof(GUITexture))]
 public class AudioWaveFormVisualizerXXX : MonoBehaviour
 {
     public RawImage rawimage;
     public AudioSource MusicPlayer;
     public int width = 500; // texture width 
     public int height = 100; // texture height 
     public Color backgroundColor = Color.black; 
     public Color waveformColor = Color.green; 
     public int size = 2048; // size of sound segment displayed in texture
     
     private Color[] blank; // blank image array 
     //private Texture2D texture;
     public Texture2D texture;
     private float[] samples; // audio samples array
     
     IEnumerator Start ()
     { 
         
         // create the samples array 
         samples = new float[size]; 
         
         // create the texture and assign to the guiTexture: 
         texture = new Texture2D (width, height);
         //rawimage = new RawImage (width, height);
         
         guiTexture.texture = texture;
         //RawImage = rawimage;
         
         // create a 'blank screen' image 
         blank = new Color[width * height]; 
         
         for (int i = 0; i < blank.Length; i++) { 
             blank [i] = backgroundColor; 
         } 
         
         // refresh the display each 100mS 
         while (true) {
             GetCurWave (); 
             yield return new WaitForSeconds (0.1f); 
         } 
     }
     
     void GetCurWave ()
     { 
         // clear the texture 
         texture.SetPixels (blank, 0);
         //RawImage.SetPixels (blank, 0);
         
         
         // get samples from channel 0 (left) 
         MusicPlayer.GetOutputData (samples, 0); 
         
         // draw the waveform 
         for (int i = 0; i < size; i++) { 
             texture.SetPixel ((int)(width * i / size), (int)(height * (samples [i] + 1f) / 2f), waveformColor);
             //RawImage.SetPixel ((int)(width * i / size), (int)(height * (samples [i] + 1f) / 2f), waveformColor);
             
         } // upload to the graphics card 
         
         texture.Apply ();
         //RawImage.Apply ();
     } 
 }
Comment
Add comment
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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Odd rendering issue: texture image is only displayed half 0 Answers

Render Texture strange noise error 1 Answer

RenderTexture on RawImage does not render anything 1 Answer

How to set the render target(s) for projector shaders? 1 Answer

Different Spectrum Data Displays 0 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