Added tutorial 6 shows how to use a custom event handler as well has removed OnInit from the audio source events.
This commit is contained in:
parent
aae976f3e4
commit
cb9ae7a72c
|
@ -0,0 +1,196 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="Tutorial6_CustomEventHandler"
|
||||
ProjectGUID="{21C636EF-FC36-4FC5-AFB4-0711F5C44B5D}"
|
||||
RootNamespace="Tutorial5_AudioEffects"
|
||||
TargetFrameworkVersion="196613"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="../../bin/win32-visual"
|
||||
IntermediateDirectory="obj/$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="cAudio.lib"
|
||||
AdditionalLibraryDirectories=""..\..\lib\win32-visual""
|
||||
GenerateDebugInformation="true"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="../../bin/win32-visual"
|
||||
IntermediateDirectory="obj/$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="true"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="cAudio.lib"
|
||||
AdditionalLibraryDirectories=""..\..\lib\win32-visual""
|
||||
GenerateDebugInformation="true"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\cTestHandler.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\main.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\cTestHandler.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
|
@ -0,0 +1,35 @@
|
|||
//****************************************************************
|
||||
//cAudio 2.0.0 Tutorial 6
|
||||
//Custom event handler
|
||||
//****************************************************************
|
||||
|
||||
#include "cTestHandler.h"
|
||||
#include <iostream>
|
||||
|
||||
void cTestHandler::onUpdate()
|
||||
{
|
||||
//We comment this out because this will be constantly
|
||||
//called as the sound is playing
|
||||
//std::cout<<"Custom Event Handler: Sound source is updating\n";
|
||||
}
|
||||
|
||||
void cTestHandler::onRelease()
|
||||
{
|
||||
std::cout<<"Custom Event Handler: Sound source was released\n";
|
||||
}
|
||||
|
||||
void cTestHandler::onPlay()
|
||||
{
|
||||
std::cout<<"Custom Event Handler: Sound source started playing\n";
|
||||
}
|
||||
|
||||
void cTestHandler::onStop()
|
||||
{
|
||||
std::cout<<"Custom Event Handler: Sound source stoped playing\n";
|
||||
}
|
||||
|
||||
void cTestHandler::onPause()
|
||||
{
|
||||
std::cout<<"Custom Event Handler: Sound source was paused\n";
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
//****************************************************************
|
||||
//cAudio 2.0.0 Tutorial 6
|
||||
//Custom event handler
|
||||
//****************************************************************
|
||||
|
||||
|
||||
///Include the ISourceHandler.h so we can inherit the interface
|
||||
#include "../../include/ISourceEventHandler.h"
|
||||
|
||||
class cTestHandler : public cAudio::ISourceEventHandler
|
||||
{
|
||||
//In order for this handler to work it must have each of the following functions
|
||||
public:
|
||||
|
||||
// This function calls on source update
|
||||
void onUpdate();
|
||||
// This function calls on source release
|
||||
void onRelease();
|
||||
// This function calls on source play
|
||||
void onPlay();
|
||||
// This function calls on source stop
|
||||
void onStop();
|
||||
// This function calls on source pause
|
||||
void onPause();
|
||||
|
||||
};
|
|
@ -0,0 +1,84 @@
|
|||
//****************************************************************
|
||||
//cAudio 2.0.0 Tutorial 6
|
||||
//Custom event handler
|
||||
//****************************************************************
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
//Include cAudio.h so we can work wtih cAudio
|
||||
#include "../../include/cAudio.h"
|
||||
|
||||
//Include the test handler
|
||||
#include "cTestHandler.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
//Some fancy text
|
||||
cout << "cAudio 2.0.0 Tutorial 6: Custom event handler. \n \n";
|
||||
|
||||
//Create an uninitialized Audio Manager
|
||||
cAudio::IAudioManager* manager = cAudio::createAudioManager(false);
|
||||
|
||||
//Make a pointer to our handler
|
||||
cTestHandler *handle = new cTestHandler;
|
||||
|
||||
if(manager)
|
||||
{
|
||||
//Allow the user to choose a playback device
|
||||
cout << "Available Playback Devices: \n";
|
||||
unsigned int deviceCount = manager->getAvailableDeviceCount();
|
||||
std::string defaultDeviceName = manager->getDefaultDeviceName();
|
||||
for(unsigned int i=0; i<deviceCount; ++i)
|
||||
{
|
||||
std::string deviceName = manager->getAvailableDeviceName(i);
|
||||
if(deviceName.compare(defaultDeviceName) == 0)
|
||||
cout << i << "): " << deviceName << " [DEFAULT] \n";
|
||||
else
|
||||
cout << i << "): " << deviceName << " \n";
|
||||
}
|
||||
cout << std::endl;
|
||||
cout << "Choose a device by number: ";
|
||||
unsigned int deviceSelection = 0;
|
||||
cin >> deviceSelection;
|
||||
cout << std::endl;
|
||||
|
||||
//Initialize the manager with the user settings
|
||||
manager->initialize(manager->getAvailableDeviceName(deviceSelection));
|
||||
|
||||
//Create a IAudio object and load a sound from a file
|
||||
cAudio::IAudioSource* mysound = manager->create("bling","../../media/cAudioTheme1.ogg",true);
|
||||
mysound->registerEventHandler(handle);
|
||||
if(mysound)
|
||||
{
|
||||
mysound->setVolume(0.5);
|
||||
//Set the IAudio Sound to play2d and loop
|
||||
mysound->play2d(false);
|
||||
|
||||
//Wait for the sound to finish playing
|
||||
while(mysound->isPlaying())
|
||||
cAudio::cAudioSleep(10);
|
||||
|
||||
}
|
||||
|
||||
//Delete all IAudio sounds
|
||||
manager->releaseAllSources();
|
||||
//Shutdown cAudio
|
||||
manager->shutDown();
|
||||
|
||||
cAudio::destroyAudioManager(manager);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Failed to create audio playback manager. \n";
|
||||
}
|
||||
|
||||
std::cout << "Press any key to quit \n";
|
||||
std::cin.get();
|
||||
std::cin.get();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -24,7 +24,6 @@ namespace cAudio
|
|||
public:
|
||||
|
||||
enum Events{
|
||||
ON_INIT,
|
||||
ON_UPDATE,
|
||||
ON_RELEASE,
|
||||
ON_PLAY,
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace cAudio
|
|||
|
||||
EffectSlotsAvailable = (numSlots <= CAUDIO_SOURCE_MAX_EFFECT_SLOTS) ? numSlots : CAUDIO_SOURCE_MAX_EFFECT_SLOTS;
|
||||
#endif
|
||||
signalEvent(ON_INIT);
|
||||
|
||||
}
|
||||
|
||||
cAudioSource::~cAudioSource()
|
||||
|
@ -756,14 +756,6 @@ namespace cAudio
|
|||
|
||||
switch(sevent){
|
||||
|
||||
case ON_INIT:
|
||||
|
||||
for(it; it != eventHandlerList.end(); it++){
|
||||
(*it)->onInit();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case ON_UPDATE:
|
||||
|
||||
for(it; it != eventHandlerList.end(); it++){
|
||||
|
|
|
@ -35,6 +35,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Tutorial5_AudioEffects", "E
|
|||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mp3Decoder", "plugins\mp3Decoder\mp3Decoder.vcproj", "{F1741962-FBBB-4BA2-AC74-A97E2DDF6B2E}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Tutorial6_CustomEventHandler", "Examples\Tutorial6_CustomEventHandler\Tutorial6_CustomEventHandler.vcproj", "{21C636EF-FC36-4FC5-AFB4-0711F5C44B5D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
|
@ -73,6 +75,10 @@ Global
|
|||
{F1741962-FBBB-4BA2-AC74-A97E2DDF6B2E}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{F1741962-FBBB-4BA2-AC74-A97E2DDF6B2E}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{F1741962-FBBB-4BA2-AC74-A97E2DDF6B2E}.Release|Win32.Build.0 = Release|Win32
|
||||
{21C636EF-FC36-4FC5-AFB4-0711F5C44B5D}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{21C636EF-FC36-4FC5-AFB4-0711F5C44B5D}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{21C636EF-FC36-4FC5-AFB4-0711F5C44B5D}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{21C636EF-FC36-4FC5-AFB4-0711F5C44B5D}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -11,8 +11,7 @@ namespace cAudio{
|
|||
{
|
||||
|
||||
public:
|
||||
//! This function calls on source initalization
|
||||
virtual void onInit() = 0;
|
||||
|
||||
//! This function calls on source update
|
||||
virtual void onUpdate() = 0;
|
||||
//! This function calls on source release
|
||||
|
|
Loading…
Reference in New Issue