ScummVM API documentation
fx_manager.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * Additional copyright for this file:
8  * Copyright (C) 1999-2000 Revolution Software Ltd.
9  * This code is based on source code created by Revolution Software,
10  * used with permission.
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef ICB_FXMANAGER_H__INCLUDED_
28 #define ICB_FXMANAGER_H__INCLUDED_
29 
30 #include "engines/icb/sound/direct_sound.h"
31 
32 #include "audio/audiostream.h"
33 #include "audio/mixer.h"
34 
35 namespace ICB {
36 
37 extern bool8 noSoundEngine;
38 
39 #define SAMPLE_NAME_LENGTH 64
40 
41 typedef struct Effect {
42  enum FxFlags { EMPTY, DELAYED, QUEUED, PLAYING, READY };
43 
44  char name[SAMPLE_NAME_LENGTH]; // Sample name
45  int32 delay; // The delay until playing
46  int32 looped; // Loop this effect
47 
48  int32 pitch; // Sampling rate (Hz)
49  int32 pan; // Pan (DirectSound scale)
50  int32 volume; // Volume (DirectSound scale)
51 
52  int32 rate; // Original buffer sample rate
53  FxFlags flags; // Status of sample
54  int32 length; // Length of sample in millisecs at base rate...
56  Audio::SoundHandle _handle;
57 } Effect;
58 
59 class FxManager {
60 private:
61  Effect m_effects[MAX_FX];
62 
63 public:
64  FxManager();
65  ~FxManager();
66 
67 public:
68  // Register wavs and unregister (high level load and unload)
69  int32 Register(const int32 id, const char *name, const int32 delay = 0, uint32 byteOffsetInCluster = 0);
70  void Unregister(int32 id);
71  void UnregisterAll();
72 
73  // Called on a timer 10 times a second
74  bool8 Poll();
75 
76  // Pretty important really
77  void Play(int32 id);
78  void Stop(int32 id);
79 
80  void StopAll(void);
81 
82  // All realtime tweakers
83  void SetVolume(int32 id, int32 vol);
84  void SetPitch(int32 id, int32 pitch);
85 
86  // A DirectSound buffer can support panning OR 3D position but not both
87  // A parameter for Register() lets you decide which to support
88  void SetPan(int32 id, int32 pan);
89 
90  // Helpers and debug shat
91  void SetLooping(int32 id, int32 loop = 1) { m_effects[id].looped = loop; }
92  bool8 IsPlaying(int32 id) { return (m_effects[id].flags == Effect::PLAYING) ? TRUE8 : FALSE8; }
93 
94  int32 GetDefaultRate(const char *name, uint32 byteOffsetInCluster = 0);
95 
96  int32 GetDefaultLength(int32 id) { return m_effects[id].length; }
97 
98 private:
99  bool8 Load(int32 id, const char *name, uint32 byteOffsetInCluster = 0);
100 
101  // Can get original sampling rate by channel or examine a wav file
102  int32 GetDefaultRateByID(int32 id) { return m_effects[id].rate; }
103  int32 GetDefaultRateByName(const char *name, uint32 byteOffsetInCluster = 0);
104 };
105 
106 } // End of namespace ICB
107 
108 #endif
Definition: fx_manager.h:59
Definition: actor.h:32
Definition: audiostream.h:212
Definition: mixer.h:49
Definition: fx_manager.h:41