1 #include "mof/sound/StreamSoundBuffer.hpp"
2 #include "mof/ConsoleIO.hpp"
3 #include "mof/sound/StreamingSoundLoader.hpp"
4 #include "mof/sound/DirectSoundDevice.hpp"
7 mof::StreamSoundBuffer::StreamSoundBuffer
9 std::shared_ptr<mof::sound::DirectSoundDevice> pDevice,
10 LPDIRECTSOUNDBUFFER8 pBuffer,
11 LPDIRECTSOUNDNOTIFY8 pSoundNotify,
14 : mof::SoundBuffer(pDevice, pBuffer , pResource)
16 m_pSoundNotify = pSoundNotify;
17 m_pSoundNotify->AddRef();
18 m_pLoadingThread = NULL;
19 m_pLoadingFunction = NULL;
26 mof::StreamSoundBuffer::~StreamSoundBuffer(void)
28 //boost::mutex::scoped_lock lock(m_pLoadingFunction->getMutex()); TODO これ付けてるとエラーになる
29 getSoundBuffer()->Stop();
30 m_pLoadingThread->join();
31 delete m_pLoadingThread;
32 delete m_pLoadingFunction;
33 m_pSoundNotify->Release();
37 bool mof::StreamSoundBuffer::initialize(){
39 m_pLoadingFunction = new StreamingSoundLoader( getSoundBuffer() , m_pSoundNotify , getResource() );
40 m_pLoadingFunction->initialize();
41 //m_pLoadingFunction->CopyBlock(0);
42 m_pLoadingThread = new boost::thread( boost::ref<StreamingSoundLoader>(*m_pLoadingFunction) );
47 bool mof::StreamSoundBuffer::play(bool looping){
48 boost::mutex::scoped_lock lock(m_pLoadingFunction->getMutex());
50 HRESULT hr = getSoundBuffer()->Play( 0 , 0 , (looping)?DSBPLAY_LOOPING : 0);
51 if(hr == DSERR_BUFFERLOST){
52 *ConsoleOut::getInstance() << _T("Failed --- PlaySound") << std::endl;
58 void mof::StreamSoundBuffer::stop(){
59 //boost::mutex::scoped_lock lock(m_pLoadingFunction->GetMutex());
60 getSoundBuffer()->Stop();
61 getSoundBuffer()->SetCurrentPosition(0);
62 getResource()->resetFile();
64 m_pLoadingThread->join();
65 //}catch(exception e){DEBUG_PRINT(_T("dd"));}
66 delete m_pLoadingThread;
67 delete m_pLoadingFunction;
68 m_pLoadingFunction = new StreamingSoundLoader( getSoundBuffer() , m_pSoundNotify , getResource() );
69 m_pLoadingFunction->initialize();
70 //m_pLoadingFunction->CopyBlock(0);
71 m_pLoadingThread = new boost::thread( boost::ref<StreamingSoundLoader>(*m_pLoadingFunction) );