Class: WSK::Model::RawReader

Inherits:
CachedBufferReader show all
Defined in:
lib/WSK/Model/RawReader.rb

Overview

Implement a RAW file reader using cached buffer reader. Buffers returned are of type String.

Constant Summary collapse

BUFFER_SIZE =

Buffer size. It is expressed in bytes.

Integer
8388608

Instance Method Summary collapse

Methods inherited from CachedBufferReader

#each_buffer, #each_reverse_buffer, #get_current_buffer, #prepare_buffer

Constructor Details

#initialize(iFile, iFirstSampleFilePos, iSampleSize, iNbrSamples) ⇒ RawReader

Constructor

Parameters
  • iFile (IO): The file descriptor. Don’t use it externally as long as it is used by this class.

  • iFirstSampleFilePos (Integer): Position in the file of the first sample

  • iSampleSize (Integer): Size of a single sample to read

  • iNbrSamples (Integer): Total number of samples



28
29
30
31
# File 'lib/WSK/Model/RawReader.rb', line 28

def initialize(iFile, iFirstSampleFilePos, iSampleSize, iNbrSamples)
  @File, @FirstSampleFilePos, @SampleSize, @NbrSamples = iFile, iFirstSampleFilePos, iSampleSize, iNbrSamples
  super()
end

Instance Method Details

#extract_sub_buffer(iBuffer, iIdxStartSample, iIdxEndSample) ⇒ Object

Extract a sub-buffer for the given index range

Parameters
  • iBuffer (Object): The buffer to extract from

  • iIdxStartSample (Integer): Index of the first sample to begin with

  • iIdxEndSample (Integer): Index of the last sample to end with

Return
  • Object: The sub buffer



70
71
72
# File 'lib/WSK/Model/RawReader.rb', line 70

def extract_sub_buffer(iBuffer, iIdxStartSample, iIdxEndSample)
  return iBuffer[iIdxStartSample*@SampleSize..(iIdxEndSample+1)*@SampleSize-1]
end

#get_nbr_samplesObject

Get the total number of samples

Return
  • Integer: Total number of samples



45
46
47
# File 'lib/WSK/Model/RawReader.rb', line 45

def get_nbr_samples
  return @NbrSamples
end

#get_nbr_samples_per_bufferObject

Get the number of samples read per buffer

Return
  • Integer: Nnumber of samples in 1 buffer



37
38
39
# File 'lib/WSK/Model/RawReader.rb', line 37

def get_nbr_samples_per_buffer
  return BUFFER_SIZE/@SampleSize
end

#read_buffer(iIdxStartSample, iIdxEndSample) ⇒ Object

Read a buffer

Parameters
  • iIdxStartSample (Integer): Index of the first sample to begin with

  • iIdxEndSample (Integer): Index of the last sample to end with

Return
  • Object: The corresponding buffer



56
57
58
59
60
# File 'lib/WSK/Model/RawReader.rb', line 56

def read_buffer(iIdxStartSample, iIdxEndSample)
  @File.seek(@FirstSampleFilePos + iIdxStartSample*@SampleSize)
  log_debug "Raw read samples [#{iIdxStartSample} - #{iIdxEndSample}]"
  return @File.read((iIdxEndSample-iIdxStartSample+1)*@SampleSize)
end