ScummVM API documentation
audio.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  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef AGS_ENGINE_MEDIA_AUDIO_AUDIO_H
23 #define AGS_ENGINE_MEDIA_AUDIO_AUDIO_H
24 
25 #include "common/std/array.h"
26 #include "ags/engine/media/audio/audio_defines.h"
27 #include "ags/shared/ac/dynobj/script_audio_clip.h"
28 #include "ags/engine/ac/dynobj/script_audio_channel.h"
29 #include "ags/engine/media/audio/ambient_sound.h"
30 #include "ags/engine/ac/timer.h"
31 
32 namespace AGS3 {
33 
34 struct SOUNDCLIP;
35 
36 class AudioChans {
37 public:
38  // Gets a clip from the channel
39  static SOUNDCLIP *GetChannel(int index);
40  // Gets a clip from the channel but only if it's in playback state
41  static SOUNDCLIP *GetChannelIfPlaying(int index);
42  // Assign new clip to the channel
43  static SOUNDCLIP *SetChannel(int index, SOUNDCLIP *clip);
44  // Move clip from one channel to another, clearing the first channel
45  static SOUNDCLIP *MoveChannel(int to, int from);
46 
47  // Tells if channel has got a clip; does not care about its state
48  static inline bool ChannelHasClip(int index) {
49  return GetChannel(index) != nullptr;
50  }
51  // Tells if channel has got a clip and clip is in playback state
52  static inline bool ChannelIsPlaying(int index) {
53  return GetChannelIfPlaying(index) != nullptr;
54  }
55 
56 private:
57  AudioChans() = delete;
58  ~AudioChans() = delete;
59 };
60 
61 void calculate_reserved_channel_count();
62 void update_clip_default_volume(ScriptAudioClip *audioClip);
63 void start_fading_in_new_track_if_applicable(int fadeInChannel, ScriptAudioClip *newSound);
64 void stop_or_fade_out_channel(int fadeOutChannel, int fadeInChannel = -1, ScriptAudioClip *newSound = nullptr);
65 SOUNDCLIP *load_sound_clip(ScriptAudioClip *audioClip, bool repeat);
66 ScriptAudioChannel *play_audio_clip_on_channel(int channel, ScriptAudioClip *clip, int priority, int repeat, int fromOffset, SOUNDCLIP *cachedClip = nullptr);
67 void remove_clips_of_type_from_queue(int audioType);
68 void update_queued_clips_volume(int audioType, int new_vol);
69 // Checks if speech voice-over is currently playing, and reapply volume drop to all other active clips
70 void update_volume_drop_if_voiceover();
71 ScriptAudioChannel *play_audio_clip(ScriptAudioClip *clip, int priority, int repeat, int fromOffset, bool queueIfNoChannel);
72 ScriptAudioChannel *play_audio_clip_by_index(int audioClipIndex);
73 void stop_and_destroy_channel_ex(int chid, bool resetLegacyMusicSettings);
74 void stop_and_destroy_channel(int chid);
75 // Exports missing AudioChannel objects to script (for importing older saves)
76 void export_missing_audiochans();
77 
78 // ***** BACKWARDS COMPATIBILITY WITH OLD AUDIO SYSTEM ***** //
79 int get_old_style_number_for_sound(int sound_number);
80 SOUNDCLIP *load_sound_clip_from_old_style_number(bool isMusic, int indexNumber, bool repeat);
81 
82 //=============================================================================
83 
84 int get_volume_adjusted_for_distance(int volume, int sndX, int sndY, int sndMaxDist);
85 void update_directional_sound_vol();
86 void update_ambient_sound_vol();
87 // Tells if the audio type is allowed to play with regards to current sound config
88 bool is_audiotype_allowed_to_play(AudioFileType type);
89 // Loads sound data referenced by audio clip item, and starts playback;
90 // returns NULL on failure
91 SOUNDCLIP *load_sound_and_play(ScriptAudioClip *aclip, bool repeat);
92 void stop_all_sound_and_music();
93 void shutdown_sound();
94 int play_sound(int val1);
95 
96 //=============================================================================
97 
98 void clear_music_cache();
99 void play_next_queued();
100 int calculate_max_volume();
101 // add/remove the volume drop to the audio channels while speech is playing
102 void apply_volume_drop_modifier(bool applyModifier);
103 // syncs logical audio channels with the audio backend state
104 void sync_audio_playback();
105 // Update the music, and advance the crossfade on a step
106 // (this should only be called once per game loop);
107 void update_audio_system_on_game_loop();
108 void stopmusic();
109 void update_music_volume();
110 void post_new_music_check();
111 // Sets up the crossfading for playing the new music track,
112 // and returns the channel number to use; the channel is guaranteed to be free
113 int prepare_for_new_music();
114 // Gets audio clip from legacy music number, which also may contain queue flag
115 ScriptAudioClip *get_audio_clip_for_music(int mnum);
116 SOUNDCLIP *load_music_from_disk(int mnum, bool doRepeat);
117 void newmusic(int mnum);
118 
119 extern void cancel_scheduled_music_update();
120 extern void schedule_music_update_at(AGS_Clock::time_point);
121 extern void postpone_scheduled_music_update_by(std::chrono::milliseconds);
122 
123 } // namespace AGS3
124 
125 #endif
Definition: sound_clip.h:53
Definition: audio.h:36
Definition: script_audio_channel.h:27
Definition: ags.h:40
Definition: script_audio_clip.h:52