win32-sound 0.5.1 → 0.6.0

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.
@@ -0,0 +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
@@ -0,0 +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,103 +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 'win32/sound'
9
- include Win32
10
-
11
- class TC_Win32_Sound < Test::Unit::TestCase
12
- def setup
13
- @wav = "c:\\windows\\media\\chimes.wav"
14
- end
15
-
16
- def test_version
17
- assert_equal('0.5.1', Sound::VERSION)
18
- end
19
-
20
- def test_beep
21
- assert_respond_to(Sound, :beep)
22
- assert_nothing_raised{ Sound.beep(55, 100) }
23
- end
24
-
25
- def test_beep_expected_errors
26
- assert_raises(ArgumentError){ Sound.beep(0, 100) }
27
- assert_raises(ArgumentError){ Sound.beep }
28
- assert_raises(ArgumentError){ Sound.beep(500) }
29
- assert_raises(ArgumentError){ Sound.beep(500, 500, 5) }
30
- end
31
-
32
- def test_devices
33
- assert_respond_to(Sound, :devices)
34
- assert_nothing_raised{ Sound.devices }
35
- assert_kind_of(Array,Sound.devices)
36
- end
37
-
38
- def test_stop
39
- assert_respond_to(Sound, :stop)
40
- assert_nothing_raised{ Sound.stop }
41
- assert_nothing_raised{ Sound.stop(true) }
42
- end
43
-
44
- def test_get_volume_basic
45
- assert_respond_to(Sound, :wave_volume)
46
- assert_respond_to(Sound, :get_wave_volume)
47
- assert_nothing_raised{ Sound.get_wave_volume }
48
- end
49
-
50
- def test_get_volume
51
- assert_kind_of(Array, Sound.get_wave_volume)
52
- assert_equal(2, Sound.get_wave_volume.length)
53
- end
54
-
55
- def test_set_volume
56
- assert_respond_to(Sound, :set_wave_volume)
57
- assert_nothing_raised{ Sound.set_wave_volume(30000) } # About half
58
- assert_nothing_raised{ Sound.set_wave_volume(30000, 30000) }
59
- end
60
-
61
- def test_play
62
- assert_respond_to(Sound, :play)
63
- assert_nothing_raised{ Sound.play(@wav) }
64
- end
65
-
66
- def test_play_alias
67
- assert_nothing_raised{ Sound.play('SystemAsterisk', Sound::ALIAS) }
68
- end
69
-
70
- def test_expected_errors
71
- assert_raises(ArgumentError){ Sound.beep(-1, 1) }
72
- end
73
-
74
- def test_constants
75
- assert_not_nil(Sound::ALIAS)
76
- assert_not_nil(Sound::APPLICATION)
77
- assert_not_nil(Sound::ASYNC)
78
- assert_not_nil(Sound::FILENAME)
79
- assert_not_nil(Sound::LOOP)
80
- assert_not_nil(Sound::MEMORY)
81
- assert_not_nil(Sound::NODEFAULT)
82
- assert_not_nil(Sound::NOSTOP)
83
- assert_not_nil(Sound::NOWAIT)
84
- assert_not_nil(Sound::PURGE)
85
- assert_not_nil(Sound::SYNC)
86
- end
87
-
88
- test "ffi functions are private" do
89
- assert_not_respond_to(Sound, :Beep)
90
- assert_not_respond_to(Sound, :waveOutSetVolume)
91
- assert_not_respond_to(Sound, :waveOutGetVolume)
92
- assert_not_respond_to(Sound, :waveOutGetNumDevs)
93
- assert_not_respond_to(Sound, :waveInGetNumDevs)
94
- assert_not_respond_to(Sound, :midiInGetNumDevs)
95
- assert_not_respond_to(Sound, :midiOutGetNumDevs)
96
- assert_not_respond_to(Sound, :auxGetNumDevs)
97
- assert_not_respond_to(Sound, :mixerGetNumDevs)
98
- end
99
-
100
- def teardown
101
- @wav = nil
102
- end
103
- 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.0', 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
@@ -1,25 +1,25 @@
1
- require 'rubygems'
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = 'win32-sound'
5
- spec.version = '0.5.1'
6
- spec.author = 'Daniel J. Berger'
7
- spec.license = 'Artistic 2.0'
8
- spec.email = 'djberg96@gmail.com'
9
- spec.homepage = 'http://github.com/djberg96/win32-sound'
10
- spec.summary = 'A library for playing with sound on MS Windows.'
11
- spec.test_file = 'test/test_win32_sound.rb'
12
- spec.files = Dir['**/*'] << ".gemtest"
13
-
14
- spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
15
- spec.rubyforge_project = 'win32utils'
16
-
17
- spec.add_dependency('ffi')
18
- spec.add_development_dependency('test-unit')
19
-
20
- spec.description = <<-EOF
21
- The win32-sound library provides an interface for playing various
22
- sounds on MS Windows operating systems, including system sounds and
23
- wave files, as well as querying and configuring sound related properties.
24
- EOF
25
- end
1
+ require 'rubygems'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'win32-sound'
5
+ spec.version = '0.6.0'
6
+ spec.author = 'Daniel J. Berger'
7
+ spec.license = 'Artistic 2.0'
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'http://github.com/djberg96/win32-sound'
10
+ spec.summary = 'A library for playing with sound on MS Windows.'
11
+ spec.test_file = 'test/test_win32_sound.rb'
12
+ spec.files = Dir['**/*'] << ".gemtest"
13
+
14
+ spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
15
+
16
+ spec.add_dependency('ffi')
17
+ spec.add_development_dependency('test-unit')
18
+ spec.add_development_dependency('rake')
19
+
20
+ spec.description = <<-EOF
21
+ The win32-sound library provides an interface for playing various
22
+ sounds on MS Windows operating systems, including system sounds and
23
+ wave files, as well as querying and configuring sound related properties.
24
+ EOF
25
+ end
metadata CHANGED
@@ -1,51 +1,61 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-sound
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
5
- prerelease:
4
+ version: 0.6.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Daniel J. Berger
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-10 00:00:00.000000000 Z
11
+ date: 2014-07-30 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: ffi
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: test-unit
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
- description: ! " The win32-sound library provides an interface for playing various\n
47
- \ sounds on MS Windows operating systems, including system sounds and\n wave
48
- files, as well as querying and configuring sound related properties.\n"
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: |2
56
+ The win32-sound library provides an interface for playing various
57
+ sounds on MS Windows operating systems, including system sounds and
58
+ wave files, as well as querying and configuring sound related properties.
49
59
  email: djberg96@gmail.com
50
60
  executables: []
51
61
  extensions: []
@@ -54,39 +64,40 @@ extra_rdoc_files:
54
64
  - README
55
65
  - MANIFEST
56
66
  files:
67
+ - .gemtest
57
68
  - CHANGES
58
- - examples/example_win32_sound.rb
59
- - lib/win32/sound.rb
60
69
  - MANIFEST
61
- - Rakefile
62
70
  - README
71
+ - Rakefile
72
+ - examples/example_win32_sound.rb
73
+ - lib/win32/sound.rb
74
+ - lib/win32/windows/functions.rb
75
+ - lib/win32/windows/structs.rb
63
76
  - test/test_win32_sound.rb
64
77
  - win32-sound.gemspec
65
- - .gemtest
66
78
  homepage: http://github.com/djberg96/win32-sound
67
79
  licenses:
68
80
  - Artistic 2.0
81
+ metadata: {}
69
82
  post_install_message:
70
83
  rdoc_options: []
71
84
  require_paths:
72
85
  - lib
73
86
  required_ruby_version: !ruby/object:Gem::Requirement
74
- none: false
75
87
  requirements:
76
- - - ! '>='
88
+ - - '>='
77
89
  - !ruby/object:Gem::Version
78
90
  version: '0'
79
91
  required_rubygems_version: !ruby/object:Gem::Requirement
80
- none: false
81
92
  requirements:
82
- - - ! '>='
93
+ - - '>='
83
94
  - !ruby/object:Gem::Version
84
95
  version: '0'
85
96
  requirements: []
86
- rubyforge_project: win32utils
87
- rubygems_version: 1.8.24
97
+ rubyforge_project:
98
+ rubygems_version: 2.2.2
88
99
  signing_key:
89
- specification_version: 3
100
+ specification_version: 4
90
101
  summary: A library for playing with sound on MS Windows.
91
102
  test_files:
92
103
  - test/test_win32_sound.rb