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 renezuidhof · Feb 05, 2015 at 11:54 PM · audiosavepitch

Store AudioClip with pitch

I have an app where users can play around with the pitch of an AudioSource. The next thing i want is the users to save the AudioClip to load it later and continue with the sounds. Without the pitch this is not a problem and i can now save an AudioClip as a .wav file in storage (code below). What it does is just save the data of the AudioClip, so it does not take the pitch in consideration (there is some more code but i think this is the most important stuff).

How can i manipulate the data to make sure it is being stored together with pitch?

 //TODO:  static void ConvertAndWrite(FileStream fileStream, AudioClip clip, float pitch) { 
 static void ConvertAndWrite(FileStream fileStream, AudioClip clip) { 
         
         var samples = new float[clip.samples];
 
         clip.GetData(samples, 0);
         
         Int16[] intData = new Int16[samples.Length];
         //converting in 2 float[] steps to Int16[], //then Int16[] to Byte[]
         
         Byte[] bytesData = new Byte[samples.Length * 2];
         //bytesData array is twice the size of
         //dataSource array because a float converted in Int16 is 2 bytes.
         
         int rescaleFactor = 32767; //to convert float to Int16
         
         for (int i = 0; i<samples.Length; i++) {
             intData[i] = (short) (samples[i] * rescaleFactor);
             Byte[] byteArr = new Byte[2];
             byteArr = BitConverter.GetBytes(intData[i]);
             byteArr.CopyTo(bytesData, i * 2);
         }
         
         fileStream.Write(bytesData, 0, bytesData.Length);
     }
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
0
Best Answer

Answer by renezuidhof · Feb 08, 2015 at 01:43 AM

I think i have found the solution, for ppl getting this issue in the future.

The only thing you have to do is expand or shrink the data array you can get from an AudioClip (Interpolating in case of shrinking (pitch > 1), Extrapolating in case of expansion (Pitch < 1))

Google a bit for those kind of stuff and you should be able to figure it out :)

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
avatar image
0

Answer by screenname_taken · Feb 06, 2015 at 01:48 PM

Dunno on saving the audio stream that's playing, but how about making a class that holds a sound file name and a pitch float, and the user saving that instead of recording and saving a whole audio file? Unless the whole point is for the user to export any funny clips they made.

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 renezuidhof · Feb 06, 2015 at 04:04 PM 0
Share

Yea, i already do that :) but i also want ppl to save there audio to load later on. I've got this working by just storing the raw audio and storing a config file with the pitch.

But indeed, the next feature i want to add is to export it to other devices like pc's. So the audio itself needs to be changed.

avatar image screenname_taken · Feb 07, 2015 at 03:47 PM 0
Share

I guess listening to the system's wave isn't possible. I mean Windows' "what you hear" path.

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

Slowly fade audio's pitch on key press? 3 Answers

Change Pitch on Collision 1 Answer

car shifting smoothed. help! 0 Answers

Rigidbody crate collide sound. 0 Answers

How to determine the pitch from GetSpectrumData() to make a polyphonic tuner? 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