Sha256: b5813651a513fe276c6f9712b14ff38255d98d5b0a66b32d694dde83f3355e6e

Contents?: true

Size: 1.47 KB

Versions: 5

Compression:

Stored size: 1.47 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe SPCore::SignalGenerator do
  before :all do
    @sample_rate = 600
    @test_freqs = [
      65.0, 100.0, 250.0
    ]
  end
  
  context '.make_signal' do
    context 'one freq at a time' do
      it 'should produce the same output as a plain Oscillator' do
        size = 60
        generator = SignalGenerator.new :sample_rate => @sample_rate, :size => size
        
        @test_freqs.each do |freq|
          signal = generator.make_signal [freq]
          
          osc = Oscillator.new(:sample_rate => @sample_rate, :frequency => freq)
          osc_output = Array.new(size)
          size.times do |i|
            osc_output[i] = osc.sample
          end
          
          signal.data.should eq(osc_output)
        end
      end
    end

    context 'many freqs at a time' do
      it 'should produce the same output as equivalent plain Oscillators' do
        size = 60
        generator = SignalGenerator.new :sample_rate => @sample_rate, :size => size
        
        oscs = []
        @test_freqs.each do |freq|
          oscs.push Oscillator.new(:sample_rate => @sample_rate, :frequency => freq)
        end
        
        signal = generator.make_signal @test_freqs

        osc_output = Array.new(size, 0.0)
        size.times do |i|
          oscs.each do |osc|
            osc_output[i] += osc.sample
          end
        end
          
        signal.data.should eq(osc_output)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spcore-0.2.1 spec/generation/signal_generator_spec.rb
spcore-0.2.0 spec/util/signal_generator_spec.rb
spcore-0.1.9 spec/util/signal_generator_spec.rb
spcore-0.1.8 spec/util/signal_generator_spec.rb
spcore-0.1.7 spec/util/signal_generator_spec.rb