cheep 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -0
- data/lib/cheep/noise/noise.rb +35 -0
- data/lib/cheep/play.rb +23 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31b1a944cdd29520ba52c86a7ab3eaf92150c95f
|
4
|
+
data.tar.gz: c0475e35f40134be32ef6790c39508af0b42bab8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8adc819320b650308de9c5d4a41f78a1f30f4bc14fa6d84135a35c4fe342649abd421256bc21b399f8151f02afc1cb4c2a3586beaefd3a0ef4e055517f67b290
|
7
|
+
data.tar.gz: 0d114d14f1ce2b18fa00fc74e13e3b1e916a51a4c7ec55f9574aa9d3308fae957efb4672c841ad9f5661526f6c30af5f201244dbfefe608f650ca5d59ceb0c8b
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Cheep
|
2
|
+
|
3
|
+
Cheep is all about systhesizing noises in a Ruby like fashion.
|
4
|
+
|
5
|
+
Or more accurately, it's a scratchpad where I learn about synthesizing noises.
|
6
|
+
It's going to change and break a lot, and it's probably going to be a huge
|
7
|
+
mess. But that's what Ruby is for. :)
|
8
|
+
|
9
|
+
### Notes
|
10
|
+
|
11
|
+
* https://github.com/alexspeller/lrug-music
|
12
|
+
* https://github.com/jstrait/nanosynth
|
13
|
+
* https://github.com/jstrait/wavefile/
|
14
|
+
* http://wavefilegem.com/
|
15
|
+
* http://stackoverflow.com/questions/5318989/reverb-algorithm
|
16
|
+
|
17
|
+
### Licence
|
18
|
+
|
19
|
+
(C) Copyright 2014 Louis Pilfold <louis@lpil.uk>
|
20
|
+
|
21
|
+
This program is free software: you can redistribute it and/or modify
|
22
|
+
it under the terms of the GNU General Public License as published by
|
23
|
+
the Free Software Foundation, either version 3 of the License, or
|
24
|
+
(at your option) any later version.
|
25
|
+
|
26
|
+
This program is distributed in the hope that it will be useful,
|
27
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
28
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
29
|
+
GNU General Public License for more details.
|
30
|
+
|
31
|
+
You should have received a copy of the GNU General Public License
|
32
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Cheep
|
2
|
+
# The base noise class. Contains an array of samples. Probably not to be
|
3
|
+
# accessed directly.
|
4
|
+
class Noise
|
5
|
+
# @param samples [Array] An array of samples as floats
|
6
|
+
# @return [Noise]
|
7
|
+
def initialize(samples)
|
8
|
+
@samples = samples
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Cheep
|
14
|
+
# A sine wave noise
|
15
|
+
class Sine < Cheep::Noise
|
16
|
+
attr_reader :samples
|
17
|
+
|
18
|
+
# Creates a sine wave noise
|
19
|
+
# @param frequency [Numeric] Frequency of wave in Hz
|
20
|
+
# @param num_samples [Integer] Number of samples
|
21
|
+
# @return [Sine]
|
22
|
+
def initialize(frequency, num_samples)
|
23
|
+
cycles_per_sample = frequency.to_f / SAMPLE_RATE
|
24
|
+
|
25
|
+
samples = []
|
26
|
+
phase = 0.0
|
27
|
+
num_samples.times do
|
28
|
+
samples << Math::sin(2 * Math::PI * phase)
|
29
|
+
phase += cycles_per_sample
|
30
|
+
end
|
31
|
+
|
32
|
+
@samples = samples
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/cheep/play.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'wavefile'
|
2
|
+
|
3
|
+
#
|
4
|
+
module Cheep
|
5
|
+
def self.play(samples, filename = 'cheep.wav')
|
6
|
+
writer_format = WaveFile::Format.new :mono, :pcm_16, SAMPLE_RATE
|
7
|
+
buffer_format = WaveFile::Format.new :mono, :float, SAMPLE_RATE
|
8
|
+
|
9
|
+
WaveFile::Writer.new filename, writer_format do |writer|
|
10
|
+
writer.write(WaveFile::Buffer.new samples, buffer_format)
|
11
|
+
end
|
12
|
+
|
13
|
+
platform = `uname`.chomp
|
14
|
+
case platform
|
15
|
+
when 'Darwin'
|
16
|
+
system "afplay #{filename}"
|
17
|
+
when 'Linux'
|
18
|
+
system "aplay #{filename}"
|
19
|
+
else
|
20
|
+
abort "I don't know how to play wavs on #{platform}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cheep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Louis Pilfold
|
@@ -16,7 +16,10 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- README.md
|
19
20
|
- lib/cheep.rb
|
21
|
+
- lib/cheep/noise/noise.rb
|
22
|
+
- lib/cheep/play.rb
|
20
23
|
homepage: http://github.com/lpil/cheep
|
21
24
|
licenses:
|
22
25
|
- MIT
|