00001 /* 00002 * This file is part of Micole Architecture 00003 * 00004 * Copyright (C) 2007 Micole partners 00005 * 00006 * Micole Architecture is free software: you can redistribute it 00007 * and/or modify it under the terms of the GNU Lesser General 00008 * Public License as published by the Free Software Foundation, 00009 * either version 3 of the License, or (at your option) any 00010 * later version. 00011 * 00012 * Micole Architecture is distributed in the hope that it will be 00013 * useful, * but WITHOUT ANY WARRANTY; without even the implied 00014 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00015 * PURPOSE. See the GNU Lesser General Public License for more 00016 * details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with Micole Architecture. If not, see 00020 * <http://www.gnu.org/licenses/>. 00021 */ 00022 00023 #ifndef SOUNDOUTPUTAGENT_H 00024 #define SOUNDOUTPUTAGENT_H 00025 00026 #include "micolelib.h" 00027 00028 00029 #define _WINSOCKAPI_ //prevent windows.h winscock inclusion (already present in cc++) 00030 #include <config.h> 00031 00032 #include "MicoleAgentThread.h" 00033 00034 #include <Display.h> 00035 #include <Scene.h> 00036 #include <Node.h> 00037 #include <Field.h> 00038 #include <SoundSource.h> 00039 00040 #include <iostream> 00041 #include <map> 00042 00043 using namespace Reachin; 00044 using namespace std; 00045 00046 //Required dependencies (Project Properties - Linker input) 00047 //ALSound_d.lib 00048 //ALut.lib 00049 //OpenAL32.lib 00050 // 00051 //Upon creation of a SoundSource, the language of choice is specified, 00052 //effectively resulting in the creation of a language specific sound. 00053 //By controlling which language version that should be played 00054 //with a variable, the choice of language can be made by the user 00055 //when the application is started. This simplifies development of 00056 //applications that utilizes a lot of speech as output, as changing 00057 //language output does not require rewriting of code. 00058 // 00059 //The user should choose which language to use when starting a 00060 //speech enabled application. The interface for choosing language 00061 //will be application specific. 00062 // 00063 //When creating the SoundOutputAgent, specify which sound library to use 00064 //e.g. 00065 //string language = "Greek"; 00066 //SoundOutputAgent * sa = new SoundOutputAgent(language); 00067 // 00068 //This will map to: 00069 //"urn:inet:reachin.se:/Sounds/Greek/" 00070 // 00071 //If there is a file called greek1.wav in the specified sound library, 00072 //play it by running IvyProbe.exe and typing PlaySound greek1.wav. 00073 // 00075 //specified action and the sound file of choice. 00076 // 00077 //Available Actions: 00078 //PlaySound greek1.wav 00079 //StopSound greek1.wav 00080 //CancelSound greek1.wav 00081 //PauseSound greek1.wav 00082 // 00083 //The pitch, gain and loop for specific sounds should be 00084 //tweaked by the application engineer, allowing for the 00085 //user to only have to adjust the master volume of 00086 //an application. 00087 00088 //The gain, loop, pitch can be set with the functions 00089 //setGain 00090 //setLoop 00091 //setPitch 00092 00093 class MICOLELIB_API SoundOutputAgent: public Node, MicoleAgent 00094 { 00095 public: 00096 SoundOutputAgent(const string &lan); 00097 00098 //********************************************************************* 00099 //TODO: put the datamembers in private ! 00100 // 00101 //********************************************************************* 00102 //stores language as specified when the 00103 //SoundOutputAgent is created 00104 string language; 00105 00106 SoundSource* sound; 00107 map< string, SoundSource* > nameToSound; 00108 typedef pair < string, SoundSource* > pair_soundname_to_soundsource; 00109 Display* dis; 00110 00111 void handlePlaySoundMessage( MicoleBus *app, int argc, const char **argv ); 00112 void handleStopSoundMessage( MicoleBus *app, int argc, const char **argv ); 00113 void handlePauseSoundMessage( MicoleBus *app, int argc, const char **argv ); 00114 void handleCancelSoundMessage( MicoleBus *app, int argc, const char **argv ); 00115 00116 void setGain(string soundname, float gain); 00117 void setPitch(string soundname, float pitch); 00118 void setLoop(string soundname, bool loop); 00119 00120 void createSound( const string &soundname, const string &language ) 00121 { 00122 SoundSource* soundsource = new SoundSource(); 00123 soundsource->play->set(false); 00124 soundsource->loop->set(true); 00125 soundsource->pitch->set(1.0); 00126 soundsource->gain->set(1.0); 00127 00128 nameToSound.insert( pair_soundname_to_soundsource( soundname, soundsource ) ); 00129 00130 //Ex: "urn:inet:reachin.se:/Sounds/Greek/greek1.wav" 00131 string url = "urn:inet:reachin.se:/Sounds/" + language + "/" + soundname; 00132 00133 soundsource->url->set(url); 00134 dis->children->add(soundsource); 00135 } 00136 private: 00137 }; 00138 00139 #endif