[Amis-vcs] SF.net SVN: amis: [2370] branches/amis3
Brought to you by:
julienq,
marisademeglio
From: <dan...@us...> - 2008-03-02 23:02:52
|
Revision: 2370 http://amis.svn.sourceforge.net/amis/?rev=2370&view=rev Author: daniel_weck Date: 2008-03-02 15:02:59 -0800 (Sun, 02 Mar 2008) Log Message: ----------- - Changed audio backend (removed AmisAudio.cpp middle-man, now direct access to dx_audio_player, for easier debugging and maintenance). The DirectShow backend is now synchronized using a critical section, which slows down the menu but avoids corruption of the state of the player. One thing has not changed: each audio clip playback require a full graph building, and it's the same for book playback via ambulant. It's definitely not ideal in terms of performance (especially given that each UI prompt also requires a watching thread for getting END events). - Removed the obsolete AudioPrompt.h/cpp Modified Paths: -------------- branches/amis3/AmisAudio/AmisAudio.vcproj branches/amis3/AmisAudio/include/directshow/dx_audio_player.h branches/amis3/AmisAudio/src/directshow/dx_audio_player.cpp branches/amis3/AmisCore/include/Media.h branches/amis3/AmisCore/src/Media.cpp branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj branches/amis3/AmisGuiMFC2/src/gui/AmisApp.cpp branches/amis3/AmisGuiMFC2/src/gui/MainFrm.cpp branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioSequencePlayer.cpp branches/amis3/AmisGuiMFC2/src/gui/self-voicing/TTSPlayer.cpp Removed Paths: ------------- branches/amis3/AmisAudio/include/AmisAudio.h branches/amis3/AmisAudio/include/StdAfx.h branches/amis3/AmisAudio/src/AmisAudio.cpp branches/amis3/AmisAudio/src/StdAfx.cpp branches/amis3/AmisGuiMFC2/include/gui/self-voicing/AudioPrompt.h branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioPrompt.cpp Modified: branches/amis3/AmisAudio/AmisAudio.vcproj =================================================================== --- branches/amis3/AmisAudio/AmisAudio.vcproj 2008-03-02 19:34:07 UTC (rev 2369) +++ branches/amis3/AmisAudio/AmisAudio.vcproj 2008-03-02 23:02:59 UTC (rev 2370) @@ -152,12 +152,6 @@ <Filter Name="include" Filter=""> - <File - RelativePath=".\include\AmisAudio.h"> - </File> - <File - RelativePath=".\include\StdAfx.h"> - </File> <Filter Name="directshow" Filter=""> @@ -194,12 +188,6 @@ <Filter Name="src" Filter=""> - <File - RelativePath=".\src\AmisAudio.cpp"> - </File> - <File - RelativePath=".\src\StdAfx.cpp"> - </File> <Filter Name="directshow" Filter=""> Deleted: branches/amis3/AmisAudio/include/AmisAudio.h =================================================================== --- branches/amis3/AmisAudio/include/AmisAudio.h 2008-03-02 19:34:07 UTC (rev 2369) +++ branches/amis3/AmisAudio/include/AmisAudio.h 2008-03-02 23:02:59 UTC (rev 2370) @@ -1,100 +0,0 @@ -/* -AMIS: Adaptive Multimedia Information System -Software for playing DAISY books -Homepage: http://amis.sf.net - -Copyright (C) 2004-2007 DAISY for All Project - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#ifndef AMISAUDIO_H -#define AMISAUDIO_H -/** The following ifdef block is the standard way of creating macros which make exporting -// from a DLL simpler. All files within this DLL are compiled with the AMISAUDIO_EXPORTS -// symbol defined on the command line. this symbol should not be defined on any project -// that uses this DLL. This way any other project whose source files include this file see -// AMISAUDIO_API functions as being imported from a DLL, wheras this DLL sees symbols -// defined with this macro as being exported. -*/ - -//#undef AMISAUDIO_EXPORTS - -#ifdef AMISAUDIO_EXPORTS -#define AMISAUDIO_API __declspec(dllexport) -#else -#define AMISAUDIO_API -#endif - -#include "directshow/dx_audio_player.h" -#include "mffmTimeCode/smilTimeCode.H" - -#if _DEBUG -//#include <vld.h> -#endif - -#ifdef _MSC_VER -#pragma warning(disable : 4251) -#endif - -#pragma warning(disable : 4786) - -typedef void (*sendMessageCallbackFn)(void); - -namespace amis -{ - namespace audio - { - class AMISAUDIO_API AmisAudio - { - protected: - AmisAudio(); - - public: - static AmisAudio* Instance(); - ~AmisAudio (); - static void DestroyInstance(); - - void play(const char * url,char* clipBegin,char* clipEnd); - void pause(); - void resume(); - void stopX(); - - bool isPlaying(); - - double getVolume(); - void setVolume (double); - - void adjustVolume(double); - void adjustRate(double); - - double getRate(); - void setRate(double); - - sendMessageCallbackFn sendMessageCallback; - void setCallback(sendMessageCallbackFn pFunction); - - void PlayerEndCallback(); - ambulantX::gui::dx::audio_playerX *m_playerToKill; - - private: - static AmisAudio* pinstance; - ambulantX::gui::dx::audio_playerX *m_player; - - }; - } -} - -#endif \ No newline at end of file Deleted: branches/amis3/AmisAudio/include/StdAfx.h =================================================================== --- branches/amis3/AmisAudio/include/StdAfx.h 2008-03-02 19:34:07 UTC (rev 2369) +++ branches/amis3/AmisAudio/include/StdAfx.h 2008-03-02 23:02:59 UTC (rev 2370) @@ -1,113 +0,0 @@ -// stdafx.h : include file for standard system include files, -// or project specific include files that are used frequently, but -// are changed infrequently -// - -#if !defined(AFX_STDAFX_H__AE5780CC_1107_4F64_ADC7_F4BACF658CC2__INCLUDED_) -#define AFX_STDAFX_H__AE5780CC_1107_4F64_ADC7_F4BACF658CC2__INCLUDED_ - -#if _MSC_VER > 1000 -#pragma once -#endif // _MSC_VER > 1000 - -/* -#ifndef _AFX_NOFORCE_LIBS - -///////////////////////////////////////////////////////////////////////////// -// Win32 libraries - -#ifndef _AFXDLL - #ifndef _UNICODE - #ifdef _DEBUG - #pragma comment(lib, "nafxcwd.lib") - #else - #pragma comment(lib, "nafxcw.lib") - #endif - #else - #ifdef _DEBUG - #pragma comment(lib, "uafxcwd.lib") - #else - #pragma comment(lib, "uafxcw.lib") - #endif - #endif -#else - #ifndef _UNICODE - #ifdef _DEBUG - #pragma comment(lib, "mfc71d.lib") - #pragma comment(lib, "mfcs71d.lib") - #else - #pragma comment(lib, "mfc71.lib") - #pragma comment(lib, "mfcs71.lib") - #endif - #else - #ifdef _DEBUG - #pragma comment(lib, "mfc71ud.lib") - #pragma comment(lib, "mfcs71ud.lib") - #else - #pragma comment(lib, "mfc71u.lib") - #pragma comment(lib, "mfcs71u.lib") - #endif - #endif -#endif - -#ifdef _DLL - #if !defined(_AFX_NO_DEBUG_CRT) && defined(_DEBUG) - #pragma comment(lib, "msvcrtd.lib") - #else - #pragma comment(lib, "msvcrt.lib") - #endif -#else -#ifdef _MT - #if !defined(_AFX_NO_DEBUG_CRT) && defined(_DEBUG) - #pragma comment(lib, "libcmtd.lib") - #else - #pragma comment(lib, "libcmt.lib") - #endif -#else - #if !defined(_AFX_NO_DEBUG_CRT) && defined(_DEBUG) - #pragma comment(lib, "libcd.lib") - #else - #pragma comment(lib, "libc.lib") - #endif -#endif -#endif - -#pragma comment(lib, "kernel32.lib") -#pragma comment(lib, "user32.lib") -#pragma comment(lib, "gdi32.lib") -#pragma comment(lib, "msimg32.lib") -#pragma comment(lib, "comdlg32.lib") -#pragma comment(lib, "winspool.lib") -#pragma comment(lib, "advapi32.lib") -#pragma comment(lib, "shell32.lib") -#pragma comment(lib, "comctl32.lib") -#pragma comment(lib, "shlwapi.lib") - -// force inclusion of NOLIB.OBJ for /disallowlib directives -#pragma comment(linker, "/include:__afxForceEXCLUDE") - -// force inclusion of DLLMODUL.OBJ for _USRDLL -#ifdef _USRDLL -#pragma comment(linker, "/include:__afxForceUSRDLL") -#endif - -// force inclusion of STDAFX.OBJ for precompiled types -#ifdef _AFXDLL -#pragma comment(linker, "/include:__afxForceSTDAFX") -#endif - -#endif //!_AFX_NOFORCE_LIBS - -*/ - -// Insert your headers here -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers - -#include <windows.h> - -// reference additional headers your program requires here - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_STDAFX_H__AE5780CC_1107_4F64_ADC7_F4BACF658CC2__INCLUDED_) Modified: branches/amis3/AmisAudio/include/directshow/dx_audio_player.h =================================================================== --- branches/amis3/AmisAudio/include/directshow/dx_audio_player.h 2008-03-02 19:34:07 UTC (rev 2369) +++ branches/amis3/AmisAudio/include/directshow/dx_audio_player.h 2008-03-02 23:02:59 UTC (rev 2370) @@ -26,6 +26,12 @@ #ifndef AMBULANT_GUI_DX_AUDIO_PLAYERX_H #define AMBULANT_GUI_DX_AUDIO_PLAYERX_H +#ifdef AMISAUDIO_EXPORTS +#define AMISAUDIO_API __declspec(dllexport) +#else +#define AMISAUDIO_API +#endif + //#include "ambulant/config/config.h" #include <string> @@ -129,18 +135,22 @@ namespace dx { -class audio_playerX { +class AMISAUDIO_API audio_playerX { typedef std::pair<bool, double> duration; - + public: - void setCallback(sendMessageCallbackFn pFunction); + + audio_playerX(); + void setCallback(sendMessageCallbackFn pFunction); - audio_playerX(const char * url); + static audio_playerX* Instance(); + static void DestroyInstance(); + ~audio_playerX(); void start(double t); - void stop(); + void stop(bool fromPlay, bool fromThread=false); //void pause(common::pause_display d=common::display_show); void pause(void); void resume(); @@ -162,12 +172,12 @@ // 0 sets a neutral balance // and 10 sets -10 db to right and -90 db to left void set_balance(long val); + bool play(const char * url); private: void end_thread(); - bool open(const char * url); void release_player(); std::string m_url; @@ -182,12 +192,17 @@ public: IMediaEvent *m_media_event; sendMessageCallbackFn sendMessageCallback; - bool bCatchEvents; - bool bProcessEvents; +private: + + CRITICAL_SECTION m_csSequence; + static audio_playerX* pinstance; + #ifdef WITH_TPB_AUDIO_SPEEDUP public: void set_rate(double rate); + double get_rate(); + private: IVuppInterface *m_audio_speedup; void initialize_speedup_filter(); Deleted: branches/amis3/AmisAudio/src/AmisAudio.cpp =================================================================== --- branches/amis3/AmisAudio/src/AmisAudio.cpp 2008-03-02 19:34:07 UTC (rev 2369) +++ branches/amis3/AmisAudio/src/AmisAudio.cpp 2008-03-02 23:02:59 UTC (rev 2370) @@ -1,275 +0,0 @@ -/* -AMIS: Adaptive Multimedia Information System -Software for playing DAISY books -Homepage: http://amis.sf.net - -Copyright (C) 2004-2007 DAISY for All Project - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#include <stdlib.h> -#include <iostream> -#include <string> -#include <process.h> - -#include "AmisAudio.h" - -using namespace amis::audio; - -#ifdef AMISAUDIO_EXPORTS -BOOL APIENTRY DllMain( HANDLE hModule, - DWORD ul_reason_for_call, - LPVOID lpReserved - ) -{ - switch (ul_reason_for_call) - { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; - } - return TRUE; -} -#endif - -static void audioFinishedCallback() -{ - AmisAudio::Instance()->PlayerEndCallback(); -} - -namespace amis -{ - namespace audio - { - - /* - void AmisAudio::play(ambulant::net::url url,char* clipBegin,char* clipEnd) - { - std::string str; - str.assign(url.get_file().c_str()); - - ambulant::net::url tmpurl = ambulant::net::url::from_url(urlOrFile); - assert(tmpurl.is_local_file()); - std::string tmpfile = tmpurl.get_file(); - thisUrl = ambulant::net::url::from_filename(tmpfile); - - ambulantX::gui::dx::audio_playerX *m_player; - if(url.is_local_file()) { // && lib::win32::file_exists(url.get_file())) - m_player = new ambulantX::gui::dx::audio_playerX(str); - int a =1; - } - else if(url.is_absolute()) { - m_player = new ambulantX::gui::dx::audio_playerX(url.get_url()); - } - else { - return; - } - */ - void AmisAudio::play(const char * url,char* clipBegin,char* clipEnd) - { - if (m_playerToKill != NULL) { - //delete m_playerToKill; - } - m_playerToKill=0; - if (m_player) { - delete m_player; // stop() and release_player() handled by destructor - } - m_player = 0; - - m_player = new ambulantX::gui::dx::audio_playerX(url); - - if (! m_player->can_play()) { - - delete m_player; // stop() and release_player() handled by destructor - - m_player = 0; - return; - } - - SmilTimeCode startStop(clipBegin, clipBegin, clipEnd); - int begin=startStop.getStart(); - int end=startStop.getEnd(); - - if (begin!=0){ - int q =1; - } - if (end!=0){ - int q =1; - } - - //double level = m_player->get_global_level(); - double level = 1.0; - m_player->set_volume((long)(level*100)); - - double dur = m_player->get_dur().second; - if (end <= 0 || end > dur) - m_player->endseek(dur); - else - m_player->endseek(end); - - m_player->setCallback((sendMessageCallbackFn)audioFinishedCallback); - - m_player->start(begin); - } - - AmisAudio* AmisAudio::pinstance = 0; - - AmisAudio* AmisAudio::Instance() - { - if (pinstance == 0) // is it the first call? - { - pinstance = new AmisAudio; // create sole instance - } - return pinstance; // address of sole instance - } - - - AmisAudio::AmisAudio() - { - m_player = 0; - m_playerToKill = 0; - } -static DWORD WINAPI killPlayer(LPVOID lpParam) { - - AmisAudio *audio = (AmisAudio*)lpParam; - if (audio->m_playerToKill != NULL) { - delete audio->m_playerToKill; - audio->m_playerToKill=0; - } - - return 0; -} - void AmisAudio::PlayerEndCallback() - { - if (m_player) { - //delete m_player; // stop() and release_player() handled by destructor - m_playerToKill = m_player; - - } - m_player = 0; - if (sendMessageCallback!=NULL) sendMessageCallback(); - - unsigned long lpdwThreadID; - HANDLE hEventHandler = CreateThread(NULL, 0, killPlayer, this, 0, &lpdwThreadID); - } - - void AmisAudio::setCallback(sendMessageCallbackFn pFunction) - { - sendMessageCallback = pFunction; - if (m_player) { - m_player->setCallback((sendMessageCallbackFn)audioFinishedCallback); - } - } - - AmisAudio::~AmisAudio() - { - if (m_playerToKill != NULL && m_player!= m_playerToKill) { - delete m_playerToKill; - - } - m_playerToKill=0; - if (m_player) { - delete m_player; // stop() and release_player() handled by destructor - } - m_player = 0; - } - - void AmisAudio::DestroyInstance() - { - if (pinstance) delete pinstance; - } - - bool AmisAudio::isPlaying() - { - if (m_player) { - return m_player->is_playing(); - } else { - return false; - } - } - - void AmisAudio::pause() - { - if (m_player) { - m_player->pause(); - } - } - - void AmisAudio::resume() - { - if (m_player) { - m_player->resume(); - } - } - void AmisAudio::stopX() - { - if (m_player) { - delete m_player; // stop() and release_player() handled by destructor - } - m_player = 0; - } - - double AmisAudio::getVolume() - { - if (m_player) { - //return m_player->get_volume(); TODO: implement this - return 100.0; - } else { - return 100.0; - } - } - - void AmisAudio::setVolume(double value) - { - if (m_player) { - m_player->set_volume(value); - } - } - - void AmisAudio::adjustVolume(double adjustment) - { - if (m_player) { - m_player->set_volume(adjustment); // TODO this won't work ! - } - } - - - void AmisAudio::adjustRate(double adjustment) - { - if (m_player) { - m_player->set_rate(adjustment); // TODO this won't work ! - } - } - - double AmisAudio::getRate() - { - if (m_player) { - //return m_player->get_rate(); TODO: Implement this - return 1.0; - } else { - return 1.0; - } - } - - void AmisAudio::setRate(double value){ - if (m_player) { - m_player->set_rate(value); - } - } - } -} \ No newline at end of file Deleted: branches/amis3/AmisAudio/src/StdAfx.cpp =================================================================== --- branches/amis3/AmisAudio/src/StdAfx.cpp 2008-03-02 19:34:07 UTC (rev 2369) +++ branches/amis3/AmisAudio/src/StdAfx.cpp 2008-03-02 23:02:59 UTC (rev 2370) @@ -1,8 +0,0 @@ -// stdafx.cpp : source file that includes just the standard includes -// AmisAudio.pch will be the pre-compiled header -// stdafx.obj will contain the pre-compiled type information - -#include "stdafx.h" - -// reference any additional headers you need in STDAFX.H -// and not in this file Modified: branches/amis3/AmisAudio/src/directshow/dx_audio_player.cpp =================================================================== --- branches/amis3/AmisAudio/src/directshow/dx_audio_player.cpp 2008-03-02 19:34:07 UTC (rev 2369) +++ branches/amis3/AmisAudio/src/directshow/dx_audio_player.cpp 2008-03-02 23:02:59 UTC (rev 2370) @@ -18,8 +18,8 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA /* - * @$Id: dx_audio_player.cpp,v 1.22 2008/01/15 10:55:59 jackjansen Exp $ - */ +* @$Id: dx_audio_player.cpp,v 1.22 2008/01/15 10:55:59 jackjansen Exp $ +*/ #ifndef __AFXWIN_H__ #include <afxwin.h> @@ -40,6 +40,24 @@ using namespace ambulantX; +#ifdef AMISAUDIO_EXPORTS +BOOL APIENTRY DllMain( HANDLE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} +#endif + //using ambulant::lib::win32::win_report_error; //using ambulant::lib::win32::win_trace_error; //using ambulant::lib::logger; @@ -64,17 +82,20 @@ gui::dx::audio_playerX *pPlayer = (gui::dx::audio_playerX*)lpParam; - while((pPlayer->bCatchEvents) && (!bSelfBreak)) { - + while(!bSelfBreak) { hResult = E_FAIL; hResult = pPlayer->m_media_event->GetEvent(&lEventCode, &lParam1, &lParam2, INFINITE); pPlayer->m_media_event->FreeEventParams(lEventCode, lParam1, lParam2); - if ((hResult == S_OK) && (pPlayer->bProcessEvents)) { + if (hResult == S_OK) { switch(lEventCode) { case EC_COMPLETE: + pPlayer->stop(false, true); pPlayer->sendMessageCallback(); + bSelfBreak = true; break; case EC_USER + 4: + //pPlayer->stop(false, true); + pPlayer->sendMessageCallback(); bSelfBreak = true; break; } @@ -84,61 +105,143 @@ return 0; } -gui::dx::audio_playerX::audio_playerX(const char * url) + +gui::dx::audio_playerX::audio_playerX() : - //m_url(url), - m_graph_builder(0), - m_media_control(0), - m_media_position(0), - m_media_event(0), +//m_url(url), +m_graph_builder(0), +m_media_control(0), +m_media_position(0), +m_media_event(0), #ifdef WITH_TPB_AUDIO_SPEEDUP - m_audio_speedup(0), +m_audio_speedup(0), #endif - m_basic_audio(0), - hEventHandler(0), - bProcessEvents(false), - bCatchEvents(false) { +m_basic_audio(0), +hEventHandler(0) +{ + set_rate(1.7); + InitializeCriticalSection(&m_csSequence); +} - open(url); +gui::dx::audio_playerX::~audio_playerX() +{ + stop(false); + DeleteCriticalSection(&m_csSequence); + int q = 0; } - -gui::dx::audio_playerX::~audio_playerX() { - stop(); + +gui::dx::audio_playerX* gui::dx::audio_playerX::pinstance = 0; + +gui::dx::audio_playerX* gui::dx::audio_playerX::Instance() +{ + if (pinstance == 0) // is it the first call? + { + pinstance = new gui::dx::audio_playerX(); // create sole instance + } + return pinstance; // address of sole instance } - +void gui::dx::audio_playerX::DestroyInstance() +{ + if (pinstance) delete pinstance; +} + + void gui::dx::audio_playerX::start(double t) { if(is_playing()) pause(); seek(t); resume(); } -void gui::dx::audio_playerX::stop() { - if(m_media_control == 0) return; +void gui::dx::audio_playerX::end_thread() { + if (hEventHandler==NULL) return; - end_thread(); + IMediaEventSink *pIMES = NULL; + m_graph_builder->QueryInterface(IID_IMediaEventSink, (void**) &pIMES); + pIMES->Notify(EC_USER + 4, 0, 0); + pIMES->Release(); + pIMES = NULL; - bProcessEvents = false; - HRESULT hr = m_media_control->Stop(); - if(FAILED(hr)) { - win_report_error("IMediaControl::stop()", hr); + if (WaitForSingleObject(hEventHandler, INFINITE) != WAIT_OBJECT_0) { + int a = 3; } - - if (m_media_control->StopWhenReady() != S_OK) { - long state, i; + hEventHandler = NULL; +} - for (i = 0; i < 100; i++) { - m_media_control->GetState(10, &state); - if (state == State_Stopped) break; +void gui::dx::audio_playerX::release_player() { + + if(m_graph_builder) { + + if(m_media_event) { + m_media_event->Release(); + m_media_event = 0; } - - if (i == 100) { - bProcessEvents = true; + if(m_media_position) { + m_media_position->Release(); + m_media_position = 0; } + if(m_media_control) { + m_media_control->Release(); + m_media_control = 0; + } + if(m_basic_audio) { + m_basic_audio->Release(); + m_basic_audio = 0; + } +#ifdef WITH_TPB_AUDIO_SPEEDUP + if(m_audio_speedup) { + m_audio_speedup->Release(); + m_audio_speedup = 0; + } +#endif + m_graph_builder->Release(); + m_graph_builder = 0; } - release_player(); } -//void gui::dx::audio_playerX::pause(common::pause_display d) { +void gui::dx::audio_playerX::stop(bool fromPlay, bool fromThread) { + + + { + if (!fromPlay) { + EnterCriticalSection(&m_csSequence); + } + if(m_media_control == 0) { + LeaveCriticalSection(&m_csSequence); + return; + } + + if (!fromThread) { + end_thread(); + } else { + hEventHandler = NULL; + } + + if (!fromThread) { + HRESULT hr = m_media_control->Stop(); + if(FAILED(hr)) { + win_report_error("IMediaControl::stop()", hr); + } + + if (m_media_control->StopWhenReady() != S_OK) { + long state, i; + + for (i = 0; i < 100; i++) { + m_media_control->GetState(10, &state); + if (state == State_Stopped) break; + } + + if (i == 100) { + int debug = 0; + } + } + } + release_player(); + if (!fromPlay) { + LeaveCriticalSection(&m_csSequence); + } + } +} + void gui::dx::audio_playerX::pause(void) { if(m_media_control == 0) return; HRESULT hr = m_media_control->Pause(); @@ -195,27 +298,39 @@ } bool gui::dx::audio_playerX::is_playing() { - - if(m_media_control == 0) return false; + EnterCriticalSection(&m_csSequence); + + if(m_media_control == 0) { + LeaveCriticalSection(&m_csSequence);return false;} + long msTimeout = 0; long state; m_media_control->GetState(msTimeout, &state); + + LeaveCriticalSection(&m_csSequence); + return (state == State_Running); - if(m_media_event == 0) return false; + /* + if(m_media_event == 0) { + LeaveCriticalSection(&m_csSequence);return false;} + long evCode = 0; HRESULT hr = m_media_event->WaitForCompletion(msTimeout, &evCode); if(hr == E_ABORT) return true; else if(hr == S_OK) return false; else if(FAILED(hr)) { - // XXXJack: this error occurs all the time... - if (hr == 0x80040227) return false; - win_trace_error("IMediaEvent::WaitForCompletion()", hr); - return false; + // XXXJack: this error occurs all the time... + if (hr == 0x80040227) return false; + win_trace_error("IMediaEvent::WaitForCompletion()", hr); + return false; } + + LeaveCriticalSection(&m_csSequence); return evCode == 0; + */ } #if 0 @@ -234,136 +349,8 @@ } #endif -////////////////////////// - -bool gui::dx::audio_playerX::open(const char * url) { - //m_url = url; - m_url.assign(url); - HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); - if (hr == S_FALSE) CoUninitialize(); - _ASSERT(hr == S_FALSE); - - hr = CoCreateInstance(CLSID_FilterGraph,0,CLSCTX_INPROC_SERVER, - IID_IGraphBuilder,(void**)&m_graph_builder); - if(FAILED(hr)) { - win_report_error("CoCreateInstance(CLSID_FilterGraph, ...)", hr); - return false; - } - - //WCHAR wsz[MAX_PATH]; - //MultiByteToWideChar(CP_ACP,0, url.c_str(), -1, wsz, MAX_PATH); - - std::string strFileName; - strFileName.assign(url); - - USES_CONVERSION; - LPCWSTR str = A2CW(strFileName.c_str()); - - hr = m_graph_builder->RenderFile(str, 0); - if(FAILED(hr)){ - m_graph_builder->Release(); - m_graph_builder = 0; - /* - if (hr == 0x800c000d) // XXX This value experimentally determined:-) - errorX("%s: Unsupported URL protocol", url.c_str()); - else if (hr == VFW_E_CANNOT_CONNECT) - errorX("%s: Unsupported video format", url.c_str()); - else - errorX("%s: DirectX error 0x%x", url.c_str(), hr); - */ - return false; - } #ifdef WITH_TPB_AUDIO_SPEEDUP - initialize_speedup_filter(); -#endif - - hr = m_graph_builder->QueryInterface(IID_IMediaControl, (void **) &m_media_control); - if(FAILED(hr)) { - win_report_error("QueryInterface(IID_IMediaControl, ...)", hr); - return false; - } - m_graph_builder->QueryInterface(IID_IMediaPosition, (void **) &m_media_position); - if(FAILED(hr)) { - win_report_error("QueryInterface(IID_IMediaPosition, ...)", hr); - return false; - } - m_graph_builder->QueryInterface(IID_IMediaEvent, (void **) &m_media_event); - if(FAILED(hr)) { - win_report_error("QueryInterface(IID_IMediaEvent, ...)", hr); - return false; - } - - m_graph_builder->QueryInterface(IID_IBasicAudio, (void **) &m_basic_audio); - if(FAILED(hr)) { - win_report_error("QueryInterface(IID_IBasicAudio, ...)", hr); - } - - hEventHandler = NULL; - bCatchEvents = true; - bProcessEvents = true; - - unsigned long lpdwThreadID; - hEventHandler = CreateThread(NULL, 0, eventHandler, this, 0, &lpdwThreadID); - - return true; -} - - -void gui::dx::audio_playerX::end_thread() { - - - if (hEventHandler==NULL) return; - - bCatchEvents = true; - bProcessEvents = true; - - IMediaEventSink *pIMES = NULL; - m_graph_builder->QueryInterface(IID_IMediaEventSink, (void**) &pIMES); - pIMES->Notify(EC_USER + 4, 0, 0); - pIMES->Release(); - pIMES = NULL; - - if (WaitForSingleObject(hEventHandler, INFINITE) != WAIT_OBJECT_0) { - int a = 3; - } - hEventHandler = NULL; -} - -void gui::dx::audio_playerX::release_player() { - if(m_graph_builder) { - - end_thread(); - - if(m_media_event) { - m_media_event->Release(); - m_media_event = 0; - } - if(m_media_position) { - m_media_position->Release(); - m_media_position = 0; - } - if(m_media_control) { - m_media_control->Release(); - m_media_control = 0; - } - if(m_basic_audio) { - m_basic_audio->Release(); - m_basic_audio = 0; - } -#ifdef WITH_TPB_AUDIO_SPEEDUP - if(m_audio_speedup) { - m_audio_speedup->Release(); - m_audio_speedup = 0; - } -#endif - m_graph_builder->Release(); - m_graph_builder = 0; - } - -} - -#ifdef WITH_TPB_AUDIO_SPEEDUP void gui::dx::audio_playerX::initialize_speedup_filter() { if (speedup_filter_available_valid && !speedup_filter_available) { // We don't seem to have the filter. Too bad. @@ -374,11 +361,12 @@ IBaseFilter *pNewFilter = NULL; + +#ifdef _DEBUG HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); if (hr == S_FALSE) CoUninitialize(); _ASSERT(hr == S_FALSE); - - +#endif HRESULT res; res = CoCreateInstance(CLSID_TPBVupp69, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&pNewFilter); @@ -397,7 +385,7 @@ } speedup_filter_available = true; speedup_filter_available_valid = true; -// AM_DBG lib::debugX("dx_audio_player: added speedup filter to graph"); + // AM_DBG lib::debugX("dx_audio_player: added speedup filter to graph"); // Next step: find out where we want to add the filter to the graph. // We iterate over the filter graph, then for each item in the graph @@ -433,28 +421,28 @@ res = pCurPin->QueryDirection(&curPinDir); HRESULT res2 = pCurPin->ConnectionMediaType(&mediaType); if (res == S_OK && - res2 == S_OK && - curPinDir == PINDIR_OUTPUT && - mediaType.majortype == MEDIATYPE_Audio&& - mediaType.subtype == MEDIASUBTYPE_PCM){ - pOutputPin = pCurPin; - res = pOutputPin->ConnectedTo(&pInputPin); - if (res != S_OK) { - // This output pin was the correct type, but not connected. - // So it cannot be the one we're looking for. - pOutputPin = pInputPin = NULL; - } else { - // Found it! - pOutputPin->AddRef(); - pInputPin->AddRef(); + res2 == S_OK && + curPinDir == PINDIR_OUTPUT && + mediaType.majortype == MEDIATYPE_Audio&& + mediaType.subtype == MEDIASUBTYPE_PCM){ + pOutputPin = pCurPin; + res = pOutputPin->ConnectedTo(&pInputPin); + if (res != S_OK) { + // This output pin was the correct type, but not connected. + // So it cannot be the one we're looking for. + pOutputPin = pInputPin = NULL; + } else { + // Found it! + pOutputPin->AddRef(); + pInputPin->AddRef(); + } } - } - if (res2 == S_OK) { - if (mediaType.cbFormat != 0) { - CoTaskMemFree((PVOID)mediaType.pbFormat); + if (res2 == S_OK) { + if (mediaType.cbFormat != 0) { + CoTaskMemFree((PVOID)mediaType.pbFormat); + } } - } - pCurPin->Release(); + pCurPin->Release(); } if (res != S_FALSE && res != S_OK) traceX("dx_audio_filter: enumerating pins: error 0x%x", res); @@ -547,6 +535,9 @@ } +double gui::dx::audio_playerX::get_rate() { + return s_current_playback_rate; +} void gui::dx::audio_playerX::set_rate(double rate) { s_current_playback_rate = rate; if (m_audio_speedup) { @@ -565,7 +556,7 @@ long cdb = (long)(20.0*log10((double)val/100.0)*100); m_basic_audio->put_Volume(cdb); } - + // can be -100 to 100 // 0 sets a neutral balance // and 10 sets -10 db to right and -90 db to left @@ -582,3 +573,119 @@ { sendMessageCallback=pFunction; } + + +////////////////////////// + +bool gui::dx::audio_playerX::play(const char * url) { + + + EnterCriticalSection(&m_csSequence); + + //m_url = url; + m_url.assign(url); + + if (m_graph_builder != NULL) { + stop(true); + } + +#ifdef _DEBUG + HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + if (hr == S_FALSE) CoUninitialize(); + _ASSERT(hr == S_FALSE); +#endif + + if (m_graph_builder == NULL) { + hr = CoCreateInstance(CLSID_FilterGraph,0,CLSCTX_INPROC_SERVER, + IID_IGraphBuilder,(void**)&m_graph_builder); + if(FAILED(hr)) { + win_report_error("CoCreateInstance(CLSID_FilterGraph, ...)", hr); + + LeaveCriticalSection(&m_csSequence); + return false; + } + } else { + int i = 0; + } + + //WCHAR wsz[MAX_PATH]; + //MultiByteToWideChar(CP_ACP,0, url.c_str(), -1, wsz, MAX_PATH); + + std::string strFileName; + strFileName.assign(url); + + USES_CONVERSION; + LPCWSTR str = A2CW(strFileName.c_str()); + + hr = m_graph_builder->RenderFile(str, 0); + if(FAILED(hr)){ + //m_graph_builder->Release(); + //m_graph_builder = 0; + /* + if (hr == 0x800c000d) // XXX This value experimentally determined:-) + errorX("%s: Unsupported URL protocol", url.c_str()); + else if (hr == VFW_E_CANNOT_CONNECT) + errorX("%s: Unsupported video format", url.c_str()); + else + errorX("%s: DirectX error 0x%x", url.c_str(), hr); + */ + + LeaveCriticalSection(&m_csSequence); + return false; + } +#ifdef WITH_TPB_AUDIO_SPEEDUP + initialize_speedup_filter(); +#endif + + if (m_media_control == NULL) { + hr = m_graph_builder->QueryInterface(IID_IMediaControl, (void **) &m_media_control); + if(FAILED(hr)) { + win_report_error("QueryInterface(IID_IMediaControl, ...)", hr); + + LeaveCriticalSection(&m_csSequence); + return false; + } + } + + if (m_media_position == NULL) { + m_graph_builder->QueryInterface(IID_IMediaPosition, (void **) &m_media_position); + if(FAILED(hr)) { + win_report_error("QueryInterface(IID_IMediaPosition, ...)", hr); + + LeaveCriticalSection(&m_csSequence); + return false; + } + } + + if (m_media_event == NULL) { + m_graph_builder->QueryInterface(IID_IMediaEvent, (void **) &m_media_event); + if(FAILED(hr)) { + win_report_error("QueryInterface(IID_IMediaEvent, ...)", hr); + + LeaveCriticalSection(&m_csSequence); + return false; + } + } + + if (m_basic_audio == NULL) { + m_graph_builder->QueryInterface(IID_IBasicAudio, (void **) &m_basic_audio); + if(FAILED(hr)) { + win_report_error("QueryInterface(IID_IBasicAudio, ...)", hr); + } + } + + if (hEventHandler == NULL) { + unsigned long lpdwThreadID; + hEventHandler = CreateThread(NULL, 0, eventHandler, this, 0, &lpdwThreadID); + } + + hr = m_media_control->Run(); + if(FAILED(hr)) { + win_report_error("IMediaControl::run()", hr); + } + + + LeaveCriticalSection(&m_csSequence); + return true; +} + Modified: branches/amis3/AmisCore/include/Media.h =================================================================== --- branches/amis3/AmisCore/include/Media.h 2008-03-02 19:34:07 UTC (rev 2369) +++ branches/amis3/AmisCore/include/Media.h 2008-03-02 23:02:59 UTC (rev 2370) @@ -63,6 +63,9 @@ string getSrc(); void setSrc(string); + string getSrcExpanded(); + void setSrcExpanded(string); + string getHref(); void setHref(string); @@ -77,6 +80,7 @@ private: string mId; string mSrc; + string mSrcExpanded; string mHref; string mLangCode; MediaNodeType mMediaNodeType; Modified: branches/amis3/AmisCore/src/Media.cpp =================================================================== --- branches/amis3/AmisCore/src/Media.cpp 2008-03-02 19:34:07 UTC (rev 2369) +++ branches/amis3/AmisCore/src/Media.cpp 2008-03-02 23:02:59 UTC (rev 2370) @@ -32,6 +32,7 @@ { mId = ""; mSrc = ""; + mSrcExpanded=""; mHref = ""; mLangCode = ""; } @@ -42,6 +43,8 @@ mId.erase(); mSrc.clear(); mSrc.erase(); + mSrcExpanded.clear(); + mSrcExpanded.erase(); mHref.clear(); mHref.erase(); mLangCode.clear(); @@ -55,6 +58,7 @@ p_new->setLangCode(this->getLangCode()); p_new->setMediaNodeType(this->getMediaNodeType()); p_new->setSrc(this->getSrc()); + p_new->setSrcExpanded(this->getSrcExpanded()); } void amis::MediaNode::setId(string id) { @@ -66,6 +70,11 @@ mSrc.assign(src); } +void amis::MediaNode::setSrcExpanded(string src) +{ + mSrcExpanded.assign(src); +} + void amis::MediaNode::setHref(string href) { mHref.assign(href); @@ -86,6 +95,11 @@ return mSrc; } +string amis::MediaNode::getSrcExpanded() +{ + return mSrcExpanded; +} + string amis::MediaNode::getHref() { return mHref; Modified: branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj =================================================================== --- branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj 2008-03-02 19:34:07 UTC (rev 2369) +++ branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj 2008-03-02 23:02:59 UTC (rev 2370) @@ -292,9 +292,6 @@ Name="self-voicing" Filter=""> <File - RelativePath=".\include\gui\self-voicing\AudioPrompt.h"> - </File> - <File RelativePath=".\include\gui\self-voicing\AudioSequence.h"> </File> <File @@ -764,21 +761,6 @@ Name="self-voicing" Filter=""> <File - RelativePath=".\src\gui\self-voicing\AudioPrompt.cpp"> - <FileConfiguration - Name="Debug|Win32"> - <Tool - Name="VCCLCompilerTool" - UsePrecompiledHeader="0"/> - </FileConfiguration> - <FileConfiguration - Name="Release|Win32"> - <Tool - Name="VCCLCompilerTool" - UsePrecompiledHeader="0"/> - </FileConfiguration> - </File> - <File RelativePath=".\src\gui\self-voicing\AudioSequence.cpp"> <FileConfiguration Name="Debug|Win32"> Deleted: branches/amis3/AmisGuiMFC2/include/gui/self-voicing/AudioPrompt.h =================================================================== --- branches/amis3/AmisGuiMFC2/include/gui/self-voicing/AudioPrompt.h 2008-03-02 19:34:07 UTC (rev 2369) +++ branches/amis3/AmisGuiMFC2/include/gui/self-voicing/AudioPrompt.h 2008-03-02 23:02:59 UTC (rev 2370) @@ -1,103 +0,0 @@ -#ifndef AUDIOPROMPT_H -#define AUDIOPROMPT_H - -#include <string> - -#include "Media.h" - -//!prompt variable structure -/*! - A variable has three properties, a name, a source function, and - a runtime value, like "yellow" or "c:\file" -*/ - -namespace amis -{ -namespace gui -{ -namespace spoken -{ - -class AudioPromptComponent -{ -public: - AudioPromptComponent(); - ~AudioPromptComponent(); - //!is this a variable? - bool mbIsVar; - //!name of the variable - std::string mVarName; - //!value of the variable as given by the source function - std::wstring mRuntimeValue; - //!a media object (if it's not a variable) - amis::MediaNode* mpMedia; - // Text alternative to the audio clip: can be used for TTS or braille. - std::wstring mTextAlternative; - - -}; - -//! prompt structure -/*! - a prompt has a name (like "dialog_intro"), a list of variables (described above), - and a sequence of items to be played. - \n\n - it could also just reference a single audio clip. -*/ -class AudioPrompt -{ -public: - AudioPrompt(); - ~AudioPrompt(); - - //!name of the prompt - std::string mName; - - int mStringResourceID; - - //!list of all actions - vector<AudioPromptComponent*> mSequence; - -}; - -//collection of audio prompts -class AudioPromptCol -{ -protected: - AudioPromptCol(); - -public: - static AudioPromptCol* Instance(); - void DestroyInstance(); - ~AudioPromptCol(); - - //!return a prompt based on its name - AudioPrompt* getPrompt(string); - - //!add a prompt to the collection - void addPrompt(AudioPrompt*); - - //!clear the collection - void clearAll(); - -public: - //!the source file path for the audio prompts XML file - std::string mFilePath; - -private: - //!clean up the collection of prompts - void cleanUpVector(); - - -private: - //!the collection of prompts - vector<AudioPrompt*> mPrompts; - -private: - static AudioPromptCol* pinstance; - - -}; -}}} - -#endif \ No newline at end of file Modified: branches/amis3/AmisGuiMFC2/src/gui/AmisApp.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/AmisApp.cpp 2008-03-02 19:34:07 UTC (rev 2369) +++ branches/amis3/AmisGuiMFC2/src/gui/AmisApp.cpp 2008-03-02 23:02:59 UTC (rev 2370) @@ -53,7 +53,7 @@ #include "gui/dialogs/PreferencesDialog.h" #include "gui/dialogs/PublicationSummaryDialog.h" -#include "AmisAudio.h" +#include "directshow/dx_audio_player.h" //using namespace amis::audio; @@ -226,11 +226,9 @@ amis::gui::MenuManip::Instance()->DestroyInstance(); amis::gui::MainWndParts::Instance()->DestroyInstance(); - if (AudioSequencePlayer::InstanceExists()) { AudioSequencePlayer::Instance()->DestroyInstance(); } - DataTree::Instance()->DestroyInstance(); @@ -301,10 +299,10 @@ //test print to an output file //p_new_data_tree->testPrint("c:\\devel\\amis\\Langpacks\\sandbox\\dataout.txt"); - AudioSequence* seq = new AudioSequence; + /*AudioSequence* seq = new AudioSequence; seq->append(L"AMIS"); seq = AudioSequencePlayer::playPromptFromStringId("canceled", false, seq); - AudioSequencePlayer::Instance()->Play(seq); + AudioSequencePlayer::Instance()->Play(seq);*/ } //if the UI file could not be read, then disable self-voicing @@ -529,7 +527,6 @@ void CAmisApp::OnSpeedUp() { amis::util::Log::Instance()->writeMessage("Speed increase", "CAmisApp::OnSpeedUp", "AmisGuiMFC2"); - amis::audio::AmisAudio::Instance()->adjustRate(1.12); long currentRate = amis::tts::TTSPlayer::Instance()->GetSpeechRate(); amis::tts::TTSPlayer::Instance()->SetSpeechRate(currentRate+2); @@ -543,7 +540,6 @@ void CAmisApp::OnSpeedDown() { amis::util::Log::Instance()->writeMessage("Speed decrease", "CAmisApp::OnSpeedDown", "AmisGuiMFC2"); - amis::audio::AmisAudio::Instance()->adjustRate(-1.12); long currentRate = amis::tts::TTSPlayer::Instance()->GetSpeechRate(); amis::tts::TTSPlayer::Instance()->SetSpeechRate(currentRate-2); @@ -557,11 +553,9 @@ void CAmisApp::OnSpeedNormal() { amis::util::Log::Instance()->writeMessage("Speed reset to normal", "CAmisApp::OnSpeedNormal", "AmisGuiMFC2"); - amis::audio::AmisAudio::Instance()->setRate(1.0); amis::tts::TTSPlayer::Instance()->SetSpeechRate(0); - //TODO: this only works with my local hacked Ambulant API (addition of this setXX() function) ambulant::gui::dx::set_global_rate(1.0); //amis::gui::spoken::AudioSequencePlayer::Instance()->playPromptFromUiId(ID_MENU_PLAY_NORMALSPEED, true, NULL); Modified: branches/amis3/AmisGuiMFC2/src/gui/MainFrm.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/MainFrm.cpp 2008-03-02 19:34:07 UTC (rev 2369) +++ branches/amis3/AmisGuiMFC2/src/gui/MainFrm.cpp 2008-03-02 23:02:59 UTC (rev 2370) @@ -27,7 +27,7 @@ #include "Preferences.h" #include "DtbWithHooks.h" -#include "AmisAudio.h" +#include "directshow/dx_audio_player.h" #include "io/BookmarksFileIO.h" #include "io/ToolbarIO.h" @@ -41,7 +41,6 @@ static char THIS_FILE[] = __FILE__; #endif -using namespace amis::audio; using namespace amis::gui; @@ -306,43 +305,6 @@ tmpstr = A2T(prompt.c_str()); dbg.Format(_T("\tPrompt for this popup 1 = --%s-- \n"), tmpstr); //DAN_MENU_DEBUG TRACE(dbg); - - - - //if this is the view menu, set the sidebar checkmark appropriately - if (prompt.compare("view") == 0) - { - //is sidebar visible? - if (MainWndParts::Instance()->mpSidebar->IsVisible() == TRUE) - { - //pPopupMenu->CheckMenuItem(0, MF_BYPOSITION | MF_CHECKED); - } - else - { - //pPopupMenu->CheckMenuItem(0, MF_BYPOSITION | MF_UNCHECKED); - } - } - - //TODO should this be the book speed ? - if (prompt.compare("play") == 0) - { - if (AmisAudio::Instance()->getRate() == 1.0) - { - //DanToDo: menu items for slow-down / fast-up - //MenuManip::Instance()->setSlowdown(false); - } - else - { - - //DanToDo: menu items for slow-down / fast-up - //MenuManip::Instance()->setSlowdown(true); - } - } - - if (amis::Preferences::Instance()->getIsSelfVoicing() == false) - { - return; - } } void CMainFrame::OnInitMenu(CMenu* pMenu) @@ -510,7 +472,7 @@ } void CMainFrame::OnUpdateCmdUiPlaySlower(CCmdUI* pCmdUi) { - if (theApp.isBookOpen() && amis::audio::AmisAudio::Instance()->getRate() > 1) + if (theApp.isBookOpen() && ambulantX::gui::dx::audio_playerX::Instance()->get_rate() > 1) pCmdUi->Enable(true); else pCmdUi->Enable(false); Deleted: branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioPrompt.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioPrompt.cpp 2008-03-02 19:34:07 UTC (rev 2369) +++ branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioPrompt.cpp 2008-03-02 23:02:59 UTC (rev 2370) @@ -1,139 +0,0 @@ -#include "gui/self-voicing/AudioPrompt.h" - -using namespace amis::gui::spoken; - -//************ -// audio prompt component -//************* -AudioPromptComponent::AudioPromptComponent() -{ - mpMedia = NULL; -} - -AudioPromptComponent::~AudioPromptComponent() -{ - if (mpMedia != NULL) - { - delete mpMedia; - } - - this->mRuntimeValue.clear(); - this->mTextAlternative.clear(); - this->mRuntimeValue.clear(); -} - - - -//************ -// audio prompt -//************* -AudioPrompt::AudioPrompt() -{ - mStringResourceID = -1; -} - -AudioPrompt::~AudioPrompt() -{ - int sz_seq = mSequence.size(); - amis::MediaNode* p_media = NULL; - int i; - - AudioPromptComponent* p_pc = NULL; - - for (i = sz_seq -1; i >=0; i--) - { - p_pc = mSequence[i]; - - mSequence.pop_back(); - - delete p_pc; - } - - this->mName.empty(); - this->mSequence.clear(); -} - -//************ -// audio prompt collection -//************* -AudioPromptCol* AudioPromptCol::pinstance = 0; - -AudioPromptCol* AudioPromptCol::Instance() -{ - if (pinstance == 0) - { - pinstance = new AudioPromptCol; - } - - return pinstance; -} - -void AudioPromptCol::DestroyInstance() -{ - delete pinstance; -} - -AudioPromptCol::AudioPromptCol() -{ -} - -AudioPromptCol::~AudioPromptCol() -{ - cleanUpVector(); - -} - -void AudioPromptCol::clearAll() -{ - cleanUpVector(); -} - -void AudioPromptCol::cleanUpVector() -{ - int sz = mPrompts.size(); - - int i; - - AudioPrompt* p_prompt = NULL; - - for (i = sz -1; i >=0; i--) - { - p_prompt = mPrompts[i]; - - mPrompts.pop_back(); - - delete p_prompt; - - } -} - -void AudioPromptCol::addPrompt(AudioPrompt* pPrompt) -{ - mPrompts.push_back(pPrompt); -} - -AudioPrompt* AudioPromptCol::getPrompt(string promptName) -{ - //search for the macro in the collection - unsigned int i; - bool b_found = false; - - for (i=0; i<mPrompts.size(); i++) - { - if (mPrompts[i]->mName.compare(promptName) == 0) - { - b_found = true; - break; - } - } - - if (b_found == false) - { - return NULL; - } - else - { - return mPrompts[i]; - } - -} \ No newline at end of file Modified: branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioSequencePlayer.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioSequencePlayer.cpp 2008-03-02 19:34:07 UTC (rev 2369) +++ branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioSequencePlayer.cpp 2008-03-02 23:02:59 UTC (rev 2370) @@ -8,7 +8,7 @@ #include "util/FilePathTools.h" -#include "AmisAudio.h" +#include "directshow/dx_audio_player.h" #include "Preferences.h" @@ -20,7 +20,6 @@ //#include "ambulant/net/url.h" -using namespace amis::audio; using namespace amis::tts; using namespace amis::gui::spoken; @@ -97,7 +96,7 @@ m_wakeUpOriginator = -1; m_nEndEventsToExpect = 0; - AmisAudio::Instance()->setCallback((sendMessageCallbackFn)clipFinishedCallback); + ambulantX::gui::dx::audio_playerX::Instance()->setCallback((sendMessageCallbackFn)clipFinishedCallback); TTSPlayer::Instance()->setCallback((sendMessageCallbackFn)ttsFinishedCallback); @@ -126,11 +125,10 @@ if (pinstance != NULL) { Stop(); + ambulantX::gui::dx::audio_playerX::Instance()->DestroyInstance(); + TTSPlayer::Instance()->DestroyInstance(); delete pinstance; } - - AmisAudio::Instance()->DestroyInstance(); - TTSPlayer::Instance()->DestroyInstance(); } AudioSequencePlayer::~AudioSequencePlayer(void) @@ -207,11 +205,12 @@ //TTSPlayer::Instance()->WaitUntilDone(); TRACE(L"####### -- STOP TTS"); } - if (AmisAudio::Instance()->isPlaying()) { + + if (ambulantX::gui::dx::audio_playerX::Instance()->is_playing()) { //bExpectEndEventForWakeUp = true; //m_nEndEventsToExpect++; //ResetEvent(pThis->m_hEventWakeup); - AmisAudio::Instance()->stopX(); + ambulantX::gui::dx::audio_playerX::Instance()->stop(false); //m_wakeUpOriginator = 3; // AUDIO CLIP END //SetEvent(m_hEventWakeup); TRACE(L"####### -- STOP AUDIO"); @@ -282,11 +281,11 @@ //TTSPlayer::Instance()->WaitUntilDone(); TRACE(L"####### STOP TTS"); } - if (AmisAudio::Instance()->isPlaying()) { + if (ambulantX::gui::dx::audio_playerX::Instance()->is_playing()) { //bExpectEndEventForWakeUp = true; //m_nEndEventsToExpect++; //ResetEvent(pThis->m_hEventWakeup); - AmisAudio::Instance()->stopX(); + ambulantX::gui::dx::audio_playerX::Instance()->stop(false); //m_wakeUpOriginator = 3; // AUDIO CLIP END //SetEvent(m_hEventWakeup); TRACE(L"####### STOP AUDIO"); @@ -334,11 +333,23 @@ if (str.length()==0) { return; } - ambulant::net::url audio_src = ambulant::net::url::from_filename(str); - amis::ModuleDescData* p_langpack_data = amis::Preferences::Instance()->getCurrentLanguageData(); - audio_src = audio_src.join_to_base(*p_langpack_data->getXmlFileName()); + string strFull = pAudio->getSrcExpanded(); + if (strFull.length()==0) { + ambulant::net::url audio_src = ambulant::net::url::from_filename(str); + + amis::ModuleDescData* p_langpack_data = amis::Preferences::Instance()->getCurrentLanguageData(); + audio_src = audio_src.join_to_base(*p_langpack_data->getXmlFileName()); + + pAudio->setSrcExpanded(audio_src.get_file()); + strFull = pAudio->getSrcExpanded(); + } + + ambulantX::gui::dx::audio_playerX::Instance()->play(strFull.c_str()); + + + /* string clipBegin = ""; string clipEnd = ""; @@ -350,17 +361,9 @@ if (pAudio->getClipEnd().size() > 0) { clipEnd = stringReplaceAll(pAudio->getClipEnd(), "npt=", ""); - } + }*/ - - /* AmisAudio::Instance()->play(audio_src, - (char*)clipBegin.c_str(), - (char*)clipEnd.c_str()); */ - - string src = audio_src.get_file(); - AmisAudio::Instance()->play(src.c_str(), - (char*)clipBegin.c_str(), - (char*)clipEnd.c_str()); + //(char*)clipBegin.c_str(), (char*)clipEnd.c_str()); } unsigned __stdcall AudioSequencePlayer::ThreadProc(void* Arg) @@ -510,7 +513,7 @@ ResetEvent(pThis->m_hEventWakeup); TRACE(L"\n============ PLAY AUDIO CLIP\n"); if (!pThis->m_bAbort) { - /* while (AmisAudio::Instance()->isPlaying()) { + /* while (ambulantX::gui::dx::audio_playerX::Instance()->isPlaying()) { TRACE(L"\nIS PLAYING..."); Sleep(500); } */ Modified: branches/amis3/AmisGuiMFC2/src/gui/self-voicing/TTSPlayer.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/self-voicing/TTSPlayer.cpp 2008-03-02 19:34:07 UTC (rev 2369) +++ branches/amis3/AmisGuiMFC2/src/gui/self-voicing/TTSPlayer.cpp 2008-03-02 23:02:59 UTC (rev 2370) @@ -175,10 +175,11 @@ { //m_iV(NULL) m_iV = NULL; - +#ifdef _DEBUG HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); if (hr == S_FALSE) CoUninitialize(); assert(hr == S_FALSE); +#endif hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_INPROC_SERVER, IID_ISpVoice, (void**) &m_iV); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |