Class: Sox::Combiner
- Inherits:
-
Object
- Object
- Sox::Combiner
- Defined in:
- lib/sox/combiner.rb
Overview
Combines input files. Technically it calls sox
with --combine
option, but allows you not to care about the rates and numbers of channels in the input files. It converts them to the same rates/channels using temporary mediate files.
Defined Under Namespace
Classes: BaseStrategy, ProcessSubstitutionStrategy, TmpFileStrategy
Constant Summary collapse
- DEFAULT_OPTIONS =
Default options
{ # Method to be used for combining sounds. See --combine of sox tool. :combine => :concatenate, # Number of channels in the output file. :channels => 1, # Rate(samples per seconds) of the output file. :rate => 22050, # Apply norm effect on output. :norm => false, # Strategy to convert input files into files with the same rates # and channels. :strategy => :process_substitution }
- STRATEGIES =
Mapping of strategy names and their implementations
{ :tmp_file => TmpFileStrategy, :process_substitution => ProcessSubstitutionStrategy }
Instance Method Summary collapse
-
#initialize(input_files, options = {}) ⇒ Combiner
constructor
A new instance of Combiner.
-
#write(output_file) ⇒ void
Run
sox
command and write output to file.
Constructor Details
#initialize(input_files, options = {}) ⇒ Combiner
Returns a new instance of Combiner.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/sox/combiner.rb', line 53 def initialize(input_files, = {}) raise(ArgumentError, "Input files are missing") if input_files.empty? opts = DEFAULT_OPTIONS.merge() strategy_name = opts.delete(:strategy) strategy_class = STRATEGIES[strategy_name] raise(ArgumentError, "Unknown strategy #{strategy_name.inspect}") unless strategy_class @strategy = strategy_class.new(input_files, opts) end |
Instance Method Details
#write(output_file) ⇒ void
This method returns an undefined value.
Run sox
command and write output to file.
69 70 71 |
# File 'lib/sox/combiner.rb', line 69 def write(output_file) @strategy.write(output_file) end |