Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Playing a variable sound (% of sound clip per % of player interaction)

Discussion in 'General Discussion' started by Vanz, Apr 8, 2021.

  1. Vanz

    Vanz

    Joined:
    Nov 19, 2013
    Posts:
    203
    Is there a way to play a sound clip from say 0% to 100% based on an interaction. For example let's say you have a sound for a creaking door opening, if the door is open from 0 to 100% you play the full sound. But, let's say the player only opens the door 40% can you play 40% of the sound and then keep playing the rest of the sound if the player decides to open the door more?

    Thanks,

    V
     
  2. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    1,902
    Nikunj Raghuvanshi, the guy behind Project Acoustics did a interesting paper on this




    edit: wrong paper. He did another on sound synthesis for continues sounds like fabric tearing.
     
  3. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,178
    You can stop the audioclip if the door stops moving, store the sample index and keep playing from that index next time it moves again. You can also vary the sound, say fast versus slow by having two clips/audiosources that mimic both and blend based on opening speed or you could blend ithem on two channels or more in an AudioMixer.
     
    Ne0mega likes this.
  4. sxa

    sxa

    Joined:
    Aug 8, 2014
    Posts:
    545
    But that's only going to be a volume crossfade, surely. So you're effectively going to play two simultaneous sounds at different pitches, not one sound with a representative intermediate speed/pitch.

    Its possibly better, (within limits), to control the playback pitch/speed ( via Audiosource.pitch )

    (However, depending on the level of realism required, I'd also say that a friction-driven sound like a creaky door is only necessarily a continuous sound above a particular speed threshold. Most people will be familiar with the fact that sometimes the sound of a door moved slowly will break up into discrete 'stuttered' segments. So the best representation, if that kind of detail was needed, would possibly be some sort of granular-audio type playback, playing back overlapping segments of the audio sample. I believe FMOD can support that, for example.)
     
  5. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,178
    Sure..if you did not design the clip or looping properly. I really don't think the OP is looking to play with Fourier transforms for a frickin' door opening. The suggestion was to counter MOADigital bad advice he hand out like candy.
     
    Last edited: Apr 9, 2021
  6. sxa

    sxa

    Joined:
    Aug 8, 2014
    Posts:
    545
    Nobody mentioned fourier transforms; that's not how Audiosource.pitch works, or how a simplified granular method would work. Can we stick to what I actually discussed please, no strawmen.

    The problem with your advice on mixing a long and a short version is that as per your actual description, unless you do anything else, the sound is always going to be the same length as the long version unless its a 100% short/0% short mix.

    If you're suggesting doing something else beyond that description of mixing short and long samples, ie clip looping, then describing why, and how that would work, would be as important as saying to mix layers.

    And if you're suggesting layering designed looped versions rather than simple long/short versions, and the loops are designed with it in mind, then you would be implementing a crude granular system, so you're now basically agreeing with me.
     
  7. sxa

    sxa

    Joined:
    Aug 8, 2014
    Posts:
    545
    Should it turn out the OP, or any other person who passes by, is interested, Andy Farnell provides a useful model for pure synthesis of door creaks (and other 'slip-stick' frictions) as Chapter 42 of his book 'Designing Sound'.
    Its based on generating a series of impulses that excite a bank of filters/resonators tuned to model the door resonances, so no fourier transforms required for that either.
     
    Last edited: Apr 9, 2021
    EternalAmbiguity likes this.
  8. stain2319

    stain2319

    Joined:
    Mar 2, 2020
    Posts:
    121
    You guys are way over engineering this. It seems like the OP just wants to be able to pause and restart an audio clip at will, and tie the "pause points" to game logic. Like a "controlled" playing of the clip. Surely it can't be this complicated?
     
    Ne0mega likes this.
  9. stain2319

    stain2319

    Joined:
    Mar 2, 2020
    Posts:
    121
    I think ippdev nailed it in his first post.
     
  10. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    1,902
    If the door can be open and closed as a motion and not boolean toogle my solution with some kind of sound synthesis is the only viable solution. But it all depends on how good you want it.
     
  11. sxa

    sxa

    Joined:
    Aug 8, 2014
    Posts:
    545
    Its good that you both think you know what the OP wants. However the OP might change his mind once they realise that restarting the clip from the last place it played from misses the portion of the sound where the friction impulses ramp from zero to full speed.

    The series of excitations ramps up, sustains, then ramps down.

    If the movement is stopped, the door cant suddenly reach its sustain speed without having ramped up again. Restarting from the middle, as though the sound of the creak a door is only defined by its rotation amount, is actually wrong.

    Also, depending on the movement speed, the sustain portion may not result in a continuous sound. How do you know this isn't some VR game where the door could be moved by physics depending on how hard the player pushes and could move slow enough that the friction generates individual staccato creaks?

    Because 'it seems like' ? That's not useful to assume.
     
    EternalAmbiguity likes this.
  12. sxa

    sxa

    Joined:
    Aug 8, 2014
    Posts:
    545
    I disagree; it can also be done with basic granularised sample playback, with the advantage of needing less computation than a purely synthetic method.
     
  13. stain2319

    stain2319

    Joined:
    Mar 2, 2020
    Posts:
    121
    If the OP changes his mind, he is free to make another post.

    Look, I don't want to discourage anyone from being helpful. Sometimes you ask a question and the answer you get is "don't do it this way" and that's a valid answer and is often appreciated.

    But a creaking door was mentioned only as an illustrative example, and the question was not necessarily "how do I make the most realistic creaking door effect". There might be a hundred other use cases for stopping the play of a sample mid-play and being able to pick up later where you paused it, so I think it's useful (to the community if not just the OP) to try and answer the actual question posed rather than going down a rabbit hole of a very very specific creaking door example.
     
  14. sxa

    sxa

    Joined:
    Aug 8, 2014
    Posts:
    545
    There are also a hundred use cases where naively continuing the sample is not going to sound right.

    And since all real-world sounds are inherently based on some kind of excitation/resonance sequence, I think it makes sense not to assume that single static samples are the answer, especially when something better can be done relatively easily.

    Given how much effort people put into wibbling about the next big visual thing that Unreal does, its kinda sad that even slightly more realistic audio gets handwaved away so quickly. There's a whole world of stuff that can be made a lot better by thinking about exactly this very simple principles as per a door; a starting portion, an ending portion, and a very small number of variants of the sequenced or sustained portion.

    Like reloading a pistol.

    sample 1 : static open mechanism
    sample 2A : looped refill individual chamber sample (repeat 1 to N times)
    sample 2B : refill all chambers via speedloader sample
    sample 3 : static close mechanism

    Or an engine. Or flapping wings/flying/landing. Yada yada.

    If you dont think your hundred use cases could be done better, fine. But I reckon there are valid reasons for reconsidering if you were right about all one hundred of them.
     
  15. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    1,902
    We care about audio :)


    In VR you have to becasue almost no actions are scripted
     
  16. stain2319

    stain2319

    Joined:
    Mar 2, 2020
    Posts:
    121
    For me, it's not about "not caring about audio" but about where to put your efforts. I'm one guy, and there are a hundred thousand aspects to making games. Maybe a person doesn't want to have to practically become an audio engineer... they just want to know how to stop and start a sound sample they downloaded from the asset store for "creaking door sound", at a specific point... just saying.
     
unityunity