Module: Gemwarrior::Audio
- Defined in:
- lib/gemwarrior/misc/audio.rb
Class Method Summary collapse
- .get_cues ⇒ Object
- .init ⇒ Object
- .play_sample(audio_cue_symbol) ⇒ Object
- .play_synth(audio_cue_symbol) ⇒ Object
Class Method Details
.get_cues ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gemwarrior/misc/audio.rb', line 34 def self.get_cues if GameOptions.data['sound_enabled'] case GameOptions.data['sound_system'] when 'win32-sound', 'feep' require_relative 'audio_cues' AudioCues.cues when 'bloops' require_relative 'bloops_cues' BloopsCues.cues end end end |
.init ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gemwarrior/misc/audio.rb', line 10 def self.init if GameOptions.data['sound_system'].eql?('win32-sound') begin require 'win32/sound' rescue GameOptions.data['errors'] = "#{GameOptions.data['sound_system']} could not be loaded. You may need to run 'gem install #{GameOptions.data['sound_system']}'. Silence for now." end elsif GameOptions.data['sound_system'].eql?('feep') begin require 'feep' rescue GameOptions.data['errors'] = "#{GameOptions.data['sound_system']} could not be loaded. You may need to run 'gem install #{GameOptions.data['sound_system']}'. Silence for now." end elsif GameOptions.data['sound_system'].eql?('bloops') begin require 'bloops' rescue GameOptions.data['errors'] = "#{GameOptions.data['sound_system']} could not be loaded. You may need to run 'gem install #{GameOptions.data['sound_system']}aphone'. Silence for now." end else GameOptions.data['errors'] = "'#{GameOptions.data['sound_system']}' is not a valid sound system. Audio subsystem load failed." end end |
.play_sample(audio_cue_symbol) ⇒ Object
123 124 125 |
# File 'lib/gemwarrior/misc/audio.rb', line 123 def self.play_sample(audio_cue_symbol) # future use end |
.play_synth(audio_cue_symbol) ⇒ Object
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 |
# File 'lib/gemwarrior/misc/audio.rb', line 47 def self.play_synth(audio_cue_symbol) if GameOptions.data['sound_enabled'] case GameOptions.data['sound_system'] when 'win32-sound' require_relative 'audio_cues' require_relative 'musical_notes' if AudioCues.cues[audio_cue_symbol] Thread.start do AudioCues.cues[audio_cue_symbol][:synth].each do |seq| threads = [] seq[:frequencies].split(',').each do |note| threads << Thread.new do Win32::Sound::play_freq(Notes::NOTE_FREQ[note], seq[:duration], GameOptions.data['sound_volume']) end end threads.each { |th| th.join } end end end when 'feep' require_relative 'audio_cues' feep_defaults = { frequencies: '440', waveform: 'sine', volume: GameOptions.data['sound_volume'], duration: 500, notext: true } if AudioCues.cues[audio_cue_symbol] Thread.start do AudioCues.cues[audio_cue_symbol][:synth].each do |seq| seq = feep_defaults.merge(seq) Feep::Base.new({ freq_or_note: seq[:frequencies], waveform: seq[:waveform], volume: seq[:volume], duration: seq[:duration], notext: seq[:notext] }) end end end when 'bloops' require_relative 'bloops_cues' if BloopsCues.cues[audio_cue_symbol] Thread.start do BloopsCues.cues[audio_cue_symbol][:synth].each do |seq| threads = [] seq.each do |note| threads << Thread.new do b = Bloops.new b.tempo = 240 snd = b.sound Bloops::SQUARE snd.punch = GameOptions.data['sound_volume']/2 snd.sustain = 0.7 snd.decay = 0.2 b.tune snd, note[1] b.play sleep 0.1 while !b.stopped? end end threads.each { |th| th.join } end end end end end end |