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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e59eb850a3b66b00df0a1f7e42523e7f1d7f6974
4
- data.tar.gz: e032678907f285574b847199f530cd66a8eaa734
3
+ metadata.gz: 4c9ade110c0c083ad59f6732c2474d8f0aaabfb3
4
+ data.tar.gz: ea1319e91994705a44a70a8c0d0124a5e6e9703e
5
5
  SHA512:
6
- metadata.gz: 69e83b10a38ed0b4a7a3378fe874fc5054b57a4bb8ec38ec02eec736c4fb8a36e3958d2e6973a092f141e32b9300857b7e92f402a3c085a37f2308402c9f5de2
7
- data.tar.gz: 545f7debf3dc9801a85a27fdba7f2531d1a682b78a22cf681add3674eda27a80dd3207dabc3c978c4fa4cf716d44e2284ca4cfecde8dd0b72c3ede03c125bcda
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- feep (0.0.1)
4
+ feep (0.0.2)
5
5
  os (~> 0.9, >= 0.9.6)
6
6
  wavefile (= 0.6.0)
7
7
 
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, this 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.
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
- For now:
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 1000 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.
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 [-fn frequency|note_name|comma-delimited_frequencies_or_note_names] [-w waveform] [-v volume] [-d duration] [-save] [-loud]`
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
- `-frequency|note_name|commad-delimted_frequences_or_note_names`: a number from 0 to 20000. You can try something bigger or smaller, but you may get odd results. You may also enter any note name from C0 to B9 (or even flats and sharps like C#6 or Eb5). You may also also enter some combination of these with commas between them and it'll play all of them together in a chord.
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
- `-volume`: a number from 0.0 (silence (why would you do this?)) to 1.0 (blast it)
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
@@ -1,3 +1,3 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
- Dir.glob('tasks/**/*.rake').each(&method(:import))
3
+ Dir.glob('tasks/**/*.rake').each(&method(:import))
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 => 1000, :save => false, :loud => false}
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 [frequency|note_name|list_of_frequencies_or_note_names] [waveform] [volume] [duration] [save] [-loud]'
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 WAVE_FORM_NAME', 'Waveform type to use for the sound') do |w|
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 "#{$0} #{Feep::VERSION}"
39
+ puts "#{$PROGRAM_NAME} #{Feep::VERSION}"
40
40
  exit
41
41
  end
42
42
 
43
- opts.on( '-h', '--help', 'Display this screen and exit') do
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 "feep: illegal option #{error.args.join(' ')}"
58
+ puts "#{$PROGRAM_NAME}: illegal option #{error.args.join(' ')}"
59
59
  puts USAGE_INSTRUCTIONS
60
60
  else
61
- puts 'An unexpected error occurred while running Feep:'
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 "feep/version"
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 = ["Michael Chadwick"]
10
+ spec.authors = ['Michael Chadwick']
11
11
  spec.email = 'mike@codana.me'
12
- spec.homepage = "http://rubygemspec.org/gems/feep"
13
- spec.summary = %q{Make your computer feep with Ruby}
14
- spec.description = %q{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.}
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 = ["lib"]
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
- return 440.0 * (2.0 ** ((midi_note.to_f-69)/12))
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
- return (69 + 12 * (Math.log2(freq.to_i.abs / 440.0))).round
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.has_key?(freq_or_note)
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].to_s}.wav"
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].to_s}.wav"
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.exists? d}.flatten
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($0).split(".")[0]}: #{msg}"
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
@@ -183,4 +183,4 @@ class Feep
183
183
  :note_name => 'Note name argument is invalid.',
184
184
  :wave_form => 'Wave form type is invalid.'
185
185
  ]
186
- end
186
+ end
data/lib/feep/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Feep
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
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.1
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-03 00:00:00.000000000 Z
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://rubygemspec.org/gems/feep
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.5
144
+ rubygems_version: 2.4.6
145
145
  signing_key:
146
146
  specification_version: 4
147
147
  summary: Make your computer feep with Ruby