windsp 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/windsp.rb +28 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81e89dccef9d88f8fae21b7da567b2991da228d5
|
4
|
+
data.tar.gz: 294759c25508f6297fcdb1d23ce87bf98e336712
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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 =
|
103
|
+
BUFFER_FLUSH_SEC = 4
|
88
104
|
def write(str)
|
89
105
|
@buffer << str
|
90
106
|
flush if @buffer.bytesize >= BUFFER_FLUSH_SEC * rate
|