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 #ifndef SOUND_H_
00026 #define SOUND_H_
00027
00028 namespace Lamp{
00029
00030 class SoundBuffer;
00031 class StereoSound;
00032 class Sound3D;
00033 class StaticSound;
00034 class StreamSound;
00035 class StaticSound3D;
00036 class StreamSound3D;
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 class Sound{
00065 friend class SoundManager;
00066 friend class SoundCache;
00067 public:
00068
00069
00070
00071
00072 static const int priorityDefault = 0;
00073
00074
00075 static const int priorityMax = Limit::shortMax;
00076
00077
00078 static const int priorityMin = Limit::shortMin;
00079
00080
00081
00082
00083
00084 enum State{
00085
00086 statePlay,
00087
00088 stateSuspend,
00089
00090 stateStop,
00091
00092 stateLost,
00093 };
00094
00095
00096
00097
00098
00099 enum Focus{
00100
00101 focusNormal = 0,
00102
00103 focusSticky,
00104
00105 focusGlobal,
00106 };
00107
00108
00109
00110
00111
00112 enum Reset{
00113
00114 resetName = (1),
00115 resetCursor = (resetName << 1),
00116 resetPriority = (resetCursor << 1),
00117 resetLoop = (resetPriority << 1),
00118 resetLoopCursor = (resetLoop << 1),
00119 resetVolume = (resetLoopCursor << 1),
00120 resetFrequency = (resetVolume << 1),
00121 resetFade = (resetFrequency << 1),
00122
00123 resetPan = (resetFade << 1),
00124
00125 resetPosition = (resetPan << 1),
00126 resetVelocity = (resetPosition << 1),
00127 resetDistance = (resetVelocity << 1),
00128 resetConeDirection = (resetDistance << 1),
00129 resetConeAngle = (resetConeDirection << 1),
00130 resetConeOutsideVolume = (resetConeAngle << 1),
00131 reset3DEnabled = (resetConeOutsideVolume << 1),
00132
00133 resetNone = (0),
00134 resetAll = (0xffffffff),
00135 resetRuntime =
00136 (resetCursor | resetVolume | resetFrequency | resetFade |
00137 resetPan | resetPosition | resetVelocity | resetConeDirection |
00138 resetConeAngle | resetConeOutsideVolume | reset3DEnabled),
00139 };
00140
00141
00142
00143
00144
00145
00146
00147
00148 virtual void setName(const String& name) = 0;
00149
00150
00151
00152
00153
00154 virtual const String& getName() const = 0;
00155
00156
00157
00158
00159
00160
00161 virtual u_int getSize() const = 0;
00162
00163
00164
00165
00166
00167 virtual float getTimeLength() const{ return byteToTime(getSize()); }
00168
00169
00170
00171
00172
00173 virtual int getSample() const = 0;
00174
00175
00176
00177
00178
00179 virtual int getChannel() const = 0;
00180
00181
00182
00183
00184
00185 virtual int getBit() const = 0;
00186
00187
00188
00189
00190
00191 virtual Focus getFocus() const = 0;
00192
00193
00194
00195
00196
00197 virtual u_int getOneSampleBytes() const{
00198 return (getChannel() * getBit() / 8);
00199 }
00200
00201
00202
00203
00204
00205 virtual u_int getOneSecondBytes() const{
00206 return (getSample() * getOneSampleBytes());
00207 }
00208
00209
00210
00211
00212
00213
00214 virtual float byteToTime(u_int byte) const{
00215 Assert(byte <= getSize());
00216 return (float)byte / (float)getOneSecondBytes();
00217 }
00218
00219
00220
00221
00222
00223
00224 virtual u_int timeToByte(float time) const{
00225 Assert((time >= 0.f) && (time < getTimeLength()));
00226 return (u_int)(time * getOneSecondBytes());
00227 }
00228
00229
00230
00231
00232
00233
00234
00235
00236 virtual bool play() = 0;
00237
00238
00239
00240
00241 virtual void stop() = 0;
00242
00243
00244
00245
00246 virtual void suspend() = 0;
00247
00248
00249
00250
00251
00252 virtual bool resume() = 0;
00253
00254
00255
00256
00257
00258 virtual void reset(Reset flags);
00259
00260
00261
00262
00263 virtual State getState() const = 0;
00264
00265
00266
00267
00268
00269
00270
00271
00272 virtual void setCursor(u_int cursor) = 0;
00273
00274
00275
00276
00277
00278 virtual u_int getCursor() const = 0;
00279
00280
00281
00282
00283
00284
00285 virtual void setCurrentTime(float timeCursor){
00286 setCursor(timeToByte(timeCursor));
00287 }
00288
00289
00290
00291
00292
00293 virtual float getCurrentTime() const{ return byteToTime(getCursor()); }
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 virtual void setPriority(int priority) = 0;
00305
00306
00307
00308
00309
00310 virtual int getPriority() const = 0;
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 virtual void setLoop(bool loop) = 0;
00322
00323
00324
00325
00326
00327 virtual bool isLoop() const = 0;
00328
00329
00330
00331
00332
00333
00334 virtual void setLoopCursor(u_int loopCursor){
00335 if(loopCursor == 0){ return; }
00336 Assert(false);
00337 }
00338
00339
00340
00341
00342
00343 virtual u_int getLoopCursor() const{ return 0; }
00344
00345
00346
00347
00348
00349
00350 virtual void setLoopTime(float loopTimeCursor){
00351 setLoopCursor(timeToByte(loopTimeCursor));
00352 }
00353
00354
00355
00356
00357
00358 virtual float getLoopTime() const{ return byteToTime(getLoopCursor()); }
00359
00360
00361
00362
00363
00364
00365
00366
00367 virtual void setVolume(float volume) = 0;
00368
00369
00370
00371
00372
00373 virtual float getVolume() const = 0;
00374
00375
00376
00377
00378
00379
00380
00381
00382 virtual void setFrequency(int frequency) = 0;
00383
00384
00385
00386
00387
00388 virtual int getFrequency() const = 0;
00389
00390
00391
00392
00393 virtual void setOriginalFrequency() = 0;
00394
00395
00396
00397
00398
00399
00400
00401
00402 virtual void fadeIn(float millisecond) = 0;
00403
00404
00405
00406
00407
00408 virtual void fadeOut(float millisecond) = 0;
00409
00410
00411
00412
00413
00414
00415
00416 virtual void fade(
00417 float millisecond, float startVolume, float endVolume) = 0;
00418
00419
00420
00421
00422 virtual void stopFade(){ fade(0.f, 0.f, 0.f); }
00423
00424
00425
00426
00427
00428 virtual bool isFading() const = 0;
00429
00430
00431
00432
00433
00434
00435
00436
00437 virtual void setComment(const String& comment) = 0;
00438
00439
00440
00441
00442
00443 virtual const String& getComment() const = 0;
00444
00445
00446
00447
00448 virtual void applyCommentOption();
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458 virtual Sound* clone(){ return NULL; }
00459
00460
00461
00462
00463
00464 virtual bool hasOwnership() const = 0;
00465
00466
00467
00468
00469
00470 virtual String toString() const;
00471
00472
00473
00474
00475
00476
00477
00478
00479 virtual bool useStream() const{ return false; }
00480
00481
00482
00483
00484
00485
00486 virtual bool isSoundBuffer() const{ return false; }
00487
00488
00489
00490
00491
00492 virtual SoundBuffer* castSoundBuffer() const{
00493 if(isSoundBuffer()){ return (SoundBuffer*)this; }
00494 return NULL;
00495 }
00496
00497
00498
00499
00500
00501
00502 virtual bool isStereoSound() const{ return false; }
00503
00504
00505
00506
00507
00508 virtual StereoSound* castStereoSound() const{
00509 if(isStereoSound()){ return (StereoSound*)this; }
00510 return NULL;
00511 }
00512
00513
00514
00515
00516
00517
00518 virtual bool isSound3D() const{ return false; }
00519
00520
00521
00522
00523
00524 virtual Sound3D* castSound3D() const{
00525 if(isSound3D()){ return (Sound3D*)this; }
00526 return NULL;
00527 }
00528
00529
00530
00531
00532
00533
00534 virtual bool isStaticSound() const{ return false; }
00535
00536
00537
00538
00539
00540 virtual StaticSound* castStaticSound() const{
00541 if(isStaticSound()){ return (StaticSound*)this; }
00542 return NULL;
00543 }
00544
00545
00546
00547
00548
00549
00550 virtual bool isStreamSound() const{ return false; }
00551
00552
00553
00554
00555
00556 virtual StreamSound* castStreamSound() const{
00557 if(isStreamSound()){ return (StreamSound*)this; }
00558 return NULL;
00559 }
00560
00561
00562
00563
00564
00565
00566 virtual bool isStaticSound3D() const{ return false; }
00567
00568
00569
00570
00571
00572 virtual StaticSound3D* castStaticSound3D() const{
00573 if(isStaticSound3D()){ return (StaticSound3D*)this; }
00574 return NULL;
00575 }
00576
00577
00578
00579
00580
00581
00582 virtual bool isStreamSound3D() const{ return false; }
00583
00584
00585
00586
00587
00588 virtual StreamSound3D* castStreamSound3D() const{
00589 if(isStreamSound3D()){ return (StreamSound3D*)this; }
00590 return NULL;
00591 }
00592
00593
00594
00595
00596
00597
00598
00599 static int volumeToDecibel(float volume);
00600
00601
00602
00603
00604
00605
00606 static float decibelToVolume(int decibel);
00607
00608 protected:
00609
00610
00611
00612
00613
00614
00615 Sound();
00616
00617
00618
00619
00620 virtual ~Sound();
00621
00622
00623
00624
00625
00626
00627 virtual void setOwnership(bool ownership) = 0;
00628
00629
00630
00631
00632
00633 virtual bool update() = 0;
00634
00635 private:
00636
00637
00638 Sound(const Sound& copy);
00639
00640
00641 void operator =(const Sound& copy);
00642
00643 };
00644
00645
00646 }
00647 #endif // End of SOUND_H_
00648