windsp 0.0.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 +7 -0
- data/.gitignore +2 -0
- data/Gemfile +3 -0
- data/README.md +58 -0
- data/Rakefile +2 -0
- data/lib/windsp.rb +98 -0
- data/windsp.gemspec +22 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9b40da30b2b860996cf31c7368ac836aa5456e56
|
4
|
+
data.tar.gz: b7da40fe4ffe89ba12110a9ec36da0dd4f5f7f54
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 877ad9b7b102de4f055b2105b6bdf407a0fbe572f3f7c0913ea85a5916941a32937e381fd36950b2c19ce8b5833e8e251db04605d83db7e968861b19f972a29d
|
7
|
+
data.tar.gz: 357b8e93fa930462ae7e9b040641b8c739fc948f666cf07663f2be73151aa50bac191708afc074871e4e95ba8ddc9779beaf751ec28fb81b5ac02685425cca21
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
[](https://rubygems.org/gems/windsp)
|
2
|
+
WinDSP
|
3
|
+
======
|
4
|
+
|
5
|
+
This software is published at https://github.com/unak/windsp .
|
6
|
+
|
7
|
+
|
8
|
+
What's This?
|
9
|
+
------------
|
10
|
+
|
11
|
+
`/dev/dsp` emulator for Windows.
|
12
|
+
|
13
|
+
|
14
|
+
Requirement
|
15
|
+
-----------
|
16
|
+
|
17
|
+
Ruby 2.0.0 or later.
|
18
|
+
|
19
|
+
And, of cource, Windows :-)
|
20
|
+
|
21
|
+
|
22
|
+
How to Use
|
23
|
+
----------
|
24
|
+
|
25
|
+
Simply require it.
|
26
|
+
After requiring, you can write PCM to pseudo I/O via `open "/dev/dsp"`.
|
27
|
+
|
28
|
+
|
29
|
+
Bug
|
30
|
+
---
|
31
|
+
|
32
|
+
Flushing (= syncing) the sound makes noise sound.
|
33
|
+
|
34
|
+
|
35
|
+
License
|
36
|
+
-------
|
37
|
+
|
38
|
+
Copyright (c) 2015 NAKAMURA Usaku <usa@garbagecollect.jp>
|
39
|
+
|
40
|
+
Redistribution and use in source and binary forms, with or without
|
41
|
+
modification, are permitted provided that the following conditions are met:
|
42
|
+
|
43
|
+
1. Redistributions of source code must retain the above copyright notice,
|
44
|
+
this list of conditions and the following disclaimer.
|
45
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
46
|
+
this list of conditions and the following disclaimer in the documentation
|
47
|
+
and/or other materials provided with the distribution.
|
48
|
+
|
49
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
|
50
|
+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
51
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
52
|
+
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
|
53
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
54
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
55
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
56
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
57
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
58
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/Rakefile
ADDED
data/lib/windsp.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'fiddle/import'
|
2
|
+
|
3
|
+
class WinDSP
|
4
|
+
module WinMM
|
5
|
+
extend Fiddle::Importer
|
6
|
+
dlload "winmm.dll"
|
7
|
+
extern "int PlaySound(void *, void *, long)"
|
8
|
+
|
9
|
+
SND_SYNC = 0x0000
|
10
|
+
SND_ASYNC = 0x0001
|
11
|
+
SND_NODEFAULT = 0x0002
|
12
|
+
SND_MEMORY = 0x0004
|
13
|
+
SND_LOOP = 0x0008
|
14
|
+
SND_NOSTOP = 0x0010
|
15
|
+
SND_NOWAIT = 0x00002000
|
16
|
+
SND_ALIAS = 0x00010000
|
17
|
+
SND_ALIAS_ID = 0x00110000
|
18
|
+
SND_FILENAME = 0x00020000
|
19
|
+
SND_RESOURCE = 0x00040004
|
20
|
+
SND_PURGE = 0x0040
|
21
|
+
SND_APPLICATION = 0x0080
|
22
|
+
SND_SENTRY = 0x00080000
|
23
|
+
SND_RING = 0x00100000
|
24
|
+
SND_SYSTEM = 0x00200000
|
25
|
+
|
26
|
+
def self.make_wave(pcm)
|
27
|
+
head = ["WAVEfmt ", 16, 1, 1, 8000, 8000 * 1 * 1, 1 * 1, 8].pack('a*VvvVVvv')
|
28
|
+
data = ["data", pcm.bytesize, pcm].pack('a*Va*')
|
29
|
+
["RIFF", head.bytesize + data.bytesize, head, data].pack('a*Va*a*')
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.play_pcm(pcm, sync: true)
|
33
|
+
flags = SND_NODEFAULT | SND_MEMORY
|
34
|
+
flags |= SND_ASYNC unless sync
|
35
|
+
PlaySound(make_wave(pcm), nil, flags)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
VERSION = "0.0.1"
|
40
|
+
|
41
|
+
def self.open(*rest, &block)
|
42
|
+
io = self.new(rest)
|
43
|
+
if block
|
44
|
+
begin
|
45
|
+
block.call(io)
|
46
|
+
ensure
|
47
|
+
io.close
|
48
|
+
end
|
49
|
+
else
|
50
|
+
io
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def initialize(*rest)
|
55
|
+
@buf = ""
|
56
|
+
end
|
57
|
+
|
58
|
+
def close
|
59
|
+
flush
|
60
|
+
WinMM.PlaySound(nil, nil, 0)
|
61
|
+
end
|
62
|
+
|
63
|
+
def flush
|
64
|
+
if @buf.bytesize >= 0
|
65
|
+
until WinMM.play_pcm(@buf, sync: false)
|
66
|
+
sleep 0.1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
@buf = ""
|
70
|
+
WinMM.play_pcm("", sync: true)
|
71
|
+
end
|
72
|
+
|
73
|
+
def write(str)
|
74
|
+
@buf << str
|
75
|
+
flush if @buf.bytesize > 8000 * 1 * 1 * 4
|
76
|
+
end
|
77
|
+
|
78
|
+
alias binwrite write
|
79
|
+
alias print write
|
80
|
+
alias syswrite write
|
81
|
+
alias << write
|
82
|
+
end
|
83
|
+
|
84
|
+
module Kernel
|
85
|
+
private
|
86
|
+
alias windsp_orig_open open
|
87
|
+
class << self
|
88
|
+
alias windsp_orig_open open
|
89
|
+
end
|
90
|
+
def open(name, *rest, &block)
|
91
|
+
if name == "/dev/dsp"
|
92
|
+
WinDSP.open(*rest, &block)
|
93
|
+
else
|
94
|
+
windsp_orig_open(name, *rest, &block)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
module_function :open
|
98
|
+
end
|
data/windsp.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# -*- Ruby -*-
|
3
|
+
require File.expand_path("lib/windsp")
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "windsp"
|
7
|
+
spec.version = WinDSP::VERSION
|
8
|
+
spec.authors = ["U.Nakamura"]
|
9
|
+
spec.email = ["usa@garbagecollect.jp"]
|
10
|
+
spec.description = %q{`/dev/dsp` emulator for Windows}
|
11
|
+
spec.summary = %q{`/dev/dsp` emulator for Windows}
|
12
|
+
spec.homepage = "https://github.com/unak/windsp"
|
13
|
+
spec.license = "BSD-2-Clause"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: windsp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- U.Nakamura
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: "`/dev/dsp` emulator for Windows"
|
42
|
+
email:
|
43
|
+
- usa@garbagecollect.jp
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- lib/windsp.rb
|
53
|
+
- windsp.gemspec
|
54
|
+
homepage: https://github.com/unak/windsp
|
55
|
+
licenses:
|
56
|
+
- BSD-2-Clause
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.4.5
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: "`/dev/dsp` emulator for Windows"
|
78
|
+
test_files: []
|