win32-sound 0.6.0 → 0.6.1
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
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGES +78 -73
- data/MANIFEST +10 -10
- data/README +57 -57
- data/Rakefile +33 -36
- data/certs/djberg96_pub.pem +21 -0
- data/examples/example_win32_sound.rb +56 -56
- data/lib/win32/sound.rb +350 -350
- data/lib/win32/windows/functions.rb +41 -41
- data/lib/win32/windows/structs.rb +78 -78
- data/test/test_win32_sound.rb +141 -141
- data/win32-sound.gemspec +26 -25
- metadata +44 -16
- metadata.gz.sig +3 -0
- data/.gemtest +0 -0
@@ -1,41 +1,41 @@
|
|
1
|
-
require 'ffi'
|
2
|
-
|
3
|
-
module Windows
|
4
|
-
module SoundFunctions
|
5
|
-
extend FFI::Library
|
6
|
-
|
7
|
-
typedef :ulong, :dword
|
8
|
-
typedef :uintptr_t, :hmodule
|
9
|
-
typedef :uintptr_t, :hwaveout
|
10
|
-
typedef :uint, :mmresult
|
11
|
-
|
12
|
-
ffi_lib :kernel32
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
# Make FFI functions private
|
17
|
-
def self.attach_pfunc(*args)
|
18
|
-
attach_function(*args)
|
19
|
-
private args[0]
|
20
|
-
end
|
21
|
-
|
22
|
-
attach_pfunc :Beep, [:dword, :dword], :bool
|
23
|
-
|
24
|
-
ffi_lib :winmm
|
25
|
-
|
26
|
-
attach_pfunc :PlaySound, [:string, :hmodule, :dword], :bool
|
27
|
-
attach_pfunc :waveOutSetVolume, [:hwaveout, :dword], :int
|
28
|
-
attach_pfunc :waveOutGetVolume, [:hwaveout, :pointer], :int
|
29
|
-
attach_pfunc :waveOutGetNumDevs, [], :int
|
30
|
-
attach_pfunc :waveInGetNumDevs, [], :int
|
31
|
-
attach_pfunc :midiOutGetNumDevs, [], :int
|
32
|
-
attach_pfunc :midiInGetNumDevs, [], :int
|
33
|
-
attach_pfunc :auxGetNumDevs, [], :int
|
34
|
-
attach_pfunc :mixerGetNumDevs, [], :int
|
35
|
-
attach_pfunc :waveOutOpen, [:pointer, :uint, :pointer, :dword, :dword, :dword], :mmresult
|
36
|
-
attach_pfunc :waveOutPrepareHeader, [:hwaveout, :pointer, :uint], :mmresult
|
37
|
-
attach_pfunc :waveOutWrite, [:hwaveout, :pointer, :uint], :mmresult
|
38
|
-
attach_pfunc :waveOutUnprepareHeader, [:hwaveout, :pointer, :uint], :mmresult
|
39
|
-
attach_pfunc :waveOutClose, [:hwaveout], :mmresult
|
40
|
-
end
|
41
|
-
end
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module Windows
|
4
|
+
module SoundFunctions
|
5
|
+
extend FFI::Library
|
6
|
+
|
7
|
+
typedef :ulong, :dword
|
8
|
+
typedef :uintptr_t, :hmodule
|
9
|
+
typedef :uintptr_t, :hwaveout
|
10
|
+
typedef :uint, :mmresult
|
11
|
+
|
12
|
+
ffi_lib :kernel32
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# Make FFI functions private
|
17
|
+
def self.attach_pfunc(*args)
|
18
|
+
attach_function(*args)
|
19
|
+
private args[0]
|
20
|
+
end
|
21
|
+
|
22
|
+
attach_pfunc :Beep, [:dword, :dword], :bool
|
23
|
+
|
24
|
+
ffi_lib :winmm
|
25
|
+
|
26
|
+
attach_pfunc :PlaySound, [:string, :hmodule, :dword], :bool
|
27
|
+
attach_pfunc :waveOutSetVolume, [:hwaveout, :dword], :int
|
28
|
+
attach_pfunc :waveOutGetVolume, [:hwaveout, :pointer], :int
|
29
|
+
attach_pfunc :waveOutGetNumDevs, [], :int
|
30
|
+
attach_pfunc :waveInGetNumDevs, [], :int
|
31
|
+
attach_pfunc :midiOutGetNumDevs, [], :int
|
32
|
+
attach_pfunc :midiInGetNumDevs, [], :int
|
33
|
+
attach_pfunc :auxGetNumDevs, [], :int
|
34
|
+
attach_pfunc :mixerGetNumDevs, [], :int
|
35
|
+
attach_pfunc :waveOutOpen, [:pointer, :uint, :pointer, :dword, :dword, :dword], :mmresult
|
36
|
+
attach_pfunc :waveOutPrepareHeader, [:hwaveout, :pointer, :uint], :mmresult
|
37
|
+
attach_pfunc :waveOutWrite, [:hwaveout, :pointer, :uint], :mmresult
|
38
|
+
attach_pfunc :waveOutUnprepareHeader, [:hwaveout, :pointer, :uint], :mmresult
|
39
|
+
attach_pfunc :waveOutClose, [:hwaveout], :mmresult
|
40
|
+
end
|
41
|
+
end
|
@@ -1,78 +1,78 @@
|
|
1
|
-
require 'ffi'
|
2
|
-
|
3
|
-
module Windows
|
4
|
-
module SoundStructs
|
5
|
-
extend FFI::Library
|
6
|
-
|
7
|
-
# Define an HWAVEOUT struct for use by all the waveOut functions.
|
8
|
-
# It is a handle to a waveOut stream, so starting up multiple
|
9
|
-
# streams using different handles allows for simultaneous playback.
|
10
|
-
# You never need to actually look at the struct, C takes care of
|
11
|
-
# its value.
|
12
|
-
#
|
13
|
-
class HWAVEOUT < FFI::Struct
|
14
|
-
layout :i, :int
|
15
|
-
end
|
16
|
-
|
17
|
-
# Define WAVEFORMATEX which defines the format (PCM in this case)
|
18
|
-
# and various properties like sampling rate, number of channels, etc.
|
19
|
-
#
|
20
|
-
class WAVEFORMATEX < FFI::Struct
|
21
|
-
|
22
|
-
# Initializes struct with sensible defaults for most commonly used
|
23
|
-
# values. While setting these manually is possible, please be
|
24
|
-
# sure you know what changes will result in, as an incorrectly
|
25
|
-
# set struct will result in unpredictable behavior.
|
26
|
-
#
|
27
|
-
def initialize(nSamplesPerSec = 44100, wBitsPerSample = 16, nChannels = 1, cbSize = 0)
|
28
|
-
self[:wFormatTag] = Win32::Sound::WAVE_FORMAT_PCM
|
29
|
-
self[:nChannels] = nChannels
|
30
|
-
self[:nSamplesPerSec] = nSamplesPerSec
|
31
|
-
self[:wBitsPerSample] = wBitsPerSample
|
32
|
-
self[:cbSize] = cbSize
|
33
|
-
self[:nBlockAlign] = (self[:wBitsPerSample] >> 3) * self[:nChannels]
|
34
|
-
self[:nAvgBytesPerSec] = self[:nBlockAlign] * self[:nSamplesPerSec]
|
35
|
-
end
|
36
|
-
|
37
|
-
layout(
|
38
|
-
:wFormatTag, :ushort,
|
39
|
-
:nChannels, :ushort,
|
40
|
-
:nSamplesPerSec, :ulong,
|
41
|
-
:nAvgBytesPerSec, :ulong,
|
42
|
-
:nBlockAlign, :ushort,
|
43
|
-
:wBitsPerSample, :ushort,
|
44
|
-
:cbSize, :ushort
|
45
|
-
)
|
46
|
-
end
|
47
|
-
|
48
|
-
#define WAVEHDR which is a header to a block of audio
|
49
|
-
#lpData is a pointer to the block of native memory that,
|
50
|
-
# in this case, is an integer array of PCM data
|
51
|
-
|
52
|
-
class WAVEHDR < FFI::Struct
|
53
|
-
|
54
|
-
# Initializes struct with sensible defaults for most commonly used
|
55
|
-
# values. While setting these manually is possible, please be
|
56
|
-
# sure you know what changes will result in, as an incorrectly
|
57
|
-
# set struct will result in unpredictable behavior.
|
58
|
-
#
|
59
|
-
def initialize(lpData, dwBufferLength, dwFlags = 0, dwLoops = 1)
|
60
|
-
self[:lpData] = lpData
|
61
|
-
self[:dwBufferLength] = dwBufferLength
|
62
|
-
self[:dwFlags] = dwFlags
|
63
|
-
self[:dwLoops] = dwLoops
|
64
|
-
end
|
65
|
-
|
66
|
-
layout(
|
67
|
-
:lpData, :pointer,
|
68
|
-
:dwBufferLength, :ulong,
|
69
|
-
:dwBytesRecorded, :ulong,
|
70
|
-
:dwUser, :ulong,
|
71
|
-
:dwFlags, :ulong,
|
72
|
-
:dwLoops, :ulong,
|
73
|
-
:lpNext, :pointer,
|
74
|
-
:reserved, :ulong
|
75
|
-
)
|
76
|
-
end
|
77
|
-
end # SoundStructs
|
78
|
-
end # Windows
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module Windows
|
4
|
+
module SoundStructs
|
5
|
+
extend FFI::Library
|
6
|
+
|
7
|
+
# Define an HWAVEOUT struct for use by all the waveOut functions.
|
8
|
+
# It is a handle to a waveOut stream, so starting up multiple
|
9
|
+
# streams using different handles allows for simultaneous playback.
|
10
|
+
# You never need to actually look at the struct, C takes care of
|
11
|
+
# its value.
|
12
|
+
#
|
13
|
+
class HWAVEOUT < FFI::Struct
|
14
|
+
layout :i, :int
|
15
|
+
end
|
16
|
+
|
17
|
+
# Define WAVEFORMATEX which defines the format (PCM in this case)
|
18
|
+
# and various properties like sampling rate, number of channels, etc.
|
19
|
+
#
|
20
|
+
class WAVEFORMATEX < FFI::Struct
|
21
|
+
|
22
|
+
# Initializes struct with sensible defaults for most commonly used
|
23
|
+
# values. While setting these manually is possible, please be
|
24
|
+
# sure you know what changes will result in, as an incorrectly
|
25
|
+
# set struct will result in unpredictable behavior.
|
26
|
+
#
|
27
|
+
def initialize(nSamplesPerSec = 44100, wBitsPerSample = 16, nChannels = 1, cbSize = 0)
|
28
|
+
self[:wFormatTag] = Win32::Sound::WAVE_FORMAT_PCM
|
29
|
+
self[:nChannels] = nChannels
|
30
|
+
self[:nSamplesPerSec] = nSamplesPerSec
|
31
|
+
self[:wBitsPerSample] = wBitsPerSample
|
32
|
+
self[:cbSize] = cbSize
|
33
|
+
self[:nBlockAlign] = (self[:wBitsPerSample] >> 3) * self[:nChannels]
|
34
|
+
self[:nAvgBytesPerSec] = self[:nBlockAlign] * self[:nSamplesPerSec]
|
35
|
+
end
|
36
|
+
|
37
|
+
layout(
|
38
|
+
:wFormatTag, :ushort,
|
39
|
+
:nChannels, :ushort,
|
40
|
+
:nSamplesPerSec, :ulong,
|
41
|
+
:nAvgBytesPerSec, :ulong,
|
42
|
+
:nBlockAlign, :ushort,
|
43
|
+
:wBitsPerSample, :ushort,
|
44
|
+
:cbSize, :ushort
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
#define WAVEHDR which is a header to a block of audio
|
49
|
+
#lpData is a pointer to the block of native memory that,
|
50
|
+
# in this case, is an integer array of PCM data
|
51
|
+
|
52
|
+
class WAVEHDR < FFI::Struct
|
53
|
+
|
54
|
+
# Initializes struct with sensible defaults for most commonly used
|
55
|
+
# values. While setting these manually is possible, please be
|
56
|
+
# sure you know what changes will result in, as an incorrectly
|
57
|
+
# set struct will result in unpredictable behavior.
|
58
|
+
#
|
59
|
+
def initialize(lpData, dwBufferLength, dwFlags = 0, dwLoops = 1)
|
60
|
+
self[:lpData] = lpData
|
61
|
+
self[:dwBufferLength] = dwBufferLength
|
62
|
+
self[:dwFlags] = dwFlags
|
63
|
+
self[:dwLoops] = dwLoops
|
64
|
+
end
|
65
|
+
|
66
|
+
layout(
|
67
|
+
:lpData, :pointer,
|
68
|
+
:dwBufferLength, :ulong,
|
69
|
+
:dwBytesRecorded, :ulong,
|
70
|
+
:dwUser, :ulong,
|
71
|
+
:dwFlags, :ulong,
|
72
|
+
:dwLoops, :ulong,
|
73
|
+
:lpNext, :pointer,
|
74
|
+
:reserved, :ulong
|
75
|
+
)
|
76
|
+
end
|
77
|
+
end # SoundStructs
|
78
|
+
end # Windows
|
data/test/test_win32_sound.rb
CHANGED
@@ -1,141 +1,141 @@
|
|
1
|
-
##########################################################################
|
2
|
-
# test_win32_sound.rb
|
3
|
-
#
|
4
|
-
# Test suite for the win32-sound library. You should run this test case
|
5
|
-
# via the 'rake test' task.
|
6
|
-
##########################################################################
|
7
|
-
require 'test-unit'
|
8
|
-
require 'stringio'
|
9
|
-
require 'win32/sound'
|
10
|
-
include Win32
|
11
|
-
|
12
|
-
class TC_Win32_Sound < Test::Unit::TestCase
|
13
|
-
def setup
|
14
|
-
@wav = "c:\\windows\\media\\chimes.wav"
|
15
|
-
end
|
16
|
-
|
17
|
-
test "version constant is set to expected value" do
|
18
|
-
assert_equal('0.6.
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_beep
|
22
|
-
assert_respond_to(Sound, :beep)
|
23
|
-
assert_nothing_raised{ Sound.beep(55, 100) }
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_beep_expected_errors
|
27
|
-
assert_raises(ArgumentError){ Sound.beep(0, 100) }
|
28
|
-
assert_raises(ArgumentError){ Sound.beep }
|
29
|
-
assert_raises(ArgumentError){ Sound.beep(500) }
|
30
|
-
assert_raises(ArgumentError){ Sound.beep(500, 500, 5) }
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_devices
|
34
|
-
assert_respond_to(Sound, :devices)
|
35
|
-
assert_nothing_raised{ Sound.devices }
|
36
|
-
assert_kind_of(Array,Sound.devices)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_stop
|
40
|
-
assert_respond_to(Sound, :stop)
|
41
|
-
assert_nothing_raised{ Sound.stop }
|
42
|
-
assert_nothing_raised{ Sound.stop(true) }
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_get_volume_basic
|
46
|
-
assert_respond_to(Sound, :wave_volume)
|
47
|
-
assert_respond_to(Sound, :get_wave_volume)
|
48
|
-
assert_nothing_raised{ Sound.get_wave_volume }
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_get_volume
|
52
|
-
assert_kind_of(Array, Sound.get_wave_volume)
|
53
|
-
assert_equal(2, Sound.get_wave_volume.length)
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_set_volume
|
57
|
-
assert_respond_to(Sound, :set_wave_volume)
|
58
|
-
assert_nothing_raised{ Sound.set_wave_volume(30000) } # About half
|
59
|
-
assert_nothing_raised{ Sound.set_wave_volume(30000, 30000) }
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_play
|
63
|
-
assert_respond_to(Sound, :play)
|
64
|
-
assert_nothing_raised{ Sound.play(@wav) }
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_play_alias
|
68
|
-
assert_nothing_raised{ Sound.play('SystemAsterisk', Sound::ALIAS) }
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_expected_errors
|
72
|
-
assert_raises(ArgumentError){ Sound.beep(-1, 1) }
|
73
|
-
end
|
74
|
-
|
75
|
-
test "play_freq basic functionality" do
|
76
|
-
assert_respond_to(Sound, :play_freq)
|
77
|
-
assert_nothing_raised{ Sound.play_freq(660.0, 500) }
|
78
|
-
end
|
79
|
-
|
80
|
-
test "play_freq raises an error if the frequency is too high or too low" do
|
81
|
-
assert_raise(ArgumentError){ Sound.play_freq(999999999, 500) }
|
82
|
-
assert_raise(ArgumentError){ Sound.play_freq(1, 500) }
|
83
|
-
end
|
84
|
-
|
85
|
-
test "play_freq raises an error if the duration is too high or too low" do
|
86
|
-
assert_raise(ArgumentError){ Sound.play_freq(660.0, 9999999) }
|
87
|
-
assert_raise(ArgumentError){ Sound.play_freq(660.0, -1) }
|
88
|
-
end
|
89
|
-
|
90
|
-
test "play_freq displays a warning if volume is too large" do
|
91
|
-
@orig_stderr = $stderr
|
92
|
-
$stderr = StringIO.new
|
93
|
-
Sound.play_freq(440, 200, 2)
|
94
|
-
$stderr.rewind
|
95
|
-
assert_equal("WARNING: Volume greater than 1 will cause audio clipping.",
|
96
|
-
$stderr.string.chomp)
|
97
|
-
$stderr = @orig_stderr
|
98
|
-
end
|
99
|
-
|
100
|
-
test "expected constants are defined" do
|
101
|
-
assert_not_nil(Sound::ALIAS)
|
102
|
-
assert_not_nil(Sound::APPLICATION)
|
103
|
-
assert_not_nil(Sound::ASYNC)
|
104
|
-
assert_not_nil(Sound::FILENAME)
|
105
|
-
assert_not_nil(Sound::LOOP)
|
106
|
-
assert_not_nil(Sound::MEMORY)
|
107
|
-
assert_not_nil(Sound::NODEFAULT)
|
108
|
-
assert_not_nil(Sound::NOSTOP)
|
109
|
-
assert_not_nil(Sound::NOWAIT)
|
110
|
-
assert_not_nil(Sound::PURGE)
|
111
|
-
assert_not_nil(Sound::SYNC)
|
112
|
-
assert_not_nil(Sound::VERSION)
|
113
|
-
assert_not_nil(Sound::WAVE_FORMAT_PCM)
|
114
|
-
assert_not_nil(Sound::WAVE_MAPPER)
|
115
|
-
assert_not_nil(Sound::HWAVEOUT)
|
116
|
-
assert_not_nil(Sound::WAVEFORMATEX)
|
117
|
-
assert_not_nil(Sound::WAVEHDR)
|
118
|
-
end
|
119
|
-
|
120
|
-
test "ffi functions are private" do
|
121
|
-
assert_not_respond_to(Sound, :Beep)
|
122
|
-
assert_not_respond_to(Sound, :PlaySound)
|
123
|
-
assert_not_respond_to(Sound, :waveOutSetVolume)
|
124
|
-
assert_not_respond_to(Sound, :waveOutGetVolume)
|
125
|
-
assert_not_respond_to(Sound, :waveOutGetNumDevs)
|
126
|
-
assert_not_respond_to(Sound, :waveInGetNumDevs)
|
127
|
-
assert_not_respond_to(Sound, :midiInGetNumDevs)
|
128
|
-
assert_not_respond_to(Sound, :midiOutGetNumDevs)
|
129
|
-
assert_not_respond_to(Sound, :auxGetNumDevs)
|
130
|
-
assert_not_respond_to(Sound, :mixerGetNumDevs)
|
131
|
-
assert_not_respond_to(Sound, :waveOutOpen)
|
132
|
-
assert_not_respond_to(Sound, :waveOutPrepareHeader)
|
133
|
-
assert_not_respond_to(Sound, :waveOutWrite)
|
134
|
-
assert_not_respond_to(Sound, :waveOutUnprepareHeader)
|
135
|
-
assert_not_respond_to(Sound, :waveOutClose)
|
136
|
-
end
|
137
|
-
|
138
|
-
def teardown
|
139
|
-
@wav = nil
|
140
|
-
end
|
141
|
-
end
|
1
|
+
##########################################################################
|
2
|
+
# test_win32_sound.rb
|
3
|
+
#
|
4
|
+
# Test suite for the win32-sound library. You should run this test case
|
5
|
+
# via the 'rake test' task.
|
6
|
+
##########################################################################
|
7
|
+
require 'test-unit'
|
8
|
+
require 'stringio'
|
9
|
+
require 'win32/sound'
|
10
|
+
include Win32
|
11
|
+
|
12
|
+
class TC_Win32_Sound < Test::Unit::TestCase
|
13
|
+
def setup
|
14
|
+
@wav = "c:\\windows\\media\\chimes.wav"
|
15
|
+
end
|
16
|
+
|
17
|
+
test "version constant is set to expected value" do
|
18
|
+
assert_equal('0.6.1', Sound::VERSION)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_beep
|
22
|
+
assert_respond_to(Sound, :beep)
|
23
|
+
assert_nothing_raised{ Sound.beep(55, 100) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_beep_expected_errors
|
27
|
+
assert_raises(ArgumentError){ Sound.beep(0, 100) }
|
28
|
+
assert_raises(ArgumentError){ Sound.beep }
|
29
|
+
assert_raises(ArgumentError){ Sound.beep(500) }
|
30
|
+
assert_raises(ArgumentError){ Sound.beep(500, 500, 5) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_devices
|
34
|
+
assert_respond_to(Sound, :devices)
|
35
|
+
assert_nothing_raised{ Sound.devices }
|
36
|
+
assert_kind_of(Array,Sound.devices)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_stop
|
40
|
+
assert_respond_to(Sound, :stop)
|
41
|
+
assert_nothing_raised{ Sound.stop }
|
42
|
+
assert_nothing_raised{ Sound.stop(true) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_get_volume_basic
|
46
|
+
assert_respond_to(Sound, :wave_volume)
|
47
|
+
assert_respond_to(Sound, :get_wave_volume)
|
48
|
+
assert_nothing_raised{ Sound.get_wave_volume }
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_get_volume
|
52
|
+
assert_kind_of(Array, Sound.get_wave_volume)
|
53
|
+
assert_equal(2, Sound.get_wave_volume.length)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_set_volume
|
57
|
+
assert_respond_to(Sound, :set_wave_volume)
|
58
|
+
assert_nothing_raised{ Sound.set_wave_volume(30000) } # About half
|
59
|
+
assert_nothing_raised{ Sound.set_wave_volume(30000, 30000) }
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_play
|
63
|
+
assert_respond_to(Sound, :play)
|
64
|
+
assert_nothing_raised{ Sound.play(@wav) }
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_play_alias
|
68
|
+
assert_nothing_raised{ Sound.play('SystemAsterisk', Sound::ALIAS) }
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_expected_errors
|
72
|
+
assert_raises(ArgumentError){ Sound.beep(-1, 1) }
|
73
|
+
end
|
74
|
+
|
75
|
+
test "play_freq basic functionality" do
|
76
|
+
assert_respond_to(Sound, :play_freq)
|
77
|
+
assert_nothing_raised{ Sound.play_freq(660.0, 500) }
|
78
|
+
end
|
79
|
+
|
80
|
+
test "play_freq raises an error if the frequency is too high or too low" do
|
81
|
+
assert_raise(ArgumentError){ Sound.play_freq(999999999, 500) }
|
82
|
+
assert_raise(ArgumentError){ Sound.play_freq(1, 500) }
|
83
|
+
end
|
84
|
+
|
85
|
+
test "play_freq raises an error if the duration is too high or too low" do
|
86
|
+
assert_raise(ArgumentError){ Sound.play_freq(660.0, 9999999) }
|
87
|
+
assert_raise(ArgumentError){ Sound.play_freq(660.0, -1) }
|
88
|
+
end
|
89
|
+
|
90
|
+
test "play_freq displays a warning if volume is too large" do
|
91
|
+
@orig_stderr = $stderr
|
92
|
+
$stderr = StringIO.new
|
93
|
+
Sound.play_freq(440, 200, 2)
|
94
|
+
$stderr.rewind
|
95
|
+
assert_equal("WARNING: Volume greater than 1 will cause audio clipping.",
|
96
|
+
$stderr.string.chomp)
|
97
|
+
$stderr = @orig_stderr
|
98
|
+
end
|
99
|
+
|
100
|
+
test "expected constants are defined" do
|
101
|
+
assert_not_nil(Sound::ALIAS)
|
102
|
+
assert_not_nil(Sound::APPLICATION)
|
103
|
+
assert_not_nil(Sound::ASYNC)
|
104
|
+
assert_not_nil(Sound::FILENAME)
|
105
|
+
assert_not_nil(Sound::LOOP)
|
106
|
+
assert_not_nil(Sound::MEMORY)
|
107
|
+
assert_not_nil(Sound::NODEFAULT)
|
108
|
+
assert_not_nil(Sound::NOSTOP)
|
109
|
+
assert_not_nil(Sound::NOWAIT)
|
110
|
+
assert_not_nil(Sound::PURGE)
|
111
|
+
assert_not_nil(Sound::SYNC)
|
112
|
+
assert_not_nil(Sound::VERSION)
|
113
|
+
assert_not_nil(Sound::WAVE_FORMAT_PCM)
|
114
|
+
assert_not_nil(Sound::WAVE_MAPPER)
|
115
|
+
assert_not_nil(Sound::HWAVEOUT)
|
116
|
+
assert_not_nil(Sound::WAVEFORMATEX)
|
117
|
+
assert_not_nil(Sound::WAVEHDR)
|
118
|
+
end
|
119
|
+
|
120
|
+
test "ffi functions are private" do
|
121
|
+
assert_not_respond_to(Sound, :Beep)
|
122
|
+
assert_not_respond_to(Sound, :PlaySound)
|
123
|
+
assert_not_respond_to(Sound, :waveOutSetVolume)
|
124
|
+
assert_not_respond_to(Sound, :waveOutGetVolume)
|
125
|
+
assert_not_respond_to(Sound, :waveOutGetNumDevs)
|
126
|
+
assert_not_respond_to(Sound, :waveInGetNumDevs)
|
127
|
+
assert_not_respond_to(Sound, :midiInGetNumDevs)
|
128
|
+
assert_not_respond_to(Sound, :midiOutGetNumDevs)
|
129
|
+
assert_not_respond_to(Sound, :auxGetNumDevs)
|
130
|
+
assert_not_respond_to(Sound, :mixerGetNumDevs)
|
131
|
+
assert_not_respond_to(Sound, :waveOutOpen)
|
132
|
+
assert_not_respond_to(Sound, :waveOutPrepareHeader)
|
133
|
+
assert_not_respond_to(Sound, :waveOutWrite)
|
134
|
+
assert_not_respond_to(Sound, :waveOutUnprepareHeader)
|
135
|
+
assert_not_respond_to(Sound, :waveOutClose)
|
136
|
+
end
|
137
|
+
|
138
|
+
def teardown
|
139
|
+
@wav = nil
|
140
|
+
end
|
141
|
+
end
|