Class: ALSA::PCM::Capture::HwParameters
- Inherits:
-
Object
- Object
- ALSA::PCM::Capture::HwParameters
- Defined in:
- lib/alsa.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_for(frame_count) ⇒ Object
- #channels ⇒ Object
- #channels=(channels) ⇒ Object
- #current_for_device ⇒ Object
- #default_for_device ⇒ Object
- #free ⇒ Object
-
#initialize(device = nil) ⇒ HwParameters
constructor
A new instance of HwParameters.
- #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.
116 117 118 119 120 121 122 123 |
# File 'lib/alsa.rb', line 116 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.
114 115 116 |
# File 'lib/alsa.rb', line 114 def device @device end |
#handle ⇒ Object
Returns the value of attribute handle.
114 115 116 |
# File 'lib/alsa.rb', line 114 def handle @handle end |
Instance Method Details
#access=(access) ⇒ Object
143 144 145 146 147 |
# File 'lib/alsa.rb', line 143 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_for(frame_count) ⇒ Object
219 220 221 |
# File 'lib/alsa.rb', line 219 def buffer_size_for(frame_count) ALSA::PCM::Native::format_size(self.sample_format, frame_count) * self.channels end |
#channels ⇒ Object
208 209 210 211 212 213 214 215 216 217 |
# File 'lib/alsa.rb', line 208 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
149 150 151 152 153 |
# File 'lib/alsa.rb', line 149 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
136 137 138 139 140 141 |
# File 'lib/alsa.rb', line 136 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
129 130 131 132 133 134 |
# File 'lib/alsa.rb', line 129 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 |
#free ⇒ Object
223 224 225 226 227 |
# File 'lib/alsa.rb', line 223 def free ALSA::try_to "unallocate hw_params" do ALSA::PCM::Native::hw_params_free self.handle end end |
#sample_format ⇒ Object
197 198 199 200 201 202 203 204 205 206 |
# File 'lib/alsa.rb', line 197 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
191 192 193 194 195 |
# File 'lib/alsa.rb', line 191 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
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/alsa.rb', line 172 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
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/alsa.rb', line 155 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
125 126 127 |
# File 'lib/alsa.rb', line 125 def update_attributes(attributes) attributes.each_pair { |name, value| send("#{name}=", value) } end |