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
2
Question by PsychoHead · May 14, 2015 at 01:19 PM · c#audioruntime

AudioClip.Create()

The Forums didn't let me post this question, they got automatically classified as spam. Forum: http://forum.unity3d.com/threads/audioclip-setdata-crackling.325833/

Hey Forum(Answers) I'm on a journey to efficiently create an Audio Source out of multiple other sources. The source should copy what other sources are playing right now. I want to use this to simulate simple sound propagation.

So far I've tried OnAudioFilterRead(), AudioClip.Create() streaming with the PCMReaderCallback and now AudioClip.Create() without streaming enabled.

OnAudioFilterRead() worked quite well, but got output as a 2D sound, without any panning or volume falloff, so that's not what I'm looking for.

AudioClip.Create() with streaming = true seemed nice at first, but I didn't get it to work. The Callbacks seem very unreliable and are oddly timed. Surely there is a way, but I failed using it. Any tips?

AudioClip.Create() with streaming = false works... almost. I call AudioSource.GetData() and .SetData() every few frames and save the result in a buffer that is long enough for the interval. The problem is, that I have small crackles in the sound whenever I call those two functions. Any ideas how to avoid those?

What's the proper way to tackle this?

stream = false version:

   public AudioSource OriginalSource;
 
   private float[] data;
   private AudioSource src;
   private AudioClip clp;
   private int refreshInterval
   private float Timer;
 
 void Update()
     {
         Timer += Time.deltaTime;
         //Timer does not need to be accurate, because data[] is longer than
         //the refreshInterval
         if (Timer > refreshInterval)
         {
             GetSampleData();
             Timer = 0;
         }
     }
 
     void GetSampleData()
     {
         OriginalSource.clip.GetData(data, OriginalSource.timeSamples);
         clp.SetData(data, 0);
         src.Play();
     }

EDIT: Got the streamed version to work, too... but again with minor crackles.

     void PCMRead(float[] tempData)
     {
         int count = 0;
         while (count < tempData.Length)
         {
             tempData[count] = data[count+position];
             count++;
         }
         position += count;
     }
 
     void Update()
     {
         GetSampleData();
         position = 0;
     }
 
     void GetSampleData()
     {   //adding 15000 to compensate the offset, magical number for now.
         OriginalSource.clip.GetData(data, OriginalSource.timeSamples + 15000);
     }
Comment
Add comment · Show 1
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 PsychoHead · May 15, 2015 at 01:04 PM 0
Share

The problem with the strea$$anonymous$$g version seems to be, that the function (PC$$anonymous$$Read) simply takes to long to process.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Sprite101 · Nov 16, 2015 at 10:11 PM

So I've been looking into this myself, and I've found no real good solution. AudioClip.Create asks you if you want the clip to be streaming, but if you read the clip's loadType, it reads as DecompressOnLoad instead of Streaming. My assumption is all the gaps in the audio on playback are due to the AudioSource trying to decompress the data...

Unfortunately, loadType is read only, and you can't access the PCMReader callback without using Create() I have yet to find a solution.

Comment
Add comment · 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

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

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Audio Trigger 3 Answers

Every few seconds, play an audio clip 3 Answers

Illuminating a 3D object's edges OnMouseOver (script in c#)? 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