So I am trying to create sound effects on my bomb upon explosion, so I need to use an “external” audio source (can’t put it on my bomb, it gets destroyed). Here are the two methods I am trying currently:
void OnDisable()
{
AudioSource.PlayClipAtPoint(explosionSound, transform.position); // Version 1
PlayClipAt(explosionSound, transform.position); // Version 2
}
For reference, here is what PlayClipAt does:
AudioSource PlayClipAt(AudioClip clip, Vector3 pos)
{
GameObject tempGO = new GameObject("TempAudio"); // create the temp object
tempGO.transform.position = pos; // set its position
AudioSource aSource = tempGO.AddComponent<AudioSource>(); // add an audio source
aSource.clip = clip; // define the clip
aSource.Play(); // start the sound
Destroy(tempGO, clip.length); // destroy object after clip duration
return aSource; // return the AudioSource reference
}
Aren’t these two pieces of codes are ideally doing the same thing? What I don’t understand is with the second option my bombs are loud no matter where it explodes (bad), but with PlayClipAtPoint they are way too stilent (also bad) I thought about inserting my own roll of mode (via using the 2nd option) but it didn’t seem the change anything no matter what I did:
I first setup an audio source component to the bomb, and specify my roll off there: logarithmic with 1 min and 50 max.
Added this to PlayClipAt:
AudioSource PlayClipAt(AudioClip clip, Vector3 pos)
{
GameObject tempGO = new GameObject("TempAudio"); // create the temp object
tempGO.transform.position = pos; // set its position
AudioSource aSource = tempGO.AddComponent<AudioSource>(); // add an audio source
aSource.clip = clip; // define the clip
// set other aSource properties here, if desired
aSource.rolloffMode = audioSource.rolloffMode;
aSource.Play(); // start the sound
Destroy(tempGO, clip.length); // destroy object after clip duration
return aSource; // return the AudioSource reference
}
Any ideas on what I am doing wrong? or what can I do better?
Thank you for this, it solved the issue of volume not changing with distance. But my main problem still stands. I use a website to generate my sound effects, and they are pretty loud there. I download them, and they’re still pretty loud if I just play them on my desktop. But I place them on my audio source on Unity and suddenly they sound significantly less loud?
All of my volumes are maxed out, and I have set the logarithmic roll off between 5-10 and I am exploding the bomb next to my character, so there is no roll off. Why do you think this might be happening?
I tried to also “amplify” my sound effect using audacity but then it starts to sound different (clipping and what not). I have very limited knowledge in the world of audio so I am feeling a little lost here…
You should try normalize your audio files. You can do that from audacity, instead of selecting amplify, select normalize. You should be able to set the db to as high as 0 without clipping, or maybe you want to leave it at -1, either way, use the same setting for all your clips.
When you normalize your audio files, you standardize their peak volumes, so that at their peaks, they are all the same volume. Then when you want to apply volume differences to your sounds, you do so by modifying the volume of the audiosource when you play them, they don’t inherently have different peak volumes.
Reading about amplify, I’m not sure why it would be clipping if you are keeping the amplify peak at 0 or less.
You could try to reduce the peak, though I don’t see why you would have to. Clipping occurs when the peak of a sound is above 0 db.
It sounds like amplify is performing a similar function to normalize.
I would tend to stick to the “normalize” function in any audio editing program though, as that is what everyone will be looking for to perform this task.
What is the issue with the sound?
Does it clip on the high end at the explosion? Does it clip on the low end rumble after the explosion? Does it clip only in unity or in audacity as well?
I did try the normalize but what does one do if the volume of the audio source is already maxed out? That is why, similarly with amplify (if you keep amplify peak at 0) there won’t be clipping, but also there won’t be enough amplification.
I guess the issue is that it sounds different [if I amplify with clipping], because some of the peaks are now “too extreme” they aren’t captured properly. If it clips, it clips in audacity.