00001
00002
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 #ifndef OSDL_SOUND_H_
00028 #define OSDL_SOUND_H_
00029
00030
00031 #include "OSDLAudible.h"
00032 #include "OSDLUtils.h"
00033
00034
00035 #include "Ceylan.h"
00036
00037
00038 #include <string>
00039
00040
00041
00042 #if ! defined(OSDL_USES_SDL_MIXER) || OSDL_USES_SDL_MIXER
00043
00044
00045 struct Mix_Chunk ;
00046
00047 #endif // ! defined(OSDL_USES_SDL_MIXER) || OSDL_USES_SDL_MIXER
00048
00049
00050
00051
00052 namespace OSDL
00053 {
00054
00055
00056
00057 namespace Audio
00058 {
00059
00060
00061
00063 #if ! defined(OSDL_USES_SDL_MIXER) || OSDL_USES_SDL_MIXER
00064
00065 typedef ::Mix_Chunk LowLevelSound ;
00066
00067 #else // OSDL_USES_SDL_MIXER
00068
00069
00074 struct LowLevelSound
00075 {
00076
00077
00079 Ceylan::Uint16 _frequency ;
00080
00081
00083 Ceylan::Uint8 _bitDepth ;
00084
00085
00087 Ceylan::Uint8 _mode ;
00088
00089
00091 Ceylan::Byte * _samples ;
00092
00093
00095 Ceylan::Uint32 _size ;
00096
00097
00098 } ;
00099
00100
00101 #endif // OSDL_USES_SDL_MIXER
00102
00103
00104
00105
00107 class OSDL_DLL SoundException: public AudibleException
00108 {
00109 public:
00110
00111 SoundException( const std::string & reason ) ;
00112 virtual ~SoundException() throw() ;
00113 } ;
00114
00115
00116
00117
00118 class Sound ;
00119
00120
00122 typedef Ceylan::CountedPointer<Sound> SoundCountedPtr ;
00123
00124
00125
00126
00148 class OSDL_DLL Sound: public Audible,
00149 public Ceylan::LoadableWithContent<LowLevelSound>
00150 {
00151
00152
00153
00154 public:
00155
00156
00157
00178 explicit Sound( const std::string & soundFile,
00179 bool preload = true ) ;
00180
00181
00182
00184 virtual ~Sound() throw() ;
00185
00186
00187
00188
00189
00190
00191
00192
00202 virtual bool load() ;
00203
00204
00205
00218 virtual bool unload() ;
00219
00220
00221
00222
00223
00224
00225
00226
00235 virtual Volume getVolume() const ;
00236
00237
00238
00251 virtual void setVolume( Volume newVolume ) ;
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00294 virtual void play( PlaybackCount playCount = 1 ) ;
00295
00296
00297
00316 virtual ChannelNumber playReturnChannel(
00317 PlaybackCount playCount = 1 ) ;
00318
00319
00320
00337 virtual void play(
00338 ChannelNumber mixingChannelNumber,
00339 PlaybackCount playCount = 1 ) ;
00340
00341
00342
00343
00344
00345
00346
00347
00366 virtual void playForAtMost(
00367 Ceylan::System::Millisecond maxDuration,
00368 PlaybackCount playCount = 1 ) ;
00369
00370
00371
00392 virtual ChannelNumber playForAtMostReturnChannel(
00393 Ceylan::System::Millisecond maxDuration,
00394 PlaybackCount playCount = 1 ) ;
00395
00396
00397
00419 virtual void playForAtMost(
00420 Ceylan::System::Millisecond maxDuration,
00421 ChannelNumber mixingChannelNumber,
00422 PlaybackCount playCount = 1 ) ;
00423
00424
00425
00426
00427
00428
00429
00430
00451 virtual void playWithFadeIn(
00452 Ceylan::System::Millisecond fadeInMaxDuration,
00453 PlaybackCount playCount = 1 ) ;
00454
00455
00456
00479 virtual ChannelNumber playWithFadeInReturnChannel(
00480 Ceylan::System::Millisecond fadeInMaxDuration,
00481 PlaybackCount playCount = 1 ) ;
00482
00483
00484
00508 virtual void playWithFadeIn(
00509 Ceylan::System::Millisecond fadeInMaxDuration,
00510 ChannelNumber mixingChannelNumber,
00511 PlaybackCount playCount = 1 ) ;
00512
00513
00514
00515
00516
00517
00518
00519
00543 virtual void playWithFadeInForAtMost(
00544 Ceylan::System::Millisecond playbackMaxDuration,
00545 Ceylan::System::Millisecond fadeInMaxDuration,
00546 PlaybackCount playCount = 1 ) ;
00547
00548
00549
00575 virtual ChannelNumber playWithFadeInForAtMostReturnChannel(
00576 Ceylan::System::Millisecond playbackMaxDuration,
00577 Ceylan::System::Millisecond fadeInMaxDuration,
00578 PlaybackCount playCount = 1 ) ;
00579
00580
00581
00608 virtual void playWithFadeInForAtMost(
00609 Ceylan::System::Millisecond playbackMaxDuration,
00610 Ceylan::System::Millisecond fadeInMaxDuration,
00611 ChannelNumber mixingChannelNumber,
00612 PlaybackCount playCount = 1 ) ;
00613
00614
00615
00616
00629 virtual const std::string toString(
00630 Ceylan::VerbosityLevels level = Ceylan::high ) const ;
00631
00632
00633
00634
00635
00636 protected:
00637
00638
00650 OSDL::Utils::DataStream * _dataStream ;
00651
00652
00653
00654
00655 private:
00656
00657
00666 explicit Sound( const Sound & source ) ;
00667
00668
00669
00678 Sound & operator = ( const Sound & source ) ;
00679
00680
00681 } ;
00682
00683
00684 }
00685
00686 }
00687
00688
00689
00690 #endif // OSDL_SOUND_H_
00691