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
67
# File 'lib/picotune.rb', line 48

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

  # hard clip

  if @left > 1.0
    @left = 1.0
  elsif @left < -1.0
    @left = -1.0
  end

  if @right > 1.0
    @right = 1.0
  elsif @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



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

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

#modify_right(operator, modifier) ⇒ Object



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

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