00001
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00033
00034 #ifndef GROOVX_MEDIA_HPSOUND_H_UTC20050626084018_DEFINED
00035 #define GROOVX_MEDIA_HPSOUND_H_UTC20050626084018_DEFINED
00036
00037 #include "media/soundrep.h"
00038
00039 #include "rutz/error.h"
00040 #include "rutz/fstring.h"
00041 #include "rutz/sfmt.h"
00042
00043 #include <Alib.h>
00044
00045 #include "rutz/trace.h"
00046 #include "rutz/debug.h"
00047
00048 namespace media
00049 {
00050
00051
00052
00054
00055 class hp_audio_sound_rep : public sound_rep
00056 {
00057 public:
00058 hp_audio_sound_rep(const char* filename = 0);
00059 virtual ~hp_audio_sound_rep() throw();
00060
00061 virtual void play();
00062
00063 private:
00064 SBucket* m_sbucket;
00065 SBPlayParams m_play_params;
00066
00067 static Audio* s_audio = 0;
00068
00069 static bool init_sound();
00070 static void close_sound();
00071 static long error_handler(Audio* audio, AErrorEvent* err);
00072 };
00073
00074 }
00075
00076 Audio* media::hp_audio_sound_rep::s_audio = 0;
00077
00078 media::hp_audio_sound_rep::hp_audio_sound_rep(const char* filename) :
00079 m_sbucket(0),
00080 m_play_params()
00081 {
00082 GVX_TRACE("hp_audio_sound_rep::hp_audio_sound_rep");
00083 init_sound();
00084 if ( !s_audio )
00085 throw rutz::error("invalid HP audio server connection", SRC_POS);
00086
00087 sound_rep::check_filename(filename);
00088
00089 m_play_params.pause_first = 0;
00090 m_play_params.start_offset.type = ATTSamples;
00091 m_play_params.start_offset.u.samples = 0;
00092 m_play_params.loop_count = 0;
00093 m_play_params.previous_transaction = 0;
00094 m_play_params.gain_matrix = *ASimplePlayer(s_audio);
00095 m_play_params.priority = APriorityNormal;
00096 m_play_params.play_volume = AUnityGain;
00097 m_play_params.duration.type = ATTFullLength;
00098 m_play_params.event_mask = 0;
00099
00100 AFileFormat file_format = AFFUnknown;
00101 AudioAttrMask attr_mask = 0;
00102 AudioAttributes attribs;
00103
00104 m_sbucket = ALoadAFile(s_audio, const_cast<char *>(filename),
00105 file_format, attr_mask, &attribs, NULL);
00106 }
00107
00108 media::hp_audio_sound_rep::~hp_audio_sound_rep() throw()
00109 {
00110 GVX_TRACE("hp_audio_sound_rep::~hp_audio_sound_rep");
00111 if ( s_audio != 0 )
00112 {
00113 if (m_sbucket)
00114 ADestroySBucket( s_audio, m_sbucket, NULL );
00115 }
00116 }
00117
00118 void media::hp_audio_sound_rep::play()
00119 {
00120 GVX_TRACE("hp_audio_sound_rep::play");
00121 init_sound();
00122 if ( !s_audio )
00123 throw rutz::error("invalid audio server connection", SRC_POS);
00124
00125 if (m_sbucket)
00126 ATransID xid = APlaySBucket( s_audio, m_sbucket, &m_play_params, NULL );
00127 }
00128
00129 bool media::hp_audio_sound_rep::init_sound()
00130 {
00131 GVX_TRACE("hp_audio_sound_rep::init_sound");
00132
00133 if (s_audio != 0) return true;
00134
00135 ASetErrorHandler(&error_handler);
00136
00137 bool retval = false;
00138
00139
00140
00141
00142 const char* server_name = "";
00143 long status = 0;
00144 s_audio = AOpenAudio( const_cast<char*>(server_name), &status );
00145 if ( status != 0 )
00146 {
00147 s_audio = NULL;
00148 retval = false;
00149 }
00150 else
00151 {
00152 ASetCloseDownMode( s_audio, AKeepTransactions, NULL );
00153 retval = true;
00154 }
00155
00156 return retval;
00157 }
00158
00159 void media::hp_audio_sound_rep::close_sound()
00160 {
00161 GVX_TRACE("hp_audio_sound_rep::close_sound");
00162 if ( s_audio )
00163 {
00164 ACloseAudio( s_audio, NULL );
00165 s_audio = 0;
00166 }
00167 }
00168
00169 long media::hp_audio_sound_rep::error_handler(Audio* audio, AErrorEvent *err)
00170 {
00171 GVX_TRACE("media::hp_audio_sound_rep::error_handler");
00172
00173 static char buf[128];
00174 AGetErrorText(audio, err->error_code, buf, 127);
00175
00176 dbg_eval_nl(3, buf);
00177
00178 throw rutz::error(rutz::sfmt("HP Audio Error: %s", buf), SRC_POS);
00179
00180
00181 return 0;
00182 }
00183
00184 static const char __attribute__((used)) vcid_groovx_media_hpsound_h_utc20050626084018[] = "$Id: hpsound.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00185 #endif // !GROOVX_MEDIA_HPSOUND_H_UTC20050626084018_DEFINED