Class: Awaaz::Decoders::BaseDecoder Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/awaaz/decoders/base_decoder.rb

Overview

This class is abstract.

Abstract base class for audio decoders in the Awaaz gem.

Provides common configuration handling, option management, and helper methods for working with audio data. Subclasses are expected to implement the #load method to perform the actual decoding process.

Since:

  • 0.1.0

Direct Known Subclasses

Mp3Decoder, WavefileDecoder

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, **options) ⇒ BaseDecoder

Returns a new instance of BaseDecoder.

Parameters:

  • filename (String)

    Path to the audio file to decode.

Since:

  • 0.1.0



44
45
46
47
# File 'lib/awaaz/decoders/base_decoder.rb', line 44

def initialize(filename, **options)
  @filename = filename
  @options = Utils::SoundConfig.new(available_options, **options)
end

Class Attribute Details

.available_optionsArray<Symbol> (readonly)

Returns The currently available option keys for this decoder class.

Returns:

  • (Array<Symbol>)

    The currently available option keys for this decoder class.

Since:

  • 0.1.0



28
29
30
# File 'lib/awaaz/decoders/base_decoder.rb', line 28

def available_options
  @available_options
end

Class Method Details

.default_available_optionsArray<Symbol>

Returns The default set of options available to all decoders.

Returns:

  • (Array<Symbol>)

    The default set of options available to all decoders.

Since:

  • 0.1.0



15
16
17
# File 'lib/awaaz/decoders/base_decoder.rb', line 15

def default_available_options
  %i[amplification_factor decoder sample_rate mono]
end

.load(filename) ⇒ Object

Loads audio from a given file using this decoder.

Parameters:

  • filename (String)

    The path to the audio file to load.

Returns:

  • (Object)

    The decoded audio data.

See Also:

Since:

  • 0.1.0



36
37
38
# File 'lib/awaaz/decoders/base_decoder.rb', line 36

def load(filename, ...)
  new(filename, ...).load
end

.set_available_options(provided_available_options = default_available_options) ⇒ void

This method returns an undefined value.

Sets the list of available options for this decoder class.

Parameters:

  • provided_available_options (Array<Symbol>) (defaults to: default_available_options)

    the list of available option keys.

Since:

  • 0.1.0



23
24
25
# File 'lib/awaaz/decoders/base_decoder.rb', line 23

def set_available_options(provided_available_options = default_available_options)
  @available_options = provided_available_options
end

Instance Method Details

#available_optionsArray<Symbol>

Returns The available options for this instance.

Returns:

  • (Array<Symbol>)

    The available options for this instance.

Since:

  • 0.1.0



61
62
63
# File 'lib/awaaz/decoders/base_decoder.rb', line 61

def available_options
  self.class.available_options
end

#loadObject

This method is abstract.

Loads audio data.

This method must be implemented by subclasses to perform the actual decoding of the file.

Raises:

  • (NotImplementedError)

    if called on the base class.

Since:

  • 0.1.0



56
57
58
# File 'lib/awaaz/decoders/base_decoder.rb', line 56

def load
  raise NotImplementedError
end