3 D Game Programming Audio MingTe Chi Department
- Slides: 34
3 D Game Programming Audio Ming-Te Chi Department of Computer Science, National Chengchi University
Goal Sound and music in game Open. AL programming Unity 3 D Audio
Music and Sound Game music – Transition animation Sound FX – Exploding – Wind blowing – Raining – Walking
Sound waves are often simplified to a description in terms of sinusoidal plane waves
Sound
Properties of sound wave Frequency, or its inverse, the period Wavelength Wavenumber Amplitude Sound pressure Sound intensity Speed of sound source Direction
Audio Format An audio format is a medium for storing sound and music. Wav and mp 3 are common format Store 44, 100 samples per second, 16 bits per sample.
Windows api BOOL WINAPI Play. Sound( LPCSTR psz. Sound, HMODULE hmod, DWORD fdw. Sound ); Simply use windows api to play wav Ex: play a wav file in“music/ding. wav” Play. Sound("music/ding. wav", NULL, SND_ASYNC | SND_FILENAME);
Open. AL (Open Audio Library) is a free software cross-platform audio API. It is designed for efficient rendering of multichannel three dimensional positional audio.
Open. AL Basic Elements Source – A source of a sound in the world – Link to buffer for actual data to play Buffer – Hold physical sound data in the memory – Cannot play buffer directly • Need to use source Listener – The ears of the world
Open. AL Architecture Buffer 0 Buffer 1 Buffer 2 Source 0 Source 1 Listener Buffer 3 Source 2 memory 3 D world
Listener For every context, there is automatically one Listener object. al. Listenerfv(AL_POSITION, listener. Pos); al. Listenerfv(AL_VELOCITY, listener. Vel); al. Listenerfv(AL_ORIENTATION, listener. Ori);
Buffer Each buffer generated by al. Gen. Buffers has properties which can be retrieved.
const int NUM_BUFFERS = 3; ALuint buffer[NUM_BUFFERS]; ALboolean al_bool; ALsizei size, freq; ALenum format; ALvoid *data = NULL; int ch; // Generate buffers, or no sound will be produced al. Gen. Buffers(NUM_BUFFERS, buffer); if(al. Get. Error() != AL_NO_ERROR) { printf("- Error creating buffers !!n"); exit(1); } else { // printf("Created buffersn"); } alut. Load. WAVFile("c. wav", &format , &data, &size, &freq, &al_bool); al. Buffer. Data(buffer[0], format, data, size, freq); alut. Unload. WAV(format, data, size, freq);
Source A source in Open. AL is exactly what it sounds like, a source of a sound in the world.
const int NUM_SOURCES = 3; ALuint source[NUM_SOURCES]; al. Get. Error(); /* clear error */ al. Gen. Sources(NUM_SOURCES, source); if(al. Get. Error() != AL_NO_ERROR) { printf("- Error creating sources !!n"); exit(2); } al. Sourcef(source[0], AL_PITCH, 1. 0 f); al. Sourcef(source[0], AL_GAIN, 1. 0 f); al. Sourcefv(source[0], AL_POSITION, source 0 Pos); al. Sourcefv(source[0], AL_VELOCITY, source 0 Vel); al. Sourcei(source[0], AL_BUFFER, buffer[0]); //attach buffer al. Sourcei(source[0], AL_LOOPING, AL_TRUE);
Play and Stop Combine with keyboardfunc(), or some other way Ex: al. Source. Play(source[0]); al. Source. Stop(source[0]); al. Source. Pause(source[0]);
AUDIO IN UNITY 3 D
Audio in Unity 3 D Audio Sources attached to objects, Audio Listener attached to another object, most often the main camera
Audio Listener Each scene can only have 1 Audio Listener to work properly.
Audio Source Plays back an Audio Clip in the scene. Volume Pitch
Audio Clip AIFF, WAV, MP 3 and Ogg formats
Play()/Stop() void Start() { Audio. Source audio = Get. Component<Audio. Source>(); audio. Play(44100); } Pause()/Un. Pause()
Play, wait, switch clip [Require. Component(typeof(Audio. Source))] public class Example. Class : Mono. Behaviour { public Audio. Clip other. Clip; IEnumerator Start() { Audio. Source audio = Get. Component<Audio. Source>(); audio. Play(); yield return new Wait. For. Seconds(audio. clip. length); audio. clip = other. Clip; audio. Play(); } }
Audio. Source. unity 嘗試各種不同的Audio. Source效果。
Audio Effects 本身不發出聲音,但可以影響Audio Source 發出的聲音或Audio Listener聽到的聲音。 音效元件: – Audio Mixer + Audio Effect – Audio Filter – Reverb Zone
Audio Mixer + Audio Effect 控制Audio Source混合的順序,每一次混 和都可以加入不同的Audio Effect。 請參閱文件: http: //docs. unity 3 d. com/Manual/Audio. M ixer. html
- đổi địa chỉ logic sang địa chỉ vật lý
- Chi chi nnn
- Chi chi tg tf
- Chi domanda lavoro
- Audiolab python
- Perbedaan linear programming dan integer programming
- Greedy programming vs dynamic programming
- System programming vs application programming
- Integer programming vs linear programming
- Programing adalah
- Gameprogrammingpatterns
- Game programming algorithms and techniques
- Texture in game programming
- Game programming patterns
- Abcde games
- The farming game rules
- A formal approach to game design and game research
- Game lab game theory
- Liar game game theory
- Liar game game theory
- Multimedia information retrieval in irs
- All set directsound hwnd@8
- Milliphone
- Scipy audio processing
- Bahan audio
- Gatsby ch 8 summary
- Goals of audio lingual method
- Thank you maam author
- Audio super resolution using neural networks
- Lovac u žitu dojam o djelu
- Jelaskan kegunaan sistem audio video
- Ipsip
- Satellite digital audio radio service
- Mrvice iz dnevnog boravka test
- Mi caballo mago audio