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 Sylafrs · Dec 19, 2013 at 06:02 PM · destroymemoryprofileraudioclipgarbage

How to properly destroy a script-created AudioClip ?

Hello everybody,

I'm currently trying to create a Speech recognition system.. and it work pretty well. The only problem I have is that my AudioClip won't be freed.

To create my AudioClip, I'm using the Microphone looping AudioClip. When I think the user has spoken (using the sample array), I create a new AudioClip and give him the part of the sample array when the user speaks.

Something like that :

     /// <summary>
     /// Takes a part within a sample array and put it within an AudioClip
     /// </summary>
     /// <param name="samples">The sample array</param>
     /// <param name="first">The first sample to take</param>
     /// <param name="last">The last sample to take</param>
     /// <param name="freq">The frequency of the AudioClip</param>
     /// <returns>the cutted AudioClip</returns>
     public static AudioClip TrimClip(
         float[] samples, int first, int last, int freq)
     {
         int nSamples = last - first;
         float[] newSamples = new float[nSamples];

         for (int i = first; i < last; i++)
         {
             newSamples[i - first] = samples[i];
         }

         AudioClip ac = AudioClip.Create(
             "ToRecognize", nSamples, 1, freq, false, false);

         ac.SetData(newSamples, 0);
         return ac;
     }

When I don't need the AudioClip, I just use this method :

     /// <summary>
     /// Frees an AudioClip
     /// </summary>
     /// <param name="ac">
     /// The AudioClip we want to remove from our memory
     /// </param>
     public static void FreeAudioClip(AudioClip ac)
     {
         AudioClip.DestroyImmediate(ac, false);
         // AudioClip.Destroy(ac);
         // Resources.UnloadAsset(ac);
         // GameObject.Destroy(ac);
     }

I'm sure I give those methods every AudioClip, I've already tested. No one among those for Destroy methods makes the Profiler drop the number of AudioClip.

So if I want to create a looot of AudioClips, my memory begins to hate me..

The only simillar I found was with Loaded assets, which is not my case, that's why I created this topic,

I thank you in advance and for reading :)

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

1 Reply

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

Answer by Sylafrs · Dec 19, 2013 at 06:32 PM

Ok, I've just found one of my issues : The Microphone clip wasn't released, but I was starting new clips..

So, I think this method works well

I'm sorry to have posted this one :/

Comment
Add comment · Show 1 · 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 Sylafrs · Dec 19, 2013 at 07:18 PM 0
Share

Now, I must use coroutine and Stream the samples.. because for now, if I let the recording audioclip exceed 10 seconds, it becomes laggy (15 FPS peaks)

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

18 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

Related Questions

When a animation is loaded to memory? 0 Answers

How to call(start play) Sound attached to a gameObject by destroing other gameObject? 1 Answer

iOS: Compressed audio not affecting memory? 2 Answers

iOS Vs New Memory Profiler 0 Answers

Attaching profiler to WindowsPlayer does nothing 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