hornetseye-alsa 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/hornetseye-alsa/alsaoutput.rb +39 -1
- data/lib/hornetseye-alsa/docs.rb +93 -0
- metadata +4 -3
data/Rakefile
CHANGED
@@ -17,12 +17,32 @@
|
|
17
17
|
# Namespace of Hornetseye computer vision library
|
18
18
|
module Hornetseye
|
19
19
|
|
20
|
+
# Class for playing sounds using the ALSA library
|
21
|
+
#
|
22
|
+
# @see http://www.alsa-project.org/
|
20
23
|
class AlsaOutput
|
21
24
|
|
22
25
|
class << self
|
23
26
|
|
24
27
|
alias_method :orig_new, :new
|
25
|
-
|
28
|
+
|
29
|
+
# Open a sound device
|
30
|
+
#
|
31
|
+
# Open the specified sound device for writing. Note that the desired sample rate
|
32
|
+
# may not be supported. In that case the sound library will provide a sampling
|
33
|
+
# rate near the desired one.
|
34
|
+
#
|
35
|
+
# @example Open a sound device
|
36
|
+
# speaker = AlsaOutput.new 'default:0', 44_100, 2, 16, 1024
|
37
|
+
#
|
38
|
+
# @param [String] pcm_name Name of the PCM device
|
39
|
+
# @param [Integer] rate Desired sampling rate.
|
40
|
+
# @param [Integer] channels Number of channels (1=mono, 2=stereo).
|
41
|
+
# @param [Integer] periods Number of audio frames of the output buffer.
|
42
|
+
# @param [Integer] frames Size of the audio frames of the output buffer.
|
43
|
+
# @return [AlsaOutput] An object for accessing the sound device.
|
44
|
+
#
|
45
|
+
# @see #rate
|
26
46
|
def new( pcm_name = 'default:0', rate = 48000, channels = 2, periods = 16,
|
27
47
|
frames = 1024 )
|
28
48
|
orig_new pcm_name, rate, channels, periods, frames
|
@@ -32,6 +52,24 @@ module Hornetseye
|
|
32
52
|
|
33
53
|
alias_method :orig_write, :write
|
34
54
|
|
55
|
+
# Write an audio frame to the sound device
|
56
|
+
#
|
57
|
+
# The audio data is written to the output buffer of the sound device. Playback is
|
58
|
+
# resumed if a buffer underflow occurred earlier. The first dimension of the array
|
59
|
+
# with the audio data must match the number of channels of the audio device. The
|
60
|
+
# second dimension is the number of audio samples.
|
61
|
+
#
|
62
|
+
# A blocking write operation is used. I.e. the program is blocked until there is
|
63
|
+
# sufficient space in the audio output buffer.
|
64
|
+
#
|
65
|
+
# @example Writing audio samples
|
66
|
+
# speaker = AlsaOutput.new 'default:0', 44_100, 2, 16, 1024
|
67
|
+
# wave = lazy( 2, 110 ) { |j,i| Math.sin( i * 2 * Math::PI / 110 ) * 0x7FFF }.to_sint
|
68
|
+
# while true
|
69
|
+
# speaker.write wave
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
# @param [Node] frame A two-dimensional array of short-integer audio samples.
|
35
73
|
def write( frame )
|
36
74
|
if frame.typecode != SINT
|
37
75
|
raise "Audio data must be of type SINT (but was #{frame.typecode})"
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# hornetseye-alsa - Play audio data using libalsa
|
2
|
+
# Copyright (C) 2010 Jan Wedekind
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
# Namespace of Hornetseye computer vision library
|
18
|
+
module Hornetseye
|
19
|
+
|
20
|
+
class AlsaInput
|
21
|
+
|
22
|
+
attr_reader :rate
|
23
|
+
|
24
|
+
attr_reader :channels
|
25
|
+
|
26
|
+
def close
|
27
|
+
end
|
28
|
+
|
29
|
+
def avail
|
30
|
+
end
|
31
|
+
|
32
|
+
def delay
|
33
|
+
end
|
34
|
+
|
35
|
+
def prepare
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
class AlsaOutput
|
41
|
+
|
42
|
+
# Get the sampling rate of the sound device
|
43
|
+
#
|
44
|
+
# The sampling rate may be different to the desired sampling rate specified in
|
45
|
+
# the constructor.
|
46
|
+
#
|
47
|
+
# @return [Integer] The sampling rate of the sound device.
|
48
|
+
attr_reader :rate
|
49
|
+
|
50
|
+
# Number of audio channels
|
51
|
+
#
|
52
|
+
# @return [Integer] Number of audio channels (1=mono, 2=stereo).
|
53
|
+
attr_reader :channels
|
54
|
+
|
55
|
+
# Close the audio device
|
56
|
+
def close
|
57
|
+
end
|
58
|
+
|
59
|
+
# Drop content of audio output buffer
|
60
|
+
def drop
|
61
|
+
end
|
62
|
+
|
63
|
+
# Wait until audio buffer underflows
|
64
|
+
def drain
|
65
|
+
end
|
66
|
+
|
67
|
+
# Space available for writing in the audio buffer
|
68
|
+
#
|
69
|
+
# @return [Integer] Number of audio samples which can be written to the audio
|
70
|
+
# buffer.
|
71
|
+
def avail
|
72
|
+
end
|
73
|
+
|
74
|
+
# Number of audio samples in the audio buffer
|
75
|
+
#
|
76
|
+
# Returns the number of audio samples left in the audio buffer. This can be used
|
77
|
+
# to properly synchronise video display with audio output.
|
78
|
+
#
|
79
|
+
# @return [Integer] Number of audio samples left to play.
|
80
|
+
def delay
|
81
|
+
end
|
82
|
+
|
83
|
+
# Reset the sound device.
|
84
|
+
#
|
85
|
+
# One needs to call this method if one wants to resume playing audio samples after
|
86
|
+
# calling #drop or #drain.
|
87
|
+
def prepare
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 2
|
9
|
+
version: 0.3.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jan Wedekind
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-17 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- COPYING
|
73
73
|
- .document
|
74
74
|
- lib/hornetseye-alsa/alsainput.rb
|
75
|
+
- lib/hornetseye-alsa/docs.rb
|
75
76
|
- lib/hornetseye-alsa/alsaoutput.rb
|
76
77
|
- lib/hornetseye_alsa_ext.rb
|
77
78
|
- ext/alsainput.cc
|