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
- #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.
57 58 59 60 61 62 63 |
# File 'lib/native_audio.rb', line 57 def initialize(clip) @clip = clip @channel = AudioSource.channels.count @delay_taps = [] @params = {} AudioSource.channels << self end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
55 56 57 |
# File 'lib/native_audio.rb', line 55 def channel @channel end |
Class Method Details
.channels ⇒ Object
136 137 138 |
# File 'lib/native_audio.rb', line 136 def self.channels @channels ||= [] end |
Instance Method Details
#add_delay_tap(time_ms:, volume:) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/native_audio.rb', line 111 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 |
#delay_taps ⇒ Object
132 133 134 |
# File 'lib/native_audio.rb', line 132 def delay_taps @delay_taps end |
#enable_reverb(enabled = true) ⇒ Object
118 119 120 121 |
# File 'lib/native_audio.rb', line 118 def enable_reverb(enabled = true) @params[:reverb_enabled] = enabled NativeAudio.audio_driver.enable_reverb(@channel, enabled) end |
#pause ⇒ Object
74 75 76 |
# File 'lib/native_audio.rb', line 74 def pause NativeAudio.audio_driver.pause(@channel) end |
#play ⇒ Object
65 66 67 68 |
# File 'lib/native_audio.rb', line 65 def play NativeAudio.audio_driver.play(@channel, @clip.clip) apply_params end |
#resume ⇒ Object
78 79 80 |
# File 'lib/native_audio.rb', line 78 def resume NativeAudio.audio_driver.resume(@channel) end |
#seek(seconds) ⇒ Object
92 93 94 |
# File 'lib/native_audio.rb', line 92 def seek(seconds) NativeAudio.audio_driver.seek(@channel, seconds) end |
#set_looping(looping) ⇒ Object
106 107 108 109 |
# File 'lib/native_audio.rb', line 106 def set_looping(looping) @params[:looping] = looping NativeAudio.audio_driver.set_looping(@channel, looping) end |
#set_pan(pan) ⇒ Object
87 88 89 90 |
# File 'lib/native_audio.rb', line 87 def set_pan(pan) @params[:pan] = pan NativeAudio.audio_driver.set_pan(@channel, pan) end |
#set_pitch(pitch) ⇒ Object
101 102 103 104 |
# File 'lib/native_audio.rb', line 101 def set_pitch(pitch) @params[:pitch] = pitch NativeAudio.audio_driver.set_pitch(@channel, pitch) end |
#set_pos(angle, distance) ⇒ Object
82 83 84 85 |
# File 'lib/native_audio.rb', line 82 def set_pos(angle, distance) @params[:pos] = [angle, distance] NativeAudio.audio_driver.set_pos(@channel, angle, distance) end |
#set_reverb(room_size: 0.5, damping: 0.3, wet: 0.3, dry: 1.0) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/native_audio.rb', line 123 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 } 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 |
#set_volume(volume) ⇒ Object
96 97 98 99 |
# File 'lib/native_audio.rb', line 96 def set_volume(volume) @params[:volume] = volume NativeAudio.audio_driver.set_volume(@channel, volume) end |
#stop ⇒ Object
70 71 72 |
# File 'lib/native_audio.rb', line 70 def stop NativeAudio.audio_driver.stop(@channel) end |