audio-playback 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/audio-playback.rb +1 -1
- data/lib/audio-playback/device/stream.rb +31 -4
- data/lib/audio-playback/playback.rb +3 -2
- data/lib/audio-playback/playback/frame_set.rb +1 -1
- data/lib/audio-playback/playback/stream_data.rb +9 -0
- data/test/device/stream_test.rb +6 -1
- data/test/playback/stream_data_test.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eecccbe6c5faee30c7857d77f3d89e230b435f2a
|
4
|
+
data.tar.gz: 4621a617d40eaa1b923642b6caec93595e7fd40d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 582c662be9f91bb72c4958e0978b852beef42a0cdcf2c9a552452a3a870f8832165db47075bc0ccd3def87cefbcc901af26b52555b26e8b3da3bd5febddefcc3
|
7
|
+
data.tar.gz: 8f7c7cb70b298584fa091806139453a0e6a634263fbbbe7a463f69ec6e4450c5b3aa427b89782567c867d321e794d41f76a13f34f5bd300acd2d7dedc9075127
|
data/README.md
CHANGED
@@ -87,7 +87,8 @@ More Ruby code examples:
|
|
87
87
|
* [Select a file and play](https://github.com/arirusso/audio-playback/blob/master/examples/select_and_play.rb)
|
88
88
|
* [Play multiple files in one stream simultaneously](https://github.com/arirusso/audio-playback/blob/master/examples/play_multiple_simultaneous.rb)
|
89
89
|
* [Play multiple files in one stream sequentially](https://github.com/arirusso/audio-playback/blob/master/examples/play_multiple_sequential.rb)
|
90
|
-
* [Play multiple files in multiple streams](https://github.com/arirusso/audio-playback/blob/master/examples/
|
90
|
+
* [Play multiple files in multiple streams](https://github.com/arirusso/audio-playback/blob/master/examples/play_multiple_streams.rb)
|
91
|
+
* [Looping playback](https://github.com/arirusso/audio-playback/blob/master/examples/loop.rb)
|
91
92
|
|
92
93
|
## License
|
93
94
|
|
data/lib/audio-playback.rb
CHANGED
@@ -4,6 +4,9 @@ module AudioPlayback
|
|
4
4
|
|
5
5
|
class Stream < FFI::PortAudio::Stream
|
6
6
|
|
7
|
+
attr_reader :is_playing
|
8
|
+
alias_method :playing?, :is_playing
|
9
|
+
|
7
10
|
# Keep track of all streams
|
8
11
|
# @return [Array<Stream>]
|
9
12
|
def self.streams
|
@@ -14,6 +17,7 @@ module AudioPlayback
|
|
14
17
|
# @param [Hash] options
|
15
18
|
# @option options [IO] logger
|
16
19
|
def initialize(output, options = {})
|
20
|
+
@is_playing = false
|
17
21
|
@is_muted = false
|
18
22
|
@gain = 1.0
|
19
23
|
@input = nil
|
@@ -28,8 +32,13 @@ module AudioPlayback
|
|
28
32
|
# @option options [IO] logger
|
29
33
|
# @return [Stream]
|
30
34
|
def play(playback, options = {})
|
35
|
+
@is_playing = true
|
31
36
|
report(playback, options[:logger]) if options[:logger]
|
32
|
-
|
37
|
+
if @stream.nil?
|
38
|
+
open_playback(playback)
|
39
|
+
else
|
40
|
+
continue(playback)
|
41
|
+
end
|
33
42
|
start
|
34
43
|
self
|
35
44
|
end
|
@@ -52,13 +61,25 @@ module AudioPlayback
|
|
52
61
|
end
|
53
62
|
rescue SystemExit, Interrupt
|
54
63
|
# Control-C
|
55
|
-
|
56
|
-
|
64
|
+
@is_playing = false
|
65
|
+
exit
|
57
66
|
end
|
67
|
+
@is_playing = false
|
68
|
+
true
|
58
69
|
end
|
59
70
|
|
60
71
|
private
|
61
72
|
|
73
|
+
def open_stream(playback)
|
74
|
+
@userdata = playback.data.to_pointer
|
75
|
+
FFI::PortAudio::API.Pa_OpenStream(@stream, @input, @output, @freq, @frames, @flags, @method, @userdata)
|
76
|
+
end
|
77
|
+
|
78
|
+
def continue(playback)
|
79
|
+
playback.reset
|
80
|
+
open_stream(playback)
|
81
|
+
end
|
82
|
+
|
62
83
|
# Initialize the callback that's fired when the stream exits
|
63
84
|
# @return [Stream]
|
64
85
|
def initialize_exit_callback(options = {})
|
@@ -75,6 +96,7 @@ module AudioPlayback
|
|
75
96
|
#close
|
76
97
|
FFI::PortAudio::API.Pa_Terminate
|
77
98
|
end
|
99
|
+
@is_playing = false
|
78
100
|
true
|
79
101
|
end
|
80
102
|
|
@@ -82,7 +104,12 @@ module AudioPlayback
|
|
82
104
|
# @param [Playback] playback
|
83
105
|
# @return [Boolean]
|
84
106
|
def open_playback(playback)
|
85
|
-
|
107
|
+
@freq = playback.sample_rate.to_i
|
108
|
+
@frames = playback.buffer_size
|
109
|
+
@flags = FFI::PortAudio::API::NoFlag
|
110
|
+
@stream = FFI::Buffer.new(:pointer)
|
111
|
+
@method = method(:process)
|
112
|
+
open_stream(playback)
|
86
113
|
true
|
87
114
|
end
|
88
115
|
|
@@ -22,7 +22,8 @@ module AudioPlayback
|
|
22
22
|
|
23
23
|
attr_reader :buffer_size, :channels, :data, :output, :num_channels, :sounds, :stream
|
24
24
|
def_delegators :@sounds, :audio_files
|
25
|
-
|
25
|
+
def_delegators :@data, :reset
|
26
|
+
|
26
27
|
# @param [Array<Sound>, Sound] sounds
|
27
28
|
# @param [Output] output
|
28
29
|
# @param [Hash] options
|
@@ -135,7 +136,7 @@ module AudioPlayback
|
|
135
136
|
# @return [Playback::Action]
|
136
137
|
def populate(options = {})
|
137
138
|
populate_channels(options)
|
138
|
-
@data = StreamData.
|
139
|
+
@data = StreamData.new(self)
|
139
140
|
self
|
140
141
|
end
|
141
142
|
|
@@ -19,6 +19,15 @@ module AudioPlayback
|
|
19
19
|
populate
|
20
20
|
end
|
21
21
|
|
22
|
+
def reset
|
23
|
+
indexes = [
|
24
|
+
Playback::METADATA.index(:pointer),
|
25
|
+
Playback::METADATA.index(:is_eof)
|
26
|
+
]
|
27
|
+
indexes.each { |index| @data[index] = 0.0 }
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
22
31
|
# A C pointer version of the audio data
|
23
32
|
# @return [FFI::Pointer]
|
24
33
|
def to_pointer
|
data/test/device/stream_test.rb
CHANGED
@@ -35,6 +35,7 @@ class AudioPlayback::Device::StreamTest < Minitest::Test
|
|
35
35
|
@stream.expects(:report).once
|
36
36
|
@stream.expects(:open_playback).once
|
37
37
|
@stream.expects(:start).once
|
38
|
+
@result = @stream.play(@playback)
|
38
39
|
end
|
39
40
|
|
40
41
|
teardown do
|
@@ -44,7 +45,11 @@ class AudioPlayback::Device::StreamTest < Minitest::Test
|
|
44
45
|
end
|
45
46
|
|
46
47
|
should "return self" do
|
47
|
-
assert_equal @stream, @
|
48
|
+
assert_equal @stream, @result
|
49
|
+
end
|
50
|
+
|
51
|
+
should "flag as playing" do
|
52
|
+
assert @stream.playing?
|
48
53
|
end
|
49
54
|
|
50
55
|
end
|
@@ -15,9 +15,9 @@ class AudioPlayback::Playback::StreamDataTest < Minitest::Test
|
|
15
15
|
@data = @playback.data
|
16
16
|
end
|
17
17
|
|
18
|
-
should "return a
|
18
|
+
should "return a stream data object" do
|
19
19
|
refute_nil @data
|
20
|
-
assert_kind_of
|
20
|
+
assert_kind_of AudioPlayback::Playback::StreamData, @data
|
21
21
|
end
|
22
22
|
|
23
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: audio-playback
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ari Russo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|