Sound Programming 제 1 장기초지식 1 Sound Programming 이란? 이미존재하는소리데이터를재생하는기술 Music Player 디지털콘텐츠에소리를입혀그현실성을높이는기술 Sound Effects for Games Sound Programming Platform 과 API 들 DirectX under Win32 DirectSound + DirectMusic DirectAudio OpenAL OpenGL 의일부분 라이센스가필요한 3 rd party audio-libraries Miles Sound System (www.radgametools.com) FMOD (www.fmod.org) Sensaura (for PC, Xbox, PS2, Nintendo, ) 2
Why OpenAL might be the correct choice for you? Cross-Platform Open Audio Library Multichannel Output of 3D Arrangements. 사운드카드하드웨어에의존적이지않다. 새버전이 CreativeLabs 사에의해서지속적으로출시된다. 새버전이출시되더라도 Backward compatibility가유지된다. 3D Game Audio 프로그래밍에가장적합 버그가적은안정적인오디오라이브러리이다. 3 OpenAL Audio Solution iphone/ipad Sound Programming Sound Effect 3D Sound Open Audio Library Ogg Vorbis MP3/MIDI Playback 은불가능 4
Anatomy of a Sound Visual Presentation of a basic sine wave Frequency, Pitch, and Tuning 주파수 (frequency) 와음의높낮이 (pitch) 는엄밀하게말하면같은의미가아님 Pitch may be described as the perceived frequency of a sound Pitch is perceived roughly as the logarithm of frequency 조율 (Tuning) 디지털사운드에서는 Equal-Tempering 기법이바람직 Every pair of adjacent notes has an identical frequency ratio 5 Anatomy of a Sound ( 계속 ) Amplitude, Loudness, and the Decibel Scale 진폭 (amplitude) 은소리세기 (loudness) 의측정치에해당 Amplitude directly corresponds to its perceived loudness. 데시벨 (db) 값으로측정됨. 어떤소리의세기가다른소리세기의두배라면, 10log 10 (2) 배, 약 3.01-dB 만큼진폭이크다고할수있다. 디지털사운드에서는볼륨이란진폭의절대치가아닌스피커사운드의상대적크기를의미함. 6
Digital Storage of Audio Sound Programming 시미디어파일의형태 Digitally Sampled Representation of the Original Recorded Sound PCM : 사운드파일저장을위한대표적포맷 Pulse Code Modulation WAV 파일에서사용함. PCM 원리 Sampled representation of a basic wave 7 Digital Storage of Audio ( 계속 ) PCM 원리 ( 계속 ) 디지털사운드의정확도는다음의두요소에좌우됨 샘플링당저장비트수 : 4 ~ 24 bits 초당샘플링횟수 : 4,000 ~ 96,000회 (44.1KHz:, 8KHz: ) Sampling Bit Depth의영향 Bit Depth 는샘플링시 y 축 (amplitude) 의해상도를의미 bit depth 값의해상도가낮을수록샘플링시왜곡이나잡음이발생할가능성이커진다 8
Digital Storage of Audio ( 계속 ) Sampling Bit Depth 의영향 ( 계속 ) bit-depth resolution 을높이면 quantization error 가줄어듦. Sample Rate 의영향 Digital sampling 이아날로그음원신호를정확히똑같게표현하지는못함. 9 Digital Storage of Audio ( 계속 ) Sample Rate 의영향 ( 계속 ) sample rate 를두배로증가시키면아날로그신호에더근접한디지털표현을만들수있음 sample rate 를계속증가시키면결국아날로그원음에가까운디지털사운드를표현할수있음. Best to use 44.1 khz 10
Digital Storage of Audio ( 계속 ) Why 44,100 Hertz? 영상을 VCR 비디오테이프에저장할당시부터유래 테이프는초당 60 frame을재생할수있고, 각 frame은 245줄로구성되어있고, 각줄은3개의색 (rgb) 으로구성 60 * 245 * 3 = 44,100? CD 는왜 74 분분량의음악만을담을수있을까? Beethoven s Ninth Symphony 전체의길이가 74 분이었음! 11 Digital Storage of Audio ( 계속 ) How your computer records audio 12
Digital Storage of Audio ( 계속 ) How your computer plays back audio 13 Digital Storage of Audio ( 계속 ) MONO and STEREO Samples 스테레오샘플링 : 두개의독립적인 waveform을듀얼채널로샘플링하여각각을별도의채널에내보내기위함. typically interleaved in the audio data stream. But, 3D 사운드시스템에서는무용지물이므로게임등에서는모노샘플링을사용함. CD에 stereo 음악 1초분량을저장하려면? CD : 44,100Hz 에샘플링당 16 비트 (2 bytes) 사용 Stereo : 2 개의채널을사용하므로, 44,100 * 2 * 2 = 176,400 바이트가필요함 만약 CD 용량이 650MB 라면대략 74 분분량이저장됨 14
Digital Storage of Audio ( 계속 ) Dolby Surround Decoders 5.1 채널을처음도입 스테레오샘플도돌비서라운드알고리즘을사용하면 3D 사운드시스템에서이용할수있음. 3D sound signal two-channel audio output 15 PC Audio Legacy PC 어댑터형태의사운드카드 ISA 용 / PCI 용 / USB 용 3D Audio Simulation By simple panning & volume simulation HRTF (Head Relative Transfer Functions) 2Ch 스테레오스피커만으로다중채널사운드를흉내내는기술 한계점 : 스피커의위치나사람의귀모양에따라효과가다름. Native Multi-Speaker Surround Support 16
PC Audio Legacy ( 계속 ) Dolby Digital 5.1 Hardware Support Hardware-based Dolby 5.1 Encoding 기능 + Dolby Digital Receiver 기능의스피커 Environmental Reverberation and Effects 최신사운드카드에는하드웨어기반반향및음양효과입히기기능이있음 같은소리라할지라도환경에따라서로다른효과를입혀야함. 관련효과음프로그래밍인터페이스 I3DL2 EAX 2.0 17 CODEC Compressor/Decompressor의약자 CD 음질을유지하면서도파일의크기를줄이기위한시도 압축안하는코덱아닌코덱종류 PCM 또는 ADPCM 압축을요하는대표적코덱.mp3: MP3(MPEG Layer 3).ogg: Ogg Vorbis.wma: Windows 사운드 18
Mixing Sound 가장단순한 Simple Additive Sound Mixing Averaging them together? 각소리들을부드럽게변화시켜버리는부작용이있음. 19 Synthesizing FM Synthesis Wave Table Synthesis 20
Music Music 과컴퓨터간의인터페이스는 MIDI 에서시작 Music Instrument Digital Interface Combined with very poor-quality two-operator FM synthesis. Digital Audio Streams CD / DVD Player from the Streaming Server MIDI Dynamic Music의일종 각종디지털음향장비들과인터페이스가능 사운드파일을아주작은크기로저장할수있게되었기때문 21 MIDI 128 개의음원장치를지정할수있음 Play a fifth octave B-flat at this volume using instrument #47 22
DLS DownLoadable Sound MIDI 보다진일보한음원포맷 Allowing each instrument to have up to 16 different samples 즉, MIDI에 real wave-table synthesis 기능을추가한것임! 현재는 DLS 버전 2 까지제정됨. 23 압축포맷의음악파일들 MP3 / WMA / Ogg Vorbis 파일안에모든샘플들이다저장되어있어서재생이쉽지만, 파일크기를줄이기위해압축이되어있음. 24
Audio Engines Commercial Audio Engines BASS MikMod FMOD ModPlug Miles Sound System Buying or Building an Audio Engine? 25 Contents-embedded Sound Programming 게임등의콘텐츠에소리를삽입하기위한프로그래밍 예 : Game Audio Programming (GAP) Game Audio Programming 을위한 API Low-Level API 2D 사운드에대한기본동작 (play, pause, stop, pan, volume, ) 3D 사운드에대한기본동작과제어 (position, velocity, ) 2D 뮤지컬세그먼트에대한기본동작 (play, pause, stop, ) Hardware 기능 Abstraction Mid-Level API PCM wave 파일로드기능 대용량오디오파일스트리밍 Sequential music segments들을큐잉 (queuing) 하는기능 Sound Resource Management Sound Load/Unload 내역관리 26
Contents-embedded Sound Programming( 계속 ) Game Audio Programming 을위한 API ( 계속 ) Mid-Level API ( 계속 ) One-function loading and playback on demand Handle multiple compressed audio formats, including Ogg Vorbis, MP3, WMA, 각종음향효과 (environmental reverberation) 지원함수들 High-Level API Script parsing and loading 기능 Creating a high-level soundscape system Creating an advanced dynamic musical cueing and transition system based on the audio scripting system. 27 Multilayered Audio Engine 28
Q & A 29