spcore 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,4 +35,8 @@ Adjust project documentation.
35
35
 
36
36
  === 0.1.6 / 2013-03-21
37
37
 
38
- Update to be compatible with hashmake-0.1.6.
38
+ Update to be compatible with hashmake-0.1.6.
39
+
40
+ === 0.1.7 2013-04-18
41
+
42
+ Require all sample rate args to be Fixnum.
@@ -9,7 +9,7 @@ class DelayLine
9
9
 
10
10
  # Used to process hashed arguments in #initialize.
11
11
  ARG_SPECS = {
12
- :sample_rate => arg_spec(:reqd => true, :type => Float, :validator => ->(a){ a > 0.0 } ),
12
+ :sample_rate => arg_spec(:reqd => true, :type => Fixnum, :validator => ->(a){ a > 0.0 } ),
13
13
  :max_delay_seconds => arg_spec(:reqd => true, :type => Float, :validator => ->(a){ (a > 0.0) } ),
14
14
  :delay_seconds => arg_spec(:reqd => false, :type => Float, :default => 0.0, :validator => ->(a){ a >= 0.0 } ),
15
15
  }
@@ -7,7 +7,7 @@ class EnvelopeDetector
7
7
 
8
8
  # Used to process hashed arguments in #initialize.
9
9
  ARG_SPECS = {
10
- :sample_rate => arg_spec(:reqd => true, :type => Float, :validator => ->(a){ a > 0.0 } ),
10
+ :sample_rate => arg_spec(:reqd => true, :type => Fixnum, :validator => ->(a){ a > 0.0 } ),
11
11
  :attack_time => arg_spec(:reqd => true, :type => Float, :validator => ->(a){ a > 0.0 } ),
12
12
  :release_time => arg_spec(:reqd => true, :type => Float, :validator => ->(a){ a > 0.0 } ),
13
13
  }
@@ -22,12 +22,12 @@ class Oscillator
22
22
 
23
23
  # Used to process hashed arguments in #initialize.
24
24
  ARG_SPECS = {
25
- :sample_rate => arg_spec(:reqd => true, :type => Float, :validator => ->(a){ a > 0.0 } ),
25
+ :sample_rate => arg_spec(:reqd => true, :type => Fixnum, :validator => ->(a){ a > 0 } ),
26
26
  :wave_type => arg_spec(:reqd => false, :type => Symbol, :default => WAVE_SINE, :validator => ->(a){ WAVES.include? a } ),
27
- :frequency => arg_spec(:reqd => false, :type => Float, :default => 1.0, :validator => ->(a){ a > 0.0 } ),
28
- :amplitude => arg_spec(:reqd => false, :type => Float, :default => 1.0 ),
29
- :phase_offset => arg_spec(:reqd => false, :type => Float, :default => 0.0 ),
30
- :dc_offset => arg_spec(:reqd => false, :type => Float, :default => 0.0 ),
27
+ :frequency => arg_spec(:reqd => false, :type => Numeric, :default => 1.0, :validator => ->(a){ a > 0.0 } ),
28
+ :amplitude => arg_spec(:reqd => false, :type => Numeric, :default => 1.0 ),
29
+ :phase_offset => arg_spec(:reqd => false, :type => Numeric, :default => 0.0 ),
30
+ :dc_offset => arg_spec(:reqd => false, :type => Numeric, :default => 0.0 ),
31
31
  }
32
32
 
33
33
  # A new instance of Oscillator. The controllable wave parameters are frequency,
@@ -9,7 +9,7 @@ class Signal
9
9
  # Used to process hashed arguments in #initialize.
10
10
  ARG_SPECS = {
11
11
  :data => arg_spec(:reqd => true, :type => Array, :validator => ->(a){ a.any? }),
12
- :sample_rate => arg_spec(:reqd => true, :type => Float, :validator => ->(a){ a > 0.0 })
12
+ :sample_rate => arg_spec(:reqd => true, :type => Fixnum, :validator => ->(a){ a > 0.0 })
13
13
  }
14
14
 
15
15
  attr_reader :data, :sample_rate
@@ -13,7 +13,7 @@ class DualSincFilter
13
13
  # Use to process hashed args in #initialize.
14
14
  ARG_SPECS = {
15
15
  :order => arg_spec(:reqd => true, :type => Fixnum, :validator => ->(a){ a % 2 == 0 } ),
16
- :sample_rate => arg_spec(:reqd => true, :type => Numeric, :validator => ->(a){ a > 0.0 } ),
16
+ :sample_rate => arg_spec(:reqd => true, :type => Fixnum, :validator => ->(a){ a > 0.0 } ),
17
17
  :left_cutoff_freq => arg_spec(:reqd => true, :type => Numeric, :validator => ->(a){ a > 0.0 } ),
18
18
  :right_cutoff_freq => arg_spec(:reqd => true, :type => Numeric, :validator => ->(a){ a > 0.0 } ),
19
19
  :window_class => arg_spec(:reqd => false, :type => Class, :default => BlackmanWindow ),
@@ -26,8 +26,8 @@ class DualSincFilter
26
26
  def initialize args
27
27
  hash_make DualSincFilter::ARG_SPECS, args
28
28
 
29
- raise ArgumentError, "left_cutoff_freq is greater than 0.5 * sample_rate" if @left_cutoff_freq > (@sample_rate / 2)
30
- raise ArgumentError, "right_cutoff_freq is greater than 0.5 * sample_rate" if @right_cutoff_freq > (@sample_rate / 2)
29
+ raise ArgumentError, "left_cutoff_freq is greater than 0.5 * sample_rate" if @left_cutoff_freq > (@sample_rate * 0.5)
30
+ raise ArgumentError, "right_cutoff_freq is greater than 0.5 * sample_rate" if @right_cutoff_freq > (@sample_rate * 0.5)
31
31
  raise ArgumentError, "left_cutoff_freq is not less than right_cutoff_freq" unless @left_cutoff_freq < @right_cutoff_freq
32
32
 
33
33
  @left_filter = SincFilter.new(
@@ -57,8 +57,8 @@ class DualSincFilter
57
57
  bandstop_kernel[size - 1 - n] = bandstop_kernel[n] = @left_filter.lowpass_fir.kernel[n] + @right_filter.highpass_fir.kernel[n]
58
58
  end
59
59
 
60
- left_transition_freq = @left_cutoff_freq / @sample_rate
61
- right_transition_freq = @right_cutoff_freq / @sample_rate
60
+ left_transition_freq = @left_cutoff_freq.to_f / @sample_rate
61
+ right_transition_freq = @right_cutoff_freq.to_f / @sample_rate
62
62
  bw_times_two = 2.0 * (right_transition_freq - left_transition_freq)
63
63
  window_center_val = window.data[@order / 2]
64
64
 
@@ -60,7 +60,7 @@ class FIR
60
60
 
61
61
  response = {}
62
62
  output.each_index do |n|
63
- frequency = (@sample_rate * n) / (output.size * 2)
63
+ frequency = (@sample_rate * n) / (output.size * 2.0)
64
64
  response[frequency] = output[n]
65
65
  end
66
66
 
@@ -14,7 +14,7 @@ class SincFilter
14
14
  # Use to process hashed args in #initialize.
15
15
  ARG_SPECS = {
16
16
  :order => arg_spec(:reqd => true, :type => Fixnum, :validator => ->(a){ a % 2 == 0 } ),
17
- :sample_rate => arg_spec(:reqd => true, :type => Numeric, :validator => ->(a){ a > 0.0 } ),
17
+ :sample_rate => arg_spec(:reqd => true, :type => Fixnum, :validator => ->(a){ a > 0 } ),
18
18
  :cutoff_freq => arg_spec(:reqd => true, :type => Numeric, :validator => ->(a){ a > 0.0 } ),
19
19
  :window_class => arg_spec(:reqd => false, :type => Class, :default => BlackmanWindow ),
20
20
  }
@@ -26,10 +26,10 @@ class SincFilter
26
26
  def initialize args
27
27
  hash_make SincFilter::ARG_SPECS, args
28
28
 
29
- raise ArgumentError, "cutoff_freq is greater than 0.5 * sample_rate" if @cutoff_freq > (@sample_rate / 2)
29
+ raise ArgumentError, "cutoff_freq is greater than 0.5 * sample_rate" if @cutoff_freq > (@sample_rate / 2.0)
30
30
 
31
31
  size = @order + 1
32
- transition_freq = @cutoff_freq / @sample_rate
32
+ transition_freq = @cutoff_freq.to_f / @sample_rate
33
33
  b = TWO_PI * transition_freq
34
34
 
35
35
  # make FIR filter kernels for lowpass and highpass
@@ -17,7 +17,7 @@ class DiscreteResampling
17
17
  filter = SincFilter.new(
18
18
  :sample_rate => (sample_rate * upsample_factor),
19
19
  :order => filter_order,
20
- :cutoff_freq => (sample_rate / 2),
20
+ :cutoff_freq => (sample_rate / 2.0),
21
21
  :window_class => NuttallWindow
22
22
  )
23
23
 
@@ -37,7 +37,7 @@ class DiscreteResampling
37
37
 
38
38
  filter = SincFilter.new(
39
39
  :sample_rate => sample_rate, :order => filter_order,
40
- :cutoff_freq => ((sample_rate / downsample_factor) / 2.0),
40
+ :cutoff_freq => ((sample_rate.to_f / downsample_factor) / 2.0),
41
41
  :window_class => NuttallWindow
42
42
  )
43
43
 
@@ -6,7 +6,7 @@ class SignalGenerator
6
6
  # used to process hashed args in #initialize.
7
7
  ARG_SPECS = {
8
8
  :size => arg_spec(:reqd => true, :type => Fixnum, :validator => ->(a){ a > 0 }),
9
- :sample_rate => arg_spec(:reqd => true, :type => Float, :validator => ->(a){ a > 0.0 })
9
+ :sample_rate => arg_spec(:reqd => true, :type => Fixnum, :validator => ->(a){ a > 0 })
10
10
  }
11
11
 
12
12
  attr_reader :sample_rate, :size
@@ -1,5 +1,5 @@
1
1
  # A library of signal processing methods and classes.
2
2
  module SPCore
3
3
  # spcore version
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.7"
5
5
  end
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe SPCore::DelayLine do
4
4
  it 'should' do
5
- SAMPLE_RATE = 400.0
5
+ SAMPLE_RATE = 400
6
6
  MAX_DELAY_SEC = 0.1
7
7
 
8
8
  5.times do
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
  describe SPCore::EnvelopeDetector do
4
4
  describe '#process_sample' do
5
5
  it 'should produce an output that follows the amplitude of the input' do
6
- sample_rate = 400.0
6
+ sample_rate = 400
7
7
  freqs = [20.0, 60.0]
8
8
 
9
9
  envelope_start = 1.0
@@ -4,7 +4,7 @@ require 'pry'
4
4
 
5
5
  describe SPCore::Oscillator do
6
6
  #it 'should look like a ...' do
7
- # sample_rate = 44000.0
7
+ # sample_rate = 44000
8
8
  # test_freq = 100.0
9
9
  # osc = SPCore::Oscillator.new :sample_rate => sample_rate, :frequency => test_freq, :wave_type => SPCore::Oscillator::WAVE_SQUARE
10
10
  # N = (5 * sample_rate / test_freq).to_i
@@ -32,7 +32,7 @@ describe SPCore::Oscillator do
32
32
  #end
33
33
 
34
34
  before :each do
35
- @sample_rate = 40000.0
35
+ @sample_rate = 40000
36
36
  @freqs = [ 20.0, 200.0, 400.0 ]
37
37
  end
38
38
 
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
3
 
4
4
  describe SPCore::SincFilter do
5
5
  before :all do
6
- @sample_rate = 4000.0
6
+ @sample_rate = 4000
7
7
  @orders = [62]
8
8
  @left_cutoffs = Scale.exponential 300.0..1500.0, 3
9
9
  @right_cutoffs = Scale.exponential 400.0..1600.0, 3
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
3
 
4
4
  describe SPCore::SincFilter do
5
5
  before :all do
6
- @sample_rate = 4000.0
6
+ @sample_rate = 4000
7
7
  @orders = [62]
8
8
  @cutoffs = Scale.exponential 400.0..1600.0, 3
9
9
  end
@@ -4,7 +4,7 @@ require 'pry'
4
4
 
5
5
  describe 'cookbook filter' do
6
6
  it 'should produce a nice frequency response graph' do
7
- #sample_rate = 4000.0
7
+ #sample_rate = 4000
8
8
  #crit_freq = 400.0
9
9
  #min_test_freq = 10.0
10
10
  #max_test_freq = (sample_rate / 2.0) - 1.0
@@ -5,7 +5,7 @@ describe SPCore::DiscreteResampling do
5
5
 
6
6
  context '.upsample' do
7
7
  it 'should produce output signal with the same max frequency (put through forward FFT)' do
8
- sample_rate = 400.0
8
+ sample_rate = 400
9
9
  test_freq = 10.0
10
10
  size = 64
11
11
  upsample_factor = 4
@@ -30,7 +30,7 @@ describe SPCore::DiscreteResampling do
30
30
 
31
31
  context '.downsample' do
32
32
  it 'should produce output signal with the same max frequency (put through forward FFT)' do
33
- sample_rate = 400.0
33
+ sample_rate = 400
34
34
  test_freq = 10.0
35
35
  size = 128
36
36
  downsample_factor = 4
@@ -55,7 +55,7 @@ describe SPCore::DiscreteResampling do
55
55
 
56
56
  context '.resample' do
57
57
  it 'should produce output signal with the same max frequency (put through forward FFT)' do
58
- sample_rate = 400.0
58
+ sample_rate = 400
59
59
  test_freq = 10.0
60
60
  size = 64
61
61
  upsample_factor = 4
@@ -5,7 +5,7 @@ describe SPCore::HybridResampling do
5
5
 
6
6
  context '.resample' do
7
7
  it 'should produce output signal with the same max frequency (put through forward FFT)' do
8
- sample_rate = 400.0
8
+ sample_rate = 400
9
9
  test_freq = 10.0
10
10
  size = 64
11
11
  upsample_factor = 4
@@ -5,7 +5,7 @@ describe SPCore::PolynomialResampling do
5
5
 
6
6
  context '.upsample' do
7
7
  it 'should produce output signal with the same max frequency (put through forward DFT)' do
8
- sample_rate = 400.0
8
+ sample_rate = 400
9
9
  test_freq = 10.0
10
10
  size = (sample_rate * 5.0 / test_freq).to_i
11
11
  upsample_factor = 2.5
@@ -7,7 +7,7 @@ describe SPCore::DFT do
7
7
 
8
8
  it 'should produce a freq magnitude response peak that is within 10 percent of the test freq' do
9
9
  dft_size = 64
10
- sample_rate = 400.0
10
+ sample_rate = 400
11
11
 
12
12
  test_freqs = [
13
13
  20.0,
@@ -39,7 +39,7 @@ describe SPCore::DFT do
39
39
 
40
40
  it 'should produce a near-identical signal to the original sent into the forward DFT (with energy that is within 10 percent error of original signal)' do
41
41
  dft_size = 32
42
- sample_rate = 400.0
42
+ sample_rate = 400
43
43
 
44
44
  test_freqs = [
45
45
  20.0,
@@ -6,7 +6,7 @@ describe SPCore::FFT do
6
6
  context '.forward' do
7
7
  it 'should produce a freq magnitude response peak that is within 10 percent of the test freq' do
8
8
  fft_size = 64
9
- sample_rate = 400.0
9
+ sample_rate = 400
10
10
 
11
11
  test_freqs = [
12
12
  20.0,
@@ -52,7 +52,7 @@ describe SPCore::FFT do
52
52
 
53
53
  it 'should produce a near-identical signal to the original sent into the forward DFT (with energy that is within 10 percent error of original signal)' do
54
54
  fft_size = 32
55
- sample_rate = 400.0
55
+ sample_rate = 400
56
56
 
57
57
  test_freqs = [
58
58
  20.0,
@@ -11,7 +11,7 @@ describe SPCore::Saturation do
11
11
  z_data = []
12
12
 
13
13
  osc = SPCore::Oscillator.new(
14
- :sample_rate => 100.0,
14
+ :sample_rate => 100,
15
15
  :frequency => 1.0,
16
16
  :wave_type => SPCore::Oscillator::WAVE_SINE,
17
17
  :amplitude => 2.5
@@ -62,7 +62,7 @@ describe SPCore::Saturation do
62
62
  y_data = []
63
63
  z_data = []
64
64
 
65
- osc = SPCore::Oscillator.new :sample_rate => 100.0, :frequency => 1.0, :wave_type => SPCore::Oscillator::WAVE_SINE, :amplitude => 2.5
65
+ osc = SPCore::Oscillator.new :sample_rate => 100, :frequency => 1.0, :wave_type => SPCore::Oscillator::WAVE_SINE, :amplitude => 2.5
66
66
  (4 * osc.sample_rate / osc.frequency).to_i.times do |n|
67
67
  x = n / osc.sample_rate
68
68
  y = osc.sample
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe SPCore::SignalGenerator do
4
4
  before :all do
5
- @sample_rate = 600.0
5
+ @sample_rate = 600
6
6
  @test_freqs = [
7
7
  65.0, 100.0, 250.0
8
8
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spcore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-22 00:00:00.000000000 Z
12
+ date: 2013-04-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashmake
@@ -222,7 +222,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
222
222
  version: '0'
223
223
  segments:
224
224
  - 0
225
- hash: 718250849
225
+ hash: 407745007
226
226
  required_rubygems_version: !ruby/object:Gem::Requirement
227
227
  none: false
228
228
  requirements:
@@ -231,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
231
  version: '0'
232
232
  segments:
233
233
  - 0
234
- hash: 718250849
234
+ hash: 407745007
235
235
  requirements: []
236
236
  rubyforge_project:
237
237
  rubygems_version: 1.8.23