Class: Awaaz::Utils::SoundConfig
- Inherits:
-
Object
- Object
- Awaaz::Utils::SoundConfig
- Defined in:
- lib/awaaz/utils/sound_config.rb
Overview
SoundConfig holds and validates configuration options used for audio processing.
It ensures that only valid options are passed in and provides convenience accessors for common audio processing settings such as sample rate, channel count, amplification factor, and decoder preferences.
Instance Method Summary collapse
-
#amplification_factor ⇒ Integer
The amplification factor for audio processing.
-
#decoder_option ⇒ Symbol?
The preferred audio decoder.
-
#initialize(valid_options, **options) ⇒ SoundConfig
constructor
Initializes a new SoundConfig instance.
-
#mono ⇒ Boolean
Whether to process audio in mono.
-
#mono? ⇒ Boolean
Convenience method to check if audio is mono.
-
#num_channels ⇒ Integer
The number of audio channels.
-
#resampling_option ⇒ Symbol
Resampling option.
-
#sample_rate ⇒ Integer
The sample rate for audio processing.
-
#soundread? ⇒ Boolean
Whether to use soundread for audio processing.
-
#stereo? ⇒ Boolean
Convenience method to check if audio is stereo.
Constructor Details
#initialize(valid_options, **options) ⇒ SoundConfig
Initializes a new SoundConfig instance.
30 31 32 33 34 35 |
# File 'lib/awaaz/utils/sound_config.rb', line 30 def initialize(, **) @options = @valid_options = prepare end |
Instance Method Details
#amplification_factor ⇒ Integer
The amplification factor for audio processing.
105 106 107 |
# File 'lib/awaaz/utils/sound_config.rb', line 105 def amplification_factor ((:amplification_factor) || 32_768).to_i end |
#decoder_option ⇒ Symbol?
The preferred audio decoder.
114 115 116 |
# File 'lib/awaaz/utils/sound_config.rb', line 114 def decoder_option (:decoder)&.to_sym end |
#mono ⇒ Boolean
Whether to process audio in mono.
51 52 53 |
# File 'lib/awaaz/utils/sound_config.rb', line 51 def mono (:mono) || true end |
#mono? ⇒ Boolean
Convenience method to check if audio is mono.
69 70 71 |
# File 'lib/awaaz/utils/sound_config.rb', line 69 def mono? mono end |
#num_channels ⇒ Integer
The number of audio channels.
96 97 98 |
# File 'lib/awaaz/utils/sound_config.rb', line 96 def num_channels mono? ? 1 : 2 end |
#resampling_option ⇒ Symbol
Resampling option
60 61 62 |
# File 'lib/awaaz/utils/sound_config.rb', line 60 def resampling_option (:resampling_option) || :linear end |
#sample_rate ⇒ Integer
The sample rate for audio processing.
42 43 44 |
# File 'lib/awaaz/utils/sound_config.rb', line 42 def sample_rate (:sample_rate) || 22_050 end |
#soundread? ⇒ Boolean
Whether to use soundread for audio processing.
87 88 89 |
# File 'lib/awaaz/utils/sound_config.rb', line 87 def soundread? (:soundread) == true end |
#stereo? ⇒ Boolean
Convenience method to check if audio is stereo.
78 79 80 |
# File 'lib/awaaz/utils/sound_config.rb', line 78 def stereo? !mono? end |