Class: NativeAudio::AudioSource
- Inherits:
-
Object
- Object
- NativeAudio::AudioSource
- Defined in:
- lib/native_audio.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
Class Method Summary collapse
Instance Method Summary collapse
- #add_delay_tap(time_ms:, volume:) ⇒ Object
- #channel_freed ⇒ Object
- #delay_taps ⇒ Object
- #enable_reverb(enabled = true) ⇒ Object
-
#initialize(clip) ⇒ AudioSource
constructor
A new instance of AudioSource.
- #pause ⇒ Object
- #play ⇒ Object
- #resume ⇒ Object
- #seek(seconds) ⇒ Object
- #set_looping(looping) ⇒ Object
- #set_pan(pan) ⇒ Object
- #set_pitch(pitch) ⇒ Object
- #set_pos(angle, distance) ⇒ Object
- #set_reverb(room_size: 0.5, damping: 0.3, wet: 0.3, dry: 1.0) ⇒ Object
- #set_volume(volume) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(clip) ⇒ AudioSource
Returns a new instance of AudioSource.
58 59 60 61 62 63 |
# File 'lib/native_audio.rb', line 58 def initialize(clip) @clip = clip @delay_taps = [] @params = {} @channel = nil end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
56 57 58 |
# File 'lib/native_audio.rb', line 56 def channel @channel end |
Class Method Details
.owners ⇒ Object
82 83 84 |
# File 'lib/native_audio.rb', line 82 def self.owners @owners ||= {} end |
.setup_channel_freed_callback ⇒ Object
86 87 88 89 90 91 |
# File 'lib/native_audio.rb', line 86 def self.setup_channel_freed_callback NativeAudio.audio_driver.on_channel_freed(proc { |channel| owner = owners.delete(channel) owner&.channel_freed }) end |
Instance Method Details
#add_delay_tap(time_ms:, volume:) ⇒ Object
130 131 132 133 134 135 |
# File 'lib/native_audio.rb', line 130 def add_delay_tap(time_ms:, volume:) tap_id = NativeAudio.audio_driver.add_delay_tap(@channel, time_ms, volume) tap = DelayTap.new(self, tap_id, time_ms, volume) @delay_taps << tap tap end |
#channel_freed ⇒ Object
78 79 80 |
# File 'lib/native_audio.rb', line 78 def channel_freed @channel = nil end |
#delay_taps ⇒ Object
153 154 155 |
# File 'lib/native_audio.rb', line 153 def delay_taps @delay_taps end |
#enable_reverb(enabled = true) ⇒ Object
137 138 139 140 |
# File 'lib/native_audio.rb', line 137 def enable_reverb(enabled = true) @params[:reverb_enabled] = enabled NativeAudio.audio_driver.enable_reverb(@channel, enabled) if @channel end |
#pause ⇒ Object
93 94 95 |
# File 'lib/native_audio.rb', line 93 def pause NativeAudio.audio_driver.pause(@channel) if @channel end |
#play ⇒ Object
65 66 67 68 69 |
# File 'lib/native_audio.rb', line 65 def play acquire_channel unless @channel NativeAudio.audio_driver.play(@channel, @clip.clip) apply_params end |
#resume ⇒ Object
97 98 99 |
# File 'lib/native_audio.rb', line 97 def resume NativeAudio.audio_driver.resume(@channel) if @channel end |
#seek(seconds) ⇒ Object
111 112 113 |
# File 'lib/native_audio.rb', line 111 def seek(seconds) NativeAudio.audio_driver.seek(@channel, seconds) if @channel end |
#set_looping(looping) ⇒ Object
125 126 127 128 |
# File 'lib/native_audio.rb', line 125 def set_looping(looping) @params[:looping] = looping NativeAudio.audio_driver.set_looping(@channel, looping) if @channel end |
#set_pan(pan) ⇒ Object
106 107 108 109 |
# File 'lib/native_audio.rb', line 106 def set_pan(pan) @params[:pan] = pan NativeAudio.audio_driver.set_pan(@channel, pan) if @channel end |
#set_pitch(pitch) ⇒ Object
120 121 122 123 |
# File 'lib/native_audio.rb', line 120 def set_pitch(pitch) @params[:pitch] = pitch NativeAudio.audio_driver.set_pitch(@channel, pitch) if @channel end |
#set_pos(angle, distance) ⇒ Object
101 102 103 104 |
# File 'lib/native_audio.rb', line 101 def set_pos(angle, distance) @params[:pos] = [angle, distance] NativeAudio.audio_driver.set_pos(@channel, angle, distance) if @channel end |
#set_reverb(room_size: 0.5, damping: 0.3, wet: 0.3, dry: 1.0) ⇒ Object
142 143 144 145 146 147 148 149 150 151 |
# File 'lib/native_audio.rb', line 142 def set_reverb(room_size: 0.5, damping: 0.3, wet: 0.3, dry: 1.0) @params[:reverb] = { room_size: room_size, damping: damping, wet: wet, dry: dry } if @channel NativeAudio.audio_driver.enable_reverb(@channel, true) NativeAudio.audio_driver.set_reverb_room_size(@channel, room_size) NativeAudio.audio_driver.set_reverb_damping(@channel, damping) NativeAudio.audio_driver.set_reverb_wet(@channel, wet) NativeAudio.audio_driver.set_reverb_dry(@channel, dry) end end |
#set_volume(volume) ⇒ Object
115 116 117 118 |
# File 'lib/native_audio.rb', line 115 def set_volume(volume) @params[:volume] = volume NativeAudio.audio_driver.set_volume(@channel, volume) if @channel end |
#stop ⇒ Object
71 72 73 74 75 76 |
# File 'lib/native_audio.rb', line 71 def stop return unless @channel NativeAudio.audio_driver.stop(@channel) self.class.owners.delete(@channel) @channel = nil end |