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
1
Question by karafs · Aug 12, 2013 at 02:37 PM · audio clipping

Combine 2 audio clip in one

How can i combine half of 2 audio clip in 1 audio clip with script?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by llq664301573 · Jul 13, 2015 at 01:39 PM

 public static AudioClip Combine(params AudioClip[] clips)
 {
     if (clips == null || clips.Length == 0)
         return null;
 
     int length = 0;
     for (int i = 0; i < clips.Length; i++)
     {
         if (clips[i] == null)
             continue;
 
         length += clips[i].samples * clips[i].channels;
     }
 
     float[] data = new float[length];
     length = 0;
     for (int i = 0; i < clips.Length; i++)
     {
         if (clips[i] == null)
             continue;
 
         float[] buffer = new float[clips[i].samples * clips[i].channels];
         clips[i].GetData(buffer, 0);
         //System.Buffer.BlockCopy(buffer, 0, data, length, buffer.Length);
         buffer.CopyTo(data, length);
         length += buffer.Length;
     }
 
     if (length == 0)
         return null;
 
     AudioClip result = AudioClip.Create("Combine", length / 2, 2, 44100, false, false);
     result.SetData(data, 0);
 
     return result;
 }
Comment
Add comment · Show 4 · 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 Burkard · Aug 14, 2015 at 11:54 PM 0
Share

Superb! Thanks, llq664301573!

avatar image jmgek · Aug 14, 2015 at 11:58 PM 0
Share

Why is the params needed?

avatar image Burkard · Aug 16, 2015 at 04:55 PM 0
Share

@jmgek, I don't think it is NEEDED, but it's used in case you have a variable number of parameters... in this case, it could be ommited... $$anonymous$$ore info here: params - C# ref - $$anonymous$$icrosoft

avatar image freedom667 · Jan 23, 2021 at 02:43 PM 0
Share

How will I use it for Combine?

avatar image
0

Answer by Electricpuppets · Oct 25, 2021 at 06:36 PM

 //AudioClip result = AudioClip.Create("Combine", length / 2, 2, 44100, false, false);
 AudioClip result = AudioClip.Create("Combine", length / 2, 2, 44100, false);

Drop second false to get around the Obsolete flag., //AudioClip result = AudioClip.Create("Combine", length / 2, 2, 44100, false, false); AudioClip result = AudioClip.Create("Combine", length / 2, 2, 44100, false);

Drop the second false to get around the Obsolete flag.

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

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

Audio Clip Getting Cut Short 1 Answer

On Collision sound clip change 1 Answer

Play audio clip on more than one object from another gameobject 2 Answers

Audio sample 1 Answer

how to import audio into Unity3D wiht coding 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