dsrc isn't necessary for this repo
[client-tools.git] / src / external / 3rd / application / UiBuilder / UIDirectSoundSoundCanvas.cpp
blob4faff85ba8c891378373d8d22e05a7604d0054d7
1 #include "FirstUiBuilder.h"
2 #include "UIDirectSoundSoundCanvas.h"
4 UIDirectSoundSoundCanvas::UIDirectSoundSoundCanvas()
6 HRESULT hr;
8 mPlaybackDevice = 0;
10 hr = DirectSoundCreate( 0, &mPlaybackDevice, 0 );
13 UIDirectSoundSoundCanvas::~UIDirectSoundSoundCanvas()
15 for( UINamedSoundMap::iterator i = mSoundMap.begin(); i != mSoundMap.end(); ++i )
17 delete const_cast<char *>( i->first );
18 i->second->Release();
20 mSoundMap.clear();
22 if( mPlaybackDevice )
23 mPlaybackDevice->Release();
26 void UIDirectSoundSoundCanvas::Play( const char *FileToPlay )
28 static_cast<void> (FileToPlay);
31 HRESULT hr;
33 if( mPlaybackDevice )
35 UINamedSoundMap::iterator CachedSound = mSoundMap.find( FileToPlay );
36 IDirectSoundBuffer *theSound;
38 if( CachedSound == mSoundMap.end() )
40 WAVEFORMATEX WaveFormat;
41 DSBUFFERDESC dsbd;
43 dsbd.dwSize = sizeof( dsbd );
44 dsbd.dwFlags = 0;
45 dsbd.dwBufferBytes = 1000;
46 dsbd.dwReserved = 0;
47 dsbd.lpwfxFormat = &WaveFormat;
48 dsbd.guid3DAlgorithm = GUID_NULL;
50 hr = mPlaybackDevice->CreateSoundBuffer( &dsbd, &theSound, 0 );
52 else
53 theSound = CachedSound->second;
55 theSound->SetCurrentPosition( 0 );
56 theSound->Play( 0, 0, 0 );