windsp 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/windsp.rb +28 -12
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9818962b3f928fab87a3900c52e0e87608473402
4
- data.tar.gz: 95377f4b3e86a0bf4168036b7afe0ab65c16af6c
3
+ metadata.gz: 81e89dccef9d88f8fae21b7da567b2991da228d5
4
+ data.tar.gz: 294759c25508f6297fcdb1d23ce87bf98e336712
5
5
  SHA512:
6
- metadata.gz: 5ac607666568ec3fed4136bbf5d431cc4746925743b491998fef6458175efe94dedcd5527f011f94c2ef41722b54e5a28d8413ec131c40562e250ac2b5adfdf3
7
- data.tar.gz: 8c800f99298c0db3f4046579d7c7415b33c40f4ae9672c69ff237b7eceafe0099c6930b45343ee64ca5635e3fe995dddc99e870ad29548192437b400c50081f7
6
+ metadata.gz: 37dbac93fac09343ab3c75a777190e6743c2dc01026c4c7b74a248440aec40a0a6e20a681c9c1079bb6483cb2b871bfec68ed13640b79d3d75d0288963283f81
7
+ data.tar.gz: e800d0ef21df75b53de9c60d477927c51f584175598acf2f01c4703056a1432bdb039c36b4a4d3228c5ec87460dbfc2559ca43f409d1393a01cbc824cda1bbe1
data/lib/windsp.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'fiddle/import'
2
2
 
3
3
  class WinDSP
4
+ VERSION = "0.0.3"
5
+
4
6
  module WinMM
5
7
  extend Fiddle::Importer
6
8
  dlload "winmm.dll"
@@ -23,8 +25,6 @@ class WinDSP
23
25
  WHDR_INQUEUE = 0x00000010
24
26
  end
25
27
 
26
- VERSION = "0.0.2"
27
-
28
28
  def self.open(*rest, &block)
29
29
  io = self.new(rest)
30
30
  if block
@@ -52,14 +52,32 @@ class WinDSP
52
52
  else
53
53
  @handle, = tmp.unpack("L!")
54
54
  end
55
+ @hdr = nil
55
56
  @buffer = ""
56
57
  end
57
58
 
58
59
  def close
59
60
  flush
61
+ if @hdr
62
+ wait(@hdr)
63
+ WinMM.waveOutUnprepareHeader(@handle, @hdr, @hdr.bytesize)
64
+ @hdr = nil
65
+ end
60
66
  WinMM.waveOutClose(@handle)
61
67
  end
62
68
 
69
+ def wait(hdr)
70
+ if /64/ =~ RUBY_PLATFORM
71
+ x = "Q!"
72
+ else
73
+ x = "L!"
74
+ end
75
+ while true
76
+ break if (hdr.unpack("pVV#{x}VVp#{x}")[4] & WinMM::WHDR_DONE) == WinMM::WHDR_DONE
77
+ sleep 0
78
+ end
79
+ end
80
+
63
81
  def flush
64
82
  if /64/ =~ RUBY_PLATFORM
65
83
  x = "Q!"
@@ -70,21 +88,19 @@ class WinDSP
70
88
  @buffer = ""
71
89
  ret = WinMM.waveOutPrepareHeader(@handle, hdr, hdr.bytesize)
72
90
  raise "error in waveOutPrepareHeader: #{ret}" if ret != 0
73
- begin
74
- ret = WinMM.waveOutWrite(@handle, hdr, hdr.bytesize)
75
- raise "error in waveOutWrite: #{ret}" if ret != 0
76
- while true
77
- break if (hdr.unpack("pVV#{x}VVp#{x}")[4] & WinMM::WHDR_DONE) == WinMM::WHDR_DONE
78
- sleep 0
79
- end
80
- ensure
81
- WinMM.waveOutUnprepareHeader(@handle, hdr, hdr.bytesize)
91
+ if @hdr
92
+ wait(@hdr)
93
+ WinMM.waveOutUnprepareHeader(@handle, @hdr, @hdr.bytesize)
94
+ @hdr = nil
82
95
  end
96
+ ret = WinMM.waveOutWrite(@handle, hdr, hdr.bytesize)
97
+ raise "error in waveOutWrite: #{ret}" if ret != 0
98
+ @hdr = hdr
83
99
 
84
100
  self
85
101
  end
86
102
 
87
- BUFFER_FLUSH_SEC = 30
103
+ BUFFER_FLUSH_SEC = 4
88
104
  def write(str)
89
105
  @buffer << str
90
106
  flush if @buffer.bytesize >= BUFFER_FLUSH_SEC * rate
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: windsp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - U.Nakamura