ruby-alsa 0.0.5 → 0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,12 +26,20 @@ module ALSA::PCM
26
26
 
27
27
  self.hardware_parameters = hardware_attributes
28
28
 
29
+ change_software_parameters do |sw_params|
30
+ sw_params.available_minimum = buffer_frame_count / 2
31
+ end
32
+
33
+ ALSA::PCM::Native.prepare(handle)
34
+
29
35
  if block_given?
30
36
  begin
31
37
  yield self
32
38
  ensure
33
39
  self.close
34
40
  end
41
+ else
42
+ self
35
43
  end
36
44
  end
37
45
 
@@ -67,7 +75,9 @@ module ALSA::PCM
67
75
  :access => :rw_interleaved,
68
76
  :channels => 2,
69
77
  :sample_format => :s16_le,
70
- :sample_rate => 44100
78
+ :sample_rate => 44100,
79
+ # :buffer_time => buffer_time_size * 1000,
80
+ # :period_time => buffer_time_size * 1000 / 4
71
81
  }.update(attributes)
72
82
 
73
83
  change_hardware_parameters do |hw_params|
@@ -75,6 +85,25 @@ module ALSA::PCM
75
85
  end
76
86
  end
77
87
 
88
+ def change_software_parameters
89
+ sw_params = software_parameters
90
+
91
+ begin
92
+ yield sw_params
93
+
94
+ ALSA::try_to "set sw parameters" do
95
+ ALSA::PCM::Native::sw_params self.handle, sw_params.handle
96
+ end
97
+ ensure
98
+ sw_params.free
99
+ end
100
+ end
101
+
102
+ def software_parameters
103
+ ALSA::PCM::SwParameters.new(self).current_for_device
104
+ end
105
+ alias_method :sw_params, :software_parameters
106
+
78
107
  def opened?
79
108
  not self.handle.nil?
80
109
  end
@@ -90,5 +119,18 @@ module ALSA::PCM
90
119
  end
91
120
  end
92
121
 
122
+ def available_frame_count
123
+ check_handle!
124
+
125
+ ALSA::try_to "wait the interface is ready" do
126
+ ALSA::PCM::Native::wait(self.handle, buffer_time_size)
127
+ end
128
+ available_frame_count = ALSA::try_to "read available space" do
129
+ ALSA::PCM::Native::avail_update(self.handle)
130
+ end
131
+
132
+ [available_frame_count, buffer_frame_count].min
133
+ end
134
+
93
135
  end
94
136
  end
@@ -0,0 +1,53 @@
1
+ module ALSA::PCM
2
+ class SwParameters
3
+
4
+ attr_accessor :handle, :device
5
+
6
+ def initialize(device = nil)
7
+ sw_params_pointer = FFI::MemoryPointer.new :pointer
8
+
9
+ ALSA::PCM::Native::sw_params_malloc sw_params_pointer
10
+ self.handle = sw_params_pointer.read_pointer
11
+
12
+ self.device = device if device
13
+ end
14
+
15
+ def update_attributes(attributes)
16
+ attributes.each_pair { |name, value| send("#{name}=", value) }
17
+ end
18
+
19
+ def current_for_device
20
+ ALSA::try_to "retrieve current hardware parameters" do
21
+ ALSA::PCM::Native::sw_params_current device.handle, self.handle
22
+ end
23
+ self
24
+ end
25
+
26
+ def avail_min=(avail_min)
27
+ ALSA::try_to "set avail_min (#{avail_min})" do
28
+ ALSA::PCM::Native::sw_params_set_avail_min self.device.handle, self.handle, avail_min
29
+ end
30
+ end
31
+ alias_method :available_minimum=, :avail_min=
32
+
33
+ def avail_min
34
+ value = nil
35
+ ALSA::try_to "get period time" do
36
+ value_pointer = FFI::MemoryPointer.new(:int)
37
+ error_code = ALSA::PCM::Native::sw_params_get_avail_min self.handle, value_pointer
38
+ value = value_pointer.read_int
39
+ value_pointer.free
40
+ error_code
41
+ end
42
+ value
43
+ end
44
+ alias_method :available_minimum, :avail_min
45
+
46
+ def free
47
+ ALSA::try_to "unallocate sw_params" do
48
+ ALSA::PCM::Native::sw_params_free self.handle
49
+ end
50
+ end
51
+
52
+ end
53
+ end
data/lib/alsa/sine.rb ADDED
@@ -0,0 +1,21 @@
1
+ class ALSA::Sine
2
+
3
+ attr_accessor :frequency, :sample_rate
4
+
5
+ def initialize(frequency, sample_rate)
6
+ @frequency = frequency
7
+ @sample_rate = sample_rate
8
+ end
9
+
10
+ def frames(length)
11
+ (0...length).collect do |frame|
12
+ 0x7F000000 * Math.sin(2 * Math::PI * frequency * frame / sample_rate)
13
+ end
14
+ end
15
+
16
+ def memory_pointer(length)
17
+ buffer = MemoryPointer.new(:int, length_count)
18
+ buffer.write_array_of_int frames(length_count)
19
+ end
20
+
21
+ end
data/log/test.log CHANGED
@@ -3280,3 +3280,220 @@ D, [2010-06-06T17:45:09.574964 #16888] DEBUG -- : write in audio interface
3280
3280
  D, [2010-06-06T17:45:09.575162 #16888] DEBUG -- : close audio device
3281
3281
  D, [2010-06-06T17:45:09.582668 #16888] DEBUG -- : dummy
3282
3282
  D, [2010-06-06T17:45:09.583909 #16888] DEBUG -- : dummy
3283
+ D, [2010-08-04T11:48:58.480158 #22893] DEBUG -- : open audio device default
3284
+ D, [2010-08-04T11:48:58.520984 #22893] DEBUG -- : initialize hardware parameter structure
3285
+ D, [2010-08-04T11:48:58.521324 #22893] DEBUG -- : set sample format
3286
+ D, [2010-08-04T11:48:58.521468 #22893] DEBUG -- : set access type
3287
+ D, [2010-08-04T11:48:58.521591 #22893] DEBUG -- : set channel count : 2
3288
+ D, [2010-08-04T11:48:58.521717 #22893] DEBUG -- : set sample rate
3289
+ D, [2010-08-04T11:48:58.521904 #22893] DEBUG -- : set hw parameters
3290
+ D, [2010-08-04T11:48:58.522223 #22893] DEBUG -- : unallocate hw_params
3291
+ D, [2010-08-04T11:48:58.522752 #22893] DEBUG -- : close audio device
3292
+ D, [2010-08-04T11:48:58.523372 #22893] DEBUG -- : open audio device default
3293
+ D, [2010-08-04T11:48:58.528819 #22893] DEBUG -- : initialize hardware parameter structure
3294
+ D, [2010-08-04T11:48:58.529099 #22893] DEBUG -- : set sample format
3295
+ D, [2010-08-04T11:48:58.529257 #22893] DEBUG -- : set access type
3296
+ D, [2010-08-04T11:48:58.529400 #22893] DEBUG -- : set channel count : 2
3297
+ D, [2010-08-04T11:48:58.529548 #22893] DEBUG -- : set sample rate
3298
+ D, [2010-08-04T11:48:58.529747 #22893] DEBUG -- : set hw parameters
3299
+ D, [2010-08-04T11:48:58.530067 #22893] DEBUG -- : unallocate hw_params
3300
+ D, [2010-08-04T11:48:58.530208 #22893] DEBUG -- : close audio device
3301
+ D, [2010-08-04T11:48:58.530585 #22893] DEBUG -- : open audio device default
3302
+ D, [2010-08-04T11:48:58.536897 #22893] DEBUG -- : initialize hardware parameter structure
3303
+ D, [2010-08-04T11:48:58.537226 #22893] DEBUG -- : set sample format
3304
+ D, [2010-08-04T11:48:58.537389 #22893] DEBUG -- : set access type
3305
+ D, [2010-08-04T11:48:58.537535 #22893] DEBUG -- : set channel count : 2
3306
+ D, [2010-08-04T11:48:58.537683 #22893] DEBUG -- : set sample rate
3307
+ D, [2010-08-04T11:48:58.537885 #22893] DEBUG -- : set hw parameters
3308
+ D, [2010-08-04T11:48:58.538216 #22893] DEBUG -- : unallocate hw_params
3309
+ D, [2010-08-04T11:48:58.538341 #22893] DEBUG -- : close audio device
3310
+ D, [2010-08-04T11:48:58.539355 #22893] DEBUG -- : open audio device default
3311
+ D, [2010-08-04T11:48:58.548917 #22893] DEBUG -- : initialize hardware parameter structure
3312
+ D, [2010-08-04T11:48:58.549159 #22893] DEBUG -- : set sample format
3313
+ D, [2010-08-04T11:48:58.549295 #22893] DEBUG -- : set access type
3314
+ D, [2010-08-04T11:48:58.549418 #22893] DEBUG -- : set channel count : 2
3315
+ D, [2010-08-04T11:48:58.549543 #22893] DEBUG -- : set sample rate
3316
+ D, [2010-08-04T11:48:58.549716 #22893] DEBUG -- : set hw parameters
3317
+ D, [2010-08-04T11:48:58.549990 #22893] DEBUG -- : unallocate hw_params
3318
+ D, [2010-08-04T11:48:58.550111 #22893] DEBUG -- : retrieve current hardware parameters
3319
+ D, [2010-08-04T11:48:58.550199 #22893] DEBUG -- : get sample rate
3320
+ D, [2010-08-04T11:48:58.550306 #22893] DEBUG -- : retrieve current hardware parameters
3321
+ D, [2010-08-04T11:48:58.550399 #22893] DEBUG -- : get channels
3322
+ D, [2010-08-04T11:48:58.550463 #22893] DEBUG -- : start read with 44100, 2 channels
3323
+ D, [2010-08-04T11:48:58.550559 #22893] DEBUG -- : retrieve current hardware parameters
3324
+ D, [2010-08-04T11:48:58.550653 #22893] DEBUG -- : retrieve current hardware parameters
3325
+ D, [2010-08-04T11:48:58.550734 #22893] DEBUG -- : get sample rate
3326
+ D, [2010-08-04T11:48:58.550835 #22893] DEBUG -- : get sample format
3327
+ D, [2010-08-04T11:48:58.550927 #22893] DEBUG -- : get channels
3328
+ D, [2010-08-04T11:48:58.550990 #22893] DEBUG -- : allocate 44100 bytes for 11025 frames
3329
+ D, [2010-08-04T11:48:58.551072 #22893] DEBUG -- : retrieve current hardware parameters
3330
+ D, [2010-08-04T11:48:58.551158 #22893] DEBUG -- : get sample format
3331
+ D, [2010-08-04T11:48:58.551243 #22893] DEBUG -- : get channels
3332
+ D, [2010-08-04T11:48:58.551342 #22893] DEBUG -- : read from audio interface
3333
+ D, [2010-08-04T11:48:58.847531 #22893] DEBUG -- : retrieve current hardware parameters
3334
+ D, [2010-08-04T11:48:58.847714 #22893] DEBUG -- : get sample format
3335
+ D, [2010-08-04T11:48:58.847812 #22893] DEBUG -- : get channels
3336
+ D, [2010-08-04T11:48:58.847923 #22893] DEBUG -- : close audio device
3337
+ D, [2010-08-04T11:48:58.848372 #22893] DEBUG -- : open audio device default
3338
+ D, [2010-08-04T11:48:58.856910 #22893] DEBUG -- : initialize hardware parameter structure
3339
+ D, [2010-08-04T11:48:58.857166 #22893] DEBUG -- : set sample format
3340
+ D, [2010-08-04T11:48:58.857306 #22893] DEBUG -- : set access type
3341
+ D, [2010-08-04T11:48:58.857430 #22893] DEBUG -- : set channel count : 2
3342
+ D, [2010-08-04T11:48:58.857559 #22893] DEBUG -- : set sample rate
3343
+ D, [2010-08-04T11:48:58.857734 #22893] DEBUG -- : set hw parameters
3344
+ D, [2010-08-04T11:48:58.858021 #22893] DEBUG -- : unallocate hw_params
3345
+ D, [2010-08-04T11:48:58.858136 #22893] DEBUG -- : retrieve current hardware parameters
3346
+ D, [2010-08-04T11:48:58.858216 #22893] DEBUG -- : get sample rate
3347
+ D, [2010-08-04T11:48:58.858319 #22893] DEBUG -- : retrieve current hardware parameters
3348
+ D, [2010-08-04T11:48:58.858403 #22893] DEBUG -- : get channels
3349
+ D, [2010-08-04T11:48:58.858465 #22893] DEBUG -- : start read with 44100, 2 channels
3350
+ D, [2010-08-04T11:48:58.858555 #22893] DEBUG -- : retrieve current hardware parameters
3351
+ D, [2010-08-04T11:48:58.858646 #22893] DEBUG -- : retrieve current hardware parameters
3352
+ D, [2010-08-04T11:48:58.858725 #22893] DEBUG -- : get sample rate
3353
+ D, [2010-08-04T11:48:58.858822 #22893] DEBUG -- : get sample format
3354
+ D, [2010-08-04T11:48:58.858910 #22893] DEBUG -- : get channels
3355
+ D, [2010-08-04T11:48:58.858974 #22893] DEBUG -- : allocate 44100 bytes for 11025 frames
3356
+ D, [2010-08-04T11:48:58.859055 #22893] DEBUG -- : retrieve current hardware parameters
3357
+ D, [2010-08-04T11:48:58.859139 #22893] DEBUG -- : get sample format
3358
+ D, [2010-08-04T11:48:58.859223 #22893] DEBUG -- : get channels
3359
+ D, [2010-08-04T11:48:58.859319 #22893] DEBUG -- : read from audio interface
3360
+ D, [2010-08-04T11:48:59.134061 #22893] DEBUG -- : read from audio interface
3361
+ D, [2010-08-04T11:48:59.411418 #22893] DEBUG -- : read from audio interface
3362
+ D, [2010-08-04T11:48:59.667415 #22893] DEBUG -- : close audio device
3363
+ D, [2010-08-04T11:48:59.668514 #22893] DEBUG -- : open audio device default
3364
+ D, [2010-08-04T11:48:59.669485 #22893] DEBUG -- : initialize hardware parameter structure
3365
+ D, [2010-08-04T11:48:59.669658 #22893] DEBUG -- : set sample format
3366
+ D, [2010-08-04T11:48:59.669757 #22893] DEBUG -- : set access type
3367
+ D, [2010-08-04T11:48:59.669843 #22893] DEBUG -- : set channel count : 2
3368
+ D, [2010-08-04T11:48:59.669931 #22893] DEBUG -- : set sample rate
3369
+ D, [2010-08-04T11:48:59.670048 #22893] DEBUG -- : set hw parameters
3370
+ D, [2010-08-04T11:48:59.670249 #22893] DEBUG -- : unallocate hw_params
3371
+ D, [2010-08-04T11:48:59.670313 #22893] DEBUG -- : write in audio interface
3372
+ D, [2010-08-04T11:48:59.670377 #22893] DEBUG -- : close audio device
3373
+ D, [2010-08-04T11:48:59.672392 #22893] DEBUG -- : dummy
3374
+ D, [2010-08-04T11:48:59.672751 #22893] DEBUG -- : dummy
3375
+ D, [2010-10-14T10:39:18.478029 #15640] DEBUG -- : dummy
3376
+ D, [2010-10-14T10:39:18.478793 #15640] DEBUG -- : dummy
3377
+ D, [2010-10-14T10:39:18.483691 #15640] DEBUG -- : open audio device default
3378
+ D, [2010-10-14T10:39:18.495477 #15640] DEBUG -- : initialize hardware parameter structure
3379
+ D, [2010-10-14T10:39:18.495730 #15640] DEBUG -- : set sample format
3380
+ D, [2010-10-14T10:39:18.495836 #15640] DEBUG -- : set access type
3381
+ D, [2010-10-14T10:39:18.495919 #15640] DEBUG -- : set channel count : 2
3382
+ D, [2010-10-14T10:39:18.496003 #15640] DEBUG -- : set sample rate
3383
+ D, [2010-10-14T10:39:18.496124 #15640] DEBUG -- : set hw parameters
3384
+ D, [2010-10-14T10:39:18.496339 #15640] DEBUG -- : unallocate hw_params
3385
+ D, [2010-10-14T10:39:18.496417 #15640] DEBUG -- : retrieve current hardware parameters
3386
+ D, [2010-10-14T10:39:18.496482 #15640] DEBUG -- : retrieve current hardware parameters
3387
+ D, [2010-10-14T10:39:18.496535 #15640] DEBUG -- : get sample rate
3388
+ D, [2010-10-14T10:39:18.496601 #15640] DEBUG -- : set avail_min (5512)
3389
+ D, [2010-10-14T10:39:18.496653 #15640] DEBUG -- : set sw parameters
3390
+ D, [2010-10-14T10:39:18.496705 #15640] DEBUG -- : unallocate sw_params
3391
+ D, [2010-10-14T10:39:18.497085 #15640] DEBUG -- : close audio device
3392
+ D, [2010-10-14T10:39:18.497550 #15640] DEBUG -- : open audio device default
3393
+ D, [2010-10-14T10:39:18.503401 #15640] DEBUG -- : initialize hardware parameter structure
3394
+ D, [2010-10-14T10:39:18.503707 #15640] DEBUG -- : set sample format
3395
+ D, [2010-10-14T10:39:18.503878 #15640] DEBUG -- : set access type
3396
+ D, [2010-10-14T10:39:18.504026 #15640] DEBUG -- : set channel count : 2
3397
+ D, [2010-10-14T10:39:18.504185 #15640] DEBUG -- : set sample rate
3398
+ D, [2010-10-14T10:39:18.504407 #15640] DEBUG -- : set hw parameters
3399
+ D, [2010-10-14T10:39:18.504782 #15640] DEBUG -- : unallocate hw_params
3400
+ D, [2010-10-14T10:39:18.504916 #15640] DEBUG -- : retrieve current hardware parameters
3401
+ D, [2010-10-14T10:39:18.505036 #15640] DEBUG -- : retrieve current hardware parameters
3402
+ D, [2010-10-14T10:39:18.505139 #15640] DEBUG -- : get sample rate
3403
+ D, [2010-10-14T10:39:18.505257 #15640] DEBUG -- : set avail_min (5512)
3404
+ D, [2010-10-14T10:39:18.505365 #15640] DEBUG -- : set sw parameters
3405
+ D, [2010-10-14T10:39:18.505469 #15640] DEBUG -- : unallocate sw_params
3406
+ D, [2010-10-14T10:39:18.505641 #15640] DEBUG -- : close audio device
3407
+ D, [2010-10-14T10:39:18.506119 #15640] DEBUG -- : open audio device default
3408
+ D, [2010-10-14T10:39:18.515478 #15640] DEBUG -- : initialize hardware parameter structure
3409
+ D, [2010-10-14T10:39:18.515832 #15640] DEBUG -- : set sample format
3410
+ D, [2010-10-14T10:39:18.516011 #15640] DEBUG -- : set access type
3411
+ D, [2010-10-14T10:39:18.516164 #15640] DEBUG -- : set channel count : 2
3412
+ D, [2010-10-14T10:39:18.516323 #15640] DEBUG -- : set sample rate
3413
+ D, [2010-10-14T10:39:18.516562 #15640] DEBUG -- : set hw parameters
3414
+ D, [2010-10-14T10:39:18.516944 #15640] DEBUG -- : unallocate hw_params
3415
+ D, [2010-10-14T10:39:18.517078 #15640] DEBUG -- : retrieve current hardware parameters
3416
+ D, [2010-10-14T10:39:18.517199 #15640] DEBUG -- : retrieve current hardware parameters
3417
+ D, [2010-10-14T10:39:18.517301 #15640] DEBUG -- : get sample rate
3418
+ D, [2010-10-14T10:39:18.517421 #15640] DEBUG -- : set avail_min (5512)
3419
+ D, [2010-10-14T10:39:18.517521 #15640] DEBUG -- : set sw parameters
3420
+ D, [2010-10-14T10:39:18.517621 #15640] DEBUG -- : unallocate sw_params
3421
+ D, [2010-10-14T10:39:18.517742 #15640] DEBUG -- : close audio device
3422
+ D, [2010-10-14T10:39:18.518850 #15640] DEBUG -- : open audio device default
3423
+ D, [2010-10-14T10:39:18.527496 #15640] DEBUG -- : initialize hardware parameter structure
3424
+ D, [2010-10-14T10:39:18.527812 #15640] DEBUG -- : set sample format
3425
+ D, [2010-10-14T10:39:18.527985 #15640] DEBUG -- : set access type
3426
+ D, [2010-10-14T10:39:18.528135 #15640] DEBUG -- : set channel count : 2
3427
+ D, [2010-10-14T10:39:18.528292 #15640] DEBUG -- : set sample rate
3428
+ D, [2010-10-14T10:39:18.528517 #15640] DEBUG -- : set hw parameters
3429
+ D, [2010-10-14T10:39:18.528889 #15640] DEBUG -- : unallocate hw_params
3430
+ D, [2010-10-14T10:39:18.529017 #15640] DEBUG -- : retrieve current hardware parameters
3431
+ D, [2010-10-14T10:39:18.529146 #15640] DEBUG -- : retrieve current hardware parameters
3432
+ D, [2010-10-14T10:39:18.529244 #15640] DEBUG -- : get sample rate
3433
+ D, [2010-10-14T10:39:18.529362 #15640] DEBUG -- : set avail_min (5512)
3434
+ D, [2010-10-14T10:39:18.529459 #15640] DEBUG -- : set sw parameters
3435
+ D, [2010-10-14T10:39:18.529556 #15640] DEBUG -- : unallocate sw_params
3436
+ D, [2010-10-14T10:39:18.529696 #15640] DEBUG -- : retrieve current hardware parameters
3437
+ D, [2010-10-14T10:39:18.529807 #15640] DEBUG -- : get sample rate
3438
+ D, [2010-10-14T10:39:18.529927 #15640] DEBUG -- : get channels
3439
+ D, [2010-10-14T10:39:18.530032 #15640] DEBUG -- : get period time
3440
+ D, [2010-10-14T10:39:18.530144 #15640] DEBUG -- : get period size
3441
+ D, [2010-10-14T10:39:18.530269 #15640] DEBUG -- : get buffer size
3442
+ D, [2010-10-14T10:39:18.530350 #15640] DEBUG -- : start read with #<ALSA::PCM::HwParameters:70235853324760 sample_rate=44100, channels=2, period_time=21333, period_size=940, buffer_size=7526>
3443
+ D, [2010-10-14T10:39:18.530455 #15640] DEBUG -- : retrieve current hardware parameters
3444
+ D, [2010-10-14T10:39:18.530574 #15640] DEBUG -- : get sample format
3445
+ D, [2010-10-14T10:39:18.530684 #15640] DEBUG -- : get channels
3446
+ D, [2010-10-14T10:39:18.530824 #15640] DEBUG -- : read from audio interface
3447
+ D, [2010-10-14T10:39:18.805160 #15640] DEBUG -- : read frame count: 11025/11025
3448
+ D, [2010-10-14T10:39:18.805408 #15640] DEBUG -- : retrieve current hardware parameters
3449
+ D, [2010-10-14T10:39:18.805527 #15640] DEBUG -- : get sample format
3450
+ D, [2010-10-14T10:39:18.805638 #15640] DEBUG -- : get channels
3451
+ D, [2010-10-14T10:39:18.805793 #15640] DEBUG -- : close audio device
3452
+ D, [2010-10-14T10:39:18.806321 #15640] DEBUG -- : open audio device default
3453
+ D, [2010-10-14T10:39:18.815294 #15640] DEBUG -- : initialize hardware parameter structure
3454
+ D, [2010-10-14T10:39:18.815599 #15640] DEBUG -- : set sample format
3455
+ D, [2010-10-14T10:39:18.815769 #15640] DEBUG -- : set access type
3456
+ D, [2010-10-14T10:39:18.815933 #15640] DEBUG -- : set channel count : 2
3457
+ D, [2010-10-14T10:39:18.816164 #15640] DEBUG -- : set sample rate
3458
+ D, [2010-10-14T10:39:18.816443 #15640] DEBUG -- : set hw parameters
3459
+ D, [2010-10-14T10:39:18.816847 #15640] DEBUG -- : unallocate hw_params
3460
+ D, [2010-10-14T10:39:18.816976 #15640] DEBUG -- : retrieve current hardware parameters
3461
+ D, [2010-10-14T10:39:18.817101 #15640] DEBUG -- : retrieve current hardware parameters
3462
+ D, [2010-10-14T10:39:18.817223 #15640] DEBUG -- : get sample rate
3463
+ D, [2010-10-14T10:39:18.817348 #15640] DEBUG -- : set avail_min (5512)
3464
+ D, [2010-10-14T10:39:18.817447 #15640] DEBUG -- : set sw parameters
3465
+ D, [2010-10-14T10:39:18.817546 #15640] DEBUG -- : unallocate sw_params
3466
+ D, [2010-10-14T10:39:18.817702 #15640] DEBUG -- : retrieve current hardware parameters
3467
+ D, [2010-10-14T10:39:18.817817 #15640] DEBUG -- : get sample rate
3468
+ D, [2010-10-14T10:39:18.817931 #15640] DEBUG -- : get channels
3469
+ D, [2010-10-14T10:39:18.818034 #15640] DEBUG -- : get period time
3470
+ D, [2010-10-14T10:39:18.818148 #15640] DEBUG -- : get period size
3471
+ D, [2010-10-14T10:39:18.818259 #15640] DEBUG -- : get buffer size
3472
+ D, [2010-10-14T10:39:18.818337 #15640] DEBUG -- : start read with #<ALSA::PCM::HwParameters:70235853311640 sample_rate=44100, channels=2, period_time=21333, period_size=940, buffer_size=7526>
3473
+ D, [2010-10-14T10:39:18.818443 #15640] DEBUG -- : retrieve current hardware parameters
3474
+ D, [2010-10-14T10:39:18.818564 #15640] DEBUG -- : get sample format
3475
+ D, [2010-10-14T10:39:18.818673 #15640] DEBUG -- : get channels
3476
+ D, [2010-10-14T10:39:18.818823 #15640] DEBUG -- : read from audio interface
3477
+ D, [2010-10-14T10:39:19.092597 #15640] DEBUG -- : read frame count: 11025/11025
3478
+ D, [2010-10-14T10:39:19.092806 #15640] DEBUG -- : read from audio interface
3479
+ D, [2010-10-14T10:39:19.348512 #15640] DEBUG -- : read frame count: 11025/11025
3480
+ D, [2010-10-14T10:39:19.348712 #15640] DEBUG -- : read from audio interface
3481
+ D, [2010-10-14T10:39:19.604556 #15640] DEBUG -- : read frame count: 11025/11025
3482
+ D, [2010-10-14T10:39:19.604747 #15640] DEBUG -- : close audio device
3483
+ D, [2010-10-14T10:39:19.606353 #15640] DEBUG -- : open audio device default
3484
+ D, [2010-10-14T10:39:19.608050 #15640] DEBUG -- : initialize hardware parameter structure
3485
+ D, [2010-10-14T10:39:19.608358 #15640] DEBUG -- : set sample format
3486
+ D, [2010-10-14T10:39:19.608530 #15640] DEBUG -- : set access type
3487
+ D, [2010-10-14T10:39:19.608676 #15640] DEBUG -- : set channel count : 2
3488
+ D, [2010-10-14T10:39:19.608828 #15640] DEBUG -- : set sample rate
3489
+ D, [2010-10-14T10:39:19.609044 #15640] DEBUG -- : set hw parameters
3490
+ D, [2010-10-14T10:39:19.609436 #15640] DEBUG -- : unallocate hw_params
3491
+ D, [2010-10-14T10:39:19.609573 #15640] DEBUG -- : retrieve current hardware parameters
3492
+ D, [2010-10-14T10:39:19.609817 #15640] DEBUG -- : retrieve current hardware parameters
3493
+ D, [2010-10-14T10:39:19.609928 #15640] DEBUG -- : get sample rate
3494
+ D, [2010-10-14T10:39:19.610056 #15640] DEBUG -- : set avail_min (5512)
3495
+ D, [2010-10-14T10:39:19.610189 #15640] DEBUG -- : set sw parameters
3496
+ D, [2010-10-14T10:39:19.610298 #15640] DEBUG -- : unallocate sw_params
3497
+ D, [2010-10-14T10:39:19.610413 #15640] DEBUG -- : write in audio interface
3498
+ D, [2010-10-14T10:39:19.610521 #15640] DEBUG -- : write frame count: 100/100
3499
+ D, [2010-10-14T10:39:19.610640 #15640] DEBUG -- : close audio device
data/refs/alsa_player ADDED
Binary file
@@ -0,0 +1,80 @@
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <alsa/asoundlib.h>
4
+
5
+ main (int argc, char *argv[])
6
+ {
7
+ int i;
8
+ int err;
9
+ short buf[128];
10
+ snd_pcm_t *playback_handle;
11
+ snd_pcm_hw_params_t *hw_params;
12
+
13
+ if ((err = snd_pcm_open (&playback_handle, argv[1], SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
14
+ fprintf (stderr, "cannot open audio device %s (%s)\n",
15
+ argv[1],
16
+ snd_strerror (err));
17
+ exit (1);
18
+ }
19
+
20
+ if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
21
+ fprintf (stderr, "cannot allocate hardware parameter structure (%s)\n",
22
+ snd_strerror (err));
23
+ exit (1);
24
+ }
25
+
26
+ if ((err = snd_pcm_hw_params_any (playback_handle, hw_params)) < 0) {
27
+ fprintf (stderr, "cannot initialize hardware parameter structure (%s)\n",
28
+ snd_strerror (err));
29
+ exit (1);
30
+ }
31
+
32
+ if ((err = snd_pcm_hw_params_set_access (playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
33
+ fprintf (stderr, "cannot set access type (%s)\n",
34
+ snd_strerror (err));
35
+ exit (1);
36
+ }
37
+
38
+ if ((err = snd_pcm_hw_params_set_format (playback_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
39
+ fprintf (stderr, "cannot set sample format (%s)\n",
40
+ snd_strerror (err));
41
+ exit (1);
42
+ }
43
+
44
+ if ((err = snd_pcm_hw_params_set_rate (playback_handle, hw_params, 44100, 0)) < 0) {
45
+ fprintf (stderr, "cannot set sample rate (%s)\n",
46
+ snd_strerror (err));
47
+ exit (1);
48
+ }
49
+
50
+ if ((err = snd_pcm_hw_params_set_channels (playback_handle, hw_params, 2)) < 0) {
51
+ fprintf (stderr, "cannot set channel count (%s)\n",
52
+ snd_strerror (err));
53
+ exit (1);
54
+ }
55
+
56
+ if ((err = snd_pcm_hw_params (playback_handle, hw_params)) < 0) {
57
+ fprintf (stderr, "cannot set parameters (%s)\n",
58
+ snd_strerror (err));
59
+ exit (1);
60
+ }
61
+
62
+ snd_pcm_hw_params_free (hw_params);
63
+
64
+ if ((err = snd_pcm_prepare (playback_handle)) < 0) {
65
+ fprintf (stderr, "cannot prepare audio interface for use (%s)\n",
66
+ snd_strerror (err));
67
+ exit (1);
68
+ }
69
+
70
+ for (i = 0; i < 1000; ++i) {
71
+ if ((err = snd_pcm_writei (playback_handle, buf, 128)) != 128) {
72
+ fprintf (stderr, "write to audio interface failed (%s)\n",
73
+ snd_strerror (err));
74
+ exit (1);
75
+ }
76
+ }
77
+
78
+ snd_pcm_close (playback_handle);
79
+ exit (0);
80
+ }