Slimdx directsound Module

Source: Internet
Author: User

The number of slimdx resources on the Internet is very small, and tracing is found.

 

1. Basic playback functions

Void createdirectsound (guid DeviceID, intptr handle) {// audio device ID _ DS = new directsound (DeviceID); // you need to use the window handle _ DS. setcooperativelevel (handle, cooperativelevel. normal);} void play (string file) {secondarysoundbuffer snd = NULL; // read the WAV audio file using (wavestream Ws = new wavestream (File )) {var DESC = new soundbufferdescription (); DESC. format = ws. format; DESC. flags = bufferflags. globalfocus | bufferflags. controlvolume | bufferflags. controlpositionpolicy | bufferflags. getcurrentposition2; DESC. sizeinbytes = (INT) WS. length; // create a second-level buffer for the sound snd = new secondarysoundbuffer (_ DS, DESC); SND. volume =-200; byte [] buffer = new byte [DESC. sizeinbytes]; ws. read (buffer, 0, buffer. length); SND. write <byte> (buffer, 0, lockflags. none);} SND. play (0, playflags. none );}

2. Callback in playback

AutoreseteventFunctions are similarJava wait/notify.Calling the waitone method is equivalent to wait, so that the current thread waits. Calling the set method is equivalent to calling notify, notifying the thread to continue execution..

Class soundunit {public int ID {Get; private set;} public soundbuffer buffer {Get; private set;} public autoresetevent event {Get; private set;} public soundunit (soundbuffer buffer) {This. id = ++ I; this. buffer = buffer; this. event = new autoresetevent (false) ;}} void play (string file) {secondarysoundbuffer snd = NULL; soundunit su = NULL; // read the WAV audio file using (wavestream Ws = new wavestream (File) {var DESC = new soundbufferdescription (); DESC. format = ws. format; DESC. flags = bufferflags. globalfocus | bufferflags. controlvolume | bufferflags. controlpositionpolicy | bufferflags. getcurrentposition2; DESC. sizeinbytes = (INT) WS. length; // create a second-level buffer for the sound snd = new secondarysoundbuffer (_ DS, DESC); SND. volume =-200; byte [] buffer = new byte [DESC. sizeinbytes]; ws. read (buffer, 0, buffer. length); SND. write & amp; lt; byte & amp; gt; (buffer, 0, lockflags. none); su = new soundunit (SND); SND. setnotifposipositions (new [] {// sets the callback new notificationposition {event = su after the playback ends. event, offset = dsbpn_offsetstop});} SND. play (0, playflags. none); console. writeline ("start playing:" + su. ID); waitfornotification (SU);} void waitfornotification (soundunit unit) {New thread () ==>{// wait until the playback is complete unit. event. waitone (); console. writeline ("playing end:" + unit. ID );}). start ();}

 

Slimdx directsound Module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.