Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Tomikland · Mar 21, 2018 at 04:01 PM · audioaudiosourcemusic

Specifying OnAudioFilterRead()'s audiosource

I'm working on a music sequencer bundled with a synthesizer, using OnAudioFilterRead to generate notes. Currently i have a gameobject for every note with an audiosource attached, as well as the Note script which implements OnAudioFilterRead.

I'm afraid that this might cause problems such as too many gameobjects or audiosources with longer arrangements, therefore i would like to move away from this solution, preferably Note being a pure C# data class. (in that caseI'm not sure if i can implement OnAudioFilterRead without deriving Monobehaviour)

However, removing the audiosource from the Note's gameobject causes OnAudioFilterRead to not generate any sound at all. I would like only a single, master audiosource with all Note scripts adding their values to its data stream. So, how can I specify what audiosource's data stream OnAudioFilterRead modifies?

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

Answer by Bunny83 · Mar 21, 2018 at 04:27 PM

If you have multiple scripts on the same gameobject each with a OnAudioFilterRead method they will be called in turn. However i guess you do not add your data but you replace it, right? In that case only the last scripts action will take effect as it will overwrite everything any other "filter" has done to the stream.


Though i wouldn't recommend to implement multiple OnAudioFilterRead methods for this. You want to have a single mixer script with the OnAudioFilterRead method which does simply mix your different sources together. Keep in mind that audio mixing (especially with many channels) is quite tricky. Accoustically you just need to add up the samples from all your sources. However depending on the amplitude of each source you can easily clip. So you either need to have enough Headroom or use some dynamic compression. Though compression usually always distorts the signals more or less heavy depending on the technique.

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 Bunny83 · Mar 21, 2018 at 05:37 PM 0
Share

You may want to have a look at this question for some mixing advice

avatar image Tomikland · Mar 21, 2018 at 06:52 PM 0
Share

I do add the data, i have tested the many notes per gameobject idea before and it does work but i don't really feel like that was an improvement as it made it a lot harder to organize the notes.

The mixer idea sounds great actually, since it sounds like i could iterate through every note in the single call of OnAudioFilterRead and run pretty much the same code as before with very few changes. After recently implementing overtones i immediately realized that more overtones meant overall louder sound so i knew i'd have to tackle the mixing subject at some point. I'll look into it.

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

97 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 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 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 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 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

GetSpectrumData over entire file 1 Answer

Glitched Music 0 Answers

PlayScheduled or PlayDelayed 0 Answers

Stereo Mix as Input? 1 Answer

Can not play a disabled audio source 2 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