Class: CoreAudio::AudioFile

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

Instance Method Summary collapse

Instance Method Details

#read(frames = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/coreaudio/audiofile.rb', line 4

def read(frames=nil)
  if frames
    frames = Integer(frames)
    if frames and frames > 0
      return read_frames(frames)
    elsif frames == 0
      return NArray.sint(0)
    else
      raise ArgumentError,
        "coreaudio: read frame number must be zero or positive"
    end
  end

  # read all frames
  chunk = self.inner_rate.to_i * 10
  total = nil
  loop do
    tmp = read_frames(chunk)
    if tmp.nil?
      break
    end
    if total.nil?
      total = tmp
    else
      new_na = NArray.sint(total.shape[0], tmp.shape[1] + total.shape[1])
      new_na[false, 0...total.shape[1]] = total
      new_na[false, total.shape[1]..-1] = tmp
      total = new_na
    end
  end

  total
end