Class: PicoTune::Sample

Inherits:
Object
  • Object
show all
Defined in:
lib/picotune.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left = 0.0, right = 0.0) ⇒ Sample

Returns a new instance of Sample.



44
45
46
# File 'lib/picotune.rb', line 44

def initialize left = 0.0, right = 0.0
  @left, @right = left.to_f, right.to_f
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



38
39
40
# File 'lib/picotune.rb', line 38

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



38
39
40
# File 'lib/picotune.rb', line 38

def right
  @right
end

Instance Method Details

#add(sample) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/picotune.rb', line 48

def add sample
  @left += sample.left
  @right += sample.right

  # "foldback" instead of hard clipping, sounds cool
  if @left > 1.0
    @left = 1.0 - (@left - 1.0) # ex: 1.0 - (1.2 - 1.0) => 1.0 - 0.2 => 0.8
  elsif @left < -1.0
    @left = -1.0 - (@left + 1.0) # ex: -1.0 - (-1.2 + 1.0) => -1.0 - -0.2 => -0.8
  end

  if @right > 1.0
    @right = 1.0 - (@right - 1.0)
  elsif @right < -1.0
    @right = -1.0 - (@right + 1.0)
  end

  self # return self to chain ops EX: sample.add(sample).add(sample) etc
end

#modify_left(operator, modifier) ⇒ Object



68
69
70
# File 'lib/picotune.rb', line 68

def modify_left operator, modifier
  @left = @left.send operator, modifier
end

#modify_right(operator, modifier) ⇒ Object



72
73
74
# File 'lib/picotune.rb', line 72

def modify_right operator, modifier
  @right = @right.send operator, modifier
end

#to_aObject



40
41
42
# File 'lib/picotune.rb', line 40

def to_a
  [@left, @right]
end