[Amis-vcs] SF.net SVN: amis: [2345] branches/amis3
Brought to you by:
julienq,
marisademeglio
From: <dan...@us...> - 2008-02-26 22:44:10
|
Revision: 2345 http://amis.svn.sourceforge.net/amis/?rev=2345&view=rev Author: daniel_weck Date: 2008-02-26 14:44:16 -0800 (Tue, 26 Feb 2008) Log Message: ----------- - Changed audio backend. Now compiles in Release and Debug mode. Problem when loading books in Release mode (graceful, but no book playback at all). Volume and Speed are ultra-buggy. Modified Paths: -------------- branches/amis3/AmisAudio/AmisAudio.vcproj branches/amis3/AmisAudio/include/AmisAudio.h branches/amis3/AmisAudio/src/AmisAudio.cpp branches/amis3/AmisCore/AmisCore.vcproj 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/VC7/amis.sln Added Paths: ----------- branches/amis3/AmisAudio/include/directshow/ branches/amis3/AmisAudio/include/directshow/dx_audio_player.h branches/amis3/AmisAudio/src/directshow/ branches/amis3/AmisAudio/src/directshow/dx_audio_player.cpp Removed Paths: ------------- branches/amis3/AmisAudio/include/TPBReader/ branches/amis3/AmisAudio/include/directx/ branches/amis3/AmisAudio/src/TPBReader/ Modified: branches/amis3/AmisAudio/AmisAudio.vcproj =================================================================== --- branches/amis3/AmisAudio/AmisAudio.vcproj 2008-02-26 17:27:09 UTC (rev 2344) +++ branches/amis3/AmisAudio/AmisAudio.vcproj 2008-02-26 22:44:16 UTC (rev 2345) @@ -17,7 +17,7 @@ OutputDirectory="../bin" IntermediateDirectory="./Debug" ConfigurationType="2" - UseOfMFC="0" + UseOfMFC="2" ATLMinimizesCRunTimeLibraryUsage="FALSE" CharacterSet="1"> <Tool @@ -26,7 +26,7 @@ AdditionalIncludeDirectories=""./include/";../AmisGuiMFC2/include/";"../AmisCore/include/"" PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_WINDOWS;_USRDLL;AMISAUDIO_EXPORTS" BasicRuntimeChecks="3" - RuntimeLibrary="1" + RuntimeLibrary="3" UsePrecompiledHeader="0" PrecompiledHeaderThrough="StdAfx.h" PrecompiledHeaderFile="./Debug/AmisAudio.pch" @@ -40,13 +40,13 @@ <Tool Name="VCLinkerTool" AdditionalOptions="/FORCE:MULTIPLE" - AdditionalDependencies="Strmiids.lib TransformSample.lib stlib.lib kernel32.lib gdi32.lib user32.lib AmisCoreD.lib" + AdditionalDependencies="libambulant_shwin32_D.lib stlib.lib kernel32.lib gdi32.lib user32.lib" ShowProgress="2" - OutputFile="../bin/AmisAudioD.dll" + OutputFile="$(OutDir)/$(ProjectName)D.dll" LinkIncremental="1" SuppressStartupBanner="TRUE" AdditionalLibraryDirectories="../lib" - IgnoreDefaultLibraryNames="libc.lib" + IgnoreDefaultLibraryNames="" GenerateDebugInformation="TRUE" ProgramDatabaseFile="./Debug/AmisAudioD.pdb" ImportLibrary="../lib/AmisAudioD.lib" @@ -82,20 +82,20 @@ </Configuration> <Configuration Name="Release|Win32" - OutputDirectory="../lib" + OutputDirectory="../bin" IntermediateDirectory="Release" - ConfigurationType="4" - UseOfMFC="0" + ConfigurationType="2" + UseOfMFC="2" ATLMinimizesCRunTimeLibraryUsage="FALSE" CharacterSet="1"> <Tool Name="VCCLCompilerTool" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories=""../AmisGuiMFC2/include/";"../AmisCore/include/"" + AdditionalIncludeDirectories=""./include/";"../AmisGuiMFC2/include/";"../AmisCore/include/"" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;AMISAUDIO_EXPORTS" StringPooling="TRUE" - RuntimeLibrary="0" + RuntimeLibrary="2" EnableFunctionLevelLinking="TRUE" UsePrecompiledHeader="0" PrecompiledHeaderThrough="stdafx.h" @@ -109,7 +109,13 @@ <Tool Name="VCCustomBuildTool"/> <Tool - Name="VCLibrarianTool"/> + Name="VCLinkerTool" + AdditionalOptions="/FORCE:MULTIPLE" + AdditionalDependencies="libambulant_shwin32.lib stlib.lib kernel32.lib gdi32.lib user32.lib" + AdditionalLibraryDirectories="../lib" + IgnoreDefaultLibraryNames="" + ImportLibrary="../lib/AmisAudio.lib" + TargetMachine="1"/> <Tool Name="VCMIDLTool" PreprocessorDefinitions="NDEBUG" @@ -133,6 +139,8 @@ <Tool Name="VCXMLDataGeneratorTool"/> <Tool + Name="VCWebDeploymentTool"/> + <Tool Name="VCManagedWrapperGeneratorTool"/> <Tool Name="VCAuxiliaryManagedWrapperGeneratorTool"/> @@ -151,44 +159,11 @@ RelativePath=".\include\StdAfx.h"> </File> <Filter - Name="TPBReader" + Name="directshow" Filter=""> <File - RelativePath=".\include\TPBReader\dmp.h"> + RelativePath=".\include\directshow\dx_audio_player.h"> </File> - <File - RelativePath=".\include\TPBReader\DmpCtl.h"> - </File> - <File - RelativePath=".\include\TPBReader\DmpPpg.h"> - </File> - <File - RelativePath=".\include\TPBReader\intvec.h"> - </File> - <File - RelativePath=".\include\TPBReader\iTPBTS.h"> - </File> - <File - RelativePath=".\include\TPBReader\RegOcx.h"> - </File> - <File - RelativePath=".\include\TPBReader\Resource.h"> - </File> - <File - RelativePath=".\include\TPBReader\StdAfxFIX.h"> - </File> - <File - RelativePath=".\include\TPBReader\TransformSample.h"> - </File> - <File - RelativePath=".\include\TPBReader\Vupp1.h"> - </File> - <File - RelativePath=".\include\TPBReader\VuppInterface.h"> - </File> - <File - RelativePath=".\include\TPBReader\VuppSample.h"> - </File> </Filter> <Filter Name="mffmTimeCode" @@ -215,112 +190,6 @@ RelativePath=".\include\mffmTimeCode\win32fix.H"> </File> </Filter> - <Filter - Name="directx" - Filter=""> - <File - RelativePath=".\include\directx\amextra.h"> - </File> - <File - RelativePath=".\include\directx\amfilter.h"> - </File> - <File - RelativePath=".\include\directx\cache.h"> - </File> - <File - RelativePath=".\include\directx\combase.h"> - </File> - <File - RelativePath=".\include\directx\cprop.h"> - </File> - <File - RelativePath=".\include\directx\ctlutil.h"> - </File> - <File - RelativePath=".\include\directx\ddmm.h"> - </File> - <File - RelativePath=".\include\directx\dllsetup.h"> - </File> - <File - RelativePath=".\include\directx\dsschedule.h"> - </File> - <File - RelativePath=".\include\directx\fourcc.h"> - </File> - <File - RelativePath=".\include\directx\measure.h"> - </File> - <File - RelativePath=".\include\directx\msgthrd.h"> - </File> - <File - RelativePath=".\include\directx\mtype.h"> - </File> - <File - RelativePath=".\include\directx\outputq.h"> - </File> - <File - RelativePath=".\include\directx\pstream.h"> - </File> - <File - RelativePath=".\include\directx\pullpin.h"> - </File> - <File - RelativePath=".\include\directx\refclock.h"> - </File> - <File - RelativePath=".\include\directx\reftime.h"> - </File> - <File - RelativePath=".\include\directx\renbase.h"> - </File> - <File - RelativePath=".\include\directx\schedule.h"> - </File> - <File - RelativePath=".\include\directx\seekpt.h"> - </File> - <File - RelativePath=".\include\directx\source.h"> - </File> - <File - RelativePath=".\include\directx\streams.h"> - </File> - <File - RelativePath=".\include\directx\strmctl.h"> - </File> - <File - RelativePath=".\include\directx\sysclock.h"> - </File> - <File - RelativePath=".\include\directx\transfrm.h"> - </File> - <File - RelativePath=".\include\directx\transip.h"> - </File> - <File - RelativePath=".\include\directx\videoctl.h"> - </File> - <File - RelativePath=".\include\directx\vtrans.h"> - </File> - <File - RelativePath=".\include\directx\winctrl.h"> - </File> - <File - RelativePath=".\include\directx\winutil.h"> - </File> - <File - RelativePath=".\include\directx\wxdebug.h"> - </File> - <File - RelativePath=".\include\directx\wxlist.h"> - </File> - <File - RelativePath=".\include\directx\wxutil.h"> - </File> - </Filter> </Filter> <Filter Name="src" @@ -332,35 +201,11 @@ RelativePath=".\src\StdAfx.cpp"> </File> <Filter - Name="TPBReader" + Name="directshow" Filter=""> <File - RelativePath=".\src\TPBReader\dmp.cpp"> + RelativePath=".\src\directshow\dx_audio_player.cpp"> </File> - <File - RelativePath=".\src\TPBReader\DmpCtl.cpp"> - </File> - <File - RelativePath=".\src\TPBReader\DmpPpg.cpp"> - </File> - <File - RelativePath=".\src\TPBReader\RegOcx.cpp"> - </File> - <File - RelativePath=".\src\TPBReader\StdAfx.cpp"> - <FileConfiguration - Name="Debug|Win32"> - <Tool - Name="VCCLCompilerTool" - ObjectFile="$(IntDir)/$(InputName)1.obj"/> - </FileConfiguration> - <FileConfiguration - Name="Release|Win32"> - <Tool - Name="VCCLCompilerTool" - ObjectFile="$(IntDir)/$(InputName)1.obj"/> - </FileConfiguration> - </File> </Filter> </Filter> <File Modified: branches/amis3/AmisAudio/include/AmisAudio.h =================================================================== --- branches/amis3/AmisAudio/include/AmisAudio.h 2008-02-26 17:27:09 UTC (rev 2344) +++ branches/amis3/AmisAudio/include/AmisAudio.h 2008-02-26 22:44:16 UTC (rev 2345) @@ -1,10 +1,10 @@ /* -AmisAudio +AMIS: Adaptive Multimedia Information System +Software for playing DAISY books +Homepage: http://amis.sf.net -Copyright (C) 2005 DAISY for All Project +Copyright (C) 2004-2007 DAISY for All Project -Licensing note: This file is released as LGPL; however, its module relies upon GPL code in third party libraries. Any reuse of this library in a closed source environment must contact the GPL license holders to negotiate terms for use with an altered license. GPL code referenced from this module includes, but may not be limited to, libfftw, WSOLA code by Matt Flax, and stlib. - 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 @@ -19,6 +19,7 @@ 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 @@ -29,120 +30,64 @@ // defined with this macro as being exported. */ +//#undef AMISAUDIO_EXPORTS + #ifdef AMISAUDIO_EXPORTS #define AMISAUDIO_API __declspec(dllexport) #else -#define AMISAUDIO_API __declspec(dllimport) +#define AMISAUDIO_API #endif -///This gets rid of some warnings -#pragma warning(disable : 4786) - - -#include "TPBReader/DmpCtl.h" -#include "TPBReader/Dmp.h" - -//#include <windows.h> - +#include "directshow/dx_audio_player.h" #include "mffmTimeCode/smilTimeCode.H" -//for message sending ... -typedef void (*sendMessageCallbackFn)(); -//using namespace std; - -enum State{NOTACTIVE,PAUSE,PLAYING}; //ACTIVE - - #ifdef _MSC_VER #pragma warning(disable : 4251) #endif -/** This class is exported from the AmisAudio.dll*/ +#pragma warning(disable : 4786) +typedef void (*sendMessageCallbackFn)(void); + namespace amis { -namespace audio -{ -class AMISAUDIO_API AmisAudio -{ -protected: - ///Constructor which is used to ensure callbacks are executed once a stream is played - //AmisAudio(HWND parentWindow); - ///Constructor which executes no callback once a stream is played - AmisAudio(); + namespace audio + { + class AMISAUDIO_API AmisAudio + { + protected: + AmisAudio(); -public: - - static AmisAudio* Instance(); - - ///Deconstructor - ~AmisAudio (); + public: + static AmisAudio* Instance(); + ~AmisAudio (); + static void DestroyInstance(); + void play(const char * url,char* clipBegin,char* clipEnd); + void pause(); + void resume(); + void stopX(); - static void DestroyInstance(); - - - void setStatePause(); + bool isPlaying(); + double getVolume(); + void setVolume (double); - //functions related to enabling/disabling audio - //these were added so that screen readers could ask AMIS to be quiet - void enableAudioPlayback(); - void disableAudioPlayback(); - bool isAudioPlaybackEnabled(); - -private: + void adjustVolume(double); + void adjustRate(double); - //private member functions - //Look in the cpp source for comments on what these functions do. + double getRate(); + void setRate(double); -public: - void enable(); - void disable(); - void play(const char *filename,char* clipBegin,char* clipEnd); + sendMessageCallbackFn sendMessageCallback; + void setCallback(sendMessageCallbackFn pFunction); - - -public: - void stop(); - void pause(); - int resume(); - double getVolume(); - void setVolume (double); - double getRate(); - void setRate(double); - bool isPlaying(); - bool isActive(); - - void adjustVolume(double); - void adjustRate(double); - - typedef void (*sendMessageCallbackFn)(void); - void setCallback(sendMessageCallbackFn pFunction); - -private: - void ShowStatePrompt(); - - //member variables - std::string mFileName; //The file name being played - double mVolume; //The volume of the stream - - State mState; //The state of the player - double mTau; //This is the playback speed - - //is the audio playback enabled? - bool mbAudioPlaybackEnabled; - -private: - static AmisAudio* pinstance; - - - CDmpCtrl* pDmpCtrl; - //CDmpApp* pDmpApp; -}; - + private: + static AmisAudio* pinstance; + ambulantX::gui::dx::audio_playerX *m_player; + }; + } } -} #endif \ No newline at end of file Added: branches/amis3/AmisAudio/include/directshow/dx_audio_player.h =================================================================== --- branches/amis3/AmisAudio/include/directshow/dx_audio_player.h (rev 0) +++ branches/amis3/AmisAudio/include/directshow/dx_audio_player.h 2008-02-26 22:44:16 UTC (rev 2345) @@ -0,0 +1,202 @@ +/* + * This file is part of Ambulant Player, www.ambulantplayer.org. + * + * Copyright (C) 2003-2008 Stichting CWI, + * Kruislaan 413, 1098 SJ Amsterdam, The Netherlands. + * + * Ambulant Player 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. + * + * Ambulant Player 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 Ambulant Player; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + * @$Id: dx_audio_player.h,v 1.21 2008/01/15 10:54:48 jackjansen Exp $ + */ + +#ifndef AMBULANT_GUI_DX_AUDIO_PLAYERX_H +#define AMBULANT_GUI_DX_AUDIO_PLAYERX_H + +#include "ambulant/config/config.h" + +#include <string> +#include <cmath> + +#include <objbase.h> +#include <strmif.h> +#include <control.h> + +#include <initguid.h> + +//#include "ambulant/common/playable.h" +//#include "ambulant/lib/win32/win32_error.h" +//#include "ambulant/lib/logger.h" + +#ifndef AMBULANT_PLATFORM_WIN32_WCE +#pragma comment (lib,"winmm.lib") +#pragma comment (lib,"amstrmid.lib") +#endif +#pragma comment (lib,"strmiids.lib") +#pragma comment (lib,"uuid.lib") + +#ifndef AMBULANT_PLATFORM_WIN32_WCE +#define WITH_TPB_AUDIO_SPEEDUP +#endif + +#ifdef WITH_TPB_AUDIO_SPEEDUP +// If this option is active during build (which is true when building +// for AmisAmbulant) we try to insert the TPB Audio Speedup/Slowdown +// filter into our filtergraph. This allows for changing audio playback +// speed without altering pitch. +// If the TPB DirectShow filter is not available we do nothing. +#include <set> + +DEFINE_GUID(CLSID_TPBVupp69, + 0x66172967, 0x56c5, 0x4b89, 0xaa, 0x92, 0xc9, 0xef, 0xec, 0x56, 0x46, 0x7b); + + +#ifdef __cplusplus +extern "C" { +#endif + +// {A33E626E-D6C4-4559-A1D6-9F1D95F0D8E2} +DEFINE_GUID(IID_IVuppInterface, +0xa33e626e, 0xd6c4, 0x4559, 0xa1, 0xd6, 0x9f, 0x1d, 0x95, 0xf0, 0xd8, 0xe2); + +DECLARE_INTERFACE_(IVuppInterface, IUnknown) { + + //Deklarera metoder: + STDMETHOD(setCrossFadeSpeed) + ( THIS_ + double speed + ) PURE; + + STDMETHOD(setWindowLength) + ( THIS_ + int length + ) PURE; + + STDMETHOD(setCycleSpeed) + ( THIS_ + short speed + ) PURE; + + STDMETHOD(setSilenceLoudnessThreshold) + ( THIS_ + short threshold + ) PURE; + + STDMETHOD(setSilenceRemainderLength) + ( THIS_ + short length + ) PURE; + + STDMETHOD(setSilenceSpeed) + ( THIS_ + short speed + ) PURE; + + STDMETHOD(getPosition) + ( THIS_ + LONGLONG &position + ) PURE; +}; + +#ifdef __cplusplus +} +#endif + + + +#endif // WITH_TPB_AUDIO_SPEEDUP + +typedef void (*sendMessageCallbackFn)(void); + +static double s_current_playback_rate = 1.0; + +namespace ambulantX { + +namespace gui { + +namespace dx { + +class audio_playerX { + + typedef std::pair<bool, double> duration; + + public: + void setCallback(sendMessageCallbackFn pFunction); + + audio_playerX(const char * url); + ~audio_playerX(); + + void start(double t); + void stop(); + //void pause(common::pause_display d=common::display_show); + void pause(void); + void resume(); + void seek(double t); + void endseek(double t); + duration get_dur(); + void wantclicks(bool want) {} + void preroll(double when, double where, double how_much) {} + + bool can_play(); + bool is_playing(); + double get_position(); + + // -val is the attenuation in decibels + // can be 0 to 100 + void set_volume(long val); + + // can be -100 to 100 + // 0 sets a neutral balance + // and 10 sets -10 db to right and -90 db to left + void set_balance(long val); + + private: + + bool open(const char * url); + void release_player(); + + std::string m_url; + + IGraphBuilder *m_graph_builder; + IMediaControl *m_media_control; + IMediaPosition *m_media_position; + IBasicAudio *m_basic_audio; + + HANDLE hEventHandler; + +public: + IMediaEvent *m_media_event; + sendMessageCallbackFn sendMessageCallback; + bool bCatchEvents; + bool bProcessEvents; + +#ifdef WITH_TPB_AUDIO_SPEEDUP + public: + void set_rate(double rate); + private: + IVuppInterface *m_audio_speedup; + void initialize_speedup_filter(); +#endif +}; + +} // namespace dx + +} // namespace gui + +} // namespace ambulantX + +#endif // AMBULANT_GUI_DX_AUDIO_PLAYERX_H + Modified: branches/amis3/AmisAudio/src/AmisAudio.cpp =================================================================== --- branches/amis3/AmisAudio/src/AmisAudio.cpp 2008-02-26 17:27:09 UTC (rev 2344) +++ branches/amis3/AmisAudio/src/AmisAudio.cpp 2008-02-26 22:44:16 UTC (rev 2345) @@ -1,10 +1,10 @@ /* -AmisAudio +AMIS: Adaptive Multimedia Information System +Software for playing DAISY books +Homepage: http://amis.sf.net -Copyright (C) 2005 DAISY for All Project +Copyright (C) 2004-2007 DAISY for All Project -Licensing note: This file is released as LGPL; however, its module relies upon GPL code in third party libraries. Any reuse of this library in a closed source environment must contact the GPL license holders to negotiate terms for use with an altered license. GPL code referenced from this module includes, but may not be limited to, libfftw, WSOLA code by Matt Flax, and stlib. - 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 @@ -19,596 +19,208 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// AmisAudio.cpp : Defines the entry point for the DLL application. - #include <stdlib.h> #include <iostream> #include <string> -#include "AmisAudio.h" - #include <process.h> + +#include "AmisAudio.h" using namespace amis::audio; -//#include "win32Fix.H" - -//#include "../AmisGuiMFC/Brain/Preferences.h" - - +#ifdef AMISAUDIO_EXPORTS BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { - switch (ul_reason_for_call) + switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; - } - return TRUE; + } + return TRUE; } +#endif - namespace amis { -namespace audio -{ -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(HWND parentWindow) -{ - mState=NOTACTIVE; - mVolume=100; - mWsolaSource=NULL; - - parentWnd=parentWindow; -}*/ - -AmisAudio::AmisAudio() -{ - //pDmpApp = 0; - pDmpCtrl = 0; - mTau=1.0; - mState=NOTACTIVE; - mVolume=1.0; - - mbAudioPlaybackEnabled = true; - - pDmpCtrl = new CDmpCtrl(); -} - -void AmisAudio::setCallback(sendMessageCallbackFn pFunction) -{ - pDmpCtrl->setCallback(pFunction); -} -/****************************************************************** -AmisAudio destructor Function -******************************************************************/ - - -AmisAudio::~AmisAudio() -{ - if (pDmpCtrl) delete pDmpCtrl; - - /*clean up code goes here*/ -} - -void AmisAudio::DestroyInstance() -{ - if (pinstance) delete pinstance; -} - -void AmisAudio::setStatePause() { - mState = PAUSE; - -} - - -/*-------------------------------------------------------------------------------------------------------------------------- -This function enables Audio plugin, initializes rate to 1.0 and volume to 100 -----------------------------------------------------------------------------------------------------------------------------*/ -void AmisAudio::enable() -{ - if (pDmpCtrl) { - mState=PAUSE; //ACTIVE - mTau=1.0; - mVolume = 1.0; - return; - } - switch(mState) + namespace audio { - case NOTACTIVE: + + /* + void AmisAudio::play(ambulant::net::url url,char* clipBegin,char* clipEnd) { + std::string str; + str.assign(url.get_file().c_str()); - mState=PAUSE; //ACTIVE - // mRate = 1.0; - mTau=1.0; - mVolume = 1.0; - return; - } - default: - return; - //return"Audio Plugin is already enabled"; - } -} + 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); -/*-------------------------------------------------------------------------------------------------------------------------- -This function disables Audio plugin -----------------------------------------------------------------------------------------------------------------------------*/ -void AmisAudio::disable() -{ - switch(mState) - { - //case ACTIVE: - case PLAYING: - case PAUSE: - //if(mState==PLAYING) - { - stop(); - ShowStatePrompt(); - mState=NOTACTIVE; - ShowStatePrompt(); - mState=NOTACTIVE; - return; - //return"Audio plugin has been disabled!!"; + 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; } - case NOTACTIVE: + else if(url.is_absolute()) { + m_player = new ambulantX::gui::dx::audio_playerX(url.get_url()); + } + else { return; - //return"Audio plugin is not enabled."; - - } - -} + } + */ + void AmisAudio::play(const char * url,char* clipBegin,char* clipEnd) + { + m_player = 0; + m_player = new ambulantX::gui::dx::audio_playerX(url); + SmilTimeCode startStop(clipBegin, clipBegin, clipEnd); + int begin=startStop.getStart(); + int end=startStop.getEnd(); -/**************************************************************** -play(char *filename,char* clipBegin,char* clipEnd) function -****************************************************************/ - -void AmisAudio::play(const char *filename,char* clipBegin,char* clipEnd){ - - - if (mbAudioPlaybackEnabled == false) - { - - return; - } - - mFileName.assign(filename); - int channel; - - //Format the beg and end from string to timeCode - SmilTimeCode startStop(clipBegin, clipBegin, clipEnd); - - unsigned long begin,end; - - ShowStatePrompt(); - - - - - switch(mState) - { - - case NOTACTIVE: - { - return; - //return "Audio plugin is not enabled.\n"; - break; + if (begin!=0){ + int q =1; } - //case ACTIVE: - case PAUSE: - case PLAYING: - { - if (pDmpCtrl) { - - if (mbAudioPlaybackEnabled == false) - { - return; - } - //stop(); - if (!pDmpCtrl->fileName(filename)) { - - pDmpCtrl->destroyFilterGraph(); - return; - } - pDmpCtrl->insertVupp(); - - begin=startStop.getStart(); - end=startStop.getEnd(); - if (! (begin == 0 && end == 0)) { - - if (begin >= 0 && begin < pDmpCtrl->getDuration()) { - pDmpCtrl->setPosition(begin); - } - - if (end >= 0 && end > begin && end < pDmpCtrl->getDuration()) { - pDmpCtrl->setStopPosition(end); - } - } - - pDmpCtrl->setVolume((long)(100*mVolume)); - pDmpCtrl->play(); - mState = PLAYING; - return; - } - - //return "now playing\n" ; + if (end!=0){ + int q =1; } - } - -} // end method + //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(sendMessageCallback); + + m_player->start(begin); + } -/**************************************************************** -stop() function -****************************************************************/ + AmisAudio* AmisAudio::pinstance = 0; -void AmisAudio::stop() -{ - switch(mState) - { - - case NOTACTIVE: - { - return; - //return "Audio plugin is not enabled.\n"; + AmisAudio* AmisAudio::Instance() + { + if (pinstance == 0) // is it the first call? + { + pinstance = new AmisAudio; // create sole instance } - - /*case ACTIVE: - { - return; - //return"No file is playing"; - }*/ + return pinstance; // address of sole instance + } - case PLAYING : - { - mState = PAUSE; //ACTIVE - - if (pDmpCtrl) { - pDmpCtrl->stop(); - //pDmpCtrl->pause(); - return; - } + AmisAudio::AmisAudio() + { + m_player = 0; + } + void AmisAudio::setCallback(sendMessageCallbackFn pFunction) + { + sendMessageCallback = pFunction; + if (m_player) { + m_player->setCallback(pFunction); + } + } - return; - //return"The playing file has been stopped"; + AmisAudio::~AmisAudio() + { + if (m_player) { + delete m_player; // stop() and release_player() handled by destructor } - - case PAUSE : - { - mState = PAUSE; //ACTIVE + m_player = 0; + } - + void AmisAudio::DestroyInstance() + { + if (pinstance) delete pinstance; + } - return; - //return"The playing file has been stopped"; - + bool AmisAudio::isPlaying() + { + if (m_player) { + return m_player->is_playing(); + } else { + return false; } - } -} - - - - -/**************************************************************** -pause() function -****************************************************************/ + } -void AmisAudio::pause(){ - - - switch(mState) - { - - case NOTACTIVE: - { - return; - //return "Audio plugin is not enabled.\n"; - + void AmisAudio::pause() + { + if (m_player) { + m_player->pause(); } - - /* case ACTIVE : - { - return; - //return "The plugin is already stopped."; - } */ - case PLAYING : - { - mState=PAUSE; + } - if (pDmpCtrl) { - //pDmpCtrl->stop(); - pDmpCtrl->pause(); - return; - } - - return; - //return"The plugin is paused"; + void AmisAudio::resume() + { + if (m_player) { + m_player->resume(); } - - - - case PAUSE : - { - return; - //return "The plugin is already paused."; + } + void AmisAudio::stopX() + { + if (m_player) { + m_player->stop(); } - - } -} + m_player = 0; + } - -/**************************************************************** -resume() function -****************************************************************/ - -int AmisAudio::resume(){ - - - switch(mState) - { - - case NOTACTIVE: - { - return -1; - //return "Audio plugin is not enabled.\n"; - - } - - //case ACTIVE : - case PAUSE : + double AmisAudio::getVolume() { - - - if (pDmpCtrl) { - - pDmpCtrl->play(); - mState=PLAYING; - return 0; - } - - //return"The plugin is resumed"; - + if (m_player) { + //return m_player->get_volume(); TODO: implement this + return 100.0; + } else { + return 100.0; + } } - - case PLAYING : + + void AmisAudio::setVolume(double value) { - return 0; - //return"The plugin is not in paused state"; + if (m_player) { + m_player->set_volume(value); + } } - - - } - -} - -/**************************************************************** -getVolume() function -****************************************************************/ -double AmisAudio::getVolume() -{ - - return mVolume; -} - - -/**************************************************************** -setVolume(char * value) function -****************************************************************/ -void AmisAudio::setVolume(double value) -{ - mVolume = value; - - switch(mState) - { - - case NOTACTIVE: + void AmisAudio::adjustVolume(double adjustment) { - return; - //return "Audio plugin is not enabled.\n"; - + if (m_player) { + m_player->set_volume(adjustment); // TODO this won't work ! + } } - - //case ACTIVE : - case PAUSE : - case PLAYING : - { - - if (pDmpCtrl) { - - pDmpCtrl->setVolume((long)(100*mVolume)); - - return ; - } - } - } -} -//adjustment is positive or negative (louder or softer) -void AmisAudio::adjustVolume(double adjustment) -{ -mVolume *= adjustment; - - setVolume(mVolume); -} - - -void AmisAudio::adjustRate(double adjustment) -{ - if (pDmpCtrl) { - double value = mTau + adjustment; - setRate(value); - } -} - - -/**************************************************************** -getRate() function -****************************************************************/ - -double AmisAudio::getRate() -{ - return mTau; -} - -/**************************************************************** -setRate() function -****************************************************************/ - -void AmisAudio::setRate(double value){ - - - switch(mState) + void AmisAudio::adjustRate(double adjustment) { - - case NOTACTIVE: - { - return; - //return "Audio plugin is not enabled.\n"; - + if (m_player) { + m_player->set_rate(adjustment); // TODO this won't work ! } - - //case ACTIVE : - case PAUSE : - case PLAYING : - { - if (pDmpCtrl) { + } - mTau=value; - - if (mTau > 1.0) { - double offset = mTau - 1.0; - /* int n = offset / 0.2; - offset *= 6; - offset = n * 0.5; */ - //mTau = 1 - offset; - } - if (mTau < 1.0) { - double offset = 1.0 - mTau; - - mTau = 0.5; - - /* int n = offset / 0.2; - offset *= 6; - offset = n * 0.5; */ - //mTau = 1 + offset; - } - //if (mTau > 3) mTau = 3; - //if (mTau < 1) mTau = 1; - - //mTau=value; - - pDmpCtrl->setRate(mTau); - return; - } - - + double AmisAudio::getRate() + { + if (m_player) { + //return m_player->get_rate(); TODO: Implement this + return 1.0; + } else { + return 1.0; } - - - - } - - -} // end method - - - - -/**************************************************************** - isPlaying() function -****************************************************************/ - -bool AmisAudio::isPlaying() -{ + } - if(mState==PLAYING) - { - return true; - } - else - { - return false; - } - - -} - -bool AmisAudio::isActive() -{ - - return (mState==PAUSE || mState==PLAYING); - -} - /**************************************************************** - ShowStatePropmt() function - ****************************************************************/ - - - void AmisAudio::ShowStatePrompt(){ - - switch(mState){ - - case NOTACTIVE: { - std::cout<<"Not Active"<<endl; - break; - } - - /* case ACTIVE: { - std::cout<<" Active"<<endl; - break; - } */ - - case PAUSE: { - std::cout<<" Pause"<<endl; - break; - } - - case PLAYING: { - std::cout<<" Playing"<<endl; - } - - + void AmisAudio::setRate(double value){ + if (m_player) { + m_player->set_rate(value); + } } - } - - - void AmisAudio::enableAudioPlayback() - { - mbAudioPlaybackEnabled = true; - } - - void AmisAudio::disableAudioPlayback() - { - mbAudioPlaybackEnabled = false; - } - - bool AmisAudio::isAudioPlaybackEnabled() - { - return mbAudioPlaybackEnabled; - } - -}} \ No newline at end of file +} \ No newline at end of file Added: branches/amis3/AmisAudio/src/directshow/dx_audio_player.cpp =================================================================== --- branches/amis3/AmisAudio/src/directshow/dx_audio_player.cpp (rev 0) +++ branches/amis3/AmisAudio/src/directshow/dx_audio_player.cpp 2008-02-26 22:44:16 UTC (rev 2345) @@ -0,0 +1,547 @@ +// This file is part of Ambulant Player, www.ambulantplayer.org. +// +// Copyright (C) 2003-2008 Stichting CWI, +// Kruislaan 413, 1098 SJ Amsterdam, The Netherlands. +// +// Ambulant Player 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. +// +// Ambulant Player 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 Ambulant Player; if not, write to the Free Software +// 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 $ + */ + +#ifndef __AFXWIN_H__ +#include <afxwin.h> +#endif + +#include "directshow/dx_audio_player.h" + +//#include "ambulant/lib/logger.h" +#include "ambulant/lib/textptr.h" +#include <math.h> +#include <vfwmsgs.h> +// CLSID_FilterGraph +//#include <uuids.h> +#include <dshow.h> +#ifndef AM_DBG +#define AM_DBG if(0) +#endif + +using namespace ambulantX; + +//using ambulant::lib::win32::win_report_error; +//using ambulant::lib::win32::win_trace_error; +//using ambulant::lib::logger; + +const ULONGLONG MILLIS_FACT = 10000; + +#ifdef WITH_TPB_AUDIO_SPEEDUP +bool speedup_filter_available; +bool speedup_filter_available_valid; +#endif + +#define win_report_error +#define win_trace_error +#define debugX +#define errorX +#define traceX + +static DWORD WINAPI eventHandler(LPVOID lpParam) { + long lEventCode, lParam1, lParam2; + HRESULT hResult = E_FAIL; + bool bSelfBreak = false; + + gui::dx::audio_playerX *pPlayer = (gui::dx::audio_playerX*)lpParam; + + while((pPlayer->bCatchEvents) && (!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)) { + switch(lEventCode) { + case EC_COMPLETE: + pPlayer->sendMessageCallback(); + break; + case EC_USER + 4: + bSelfBreak = true; + break; + } + } + } + CoUninitialize(); + return 0; +} + +gui::dx::audio_playerX::audio_playerX(const char * url) +: + //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), +#endif + m_basic_audio(0), + hEventHandler(0), + bProcessEvents(false), + bCatchEvents(false) { + + open(url); +} + +gui::dx::audio_playerX::~audio_playerX() { + stop(); +} + +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; + HRESULT hr = m_media_control->Stop(); + if(FAILED(hr)) { + win_report_error("IMediaControl::stop()", hr); + } + release_player(); +} + +//void gui::dx::audio_playerX::pause(common::pause_display d) { +void gui::dx::audio_playerX::pause(void) { + if(m_media_control == 0) return; + HRESULT hr = m_media_control->Pause(); + if(FAILED(hr)) { + win_report_error("IMediaControl::pause()", hr); + } +} + +void gui::dx::audio_playerX::resume() { + if(m_media_control == 0) { + debugX("Invalid call to audio_playerX::run"); + return; + } + HRESULT hr = m_media_control->Run(); + if(FAILED(hr)) { + win_report_error("IMediaControl::run()", hr); + } +} + +void gui::dx::audio_playerX::seek(double t) { + if(m_media_position == 0) return; + HRESULT hr = m_media_position->put_CurrentPosition(REFTIME(t)); + if(FAILED(hr)) + win_report_error("IMediaPosition::put_CurrentPosition()", hr); +} + +void gui::dx::audio_playerX::endseek(double t) { + if(m_media_position == 0) return; + HRESULT hr = m_media_position->put_StopTime(REFTIME(t)); + if(FAILED(hr)) + win_report_error("IMediaPosition::put_StopTime()", hr); +} + +std::pair<bool, double> gui::dx::audio_playerX::get_dur() { + if(m_media_position == 0) { + debugX("Invalid call to audio_playerX::get_duration"); + return std::pair<bool, double>(false, 0); + } + REFTIME dur = 0.0; + HRESULT hr = m_media_position->get_Duration(&dur); + if(FAILED(hr)) { + win_report_error("IMediaPosition::get_Duration()", hr); + return std::pair<bool, double>(false, 0); + } + return std::pair<bool, double>(dur>0, dur); +} + +bool gui::dx::audio_playerX::can_play() { + return m_graph_builder && + m_media_event && + m_media_position && + m_media_control && + m_media_event; +} + +bool gui::dx::audio_playerX::is_playing() { + if(m_media_event == 0) return false; + long msTimeout = 0; + 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; + } + return evCode == 0; +} + +#if 0 +double gui::dx::audio_playerX::get_position() { + if(m_media_position == 0) { + debugX("Invalid call to audio_playerX::get_current_position"); + return 0.0; + } + REFTIME pos = 0.0; + HRESULT hr = m_media_position->get_CurrentPosition(&pos); + if(FAILED(hr)) { + win_report_error("IMediaPosition::get_CurrentPosition()", hr); + return 0.0; + } + return pos; +} +#endif + +////////////////////////// + +bool gui::dx::audio_playerX::open(const char * url) { + //m_url = url; + m_url.assign(url); + + HRESULT hrr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + + if (hrr) { + int a= 3; + //lib::logger::get_logger()->trace("win32_event_processor::run: CoInitializeEx failed with 0x%x", hr); + } + //CoInitialize(NULL); + //CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + //CoInitializeEx(NULL, COINIT_MULTITHREADED); + + + HRESULT 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)){ + /* + 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::release_player() { + if(m_graph_builder) { + + 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) { + //return false; + } + 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; + } + + CoUninitialize(); +} + +#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. + return; + } + // Either the filter exists or we haven't tried yet. Let's try to create + // it and remember whether it worked. + IBaseFilter *pNewFilter = NULL; + HRESULT res; + res = CoCreateInstance(CLSID_TPBVupp69, NULL, CLSCTX_INPROC_SERVER, + IID_IBaseFilter, (void**)&pNewFilter); + + if (res != S_OK) { + traceX("dx_audio_player: Speedup filter not available, error 0x%x", res); + speedup_filter_available = false; + speedup_filter_available_valid = true; + return; + } + res = m_graph_builder->AddFilter(pNewFilter, NULL); + if (res != S_OK) { + traceX("dx_audio_player: AddFilter(Speedup filter): error 0x%x", res); + pNewFilter->Release(); + return; + } + speedup_filter_available = true; + speedup_filter_available_valid = true; +// 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 + // we iterate over the connected output pins util we find one we like. + IPin *pOutputPin = NULL; + IPin *pInputPin = NULL; + IEnumFilters *pEnumFilters = NULL; + res = m_graph_builder->EnumFilters(&pEnumFilters); + if (res != S_OK) { + traceX("dx_audio_filter: EnumFilters: error 0x%x", res); + return; + } + + IBaseFilter *pCurFilter; + while (pOutputPin == NULL && (res=pEnumFilters->Next(1, &pCurFilter, NULL)) == S_OK) { + AM_DBG { + FILTER_INFO info; + LPWSTR vendorInfo; + res = pCurFilter->QueryFilterInfo(&info); + if (res != S_OK) info.achName[0] = 0; + res = pCurFilter->QueryVendorInfo(&vendorInfo); + if (res != S_OK) vendorInfo = L""; + ambulant::lib::textptr tInfo(info.achName); + ambulant::lib::textptr tVendorInfo(vendorInfo); + //lib::debugX("dx_audio_filter: filter found: '%s' vendor '%s'", tInfo.c_str(), tVendorInfo.c_str()); + } + IEnumPins *pEnumPins; + res = pCurFilter->EnumPins(&pEnumPins); + IPin *pCurPin; + while (pOutputPin == NULL && (res=pEnumPins->Next(1, &pCurPin, NULL)) == S_OK) { + AM_MEDIA_TYPE mediaType; + PIN_DIRECTION curPinDir; + 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(); + } + } + if (res2 == S_OK) { + if (mediaType.cbFormat != 0) { + CoTaskMemFree((PVOID)mediaType.pbFormat); + } + } + pCurPin->Release(); + } + if (res != S_FALSE && res != S_OK) + traceX("dx_audio_filter: enumerating pins: error 0x%x", res); + pEnumPins->Release(); + pCurFilter->Release(); + } + if (res != S_FALSE && res != S_OK) + traceX("dx_audio_filter: enumerating filters: error 0x%x", res); + + pEnumFilters->Release(); + // We have the correct pins now. + if (pOutputPin) { + traceX("dx_audio_filter: found the right pins!"); + } else { + traceX("dx_audio_filter: could not find a good pin"); + pOutputPin->Release(); + pInputPin->Release(); + return; + } + // Now we need to find the pins on our speedup filter. + IPin *pFilterInputPin = NULL; + IPin *pFilterOutputPin = NULL; + IEnumPins *pEnumPins; + res = pNewFilter->EnumPins(&pEnumPins); + IPin *pCurPin; + while (res=pEnumPins->Next(1, &pCurPin, NULL) == S_OK) { + PIN_DIRECTION pinDir; + res = pCurPin->QueryDirection(&pinDir); + //assert(res == S_OK); + if (pinDir == PINDIR_INPUT) { + if (pFilterInputPin) { + traceX("dx_audio_filter: multiple input pins on filter"); + goto bad; + } + pFilterInputPin = pCurPin; + pFilterInputPin->AddRef(); + } else { + if (pFilterOutputPin) { + traceX("dx_audio_filter: multiple output pins on filter"); + goto bad; + } + pFilterOutputPin = pCurPin; + pFilterOutputPin->AddRef(); + } + } + if (!pFilterInputPin) { + traceX("dx_audio_filter: no input pin on filter"); + goto bad; + } + if (!pFilterOutputPin) { + traceX("dx_audio_filter: no output pin on filter"); + goto bad; + } + // We have everything. Sever the old connection and insert the filter. + res = m_graph_builder->Disconnect(pOutputPin); + if (res) { + traceX("dx_audio_filter: Severing old connection: error 0x%x", res); + goto bad; + } + res = m_graph_builder->Disconnect(pInputPin); + if (res) { + traceX("dx_audio_filter: Severing old connection: error 0x%x", res); + goto bad; + } + res = m_graph_builder->Connect(pOutputPin, pFilterInputPin); + if (res) { + traceX("dx_audio_filter: Creating filter input connection: error 0x%x", res); + goto bad; + } + res = m_graph_builder->Connect(pFilterOutputPin, pInputPin); + if (res) { + traceX("dx_audio_filter: Creating filter output connection: error 0x%x", res); + goto bad; + } + // Finally remember the interface to set speedup/slowdown, and register ourselves + // in the global pool (so Amis can change our speed). + res = pNewFilter->QueryInterface(IID_IVuppInterface, (void**) &m_audio_speedup); + if (res != S_OK) { + traceX("dx_audio_filter: filter does not provide IVuppInterface"); + goto bad; + } + set_rate(s_current_playback_rate); + +bad: + if (pOutputPin) pOutputPin->Release(); + if (pInputPin) pInputPin->Release(); + if (pFilterOutputPin) pFilterOutputPin->Release(); + if (pFilterInputPin) pFilterInputPin->Release(); + return; + +} + +void gui::dx::audio_playerX::set_rate(double rate) { + s_current_playback_rate = rate; + if (m_audio_speedup) { + m_audio_speedup->setCycleSpeed((short)(rate*100)); + } +} + +#endif + +// -val is the attenuation in decibels +// can be 0 to 100 +void gui::dx::audio_playerX::set_volume(long val) { + if(m_basic_audio == 0) return; + if (val < 0) val = 0; + if (val > 100) val = 100; + 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 +void gui::dx::audio_playerX::set_balance(long val) { + if(m_basic_audio == 0) return; + val = (val>=-100)?val:-100; + val = (val<=100)?val:100; + long cdb = val*100; + m_basic_audio->put_Balance(cdb); +} + + +void gui::dx::audio_playerX::setCallback(sendMessageCallbackFn pFunction) +{ + sendMessageCallback=pFunction; +} Modified: branches/amis3/AmisCore/AmisCore.vcproj =================================================================== --- branches/amis3/AmisCore/AmisCore.vcproj 2008-02-26 17:27:09 UTC (rev 2344) +++ branches/amis3/AmisCore/AmisCore.vcproj 2008-02-26 22:44:16 UTC (rev 2345) @@ -65,7 +65,7 @@ Name="VCCLCompilerTool" AdditionalIncludeDirectories="./include; ../../../../xerces-c-src/src;../../../../ambulant/include" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" - RuntimeLibrary="0" + RuntimeLibrary="2" EnableFunctionLevelLinking="TRUE" UsePrecompiledHeader="0" WarningLevel="3" Modified: branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj =================================================================== --- branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj 2008-02-26 17:27:09 UTC (rev 2344) +++ branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj 2008-02-26 22:44:16 UTC (rev 2345) @@ -20,7 +20,7 @@ <Tool Name="VCCLCompilerTool" Optimization="0" - AdditionalIncludeDirectories="include;../../../../ambulant/include/;"../../../../ambulant-private/pdtbplugin";"../../../../ambulant-private/pdtbplugin/PdtbIePlugin";../AmisCore/include;"../../../../xerces-c-src/src";"$(VSInstallDir)\..\Microsoft Speech SDK 5.1\Include"" + AdditionalIncludeDirectories="include;../AmisAudio/include;../../../../ambulant/include/;"../../../../ambulant-private/pdtbplugin";"../../../../ambulant-private/pdtbplugin/PdtbIePlugin";../AmisCore/include;"../../../../xerces-c-src/src";"$(VSInstallDir)\..\Microsoft Speech SDK 5.1\Include"" PreprocessorDefinitions="WIN32;_WINDOWS;_DEBUG" MinimalRebuild="TRUE" BasicRuntimeChecks="3" @@ -35,7 +35,7 @@ Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" - AdditionalDependencies="AmisCoreD.lib xerces-c_2D.lib libambulant_shwin32_D.lib AmisAudioD.lib" + AdditionalDependencies="AmisCoreD.lib xerces-c_2D.lib libambulant_shwin32_D.lib" LinkIncremental="2" AdditionalLibraryDirectories="../lib;../../../../ambulant/lib/win32;"$(VSInstallDir)\..\Microsoft Speech SDK 5.1\Lib\i386"" IgnoreDefaultLibraryNames="uafxcwd.lib;uafxcw.lib;LIBCD.lib;LIBC.lib;msvcrt.lib;libcmt.lib" @@ -71,14 +71,14 @@ </Configuration> <Configuration Name="Release|Win32" - OutputDirectory="Release" + OutputDirectory="../bin" IntermediateDirectory="Release" ConfigurationType="1" UseOfMFC="2" CharacterSet="1"> <Tool Name="VCCLCompilerTool" - AdditionalIncludeDirectories="include;../../../../ambulant/include/;"../../../../ambulant-private/pdtbplugin";"../../../../ambulant-private/pdtbplugin/PdtbIePlugin";../AmisCore/include;"../../../../xerces-c-src/src";"$(VSInstallDir)\..\Microsoft Speech SDK 5.1\Include"" + AdditionalIncludeDirectories="include;../AmisAudio/include;../../../../ambulant/include/;"../../../../ambulant-private/pdtbplugin";"../../../../ambulant-private/pdtbplugin/PdtbIePlugin";../AmisCore/include;"../../../../xerces-c-src/src";"$(VSInstallDir)\..\Microsoft Speech SDK 5.1\Include"" PreprocessorDefinitions="WIN32;_WINDOWS;NDEBUG" MinimalRebuild="FALSE" RuntimeLibrary="2" @@ -91,7 +91,7 @@ Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" - AdditionalDependencies="xerces-c_2.lib AmisCore.lib AmisAudio.lib libambulant_shwin32.lib Strmiids.lib stlib.lib kernel32.lib gdi32.lib user32.lib" + AdditionalDependencies="xerces-c_2.lib AmisCore.lib libambulant_shwin32.lib Strmiids.lib stlib.lib kernel32.lib gdi32.lib user32.lib" LinkIncremental="1" AdditionalLibraryDirectories="../lib;../../../../ambulant/lib/win32;"$(VSInstallDir)\..\Microsoft Speech SDK 5.1\Lib\i386"" IgnoreAllDefaultLibraries="FALSE" @@ -784,6 +784,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> </File> <File RelativePath=".\src\gui\self-voicing\AudioSequence.cpp"> @@ -793,6 +799,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> </File> <File RelativePath=".\src\gui\self-voicing\AudioSequenceComponent.cpp"> @@ -802,6 +814,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> </File> <File RelativePath=".\src\gui\self-voicing\AudioSequencePlayer.cpp"> @@ -811,6 +829,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> </File> <File RelativePath=".\src\gui\self-voicing\PreTranslateMessageHandler.cpp"> @@ -820,6 +844,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> </File> <File RelativePath=".\src\gui\self-voicing\Prompt.cpp"> @@ -829,6 +859,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> </File> <File RelativePath=".\src\gui\self-voicing\PromptResolver.cpp"> @@ -838,6 +874,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> </File> <File RelativePath=".\src\gui\self-voicing\TTSPlayer.cpp"> @@ -847,6 +889,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> </File> <File RelativePath=".\src\gui\self-voicing\UiMediaTypes.cpp"> @@ -856,6 +904,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> </File> <Filter Name="datamodel" @@ -868,6 +922,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> </File> <File RelativePath=".\src\gui\self-voicing\datamodel\Action.cpp"> @@ -877,6 +937,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> </File> <File RelativePath=".\src\gui\self-voicing\datamodel\Container.cpp"> @@ -886,6 +952,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> </File> <File RelativePath=".\src\gui\self-voicing\datamodel\DataTree.cpp"> @@ -895,6 +967,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> </File> <File RelativePath=".\src\gui\self-voicing\datamodel\Dialog.cpp"> @@ -904,6 +982,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> </File> <File RelativePath=".\src\gui\self-voicing\datamodel\DialogControl.cpp"> @@ -913,6 +997,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> </File> <File RelativePath=".\src\gui\self-voicing\datamodel\IniFile.cpp"> @@ -922,6 +1012,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> </File> <File RelativePath=".\src\gui\self-voicing\datamodel\Label.cpp"> @@ -931,6 +1027,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> </FileConfiguration> + <FileConfiguration + Name="Release|Win32"> + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="0"/> + </FileConfiguration> </File> <File RelativePath=".\src\gui\self-voicing\datamodel\LabelList.cpp"> @@ -940,6 +1042,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> ... [truncated message content] |