Module: Audio

Defined in:
scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00600 Audio.rb,
scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb,
scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb,
scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb,
scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00800 Audio___Cache.rb

Overview

The RGSS Audio module

Defined Under Namespace

Modules: Cache

Constant Summary collapse

FadeInTime =

Time it takes to fade in (in ms)

1000
EXT =

List of extension that FmodEx can read (used to find files from names without ext name)

['.ogg', '.mp3', '.wav', '.flac']

Class Method Summary collapse

Class Method Details

.__reset__

Reset the sound engine



474
475
476
477
478
479
480
481
482
483
484
485
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 474

def __reset__
  bgm_stop
  bgs_stop
  me_stop
  se_stop
  @bgm_sound = nil
  @bgs_sound = nil
  @me_sound = nil
  @se_sounds = {}
  @fading_sounds = {}
  @was_playing_callback = nil
end

.adjust_channel(channel, volume, pitch)

Adjust channel volume and pitch

Parameters:

  • channel (Fmod::Channel)
  • volume (Numeric)

    target volume

  • pitch (Numeric)

    target pitch



458
459
460
461
462
463
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 458

def adjust_channel(channel, volume, pitch)
  channel.setPriority([@bgm_channel, @me_channel, @bgs_channel].index(channel) || 128)
  channel.setVolume(volume / 100.0)
  channel.setPitch(pitch / 100.0)
  channel.setPaused(false)
end

.autoloop(music, memory)

Auto loop a music (only works for ogg if tags are in 2048 first bytes)

Parameters:

  • music (SFML::Music)

    the music object

  • memory (String)

    the file data



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 343

def autoloop(sound)
  start = sound.getTag('LOOPSTART', 0)[2].to_i rescue nil
  length = sound.getTag('LOOPLENGTH', 0)[2].to_i rescue nil
  unless start && length # Probably an MP3
    index = 0
    while (tag = sound.getTag('TXXX', index) rescue nil)
      index += 1
      next unless tag[2].is_a?(String)
      name, data = tag[2].split("\x00")
      if name == 'LOOPSTART' && !start
        start = data.to_i
      elsif name == 'LOOPLENGTH' && !length
        length = data.to_i
      end
    end
  end
  return unless start && length
  log_info "LOOP: #{start} -> #{start + length}" unless PSDK_CONFIG.release?
  sound.setLoopPoints(start, FMOD::TIMEUNIT::PCM, start + length, FMOD::TIMEUNIT::PCM)
end

.bgm_fade(time)

Fades the BGM

Parameters:

  • time (Integer)

    fade time in ms



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 94

def bgm_fade(time)
  synchronize(@bgm_mutex) do
    return unless @bgm_channel
    return unless (sound = @bgm_sound)
    return if @fading_sounds[sound]

    fade(time, @fading_sounds[sound] = @bgm_channel)
    @bgm_channel = nil
  rescue FMOD::Error
    @fading_sounds.delete(sound)
    @bgm_channel = nil
  end
end

.bgm_play

plays a BGM and stop the current one

Parameters:

  • file_name (String)

    name of the audio file

  • volume (Integer)

    volume of the BGM between 0 and 100

  • pitch (Integer)

    speed of the BGM in percent

  • fade_in (Boolean, Integer)

    (ignored)



31
32
33
34
35
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 31

def bgm_play(file_name, volume = 100, pitch = 100, fade_in = true)
  Thread.new do
    synchronize(@bgm_mutex) { bgm_play_internal(file_name, volume, pitch, fade_in) }
  end
end

.bgm_play_internal(file_name, volume, pitch, fade_in)

plays a BGM and stop the current one

Parameters:

  • file_name (String)

    name of the audio file

  • volume (Integer)

    volume of the BGM between 0 and 100

  • pitch (Integer)

    speed of the BGM in percent

  • fade_in (Boolean, Integer)

    if the BGM fades in when different (or time in ms)



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
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 42

def bgm_play_internal(file_name, volume, pitch, fade_in)
  volume = volume * @music_volume / 100
  filename = search_filename(file_name)
  was_playing = was_sound_previously_playing?(file_name.downcase, @bgm_name, @bgm_sound, @bgm_channel, fade_in)
  @bgm_name = file_name.downcase
  fade_in = (fade_in and @bgm_sound and !was_playing)
  release_fading_sounds((was_playing || fade_in) ? nil : @bgm_sound)
  # Unless the sound was playing, we create it
  unless was_playing
    @bgm_sound = @bgm_channel = nil
    # @bgm_sound = FMOD::System.createSound(filename, FMOD::MODE::LOOP_NORMAL | FMOD::MODE::FMOD_2D, nil)
    return unless (@bgm_sound = Cache.create_sound_sound(filename))
    autoloop(@bgm_sound)
  end
  # we create a channel if there was no channel or the sound was not playing
  @bgm_channel = FMOD::System.playSound(@bgm_sound, true) unless was_playing and @bgm_channel
  adjust_channel(@bgm_channel, volume, pitch)
  @bgm_channel.setDelay(@me_bgm_restart, 0, fade_in = false) if @me_bgm_restart and @me_bgm_restart > @bgm_channel.getDSPClock.last
  fade(fade_in == true ? FadeInTime : fade_in, @bgm_channel, 0, 1.0) if fade_in
  @fading_sounds.delete(@bgm_sound) # Reused channel error prevention
rescue FMOD::Error
  if File.exist?(filename)
    log_error("Le fichier #{file_name} n'a pas pu être lu...\nErreur : #{$!.message}")
  else
    log_error("Le fichier #{filename} n'a pas été trouvé !")
  end
  bgm_stop
ensure
  call_was_playing_callback
end

.bgm_positionInteger

Returns the BGM position

Returns:



75
76
77
78
79
80
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 75

def bgm_position
  synchronize(@bgm_mutex) do
    return @bgm_channel.getPosition(FMOD::TIMEUNIT::PCM) if @bgm_channel
  end
  return 0
end

.bgm_position=

Set the BGM position

Parameters:



84
85
86
87
88
89
90
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 84

def bgm_position=(position)
  synchronize(@bgm_mutex) do
    @bgm_channel&.setPosition(position, FMOD::TIMEUNIT::PCM)
  end
rescue StandardError
  log_error("bgm_position= : #{$!.message}")
end

.bgm_stop

Stop the BGM



109
110
111
112
113
114
115
116
117
118
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 109

def bgm_stop
  synchronize(@bgm_mutex) do
    return unless @bgm_channel
    @bgm_channel.stop
    @bgm_channel = nil
  end
rescue FMOD::Error => e
  @bgm_channel = nil
  puts e.message if debug?
end

.bgs_fade(time)

Fades the BGS

Parameters:

  • time (Integer)

    fade time in ms



169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 169

def bgs_fade(time)
  synchronize(@bgs_mutex) do
    return unless @bgs_channel
    return unless (sound = @bgs_sound)
    return if @fading_sounds[sound]

    fade(time, @fading_sounds[sound] = @bgs_channel)
    @bgs_channel = nil
  rescue FMOD::Error
    @fading_sounds.delete(sound)
    @bgs_channel = nil
  end
end

.bgs_play

plays a BGS and stop the current one

Parameters:

  • file_name (String)

    name of the audio file

  • volume (Integer)

    volume of the BGS between 0 and 100

  • pitch (Integer)

    speed of the BGS in percent

  • fade_in (Boolean, Integer)

    if the BGS fades in when different (Integer = time to fade)



125
126
127
128
129
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 125

def bgs_play(file_name, volume = 100, pitch = 100, fade_in = true)
  Thread.new do
    synchronize(@bgs_mutex) { bgs_play_internal(file_name, volume, pitch, fade_in) }
  end
end

.bgs_play_internal(file_name, volume, pitch, fade_in)

plays a BGS and stop the current one

Parameters:

  • file_name (String)

    name of the audio file

  • volume (Integer)

    volume of the BGS between 0 and 100

  • pitch (Integer)

    speed of the BGS in percent

  • fade_in (Boolean, Integer)

    if the BGS fades in when different (Integer = time to fade)



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
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 136

def bgs_play_internal(file_name, volume, pitch, fade_in)
  volume = volume * @sfx_volume / 100
  filename = search_filename(file_name)
  was_playing = was_sound_previously_playing?(file_name.downcase, @bgs_name, @bgs_sound, @bgs_channel, fade_in)
  @bgs_name = file_name.downcase
  fade_in = (fade_in and @bgs_sound and !was_playing)
  release_fading_sounds((was_playing || fade_in) ? nil : @bgs_sound)
  # Unless the sound was playing, we create it
  unless was_playing
    @bgs_sound = @bgs_channel = nil
    # @bgs_sound = FMOD::System.createSound(filename, FMOD::MODE::LOOP_NORMAL | FMOD::MODE::FMOD_2D, nil)
    return unless (@bgs_sound = Cache.create_sound_sound(filename))
    autoloop(@bgs_sound)
  end
  # we create a channel if there was no channel or the sound was not playing
  @bgs_channel = FMOD::System.playSound(@bgs_sound, true) unless was_playing and @bgs_channel
  adjust_channel(@bgs_channel, volume, pitch)
  fade(fade_in == true ? FadeInTime : fade_in, @bgs_channel, 0, 1.0) if fade_in
  @fading_sounds.delete(@bgs_sound) # Reused channel error prevention
rescue FMOD::Error
  if File.exist?(filename)
    cc 0x01
    log_error("Le fichier #{file_name} n'a pas pu être lu...\nErreur : #{$!.message}")
  else
    log_error("Le fichier #{filename} n'a pas été trouvé !")
  end
  bgs_stop
ensure
  call_was_playing_callback
end

.bgs_stop

Stop the BGS



184
185
186
187
188
189
190
191
192
193
194
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 184

def bgs_stop
  synchronize(@bgs_mutex) do
    return unless @bgs_channel

    @bgs_channel.stop
    @bgs_channel = nil
  end
rescue FMOD::Error => e
  @bgs_channel = nil
  puts e.message if debug?
end

.call_was_playing_callback

Automatically call the “was playing callback”



466
467
468
469
470
471
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 466

def call_was_playing_callback
  @was_playing_callback&.call
  @was_playing_callback = nil
rescue StandardError
  @was_playing_callback = nil
end

.channel_stop_time_exceeded(channel) ⇒ Boolean

Note:

will return true if the channel handle is invalid

Return if the channel time is higher than the stop time

Parameters:

  • channel (FMOD::Channel)

Returns:

  • (Boolean)


427
428
429
430
431
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 427

def channel_stop_time_exceeded(channel)
  return channel.getDSPClock.last >= channel.instance_variable_get(:@stop_time).to_i
rescue FMOD::Error
  return true
end

.cry_exist?(filename) ⇒ Boolean

Tells if a cry file exists or not

Parameters:

  • filename (String)

    the name of the cry file

Returns:

  • (Boolean)


42
43
44
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00600 Audio.rb', line 42

def cry_exist?(filename)
  return File.exist?(filename)
end

.cry_play(filename, volume = 100, pitch = 100)

A weird alias of #se_play



35
36
37
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00600 Audio.rb', line 35

def cry_play(filename, volume = 100, pitch = 100)
  se_play(filename, volume, pitch)
end

.fade(time, channel, start_value = 1.0, end_value = 0)

Fade a channel

Parameters:

  • time (Integer)

    number of miliseconds to perform the fade

  • channel (FMOD::Channel)

    the channel to fade

  • start_value (Numeric) (defaults to: 1.0)
  • end_value (Numeric) (defaults to: 0)


369
370
371
372
373
374
375
376
377
378
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 369

def fade(time, channel, start_value = 1.0, end_value = 0)
  sr = FMOD::System.getSoftwareFormat.first
  pdsp = channel.getDSPClock.last
  stop_time = pdsp + Integer(time * sr / 1000)
  channel.addFadePoint(pdsp, start_value)
  channel.addFadePoint(stop_time, end_value)
  channel.setDelay(0, stop_time + 20, false) if end_value == 0
  channel.setVolumeRamp(true)
  channel.instance_variable_set(:@stop_time, stop_time)
end

.fade_in_out(channel, fadeout_time, sleep_time, fadein_time, sleep_type = :ms, lowest_volume = 0.0)

Fade in out a channel

Parameters:

  • channel (FMOD::Channel)

    the channel to fade

  • fadeout_time (Integer)

    number of miliseconds to perform the fade out

  • sleep_time (Integer)

    number of miliseconds to wait before fading in

  • fadein_time (Integer)

    number of miliseconds to perform the fade in

  • sleep_type (Symbol) (defaults to: :ms)

    tell the sleep_time type (:ms, :pcm)

  • lowest_volume (Integer) (defaults to: 0.0)

    lowest volume in %



387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 387

def fade_in_out(channel, fadeout_time, sleep_time, fadein_time, sleep_type = :ms, lowest_volume = 0.0)
  sr = FMOD::System.getSoftwareFormat.first
  pdsp = channel.getDSPClock.last
  sleep_time = sleep_time * sr / 1000 if sleep_type == :ms
  p1_time = pdsp + Integer(fadeout_time * sr / 1000)
  p2_time = pdsp + Integer(fadeout_time * sr / 1000) + sleep_time
  p3_time = pdsp + Integer((fadeout_time + fadein_time) * sr / 1000) + sleep_time
  channel.addFadePoint(pdsp, 1.0)
  channel.addFadePoint(p1_time, lowest_volume)
  channel.addFadePoint(p2_time, lowest_volume)
  channel.addFadePoint(p3_time, 1.0)
  channel.setVolumeRamp(true)
end

.load_file_data(filename) ⇒ String?

Load the file data

Parameters:

  • filename (String)

    name of the file without extension

Returns:



674
675
676
677
678
679
680
681
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 674

def load_file_data(filename)
  real_filename = search_filename(filename)
  unless File.exist?(real_filename)
    log_error("The audio file #{real_filename} couldn't be loaded")
    return nil
  end
  return File.binread(real_filename)
end

.me_fade(time)

Fades the ME

Parameters:

  • time (Integer)

    fade time in ms



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 253

def me_fade(time)
  synchronize(@me_mutex) do
    return unless @me_channel
    return unless (sound = @me_sound)
    return if @fading_sounds[sound]

    fade(time, @me_channel)
  rescue FMOD::Error => e
    puts e.message if debug?
  ensure
    if @bgm_channel
      sr = FMOD::System.getSoftwareFormat.first
      delay = @bgm_channel.getDSPClock.last + Integer(time * sr / 1000)
      @bgm_channel.setDelay(delay, 0, false) if !@me_bgm_restart || @me_bgm_restart > delay
    end
    @me_channel = nil
  end
end

.me_play

plays a ME and stop the current one, the BGM will be paused during the ME play

Parameters:

  • file_name (String)

    name of the audio file

  • volume (Integer)

    volume of the ME between 0 and 100

  • pitch (Integer)

    speed of the ME in percent

  • preserve_bgm (Boolean)

    tell the function not to pause the bgm



201
202
203
204
205
206
207
208
209
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 201

def me_play(file_name, volume = 100, pitch = 100, preserve_bgm = false)
  Thread.new do
    synchronize(@bgm_mutex) do
      synchronize(@me_mutex) do
        me_play_internal(file_name, volume, pitch, preserve_bgm)
      end
    end
  end
end

.me_play_internal(file_name, volume, pitch, preserve_bgm)

plays a ME and stop the current one, the BGM will be paused during the ME play

Parameters:

  • file_name (String)

    name of the audio file

  • volume (Integer)

    volume of the ME between 0 and 100

  • pitch (Integer)

    speed of the ME in percent

  • preserve_bgm (Boolean)

    tell the function not to pause the bgm



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 216

def me_play_internal(file_name, volume, pitch, preserve_bgm)
  volume = volume * @music_volume / 100
  filename = search_filename(file_name)
  was_playing = was_sound_previously_playing?(file_name.downcase, @me_name, @me_sound, @me_channel)
  @me_name = file_name.downcase
  release_fading_sounds(was_playing ? nil : @me_sound)
  # Unless the sound was playing, we create it
  unless was_playing
    @me_sound = @me_channel = nil
    return unless (@me_sound = Cache.create_sound_sound(filename, FMOD::MODE::LOOP_OFF | FMOD::MODE::FMOD_2D)) # FMOD::System.createStream(filename, FMOD::MODE::LOOP_OFF | FMOD::MODE::FMOD_2D, nil)
  end
  # we create a channel if there was no channel or the sound was not playing
  @me_channel = FMOD::System.playSound(@me_sound, true)
  adjust_channel(@me_channel, volume, pitch)
  @fading_sounds.delete(@me_sound) # Reused channel error prevention
  return if preserve_bgm
  if @bgm_channel
    length = @me_sound.getLength(FMOD::TIMEUNIT::PCM) * 100
    length /= pitch
    @bgm_channel.setDelay(@me_bgm_restart = @bgm_channel.getDSPClock.last + length, 0, false)
  else
    @me_bgm_restart = nil
  end
rescue FMOD::Error
  if File.exist?(filename)
    cc 0x01
    log_error("Le fichier #{file_name} n'a pas pu être lu...\nErreur : #{$!.message}")
  else
    log_error("Le fichier #{filename} n'a pas été trouvé !")
  end
  me_stop
ensure
  call_was_playing_callback
end

.me_stop

Stop the ME



273
274
275
276
277
278
279
280
281
282
283
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 273

def me_stop
  synchronize(@me_mutex) do
    return unless @me_channel
    @bgm_channel&.setDelay(0, 0, false)
    @me_channel.stop
    @me_channel = nil
  end
rescue FMOD::Error => e
  @me_channel = nil
  puts e.message if debug?
end

.music_volumeInteger

Get volume of bgm and me

Returns:

  • (Integer)

    a value between 0 and 100



10
11
12
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00600 Audio.rb', line 10

def music_volume
  return @music_volume
end

.music_volume=(value)

Set the volume of bgm and me

Parameters:

  • value (Integer)

    a value between 0 and 100



16
17
18
19
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00600 Audio.rb', line 16

def music_volume=(value)
  value = value.to_i.abs
  @music_volume = value < 101 ? value : 100
end

.release_fading_sounds(additionnal_sound)

Note:

: Warning ! Doing sound.release before channel.anything make the channel invalid and raise an FMOD::Error

Try to release all fading sounds that are done fading

Parameters:

  • additionnal_sound (FMOD::Sound, nil)

    a sound that should be released with the others



404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 404

def release_fading_sounds(additionnal_sound)
  unless @fading_sounds.empty?
    sound_guardian = [@bgm_sound, @bgs_sound, @me_sound]
    sounds_to_delete = []
    @fading_sounds.each do |sound, channel|
      additionnal_sound = nil if additionnal_sound == sound
      next unless channel_stop_time_exceeded(channel)
      sounds_to_delete << sound
      channel.stop
      next if sound_guardian.include?(sound)
      sound.release
    rescue FMOD::Error
      next # Next iteration if channel.stop failed
    end
    sounds_to_delete.each { |sound| @fading_sounds.delete(sound) }
  end
  additionnal_sound&.release
end

.se_play

plays a SE if possible

Parameters:

  • file_name (String)

    name of the audio file

  • volume (Integer)

    volume of the SE between 0 and 100

  • pitch (Integer)

    speed of the SE in percent



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 289

def se_play(file_name, volume = 100, pitch = 100)
  volume = volume * @sfx_volume / 100
  filename = search_filename(file_name)
  unless (sound = @se_sounds[file_name])
    sound = FMOD::System.createStream(filename, FMOD::MODE::LOOP_OFF | FMOD::MODE::FMOD_2D, nil)
    if filename.include?('/cries/')
      @cries_stack << sound
      @cries_stack.shift.release if @cries_stack.size > 5
    else
      @se_sounds[file_name] = sound
    end
  end
  channel = FMOD::System.playSound(sound, true)
  channel.setPriority(250)
  channel.setVolume(volume / 100.0)
  channel.setPitch(pitch / 100.0)
  channel.setPaused(false)
rescue FMOD::Error
  if !File.exist?(filename)
    log_error("Le fichier #{filename} n'a pas été trouvé !")
  elsif $!.message.delete('FmodError ').to_i == 46
    p @se_sounds
    se_stop
    retry
  else
    cc 0x01
    log_error("Le fichier #{file_name} n'a pas pu être lu...\nErreur : #{$!.message}")
  end
end

.se_stop

Stops every SE



320
321
322
323
324
325
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 320

def se_stop
  @se_sounds.each_value(&:release)
  @cries_stack.each(&:release)
  @cries_stack.clear
  @se_sounds.clear
end

.search_filename(file_name) ⇒ String

Search the real filename of the audio file

Parameters:

  • file_name (String)

    filename of the audio file

Returns:

  • (String)

    real filename if found or file_name



330
331
332
333
334
335
336
337
338
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 330

def search_filename(file_name)
  file_name = file_name.downcase
  return file_name if File.exist?(file_name)
  EXT.each do |ext|
    filename = file_name + ext
    return filename if File.exist?(filename)
  end
  return file_name
end

.sfx_volumeInteger

Get volume of sfx

Returns:

  • (Integer)

    a value between 0 and 100



23
24
25
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00600 Audio.rb', line 23

def sfx_volume
  return @sfx_volume
end

.sfx_volume=(value)

Set the volume of sfx

Parameters:

  • value (Integer)

    a value between 0 and 100



29
30
31
32
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00600 Audio.rb', line 29

def sfx_volume=(value)
  value = value.to_i.abs
  @sfx_volume = value < 101 ? value : 100
end

.synchronize(mutex, &block)

Synchronize a mutex

Parameters:

  • mutex (Mutex)

    the mutex to safely synchronize

  • block (Proc)

    the block to call



490
491
492
493
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 490

def synchronize(mutex, &block)
  return yield if mutex.locked? && mutex.owned?
  mutex.synchronize(&block)
end

.update

Update the Audio



496
497
498
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 496

def update
  FMOD::System.update
end

.update_fade(sound, start_time, volume, duration) ⇒ Boolean

Update a fading operation

Parameters:

  • sound (SFMLAudio::Music)
  • start_time (Time)
  • volume (Float)
  • duration (Float)

Returns:

  • (Boolean)

    if the sound should be stopped



739
740
741
742
743
744
745
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 739

def update_fade(sound, start_time, volume, duration)
  current_duration = Graphics.current_time - start_time
  return true if current_duration >= duration

  sound.set_volume(volume * (1 - current_duration / duration))
  return false
end

.was_sound_previously_playing?(filename, old_filename, sound, channel, fade_out = false) ⇒ Boolean

Note:

If the sound wasn't the same, the channel will be stopped if not nil

Function that detects if the previous playing sound is the same as the next one

Parameters:

  • filename (String)

    the filename of the sound

  • old_filename (String)

    the filename of the old sound

  • sound (FMOD::Sound)

    the previous playing sound

  • channel (FMOD::Channel, nil)

    the previous playing channel

  • fade_out (Boolean, Integer) (defaults to: false)

    if the channel should fades out (Integer = time to fade)

Returns:

  • (Boolean)


441
442
443
444
445
446
447
448
449
450
451
452
# File 'scripts/00000 Dependencies/00400 Patch_Ajouts_LiteRGSS/00700 Audio___Fmod.rb', line 441

def was_sound_previously_playing?(filename, old_filename, sound, channel, fade_out = false)
  return false unless sound
  return true unless filename != old_filename
  return false unless channel && (channel.isPlaying rescue false)
  if fade_out && !@fading_sounds[sound]
    fade_time = fade_out == true ? FadeInTime : fade_out
    @was_playing_callback = proc { fade(fade_time, @fading_sounds[sound] = channel) }
  else
    @was_playing_callback = proc { channel.stop }
  end
  return false
end