-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
RS_WaveSupport.js
179 lines (159 loc) · 5.25 KB
/
RS_WaveSupport.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//================================================================
// RS_WaveSupport.js
// ---------------------------------------------------------------
// The MIT License
// Copyright (c) 2015 biud436
// ---------------------------------------------------------------
// Free for commercial and non commercial use.
//================================================================
/*:
* RS_WaveSupport.js
*
* @plugindesc This can be used to control playback of .wav files.(AudioManager supports addtional playing the wav file)
* @author biud436
*
* @param Wave Volume Text
* @desc
* @default Wave Volume
*
* @help
*
* You can play the wav files by using the following code.
*
* - Start playing the sound.
* The string parameter specifies a WAV file name. (Download the .wav file and place it in your Audio/wav folder)
* AudioManager.playWav('file_name');
*
* - Stop a previously played sound.
* AudioManager.stopWav();
*
* - Change Log
* 2015.12.25 (v1.0.0) - First Release Date.
* 2024.04.20 (v1.1.0) :
* - added missing code for blobUrl.
*
*/
var Imported = Imported || {};
Imported.RS_WaveSupport = true;
(function () {
var parameters = PluginManager.parameters('RS_WaveSupport');
var _wavText = parameters['Wave Volume Text'] || 'Wave Volume Text';
//-----------------------------------------------------------------------------
// WebAudio
//
//
var alias_detectCodecs = WebAudio._detectCodecs;
WebAudio._detectCodecs = function () {
alias_detectCodecs.call(this);
var audio = document.createElement('audio');
if (audio.canPlayType) {
this._canPlayWav = audio.canPlayType('audio/wav; codecs="1"');
}
};
WebAudio.canPlayWav = function () {
if (!this._initialized) {
this.initialize();
}
return !!this._canPlayWav;
};
//-----------------------------------------------------------------------------
// AudioManager
//
//
AudioManager._wavVolume = 100;
AudioManager._wavBuffers = [];
Object.defineProperty(AudioManager, 'wavVolume', {
get: function () {
return this._wavVolume;
},
set: function (value) {
this._wavVolume = value;
},
configurable: true,
});
AudioManager.createBuffer = function (folder, name, extension) {
var ext = extension || this.audioFileExt();
var url = this._path + folder + '/' + encodeURIComponent(name) + ext;
if (this.shouldUseHtml5Audio() && folder === 'bgm') {
if (this._blobUrl) Html5Audio.setup(this._blobUrl);
else Html5Audio.setup(url);
return Html5Audio;
} else {
return new WebAudio(url);
}
};
var alias_stopAll = AudioManager.stopAll;
AudioManager.stopAll = function () {
alias_stopAll.call(this);
this.stopWav();
};
var alias_checkErrors = AudioManager.checkErrors;
AudioManager.checkErrors = function () {
alias_checkErrors.call(this);
this._wavBuffers.forEach(
function (buffer) {
this.checkWebAudioError(buffer);
}.bind(this)
);
};
// Wave
AudioManager.playWav = function (wavName, vol) {
var wav = {
name: wavName,
pan: 0,
pitch: 100,
volume: vol || ConfigManager.wavVolume,
};
if (wav.name) {
this._wavBuffers = this._wavBuffers.filter(function (audio) {
return audio.isPlaying();
});
var buffer = this.createBuffer('wav', wav.name, '.wav');
this.updateSeParameters(buffer, wav);
buffer.play(false);
this._wavBuffers.push(buffer);
}
};
AudioManager.stopWav = function () {
this._wavBuffers.forEach(function (buffer) {
buffer.stop();
});
this._wavBuffers = [];
};
AudioManager.updateWavParameters = function (buffer, wav) {
this.updateBufferParameters(buffer, this._wavVolume, wav);
};
//-----------------------------------------------------------------------------
// ConfigManager
//
//
Object.defineProperty(ConfigManager, 'wavVolume', {
get: function () {
return AudioManager.wavVolume;
},
set: function (value) {
AudioManager.wavVolume = value;
},
configurable: true,
});
var alias_makeData = ConfigManager.makeData;
ConfigManager.makeData = function () {
var config = alias_makeData.call(this);
config.wavVolume = this.wavVolume;
return config;
};
var alias_applyData = ConfigManager.applyData;
ConfigManager.applyData = function (config) {
alias_applyData.call(this, config);
this.wavVolume = this.readVolume(config, 'wavVolume');
};
//-----------------------------------------------------------------------------
// Window_Options
//
// The window for changing various settings on the options screen.
var alias_addVolumeOptions = Window_Options.prototype.addVolumeOptions;
Window_Options.prototype.addVolumeOptions = function () {
alias_addVolumeOptions.call(this);
this.addCommand(_wavText, 'wavVolume');
};
})();