Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mechanical sound support. #453

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

Mr-Jay-Gatsby
Copy link

This is the initial commit for the mechanical sounds as discussed here:
#449.

Main items added are:
Sound Asset(scriptable object)
Sound Inspector
Mechanical Sounds Data
Mechanical Sounds Component
Mechanical Sounds Inspector
ISoundEmitter

@Mr-Jay-Gatsby
Copy link
Author

When working in the specific table project, I did add an AudioMixer asset called SoundMixer to try and alter the speed of sounds. I exposed the pitch shifter parameter and called the mixer in the sound inspector script but the setfloat method wasnt working (getfloat did work). I dont know another way to change the speed unless there are some external plugins to use.

Copy link
Owner

@freezy freezy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff, thanks a lot!

You'll see in my comments that most of the code in MechSoundsComponent should be moved to the individual components. I'd suggest to just do it for the flipper, then I'll help doing the rest of the items.

There are some minor code style incoherences that I'll comment on as this PR matures.

All in all, awesome work. Looking forward to getting this in. :)

Mr-Jay-Gatsby and others added 5 commits February 15, 2023 16:28
…component. Have mechsoundcomponent inherit from monobehaviour directly. Update mechsoundinspector to inherit from unity editor directly and by adding a propertydrawer to handle mechsound appearance. Initialize soundlist in mechsoundscomponent.
…he MechSound Drawer. Handle when no component attached to the gameobject implements it.
…om methods, refactor handling of audio clip playing using an established gameobject's audiosource, and moved call to update event into OnEnable method. Also deleted mechsounddata and some other minor cleanup.
@freezy freezy changed the title sounds: Initial commit. Add mechanical sound support. Feb 19, 2023
@freezy
Copy link
Owner

freezy commented Mar 1, 2023

I've pushed a few commits. Changes:

  • Use a static audio source for the editor instead of temp creating one on play.
  • Let Unity handle looping, since AudioSource supports it
  • Dropped "Speed" for now, since it needs a mixer hooked to an effect
  • Ditched the volume emitter, since it's actually not needed (volume is defined at runtime when the event occurs).
  • Move classes into separate files and all to a common folder
  • Renamed variables and members to existing conventions
  • Simplified MechSoundDrawer and MechSoundInspector

Still TODO:

  • Propagate and velocity of the collision
  • Do the other game items
  • Add proper icons
  • Figure out how the mixer works
  • Deal with spatial vs 2D audio
  • Implement the fade feature
  • Documentation

@freezy freezy requested a review from jsm174 March 1, 2023 23:40
@linojon
Copy link

linojon commented Jan 6, 2024

Hello. I've resumed work on this feature. Work in progress resides in my fork branch https://github.com/linojon/VisualPinball.Engine/tree/feature/sounds . I am building it into the Volley table (https://github.com/jsm174/vpe-volley/tree/sounds ). using that as a baseline project and trying get our sounds like the VPX version (https://vpuniverse.com/files/file/8185-volley-gottlieb-1976/ ).

Changes so far:

  • Implemented mechanical sound Stop action (e.g. for looping sounds)
  • Fixed support for multiple concurrent sounds from same game object (requires multiple Audio Sources on the object).
  • Optionally give an Audio Mixer, else it searches for one in the nearest parent up the scene hierarchy.
  • When adding a sound clip to the mech sounds list, Unity ignores default values so i added an Add button that initializes Volume to 1
  • Verified sound emitter support in Flippers, Bumpers, Kickers, Plunger
  • Added sound emitter support to Targets (Hit and Drop), Trigger Switches

To test and verify, i am using the vpe-volley project,

  • Added the Mechanical Sounds component to bumpers (3X), flippers (2X), targets (yellox 5X, blue 5X, green 5X), kickers (drain, ballRelease), plunger, triggers (9X)
  • Added corresponding Sound Assets
  • Note, i'm only adding the sounds actually used in VPX script which is a subset of the sounds included in (and imported from) that table.

Sounds todo:

  • Drop target bank reset
  • Chimes
  • Mechanical score wheel
  • Bonus score
  • Collect points
  • New game
  • High score initials

Plus object collision and ball rolling sounds. I'll make a separate github issue #463

@linojon
Copy link

linojon commented Jan 8, 2024

i've committed my current work in progress. I have questions, could use some help as i'm still just getting familiar with how VPE works.

  • as mentioned, we now have sounds for flippers, bumpers, kickers, plunger, hit targets, drop targets, switches.

  • Drop target reset: there's 2 ways to do this. For each target, play a reset sound. I have this implemented. See DropTargetComponent.cs and DropTargetApi.cs. So that's 15 separate simultaneous sounds (i dont know if that matters but just saying).

Or, we could play one sound for the whole target bank reset (this is what the VPX game does). I tried this and it works but the code is messy, as I needed to add ItemApi to DropTargetBankApi.cs, which (in order to reference local variable MainComponent) requires i derive DropTargetBank from something like MainRenderableComponent, which in turn required i add a bunch of unused methods. See DropTargetBankComponent.cs. If this is a bad idea, i'll clean up the code.

  • Score Motor / Reel sounds: as with DropTargetBank, does not recognized MainCompponent I'm guessing the sound would be added to ScoreMotorComponent. Currently this is commented out, see ScoreMotorComponet.cs, ScoreMotorApi.cs. Note that the motor component is on the Volley game object, which seems pretty high up in the hierarchy to add mechanical sounds.

  • Chimes: VPX script triggers chimes when the score is incremented (see sub AddScore1, sub AddScore2). Whats the best place to add chimes in VPE? I expect we add it to the specific score reel (10's, 100's, etc)? Currently, the ScoreReelComponent is a MonoBehaviour and doesnt have any interfaces.

  • Start Game: I tried trace what happens when you press "1" to start a new game, so i can play a new game sound (score motor reels and targets resetting). Maybe the reset sounds belongs in SwitchPlayer? or by the respective objects?

  • Also could use advise how to add sounds for ball rolling and collisions. Try to use ISoundEmitter for this too or something different?

@freezy
Copy link
Owner

freezy commented Jan 8, 2024

Awesome! Could you open a PR from your branch to feature/sounds? This branch is the rebased version of this PR, that would allow to properly review and at the same time keep @Mr-Jay-Gatsby's work. I'll then close this one here and we can continue discussing there.

About your questions:

  • Drop targets: TBH I'm not sure what's best. I could see both approaches work. They probably won't work if there's only one sample for each reset sound, but if there are multiple, it might work. I haven't looked at your code yet.
  • Score Motor: Yes, we'll need a score motor MainComponent for this. I think this might be a new use case where we have a non-renderable object that still needs to be positioned in the scene so the spatial sound works. So, there's probably some refactoring needed.
  • Chimes: I think chimes can be used for all kinds of things, not just scores. So that'd be something to be linked through the (visual) table script. So we'd need a way to create sound emitters on the playfield that we can reference in visual scripting. Probably the same as the last point.
  • Start Game: This should come from the score motor and target components, right? Independently whether a game started or in-game.
  • Ball rolling is out of scope for this one, since it's not linked to any components (well, the ball, but it's more complex than the rest). Collision sounds need the correct data from the physics engine. I'll look into that.

Apologies for not being 100% in the context yet. I'll need to re-read the code that has been written so far to be of more use. Many thanks already for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants