windows 8 - How to play overlapping audio in winrt? -


i'm porting app wp8 requires playback of various sounds can overlap. way i've found far use mediaelement, doesn't allow overlapping sounds.

question - easiest , best audio engine use play overlapping audio? ideally need small example of how can this.

i've looked wasapi (http://code.msdn.microsoft.com/windowsapps/windows-audio-session-22dcab6b), doesn't supports simple playback ?

maybe can wrap mediafoundation , call winrt? (mediaengine audio playback on winrt)

here code now, when play new sound cuts off playing 1 rather blending them.

    threadutility.runonuithread(       async delegate()       {         // todo doesn't allow sounds overlap!         uri uri = new uri(r.base_uri, r.raw.uri_prefix + resourceid);         storagefile storagefile =           await windows.storage.storagefile.getfilefromapplicationuriasync(           uri);         mediaelement element = new mediaelement();          var randomaccessstream = await storagefile.openreadasync();          element.setsource(randomaccessstream, storagefile.contenttype);         element.volume = volume;         element.playbackrate = pitch;         //todo element.pan = pan;         element.play();       }     ); 

solution (as per filip's answer):

in page class:

      var mediaelements = new linkedlist<mediaelement>();       {         (int channel = 0; channel < teachersoundgroover.num_channels; channel++)         {           var mediaelement = new mediaelement();           mediaelements.add(mediaelement);            // must in tree otherwise won't overlap!           m_titlepanel.children.add(mediaelement);         }       }       m_soundplayer = new mysoundplayer(mediaelements);     } 

in mysoundplayer class:

    threadutility.runonuithread(       async delegate()       {         uri uri = new uri(r.base_uri, r.raw.uri_prefix + resourceid);         storagefile storagefile =           await windows.storage.storagefile.getfilefromapplicationuriasync(           uri);          if(m_mediaelements != null)         {           int count = m_mediaelements.size();           if (count > 0)           {             int channel = m_nextmediaelementtouse % count;             m_nextmediaelementtouse++;             mediaelement element = m_mediaelements.get(channel);              var randomaccessstream = await storagefile.openreadasync();              element.stop();             element.defaultplaybackrate = rate;             element.setsource(randomaccessstream, storagefile.contenttype);             element.volume = volume;             element.balance = pan;             element.play();           }         }       }     ); 

the easiest thing use multiple mediaelement controls, though might not give desired results. best way use xaudio2 either directly or through sharpdx if want avoid creating c++/cx winrt component.


Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -