Windows audio architecture Win MM Application l Direct

  • Slides: 16
Download presentation
Windows audio architecture Win MM Application l Direct. Sound Application Windows Driver Model –

Windows audio architecture Win MM Application l Direct. Sound Application Windows Driver Model – – Win. MM. DLL DSound. DLL User Mode l APIs – Kernel Mode Sys. Audio. SYS – l Direct. Sound Win. MM Kernel streaming Kmixer. SYS – multiple audio streams can be played at the same time Device Drive Container – Sys. Audio. SYS decides the optimal audio format and sample rate conversion – Kmixer. SYS performs the actual converting Windows Components By Hardware Vendor ISA CARD Driver supported by Win 98, Win ME, Win 2 K and Win XP a single audio driver works for multiple Windows versions PCI CARD Driver USB Device Driver IEEE 1394 Device Driver

Win. MM API l Simple, but – – – l Play audio – –

Win. MM API l Simple, but – – – l Play audio – – l high latency inability to take advantage of hardware acceleration no easy way to implement features, e. g. 3 -D positioning, effect processing wave. Out. Open(…) - open the output audio device wave. Out. Write(…) - write the waveform audio data wave. Out. Close(…) - close the output audio device need to use callback or polling to check the result Not very interesting to real-time applications

Direct. Sound API - over view l Audio component of Direct. X package –

Direct. Sound API - over view l Audio component of Direct. X package – – l Two programming interfaces – – l low latency use hardware acceleration direct access to sound device support capturing sound COM (Component Object Model) in C++. NET in C++, C#, Visual Basic, etc. Important objects – – – secondary buffers: write/read audio data buffer cursors: point to current captured/played audio data buffer notifications: send events when buffer cursors reach a position

Direct. Sound API - COM interfaces IDirect. Sound 8 l – – Create. Sound.

Direct. Sound API - COM interfaces IDirect. Sound 8 l – – Create. Sound. Buffer(descriptor, buffer. Pointer, …) l create a sound buffer object to manage audio samples l fields of descriptor – buffer size – audio format: commonly 16 bits linear PCM – buffer features Set. Cooperative. Level(window. Handle, level) l set the priority of the sound buffer

Direct. Sound API - COM interfaces IDirect. Sound. Buffer 8 l – Lock(offset, size,

Direct. Sound API - COM interfaces IDirect. Sound. Buffer 8 l – Lock(offset, size, addr 1, size 1, addr 2, size 2, flag) l – Play(reserved, priority, flags) l – cause the sound buffer to play, starting from the play cursor Unlock(addr 1, size 1, addr 2, size 2) l – ready all or part of the buffer for a data write and return pointers to which data can be written release a locked sound buffer Stop() l cause the sound buffer to stop playing

Direct. Sound API - COM interfaces IDirect. Sound. Notify 8 l – l Set.

Direct. Sound API - COM interfaces IDirect. Sound. Notify 8 l – l Set. Notification. Positions(Number. Of. Notify. Structure, Arrayof. Notify. Structure) l set the notification positions; during playback, whenever the play cursor reaches one of the specified offsets, the associated event is signaled l fields of Notify. Structure – buffer offset – notify event Sound capturing is similar

Direct. Sound API - code example 1. Streaming audio in an event-driven thread while

Direct. Sound API - code example 1. Streaming audio in an event-driven thread while (true) { DWORD r = Wait. For. Single. Object(event, INFINITE); // receives notification of refilling buffer if (r == WAIT_OBJECT_0) { Buffer. Lock(offset, size, &addr 1, &size 1, &addr 2, &size 2, 0); // copy audio to buffer addresses returned // by Direct. Sound // could be two addresses because of buffer // wrap-around memcpy(addr 1, audio, size 1); if (size 2 != 0) { memcpy(addr 2, left, size 2); } Buffer. Unlock(addr 1, size 1, addr 2, size 2); } } // while

Windows audio architecture revisited Win MM Application l Direct. Sound Application Can we achieve

Windows audio architecture revisited Win MM Application l Direct. Sound Application Can we achieve lower latency? – Win. MM. DLL DSound. DLL User Mode Kernel Mode – Windows Components – Sys. Audio. SYS Kmixer. SYS Device Drive Container By Hardware Vendor ISA CARD Driver PCI CARD Driver USB Device Driver IEEE 1394 Device Driver kernel mixing introduces at least 30 ms of delay kernel mixing is not necessary if I’m the only application generating audio streams How about interacting with device drivers directly?

Direct. KS - the unofficial audio API Win MM Application Direct. Sound Application l

Direct. KS - the unofficial audio API Win MM Application Direct. Sound Application l Direct. KS Application – l Win. MM. DLL DSound. DLL Pros Direct. KS User Mode Cons – Kernel Mode Sys. Audio. SYS – Kmixer. SYS Device Drive Container Windows Components By Hardware Vendor ISA CARD Driver PCI CARD Driver USB Device Driver IEEE 1394 Device Driver very low latency – only one application can play sound at one time applications need to handle audio format and sample rate conversion might not work in future version of Windows

The next-generation Windows audio – None of the current audio interfaces satisfies realtime applications

The next-generation Windows audio – None of the current audio interfaces satisfies realtime applications l l l – transition between user mode and kernel mode for each I/O request blocking upon completion of an I/O request CPU cycles for copying data Wave. RT (wave real-time) drivers in the next version of Windows - “Longhorn” l data flow directly between the client and the audio hardware

Learn more – URLs l overview – l Windows Driver Model (WDM) – l

Learn more – URLs l overview – l Windows Driver Model (WDM) – l http: //www. microsoft. com/whdc/hwdev/tech/audio/w dmaudio. mspx#wdm 1 Direct. KS – l http: //msdn. microsoft. com/library/default. asp? url=/lib rary/en-us/dnwmt/html/audiooverview. asp http: //www. microsoft. com/whdc/hwdev/tech/audio/Di rect. KS. mspx Wave. RT – http: //www. microsoft. com/whdc/hwdev/tech/audio/Wave. R Tport. mspx

Audio library overview – Transmit audio over the internet l use low latency audio

Audio library overview – Transmit audio over the internet l use low latency audio APIs – l pluggable codecs – l l – Direct. Sound or Direct. KS G. 711, GSM, Speex, i. LBC modular playout buffer integrated with rtplib++ System Requirements l l l Windows XP or Windows 2 K Direct. Sound 9. x runtime libraries Visual C++ runtime libraries

Audio library architecture SIP user agent Audio tool GUI Direct. Sound/Direct. KS Playout buffer

Audio library architecture SIP user agent Audio tool GUI Direct. Sound/Direct. KS Playout buffer Decoder Encoder Rtplib++ Socket Network

Audio library API – Initialization l set. User. Name(name) – l set. Remote. Address(host/IP,

Audio library API – Initialization l set. User. Name(name) – l set. Remote. Address(host/IP, port) – l receive audio from this address set. Player. Audio. Format(audio. Format) – l send audio to this address set. Local. Address(host/IP, port) – l set the local user name play audio in this format set. Capturer. Audio. Format(audio. Format) – capture audio in this format

Audio library API – Initialization (Cont. ) l set. Encoder(encoder) use this encoder to

Audio library API – Initialization (Cont. ) l set. Encoder(encoder) use this encoder to encode audio – encoder can be created by – l l set. Decoder(decoder) – – encoder = Speex. Encoder - create a Speex encoder instance encoder. set. Payload. Type(pay. Load. Type) - set RTP payload type encoder. set. Output. Audio. Format(audio. Format) - set the encoded format … (similar to encoder) Start l start. Receiver()/start. Sender() – start to receive/send audio

Audio library delay – One-way mouth-to-ear delay measurement of audio library using Direct. Sound

Audio library delay – One-way mouth-to-ear delay measurement of audio library using Direct. Sound and Direct. KS l Direct. KS shows close to 30 ms improvement over Direct. Sound