Class: Raiff

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

Defined Under Namespace

Classes: Chunk, File

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file = nil) ⇒ Raiff

Instance Methods =====================================================



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/raiff.rb', line 26

def initialize(file = nil)
  @offset = 0
  
  if (file)
    @file = Raiff::File.new(file)
  
    @form = Raiff::Chunk::Form.new(@file)
    @chunks = @form.chunks
    
    common_chunk = (@chunks['COMM'] and @chunks['COMM'][0])
    
    if (common_chunk)
      @channels = common_chunk.channels
      @sample_frames = common_chunk.sample_frames
      @sample_size = common_chunk.sample_size
      @sample_rate = common_chunk.sample_rate
    end
  end
end

Instance Attribute Details

#channelsObject (readonly)

Properties ===========================================================



9
10
11
# File 'lib/raiff.rb', line 9

def channels
  @channels
end

#sample_framesObject (readonly)

Properties ===========================================================



9
10
11
# File 'lib/raiff.rb', line 9

def sample_frames
  @sample_frames
end

#sample_rateObject (readonly)

Properties ===========================================================



9
10
11
# File 'lib/raiff.rb', line 9

def sample_rate
  @sample_rate
end

#sample_sizeObject (readonly)

Properties ===========================================================



9
10
11
# File 'lib/raiff.rb', line 9

def sample_size
  @sample_size
end

#samplesObject (readonly)

Returns the value of attribute samples.



10
11
12
# File 'lib/raiff.rb', line 10

def samples
  @samples
end

Class Method Details

.open(file) {|raiff| ... } ⇒ Object

Class Methods ========================================================

Yields:

  • (raiff)


16
17
18
19
20
21
22
# File 'lib/raiff.rb', line 16

def self.open(file)
  raiff = new(file)
  
  yield(raiff) if (block_given?)
  
  raiff
end

Instance Method Details

#each_sampleObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/raiff.rb', line 50

def each_sample
  @chunks['SSND'].each do |sound_data|
    @file.seek(sound_data.start_offset)

    sound_data.samples_count.times do
      sample = sound_data.read_sample

      yield(sample)
    end
  end
end

#each_sample_block(size) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/raiff.rb', line 62

def each_sample_block(size)
  @chunks['SSND'].each do |sound_data|
    @file.seek(sound_data.start_offset)

    block_count = (@sample_frames - 1) / size + 1
    
    block_count.times do
      yield(sound_data.read_samples(size))
    end
  end
end

#inspectObject



46
47
48
# File 'lib/raiff.rb', line 46

def inspect
  "<Raiff\##{object_id} channels=#{channels} sample_frames=#{sample_frames} sample_size=#{sample_size} sample_rate=#{sample_rate}>"
end