feep 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +17 -16
- data/Rakefile +1 -1
- data/bin/feep +9 -9
- data/feep.gemspec +10 -10
- data/lib/feep.rb +10 -10
- data/lib/feep/constants.rb +1 -1
- data/lib/feep/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c9ade110c0c083ad59f6732c2474d8f0aaabfb3
|
4
|
+
data.tar.gz: ea1319e91994705a44a70a8c0d0124a5e6e9703e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cf79e2486d896848f42add1472d5eee509f1aa657a3a33099459fac90479ff5f66612c39124693471c3e795c1268ffe784b09ee71233c068d2957236a0c1827
|
7
|
+
data.tar.gz: a9f0d7edf48f2940a3e90f2e46fd45378dce2e46beb062b0cabb523ffb1b7d7d42bb4ad632a9f25a3bb63eeb5fb7129cdec5fab304837dfe3c5e310b98a6279e
|
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
|
-
gemspec
|
2
|
+
gemspec
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -7,32 +7,33 @@ _Note:_ In order for the sound-playing magic to work on Windows, you will need [
|
|
7
7
|
|
8
8
|
## Why?
|
9
9
|
|
10
|
-
Besides a quick way to make some kind of noise, which I always appreciate,
|
10
|
+
Besides a quick way to make some kind of noise for fun or testing your speakers, which I always appreciate, `feep` could be used to tie into another Ruby script for an alert tone or maybe even some wicked cool command-line game that needs musical note sound effects. The opportunities are essentially endless.
|
11
11
|
|
12
12
|
## How?
|
13
13
|
|
14
|
-
|
15
|
-
1. `git clone git@github.com:michaelchadwick/feep`
|
16
|
-
2. `cd feep`
|
17
|
-
3. `gem build feep.gemspec`
|
18
|
-
4. `gem install feep-0.0.1.gem`
|
19
|
-
5. `bundle install`
|
20
|
-
6. `feep`
|
14
|
+
* `gem install feep`
|
21
15
|
|
22
|
-
Feep doesn't require any parameters, as it will play a 440Hz/A4 sine wave at 50% full volume for
|
16
|
+
Feep doesn't require any parameters, as it will play a 440Hz/A4 sine wave at 50% full volume for 200 milliseconds unless you supply one of the below options. Feep will only save the resulting WAV file it creates if you specify the `-save` parameter.
|
23
17
|
|
24
18
|
The full usage looks like this:
|
25
19
|
|
26
|
-
`feep [-
|
20
|
+
`feep [-f, -n, --freq-or-note FREQUENCY|NOTE_NAME] [-w, --waveform WAVEFORM] [-a, --amplitude MAX_AMPLITUDE] [-d, --duration DURATION] [-save] [-loud]`
|
27
21
|
|
28
|
-
`-
|
22
|
+
`-f, -n, --freq-or-note`: a number from 0 to 20000, or a valid note name from C0 to B9 (including sharps and flats). You can try a frequency outside of this range, but you may get odd results. You may also enter some combination of these with commas between them and it'll play all of them together in a chord.
|
29
23
|
|
30
|
-
`-waveform`: a string equal to "sine", "square", "saw", "triangle", or "noise".
|
24
|
+
`-w, --waveform`: a string equal to "sine", "square", "saw", "triangle", or "noise".
|
31
25
|
|
32
|
-
`-
|
26
|
+
`-a, --amplitude`: a number from 0.0 (silence (why would you do this?)) to 1.0 (blast it)
|
33
27
|
|
34
|
-
`-duration`: number of milliseconds for the sound to last
|
28
|
+
`-d, --duration`: number of milliseconds for the sound to last
|
35
29
|
|
36
|
-
`-save`: save the resulting WAV file in the current directory. Will create it in the format of `waveform_frequency-in-Hz_volume_duration.wav`
|
30
|
+
`-save`: switch to save the resulting WAV file in the current directory. Will create it in the format of `waveform_frequency-in-Hz_volume_duration.wav`
|
37
31
|
|
38
|
-
`-loud`: displays note and file-making information
|
32
|
+
`-loud`: switch that displays note and file-making information
|
33
|
+
|
34
|
+
## Examples
|
35
|
+
|
36
|
+
`feep` - play a C4 sine wave note at 50% full volume for 200 ms
|
37
|
+
`feep -n Ab6 -w saw` - play a Ab6 sawtooth wave note at 50% full volume for 200 ms
|
38
|
+
`feep -n C#5 -w square -a 0.4 -d 500` - play a C#5 square wave note at 40% full volume for 500 ms
|
39
|
+
`feep -n 2000 -w triangle -a 0.8 -d 2000` - play a 2000Hz triangle wave note at 80% full volume for 2000 ms
|
data/Rakefile
CHANGED
data/bin/feep
CHANGED
@@ -6,16 +6,16 @@ require 'feep'
|
|
6
6
|
USAGE_INSTRUCTIONS = ''
|
7
7
|
|
8
8
|
def parse_options
|
9
|
-
options = {:freq_or_note => '440.000', :waveform => 'sine', :volume => 0.5, :duration =>
|
9
|
+
options = {:freq_or_note => '440.000', :waveform => 'sine', :volume => 0.5, :duration => 200, :save => false, :loud => false}
|
10
10
|
|
11
11
|
optparse = OptionParser.new do |opts|
|
12
|
-
opts.banner = 'usage: feep [
|
12
|
+
opts.banner = 'usage: feep [-f, -n, --freq-or-note FREQUENCY|NOTE_NAME] [-w, --waveform WAVEFORM] [-a, --amplitude MAX_AMPLITUDE] [-d, --duration DURATION] [-save] [-loud]'
|
13
13
|
|
14
14
|
opts.on('-f', '-n', '--freq-or-note FREQUENCY|NOTE_NAME', 'One or more frequencies or note names to play at once, e.g. 440 or A4 or 220,440,880') do |f_or_n|
|
15
15
|
options[:freq_or_note] = f_or_n
|
16
16
|
end
|
17
17
|
|
18
|
-
opts.on('-w', '--wave
|
18
|
+
opts.on('-w', '--wave WAVEFORM', 'Waveform type to use for the sound') do |w|
|
19
19
|
options[:waveform] = w
|
20
20
|
end
|
21
21
|
|
@@ -36,11 +36,11 @@ def parse_options
|
|
36
36
|
end
|
37
37
|
|
38
38
|
opts.on('-v', '--version', 'Display version number and exit') do
|
39
|
-
puts "#{$
|
39
|
+
puts "#{$PROGRAM_NAME} #{Feep::VERSION}"
|
40
40
|
exit
|
41
41
|
end
|
42
42
|
|
43
|
-
opts.on(
|
43
|
+
opts.on('-h', '--help', 'Display this screen and exit') do
|
44
44
|
puts opts
|
45
45
|
exit
|
46
46
|
end
|
@@ -55,19 +55,19 @@ end
|
|
55
55
|
def print_error(error)
|
56
56
|
case error
|
57
57
|
when OptionParser::InvalidOption
|
58
|
-
puts "
|
58
|
+
puts "#{$PROGRAM_NAME}: illegal option #{error.args.join(' ')}"
|
59
59
|
puts USAGE_INSTRUCTIONS
|
60
60
|
else
|
61
|
-
puts
|
61
|
+
puts "An unexpected error occurred while running #{$PROGRAM_NAME}:"
|
62
62
|
puts " #{error}\n"
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
begin
|
67
|
-
options = parse_options
|
67
|
+
options = parse_options
|
68
68
|
|
69
69
|
Feep.new(options)
|
70
70
|
rescue => error
|
71
71
|
print_error(error)
|
72
72
|
exit(false)
|
73
|
-
end
|
73
|
+
end
|
data/feep.gemspec
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require 'feep/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'feep'
|
8
8
|
spec.version = Feep::VERSION
|
9
9
|
spec.platform = Gem::Platform::RUBY
|
10
|
-
spec.authors = [
|
10
|
+
spec.authors = ['Michael Chadwick']
|
11
11
|
spec.email = 'mike@codana.me'
|
12
|
-
spec.homepage =
|
13
|
-
spec.summary =
|
14
|
-
spec.description =
|
12
|
+
spec.homepage = 'http://rubygems.org/gems/feep'
|
13
|
+
spec.summary = 'Make your computer feep with Ruby'
|
14
|
+
spec.description = 'Use Ruby to make your computer beep at a certain frequency for a certain duration. Do it for fun, or add it to other programs for easy alert sounds.'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split("\n")
|
17
17
|
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
-
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
-
spec.require_paths = [
|
18
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
spec.license = 'MIT'
|
21
|
-
|
21
|
+
|
22
22
|
spec.add_runtime_dependency 'wavefile', '= 0.6.0'
|
23
23
|
spec.add_runtime_dependency 'os', '~> 0.9', '>= 0.9.6'
|
24
|
-
|
24
|
+
|
25
25
|
spec.add_development_dependency 'pry-byebug', '~> 3.0'
|
26
26
|
spec.add_development_dependency 'bundler', '~> 1.8'
|
27
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
28
28
|
spec.add_development_dependency 'rspec', '>= 3.0'
|
29
|
-
end
|
29
|
+
end
|
data/lib/feep.rb
CHANGED
@@ -12,19 +12,19 @@ class Feep
|
|
12
12
|
|
13
13
|
# convert midi notes to frequencies
|
14
14
|
def midi_to_freq(midi_note)
|
15
|
-
|
15
|
+
440.0 * (2.0 ** ((midi_note.to_f-69)/12))
|
16
16
|
end
|
17
17
|
|
18
18
|
# convert frequencies to midi notes
|
19
19
|
def freq_to_midi(freq)
|
20
|
-
|
20
|
+
(69 + 12 * (Math.log2(freq.to_i.abs / 440.0))).round
|
21
21
|
end
|
22
22
|
|
23
23
|
# makes sure that whatever kind of sound was entered on the CLI
|
24
24
|
# it is now a frequency to feed into the sample data generator
|
25
25
|
def convert_note_to_freq(freq_or_note)
|
26
26
|
if freq_or_note.match(/[A-Za-z]/)
|
27
|
-
if NOTE_FREQ.
|
27
|
+
if NOTE_FREQ.key?(freq_or_note)
|
28
28
|
frequency = NOTE_FREQ[freq_or_note]
|
29
29
|
else
|
30
30
|
app_error(ERROR_MSG[:note_name])
|
@@ -58,7 +58,7 @@ class Feep
|
|
58
58
|
threads = []
|
59
59
|
options[:freq_or_note].split(',').each do |note|
|
60
60
|
sound_to_play = convert_note_to_freq(note)
|
61
|
-
output_filename = "#{options[:waveform]}_#{sound_to_play}Hz_#{options[:volume].to_f}_#{options[:duration]
|
61
|
+
output_filename = "#{options[:waveform]}_#{sound_to_play}Hz_#{options[:volume].to_f}_#{options[:duration]}.wav"
|
62
62
|
threads << Thread.new {
|
63
63
|
play_note(sound_to_play.to_f, options[:waveform], options[:volume].to_f, options[:duration].to_i, samples_to_write, output_filename)
|
64
64
|
}
|
@@ -67,7 +67,7 @@ class Feep
|
|
67
67
|
else
|
68
68
|
# no, it's a single note
|
69
69
|
sound_to_play = convert_note_to_freq(options[:freq_or_note])
|
70
|
-
output_filename = "#{options[:waveform]}_#{sound_to_play}Hz_#{options[:volume].to_f}_#{options[:duration]
|
70
|
+
output_filename = "#{options[:waveform]}_#{sound_to_play}Hz_#{options[:volume].to_f}_#{options[:duration]}.wav"
|
71
71
|
play_note(sound_to_play, options[:waveform], options[:volume].to_f, options[:duration].to_i, samples_to_write, output_filename)
|
72
72
|
end
|
73
73
|
end
|
@@ -76,7 +76,7 @@ class Feep
|
|
76
76
|
def play_sound(file, duration)
|
77
77
|
delimiter = OS.windows? ? ';' : ':'
|
78
78
|
|
79
|
-
system_apps = ENV['PATH'].split(delimiter).collect {|d| Dir.entries d if Dir.
|
79
|
+
system_apps = ENV['PATH'].split(delimiter).collect { |d| Dir.entries d if Dir.exist? d }.flatten
|
80
80
|
|
81
81
|
if OS.windows?
|
82
82
|
if system_apps.include? SNDPLAYER_WIN
|
@@ -123,9 +123,9 @@ class Feep
|
|
123
123
|
formatted_duration = duration.minutes.to_s.rjust(2, '0') << ':' <<
|
124
124
|
duration.seconds.to_s.rjust(2, '0') << ':' <<
|
125
125
|
duration.milliseconds.to_s.rjust(3, '0')
|
126
|
-
puts
|
126
|
+
puts ''
|
127
127
|
puts "Created #{file}"
|
128
|
-
puts
|
128
|
+
puts '---'
|
129
129
|
puts "Length: #{formatted_duration}"
|
130
130
|
puts "Format: #{info.audio_format}"
|
131
131
|
puts "Channels: #{info.channels}"
|
@@ -205,9 +205,9 @@ class Feep
|
|
205
205
|
|
206
206
|
# displays error, usage, and exits
|
207
207
|
def app_error(msg)
|
208
|
-
puts "#{File.basename($
|
208
|
+
puts "#{File.basename($PROGRAM_NAME).split('.')[0]}: #{msg}"
|
209
209
|
puts 'usage: feep [frequency|note_name|list_of_frequencies_or_note_names] [sine|square|saw|triangle|noise] [volume] [duration] [save]'
|
210
210
|
exit
|
211
211
|
end
|
212
212
|
|
213
|
-
end
|
213
|
+
end
|
data/lib/feep/constants.rb
CHANGED
data/lib/feep/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Chadwick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: wavefile
|
@@ -121,7 +121,7 @@ files:
|
|
121
121
|
- spec/feep_spec.rb
|
122
122
|
- spec/spec_helper.rb
|
123
123
|
- tasks/rspec.rake
|
124
|
-
homepage: http://
|
124
|
+
homepage: http://rubygems.org/gems/feep
|
125
125
|
licenses:
|
126
126
|
- MIT
|
127
127
|
metadata: {}
|
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
143
|
rubyforge_project:
|
144
|
-
rubygems_version: 2.4.
|
144
|
+
rubygems_version: 2.4.6
|
145
145
|
signing_key:
|
146
146
|
specification_version: 4
|
147
147
|
summary: Make your computer feep with Ruby
|