-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start fresh; model IO class and treat Audio Devices as such
- Loading branch information
Showing
8 changed files
with
89 additions
and
68 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'sound' | ||
include Sound | ||
# Example of opening a device, writing to it, and closing it up | ||
device = Device.open(Device::DEFAULT, "w", Format::PCM) | ||
file = File.open("bin/sounds.wav", "r") | ||
device.write(file) | ||
device.close | ||
|
||
# This will close the device on its own after the block finishes | ||
Device.open(Device::DEFAULT, "w", Format::PCM) do |device| | ||
device.write(File.open("bin/sounds.wav", "r")) | ||
end | ||
|
||
format = Format.new | ||
|
||
Device.open(Device::DEFAULT, "w", format) | ||
|
||
#file = File.open | ||
#file.write | ||
#file.close | ||
|
||
data = "" | ||
|
||
device = Device.open | ||
device.write(data) | ||
device.close |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,2 @@ | ||
require_relative 'os/os' | ||
|
||
if OS.windows? | ||
require 'win32/sound' | ||
else | ||
warn("Sound output not yet implemented for this platform: #{OS.os}") | ||
end | ||
|
||
require_relative 'sound/sound' | ||
require_relative 'sound/out' | ||
require 'sound/device' | ||
require 'sound/format' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
module Sound | ||
|
||
WAVE_FORMAT_PCM = 1 | ||
WAVE_MAPPER = -1 | ||
|
||
class Device | ||
|
||
def initialize(device_id) | ||
|
||
end | ||
|
||
DEFAULT = self.new(WAVE_MAPPER) | ||
|
||
class << self | ||
# Opens a sound device for reading or writing | ||
# device_id is an id of one of several devices, usually defined by a constant | ||
# direction is reading or writing or both | ||
# format_id is MIDI vs PCM or others | ||
# this method can take a block and if so closes the device after execution | ||
def open(device = Device.new(WAVE_MAPPER), direction = "w", format = Format.new(WAVE_FORMAT_PCM), &block) | ||
if block_given? | ||
block.call(device) | ||
device.close | ||
else | ||
device | ||
end | ||
end | ||
end | ||
|
||
def write(data) | ||
|
||
end | ||
|
||
def close | ||
|
||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
|
||
module Sound | ||
|
||
class Format | ||
attr_accessor :channels, :sample_rate, :bps | ||
def initialize(format_type = WAVE_FORMAT_PCM) | ||
channels = 1 | ||
sample_rate = 44100 | ||
bps = 16 | ||
end | ||
PCM = self.new | ||
def block_align | ||
(bps >> 3) * channels | ||
end | ||
def avg_bps | ||
block_align * sample_rate | ||
end | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.