audio_stream 1.2.2 → 1.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 450d5f725255284de3f97fa089d98a34603cee45b7cdfe1145f35925f87ecd6d
4
- data.tar.gz: 285d5688d7f1b87644f613e9339bd0fccd38b20f1321cce00b5ba46bfe4709a4
3
+ metadata.gz: d68afffda6b1f4c82e28430669330ef49e22c7765d70264686cc6011428ade0e
4
+ data.tar.gz: 783d2ab1c2f6a69e783064a581c472d66e8f1139e8da208715b4edfef3999dfe
5
5
  SHA512:
6
- metadata.gz: 6a836a10b9a92aaf6b91d2c4c8ca93a2d669d579f41ad1f6431357f789fadc161747fd15532c7d17c96ffd8d84211abbd4ab0fca87af92f8b99d07eed07125a7
7
- data.tar.gz: caa08fc1765ad8aa22ea177ea50231b2775ecbf43563b798f8617930e6ce30601a0c2a783b2cd2632d4df1844a43d0d1c8854f469968c825c4edf533b6793874
6
+ metadata.gz: 1a4c6364f40be8a8125d1c08124a4b4b2e81e955e9f17dff7189f353bca537f581fe6beaba2d3044b61f3eb389e02a2e34531d6f618fee82808371ad4e73e987
7
+ data.tar.gz: 7c6b41a5baec7931ac771aee1838ed614b13cefd3134fe4e7954ac26993e59b98c33e2a55512ad95a457e64c5af5954f5bc746c0c09814156b15c934a2a01a1c
@@ -15,6 +15,13 @@ module AudioStream
15
15
  }
16
16
  end
17
17
 
18
+ def disconnect
19
+ if @connection
20
+ @connection.join
21
+ @connection = nil
22
+ end
23
+ end
24
+
18
25
  def stream
19
26
  @stream ||= Rx::Observable.create do |observer|
20
27
  each {|buf|
@@ -40,9 +47,5 @@ module AudioStream
40
47
  def self.device(soundinfo:)
41
48
  AudioInputDevice.default_device(soundinfo: soundinfo)
42
49
  end
43
-
44
- def self.sin(hz, repeat, soundinfo:)
45
- AudioInputSin.new(hz, repeat, soundinfo: soundinfo)
46
- end
47
50
  end
48
51
  end
@@ -13,11 +13,21 @@ module AudioStream
13
13
  @dev.name
14
14
  end
15
15
 
16
+ def connect
17
+ @inbuf = @dev.input_buffer(@soundinfo.window_size)
18
+ @inbuf.start
19
+ super
20
+ end
21
+
22
+ def disconnect
23
+ if @inbuf
24
+ @inbuf.stop
25
+ super
26
+ end
27
+ end
28
+
16
29
  def each(&block)
17
30
  Enumerator.new do |y|
18
- @inbuf = @dev.input_buffer(@soundinfo.window_size)
19
- @inbuf.start
20
-
21
31
  channels = @dev.input_stream.channels
22
32
  buf = Buffer.float(@soundinfo.window_size, channels)
23
33
 
@@ -6,10 +6,21 @@ module AudioStream
6
6
 
7
7
  def initialize(path, soundinfo:)
8
8
  @path = path
9
- @sound = RubyAudio::Sound.open(path)
10
9
  @soundinfo = soundinfo
11
10
  end
12
11
 
12
+ def connect
13
+ @sound = RubyAudio::Sound.open(@path)
14
+ super
15
+ end
16
+
17
+ def disconnect
18
+ if @sound && !@sound.closed?
19
+ @sound.close
20
+ super
21
+ end
22
+ end
23
+
13
24
  def seek(frames, whence=IO::SEEK_SET)
14
25
  @sound.seek(frames, whence)
15
26
  self
@@ -3,7 +3,6 @@ module AudioStream
3
3
 
4
4
  def initialize
5
5
  super()
6
- @sync = Sync.new
7
6
  end
8
7
 
9
8
  def self.file(fname, soundinfo:)
@@ -17,10 +17,6 @@ module AudioStream
17
17
  @buf.stop
18
18
  end
19
19
 
20
- def join
21
- @sync.yield_wait
22
- end
23
-
24
20
  def on_next(input)
25
21
  window_size = input.size
26
22
  channels = input.channels
@@ -44,7 +40,7 @@ module AudioStream
44
40
  end
45
41
 
46
42
  def on_completed
47
- @sync.finish
43
+ disconnect
48
44
  end
49
45
 
50
46
  def self.default_device(soundinfo:)
@@ -11,10 +11,7 @@ module AudioStream
11
11
  end
12
12
 
13
13
  def disconnect
14
- end
15
-
16
- def join
17
- @sync.yield_wait
14
+ @sound.close
18
15
  end
19
16
 
20
17
  def on_next(input)
@@ -28,8 +25,7 @@ module AudioStream
28
25
  end
29
26
 
30
27
  def on_completed
31
- @sound.close
32
- @sync.finish
28
+ disconnect
33
29
  end
34
30
  end
35
31
  end
@@ -7,32 +7,34 @@ module AudioStream
7
7
 
8
8
  def connect
9
9
  @outputs.map(&:connect)
10
- @input_connections = @inputs.map(&:connect)
10
+ @inputs.map(&:connect)
11
11
 
12
12
  @sync_thread = Thread.start {
13
- loop {
14
- @inputs.each {|t|
15
- t.sync.resume
16
- }
13
+ catch :break do
14
+ loop {
15
+ @inputs.each {|t|
16
+ t.sync.resume
17
+ }
18
+
19
+ @inputs.each {|t|
20
+ stat = t.sync.yield_wait
21
+ if stat==Sync::COMPLETED
22
+ throw :break
23
+ end
24
+ }
17
25
 
18
- @inputs.each {|t|
19
- stat = t.sync.yield_wait
20
- if stat==Sync::COMPLETED
21
- @inputs.delete(t)
26
+ if @inputs.length==0
27
+ throw :break
22
28
  end
23
29
  }
24
-
25
- if @inputs.length==0
26
- break
27
- end
28
- }
30
+ end
29
31
  }
30
32
  end
31
33
 
32
34
  def join
33
- @outputs.map(&:join)
34
- @input_connections.map(&:join)
35
35
  @sync_thread.join
36
+ @inputs.map(&:disconnect)
37
+ @outputs.map(&:disconnect)
36
38
  end
37
39
  end
38
40
  end
@@ -4,9 +4,8 @@ module AudioStream
4
4
  COMPLETED = :completed
5
5
 
6
6
  def initialize
7
- buffering = 1
8
- @resume_queue = SizedQueue.new(buffering)
9
- @yield_queue = SizedQueue.new(buffering)
7
+ @resume_queue = SizedQueue.new(1)
8
+ @yield_queue = SizedQueue.new(1)
10
9
  end
11
10
 
12
11
  def resume
@@ -1,3 +1,3 @@
1
1
  module AudioStream
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: audio_stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshida Tetsuya
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-18 00:00:00.000000000 Z
11
+ date: 2019-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler