Class: ALSA::PCM::HwParameters
- Inherits:
-
Object
- Object
- ALSA::PCM::HwParameters
- Defined in:
- lib/alsa/pcm/hw_parameters.rb
Instance Attribute Summary collapse
-
#device ⇒ Object
Returns the value of attribute device.
-
#handle ⇒ Object
Returns the value of attribute handle.
Instance Method Summary collapse
- #access=(access) ⇒ Object
- #buffer_size ⇒ Object
- #buffer_size_for(frame_count) ⇒ Object
- #buffer_time=(buffer_time) ⇒ Object
- #buffer_time_max ⇒ Object
- #channels ⇒ Object
- #channels=(channels) ⇒ Object
- #current_for_device ⇒ Object
- #default_for_device ⇒ Object
- #frame_count_for(byte_count) ⇒ Object
- #free ⇒ Object
-
#initialize(device = nil) ⇒ HwParameters
constructor
A new instance of HwParameters.
- #inspect ⇒ Object
- #period_size ⇒ Object
- #period_time ⇒ Object
- #period_time=(period_time) ⇒ Object
- #sample_format ⇒ Object
- #sample_format=(sample_format) ⇒ Object
- #sample_rate ⇒ Object
- #sample_rate=(sample_rate) ⇒ Object
- #update_attributes(attributes) ⇒ Object
Constructor Details
#initialize(device = nil) ⇒ HwParameters
Returns a new instance of HwParameters.
6 7 8 9 10 11 12 13 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 6 def initialize(device = nil) hw_params_pointer = FFI::MemoryPointer.new :pointer ALSA::PCM::Native::hw_params_malloc hw_params_pointer self.handle = hw_params_pointer.read_pointer self.device = device if device end |
Instance Attribute Details
#device ⇒ Object
Returns the value of attribute device.
4 5 6 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 4 def device @device end |
#handle ⇒ Object
Returns the value of attribute handle.
4 5 6 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 4 def handle @handle end |
Instance Method Details
#access=(access) ⇒ Object
33 34 35 36 37 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 33 def access=(access) ALSA::try_to "set access type" do ALSA::PCM::Native::hw_params_set_access self.device.handle, self.handle, ALSA::PCM::Native::Access.const_get(access.to_s.upcase) end end |
#buffer_size ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 199 def buffer_size value = nil ALSA::try_to "get buffer size" do value_pointer = FFI::MemoryPointer.new(:int) error_code = ALSA::PCM::Native::hw_params_get_buffer_size self.handle, value_pointer value = value_pointer.read_int value_pointer.free error_code end value end |
#buffer_size_for(frame_count) ⇒ Object
213 214 215 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 213 def buffer_size_for(frame_count) ALSA::PCM::Native::format_size(self.sample_format, frame_count) * self.channels end |
#buffer_time=(buffer_time) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 116 def buffer_time=(buffer_time) ALSA::try_to "set buffer time (#{buffer_time})" do value = FFI::MemoryPointer.new(:int) value.write_int(buffer_time) dir = FFI::MemoryPointer.new(:int) dir.write_int(-1) error_code = ALSA::PCM::Native::hw_params_set_buffer_time_near self.device.handle, self.handle, value, dir value.free dir.free error_code end end |
#buffer_time_max ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 78 def buffer_time_max value = nil ALSA::try_to "get buffer time max" do value_pointer = FFI::MemoryPointer.new(:int) dir_pointer = FFI::MemoryPointer.new(:int) dir_pointer.write_int(0) error_code = ALSA::PCM::Native::hw_params_get_buffer_time_max self.handle, value_pointer, dir_pointer value = value_pointer.read_int value_pointer.free dir_pointer.free error_code end value end |
#channels ⇒ Object
169 170 171 172 173 174 175 176 177 178 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 169 def channels channels = nil FFI::MemoryPointer.new(:int) do |channels_pointer| ALSA::try_to "get channels" do ALSA::PCM::Native::hw_params_get_channels self.handle, channels_pointer end channels = channels_pointer.read_int end channels end |
#channels=(channels) ⇒ Object
39 40 41 42 43 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 39 def channels=(channels) ALSA::try_to "set channel count : #{channels}" do ALSA::PCM::Native::hw_params_set_channels self.device.handle, self.handle, channels end end |
#current_for_device ⇒ Object
26 27 28 29 30 31 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 26 def current_for_device ALSA::try_to "retrieve current hardware parameters" do ALSA::PCM::Native::hw_params_current device.handle, self.handle end self end |
#default_for_device ⇒ Object
19 20 21 22 23 24 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 19 def default_for_device ALSA::try_to "initialize hardware parameter structure" do ALSA::PCM::Native::hw_params_any device.handle, self.handle end self end |
#frame_count_for(byte_count) ⇒ Object
217 218 219 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 217 def frame_count_for(byte_count) ALSA::PCM::Native::bytes_to_frames(self.device.handle, byte_count) end |
#free ⇒ Object
221 222 223 224 225 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 221 def free ALSA::try_to "unallocate hw_params" do ALSA::PCM::Native::hw_params_free self.handle end end |
#inspect ⇒ Object
227 228 229 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 227 def inspect "#<ALSA::PCM::HwParameters:#{object_id} sample_rate=#{sample_rate}, channels=#{channels}, period_time=#{period_time}, period_size=#{period_size}, buffer_size=#{buffer_size}>" end |
#period_size ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 180 def period_size value = nil ALSA::try_to "get period size" do value_pointer = FFI::MemoryPointer.new(:int) dir_pointer = FFI::MemoryPointer.new(:int) dir_pointer.write_int(0) error_code = ALSA::PCM::Native::hw_params_get_period_size self.handle, value_pointer, dir_pointer value = value_pointer.read_int value_pointer.free dir_pointer.free error_code end value end |
#period_time ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 97 def period_time value = nil ALSA::try_to "get period time" do value_pointer = FFI::MemoryPointer.new(:int) dir_pointer = FFI::MemoryPointer.new(:int) dir_pointer.write_int(0) error_code = ALSA::PCM::Native::hw_params_get_period_time self.handle, value_pointer, dir_pointer value = value_pointer.read_int value_pointer.free dir_pointer.free error_code end value end |
#period_time=(period_time) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 62 def period_time=(period_time) ALSA::try_to "set period time (#{period_time})" do value = FFI::MemoryPointer.new(:int) value.write_int(period_time) dir = FFI::MemoryPointer.new(:int) dir.write_int(-1) error_code = ALSA::PCM::Native::hw_params_set_period_time_near self.device.handle, self.handle, value, dir value.free dir.free error_code end end |
#sample_format ⇒ Object
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 158 def sample_format format = nil FFI::MemoryPointer.new(:int) do |format_pointer| ALSA::try_to "get sample format" do ALSA::PCM::Native::hw_params_get_format self.handle, format_pointer end format = format_pointer.read_int end format end |
#sample_format=(sample_format) ⇒ Object
152 153 154 155 156 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 152 def sample_format=(sample_format) ALSA::try_to "set sample format" do ALSA::PCM::Native::hw_params_set_format self.device.handle, self.handle, ALSA::PCM::Native::Format.const_get(sample_format.to_s.upcase) end end |
#sample_rate ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 132 def sample_rate rate = nil ALSA::try_to "get sample rate" do rate_pointer = FFI::MemoryPointer.new(:int) dir_pointer = FFI::MemoryPointer.new(:int) dir_pointer.write_int(0) error_code = ALSA::PCM::Native::hw_params_get_rate self.handle, rate_pointer, dir_pointer rate = rate_pointer.read_int rate_pointer.free dir_pointer.free error_code end rate end |
#sample_rate=(sample_rate) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 45 def sample_rate=(sample_rate) ALSA::try_to "set sample rate" do rate = FFI::MemoryPointer.new(:int) rate.write_int(sample_rate) dir = FFI::MemoryPointer.new(:int) dir.write_int(0) error_code = ALSA::PCM::Native::hw_params_set_rate_near self.device.handle, self.handle, rate, dir rate.free dir.free error_code end end |
#update_attributes(attributes) ⇒ Object
15 16 17 |
# File 'lib/alsa/pcm/hw_parameters.rb', line 15 def update_attributes(attributes) attributes.each_pair { |name, value| send("#{name}=", value) } end |