Sound / Audio / Music
How do we obtain sounds?
We sample them! We sample them!
Sampling: – analog to digital – continuous to discrete Must be done carefully!
stereo
Problem: Correct and incorrect sampling rates (sampling frequency; x direction).
Problem: Quantization (not enough bits in our ADC; y direction).
Audio File Formats Unity supported audio file formats Unity supported audio file formats MP(EG)1/2/3, Ogg Vorbis, wav, and AIFF MP(EG)1/2/3, Ogg Vorbis, wav, and AIFF mono or stereo mono or stereo Torque supported audio file formats Torque supported audio file formats.wav files &.ogg files (Ogg Vorbis).wav files &.ogg files (Ogg Vorbis) mono or stereo mono or stereo
Audio File Formats Compression (AKA CODECS) types: Compression (AKA CODECS) types: lossy vs. lossless lossy vs. lossless Ex. Ex. 6.1M mp3 file converted to a 5.1M.ogg file and a 33.9M.wav file 6.1M mp3 file converted to a 5.1M.ogg file and a 33.9M.wav file 7.6M mp3 file converted to a 8.6M.ogg file and a 83.2M.wav file 7.6M mp3 file converted to a 8.6M.ogg file and a 83.2M.wav file But game engines may pause while decompressing large files. But game engines may pause while decompressing large files.
Audio File Formats Compressed Compressed Compress sounds by choosing the compressed option from inside the Editor. The audio data will be small, but will cost CPU cycles to decode at play time. Depending on the target, Unity will encode the audio to either Ogg Vorbis (Mac/PC/Consoles) or MP3 (Mobile platforms). Compress sounds by choosing the compressed option from inside the Editor. The audio data will be small, but will cost CPU cycles to decode at play time. Depending on the target, Unity will encode the audio to either Ogg Vorbis (Mac/PC/Consoles) or MP3 (Mobile platforms). For the best sound quality supply the audio in an uncompressed format such as WAV or AIFF (containing PCM data) and let Unity do the encoding. For the best sound quality supply the audio in an uncompressed format such as WAV or AIFF (containing PCM data) and let Unity do the encoding. If only targeting Mac/PC (standalones, webplayers) importing an Ogg Vorbis file will not degrade the quality. But converting to mobile platforms will force a re-encode to MP3 and cause a slight quality degradation. Same goes for importing MP3, when only targeting mobile platforms. If only targeting Mac/PC (standalones, webplayers) importing an Ogg Vorbis file will not degrade the quality. But converting to mobile platforms will force a re-encode to MP3 and cause a slight quality degradation. Same goes for importing MP3, when only targeting mobile platforms. Native Native Use Native (WAV, AIFF) audio for short sound effects. The audio data will be larger, but sounds won't need to be decoded at play time. Use Native (WAV, AIFF) audio for short sound effects. The audio data will be larger, but sounds won't need to be decoded at play time.
Audio File Editor: Audacity (audacity.sourceforge.net)
Audacity: record, play, etc.
Audacity: select and cut
Audacity: after cut
Audacity: Fit-in-Window
Audacity: after Fit-in-Window
Audacity: add reverb effect to selection
Add a cheesy wah wah effect to your selection (but preview it first).
Audio in Unity Audio Components Audio Clip Audio Clip Audio Listener Audio Listener Audio Source Audio Source Audio Effects(PRO only) Audio Effects(PRO only) Audio Low Pass Filter(PRO only) Audio Low Pass Filter(PRO only) Audio High Pass Filter(PRO only) Audio High Pass Filter(PRO only) Audio Echo Filter(PRO only) Audio Echo Filter(PRO only) Audio Distortion Filter(PRO only) Audio Distortion Filter(PRO only) Audio Reverb Filter(PRO only) Audio Reverb Filter(PRO only) Audio Chorus Filter(PRO only) Audio Chorus Filter(PRO only) Reverb Zones Reverb Zones
Audio in Unity Audio Components The following slides were compiled from information available from the excellent Unity reference manual ( nts/index.html).
AUDIO CLIP
Audio in Unity Audio Components: Audio Clip Audio Clips are audio data used by Audio Sources. Unity supports mono, stereo and multi (up to 8) channels audio assets. Unity supports importing the following audio file formats:.aif,.wav,.mp3, and.ogg. Audio Clips are audio data used by Audio Sources. Unity supports mono, stereo and multi (up to 8) channels audio assets. Unity supports importing the following audio file formats:.aif,.wav,.mp3, and.ogg.
Audio in Unity Audio Components: Audio Clip
Audio in Unity Audio Components: Audio Clip Audio FormatThe specific format that will be used for the sound at runtime. Audio FormatThe specific format that will be used for the sound at runtime. NativeLarger file size, higher quality. Best for very short sound effects. NativeLarger file size, higher quality. Best for very short sound effects. CompressedSmaller file size, lower/variable quality. Best for medium length sound effects and music. CompressedSmaller file size, lower/variable quality. Best for medium length sound effects and music. 3D SoundIf enabled, the sound will play back in 3D space. Both Mono and Stereo sounds can be played in 3D. 3D SoundIf enabled, the sound will play back in 3D space. Both Mono and Stereo sounds can be played in 3D. Force to monoIf enabled, the audio clip will be down-mixed to a single channel sound. Force to monoIf enabled, the audio clip will be down-mixed to a single channel sound.
Audio in Unity Audio Components: Audio Clip (cont’d.) Load TypeThe way Unity load audio assets runtime. Load TypeThe way Unity load audio assets runtime. Decompress on loadDecompress sounds upon load. Use this for smaller compressed sounds to avoid the performance overhead of decompressing on the fly. Beware that a compressed sound will use ~10x more memory that when decompressed, so don't use this for large files. Decompress on loadDecompress sounds upon load. Use this for smaller compressed sounds to avoid the performance overhead of decompressing on the fly. Beware that a compressed sound will use ~10x more memory that when decompressed, so don't use this for large files. Compressed in memoryKeep sounds compressed in memory and decompress while playing. This have a slight performance overhead (esp. for Ogg/Vorbis compressed files) so only use this for bigger files. Compressed in memoryKeep sounds compressed in memory and decompress while playing. This have a slight performance overhead (esp. for Ogg/Vorbis compressed files) so only use this for bigger files. Stream from discStream audio data directly from disc. This uses a fraction of the original sounds size of memory. Use this for your music or very long tracks. Depending on the hardware, a general advice is to keep this down to 1-2 simultaneously streams. Stream from discStream audio data directly from disc. This uses a fraction of the original sounds size of memory. Use this for your music or very long tracks. Depending on the hardware, a general advice is to keep this down to 1-2 simultaneously streams. CompressionAmount of Compression to be applied to a Compressed clip. Statistics about file size can be seen beneath the slider. It is suggested to drag the slider to a place that leaves the playback "good enough" but still at a small enough size to meet your file size/distribution needs. CompressionAmount of Compression to be applied to a Compressed clip. Statistics about file size can be seen beneath the slider. It is suggested to drag the slider to a place that leaves the playback "good enough" but still at a small enough size to meet your file size/distribution needs.
AUDIO LISTENER
Audio in Unity Audio Components: Audio Listener The Audio Listener acts as a microphone-like device. It receives input from any given Audio Source in the scene and plays sounds through the computer speakers. The Audio Listener acts as a microphone-like device. It receives input from any given Audio Source in the scene and plays sounds through the computer speakers. For most applications it makes the most sense to attach the listener to the Main Camera. For most applications it makes the most sense to attach the listener to the Main Camera. If an audio listener is within the boundaries of a Reverb Zone reverberation is applied to all audible sounds in the scene. (PRO only) Furthermore, Audio Effects can be applied to the listener and it will be applied to all audible sounds in the scene. If an audio listener is within the boundaries of a Reverb Zone reverberation is applied to all audible sounds in the scene. (PRO only) Furthermore, Audio Effects can be applied to the listener and it will be applied to all audible sounds in the scene.
AUDIO SOURCE
Audio in Unity Audio Components: Audio Source The Audio Source plays back an Audio Clip in the scene. If the Audio Clip is a 3D clip, the source is played back at a given position and will attenuate over distance. The audio can be spread out between speakers (stereo to 7.1) (Spread) and morphed between 3D and 2D (PanLevel). This can be controlled over distance with falloff curves. Also, if the listener is within 1 or multiple Reverb Zones, reverberations is applied to the source. (PRO only) Individual filters can be applied to each audio source for an even richer audio experience. See Audio Effects for more details. The Audio Source plays back an Audio Clip in the scene. If the Audio Clip is a 3D clip, the source is played back at a given position and will attenuate over distance. The audio can be spread out between speakers (stereo to 7.1) (Spread) and morphed between 3D and 2D (PanLevel). This can be controlled over distance with falloff curves. Also, if the listener is within 1 or multiple Reverb Zones, reverberations is applied to the source. (PRO only) Individual filters can be applied to each audio source for an even richer audio experience. See Audio Effects for more details.
Audio in Unity Audio Components: Audio Source The Audio Source gizmo in the Scene View and its settings in the inspector.
Audio in Unity Audio Components: Audio Source Rolloff mode: How fast the sound fades. The higher the value, the closer the Listener has to be before hearing the sound. Rolloff mode: How fast the sound fades. The higher the value, the closer the Listener has to be before hearing the sound.
Audio in Unity Audio Components: Audio Source Rolloff mode types: Rolloff mode types: 1. Logarithmic rolloff: The sound is loud when you are close to the audio source, but when you get away from the object it decreases significantly fast. 2. Linear rolloff: The more far away from the audio source you go, the less you can hear it. 3. Custom rolloff: The sound from the audio source behaves accordingly to how you set the graph of roll offs.
Audio in Unity Audio Components: Audio Source Rolloff mode types: Rolloff mode types: 1. Logarithmic Rolloff 2. Linear Rolloff 3. Custom Rolloff
Audio in Unity Audio Components: Audio Source Distance Functions Distance Functions There are several properties of the audio that can be modified as a function of the distance between the audio source and the audio listener. There are several properties of the audio that can be modified as a function of the distance between the audio source and the audio listener. Volume:Amplitude( ) over distance. Volume:Amplitude( ) over distance. Pan:Left(-1.0) to Right(1.0) over distance. Pan:Left(-1.0) to Right(1.0) over distance. Spread:Angle (degrees ) over distance. Spread:Angle (degrees ) over distance. Low-Pass (only if LowPassFilter is attached to the AudioSource): Cutoff Frequency ( ) over distance. Low-Pass (only if LowPassFilter is attached to the AudioSource): Cutoff Frequency ( ) over distance.
Audio in Unity Audio Components: Audio Source properties Audio ClipReference to the sound clip file that will be played. Audio ClipReference to the sound clip file that will be played. MuteIf enabled the sound will be playing but muted. MuteIf enabled the sound will be playing but muted. Bypass EffectsThis Is to quickly "by-pass" filter effects applied to the audio source. An easy way to turn all effects on/off. Bypass EffectsThis Is to quickly "by-pass" filter effects applied to the audio source. An easy way to turn all effects on/off. Play On AwakeIf enabled, the sound will start playing the moment the scene launches. If disabled, you need to start it using the Play() command from scripting. Play On AwakeIf enabled, the sound will start playing the moment the scene launches. If disabled, you need to start it using the Play() command from scripting. LoopEnable this to make the Audio Clip loop when it reaches the end. LoopEnable this to make the Audio Clip loop when it reaches the end. PriorityDetermines the priority of this audio source among all the ones that coexist in the scene. (Priority: 0 = most important. 256 = least important. Default = 128.). Use 0 for music tracks to avoid it getting occasionally swapped out. PriorityDetermines the priority of this audio source among all the ones that coexist in the scene. (Priority: 0 = most important. 256 = least important. Default = 128.). Use 0 for music tracks to avoid it getting occasionally swapped out. VolumeHow loud the sound is at a distance of 1 world unit (1 meter) from the Audio Listener. VolumeHow loud the sound is at a distance of 1 world unit (1 meter) from the Audio Listener. PitchAmount of change in pitch due to slowdown/speed up of the Audio Clip. Value 1 is normal playback speed. PitchAmount of change in pitch due to slowdown/speed up of the Audio Clip. Value 1 is normal playback speed. 3D Sound SettingsSettings that are applied to the audio source if the is a 3D Sound. 3D Sound SettingsSettings that are applied to the audio source if the is a 3D Sound.
Audio in Unity Audio Components: Audio Source properties (cont’d.) Pan LevelSets how much the 3d engine has an effect on the audio source. Pan LevelSets how much the 3d engine has an effect on the audio source. SpreadSets the spread angle to 3d stereo or multichannel sound in speaker space. SpreadSets the spread angle to 3d stereo or multichannel sound in speaker space. Doppler LevelDetermines how much doppler effect will be applied to this audio source (if is set to 0, then no effect is applied). Doppler LevelDetermines how much doppler effect will be applied to this audio source (if is set to 0, then no effect is applied). Min DistanceWithin the MinDistance, the sound will stay at loudest possible. Outside MinDistance it will begin to attenuate. Increase the MinDistance of a sound to make it 'louder' in a 3d world, and decrease it to make it 'quieter' in a 3d world. Min DistanceWithin the MinDistance, the sound will stay at loudest possible. Outside MinDistance it will begin to attenuate. Increase the MinDistance of a sound to make it 'louder' in a 3d world, and decrease it to make it 'quieter' in a 3d world. Max DistanceThe distance where the sound stops attenuating at. Beyond this point it will stay at the volume it would be at MaxDistance units from the listener and will not attenuate any more. Max DistanceThe distance where the sound stops attenuating at. Beyond this point it will stay at the volume it would be at MaxDistance units from the listener and will not attenuate any more. Rolloff ModeHow fast the sound fades. The higher the value, the closer the Listener has to be before hearing the sound. Rolloff ModeHow fast the sound fades. The higher the value, the closer the Listener has to be before hearing the sound. 2D Sound SettingsSettings that are applied to the audio source if the is a 3D Sound. 2D Sound SettingsSettings that are applied to the audio source if the is a 3D Sound. Pan 2DSets how much the engine has an effect on the audio source. Pan 2DSets how much the engine has an effect on the audio source.
AUDIO EFFECTS
Audio in Unity Audio Components Audio Effects(PRO only) Audio Effects(PRO only) Audio Low Pass Filter(PRO only) Audio Low Pass Filter(PRO only) Audio High Pass Filter(PRO only) Audio High Pass Filter(PRO only) Audio Echo Filter(PRO only) Audio Echo Filter(PRO only) Audio Distortion Filter(PRO only) Audio Distortion Filter(PRO only) Audio Reverb Filter(PRO only) Audio Reverb Filter(PRO only) Audio Chorus Filter(PRO only) Audio Chorus Filter(PRO only)
Audio in Unity Audio Components Audio Effects(PRO only) Audio Effects(PRO only) Audio Low Pass Filter(PRO only) Audio Low Pass Filter(PRO only) Audio High Pass Filter(PRO only) Audio High Pass Filter(PRO only) Audio Echo Filter(PRO only) Audio Echo Filter(PRO only) Audio Distortion Filter(PRO only) Audio Distortion Filter(PRO only) Audio Reverb Filter(PRO only) Audio Reverb Filter(PRO only) Audio Chorus Filter(PRO only) Audio Chorus Filter(PRO only)
REVERB ZONES
Audio in Unity Audio Components: Reverb Zones Reverb Zones take an Audio Clip and distortionates it depending where the audio listener is located inside the reverb zone. Reverb Zones take an Audio Clip and distortionates it depending where the audio listener is located inside the reverb zone. They are used when you want to gradually change from a point where there is no ambient effect to a place where there is one. For example when you are entering a cavern. They are used when you want to gradually change from a point where there is no ambient effect to a place where there is one. For example when you are entering a cavern.
Audio in Unity Audio Components: Reverb Zones The Audio Reverb Zone gizmo seen in the inspector: The Audio Reverb Zone gizmo seen in the inspector:
Audio in Unity Audio Components: Reverb Zones Properties Min Distance - Represents the radius of the inner circle in the gizmo, this determines the zone where there is a gradually reverb effect and a full reverb zone. Min Distance - Represents the radius of the inner circle in the gizmo, this determines the zone where there is a gradually reverb effect and a full reverb zone. Max Distance - Represents the radius of the outer circle in the gizmo, this determines the zone where there is no effect and where the reverb starts to get applied gradually. Max Distance - Represents the radius of the outer circle in the gizmo, this determines the zone where there is no effect and where the reverb starts to get applied gradually. Reverb Preset - Determines the reverb effect that will be used by the reverb zone. Reverb Preset - Determines the reverb effect that will be used by the reverb zone.
Examples Player sounds (footsteps, utterances) Player sounds (footsteps, utterances) Weapon sounds Weapon sounds Vehicle sounds Vehicle sounds Environmental sounds Environmental sounds Interface sounds Interface sounds
Converting stereo to mono with Audacity (Many game engines require mono sources for 3D sound, i.e. sound with volume based upon listener distance.) 1. Split stereo track. 2. Make both tracks mono. 3. Use the level control for each track, found on the left of the track, to set to: "Gain: -6 dB". Then when you quick mix, it is guaranteed to not clip. 4. Select both tracks 5. Project -> Quick Mix. 6. Save mono audio as.wav or.ogg.
Sounds on the internet The altavista.com search engine no longer allows you to search for audio files (and specific audio file formats). The altavista.com search engine no longer allows you to search for audio files (and specific audio file formats).
Sound/audio example Demo Audacity and “Good Times.” file:///j://pub_html/csc343/slides/gt.aup file:///j://pub_html/csc343/slides/gt.aup file:///j://pub_html/csc343/slides/gt.aup (actually an XML file) (actually an XML file) Isolate the bass track. Isolate the bass track. 1. lowpass filter 2. slow tempo but maintain pitch 1. Unity Sound exercise.
Sound/audio exercise Unity Sound exercise.