Class: WaveFile::SamplerLoop

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

Overview

Public: Provides a way to indicate the data about sampler loop points

in a file's "smpl" chunk. That is, information about how a sampler
could loop between a sample range while playing this *.wav as a note.
If a *.wav file contains a "smpl" chunk, then Reader.sampler_info.loops
will return an array of SamplerLoop objects with the relevant info.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: required("id"), type: required("type"), start_sample_frame: required("start_sample_frame"), end_sample_frame: required("end_sample_frame"), fraction: required("fraction"), play_count: required("play_count")) ⇒ SamplerLoop

Public: Constructs a new SamplerLoop instance.

id - A numeric ID which identifies the specific loop. Should be an Integer 0 or greater. type - Indicates which direction the loop should run. Should either be one of the symbols

+:forward+, +:alternating+, +:backward+, or a positive Integer. If an Integer, then 0 will
be normalized to +:forward+, 1 to +:alternating+, 2 to +:backward+. Integer values 3 or
greater are allowed by the *.wav file spec, but don't necessarily have a defined meaning.

start_sample_frame - The first sample frame in the loop. end_sample_frame - The last sample frame in the loop. fraction - A Float >= 0.0 and < 1.0 which specifies a fraction of a sample at which to start

the loop. This allows a loop start to be fine tuned at a resolution finer than one sample.

play_count - The number of times to loop. Can be an Integer 0 or greater, or Float::INFINITY.

A value of 0 will be normalized to Float::INFINITY, because in the file format a
value of 0 means to repeat the loop indefinitely.

Raises InvalidSamplerLoopError if the given arguments can’t be written to a *.wav file.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/wavefile/sampler_loop.rb', line 40

def initialize(id: required("id"),
              type: required("type"),
              start_sample_frame: required("start_sample_frame"),
              end_sample_frame: required("end_sample_frame"),
              fraction: required("fraction"),
              play_count: required("play_count"))
  type = normalize_type(type)
  if play_count == 0
    play_count = Float::INFINITY
  end

  validate_32_bit_integer_field(id, "id")
  validate_loop_type(type)
  validate_32_bit_integer_field(start_sample_frame, "start_sample_frame")
  validate_32_bit_integer_field(end_sample_frame, "end_sample_frame")
  validate_fraction(fraction)
  validate_play_count(play_count)

  @id = id
  @type = type
  @start_sample_frame = start_sample_frame
  @end_sample_frame = end_sample_frame
  @fraction = fraction
  @play_count = play_count
end

Instance Attribute Details

#end_sample_frameObject (readonly)

Public: Returns the last sample frame of the loop.



78
79
80
# File 'lib/wavefile/sampler_loop.rb', line 78

def end_sample_frame
  @end_sample_frame
end

#fractionObject (readonly)

Public: A value >= 0.0 and < 1.0 which specifies a fraction of a sample at which to loop.

This allows a loop to be fine tuned at a resolution finer than one sample.


82
83
84
# File 'lib/wavefile/sampler_loop.rb', line 82

def fraction
  @fraction
end

#idObject (readonly)

Public: Returns a numeric ID which identifies the specific loop



67
68
69
# File 'lib/wavefile/sampler_loop.rb', line 67

def id
  @id
end

#play_countObject (readonly)

Public: Returns the number of times to loop. Will be an Integer 1 or greater, or Float::INFINITY.



85
86
87
# File 'lib/wavefile/sampler_loop.rb', line 85

def play_count
  @play_count
end

#start_sample_frameObject (readonly)

Public: Returns the first sample frame of the loop.



75
76
77
# File 'lib/wavefile/sampler_loop.rb', line 75

def start_sample_frame
  @start_sample_frame
end

#typeObject (readonly)

Public: Returns a symbol indicating which direction the loop should run. The possible values

are :forward, :alternating, :backward, or a positive Integer. Integer values 3 or greater
are allowed by the *.wav file spec, but don't necessarily have a defined meaning.


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

def type
  @type
end