class Musicality::Tasks::FileRaker::Audio

Public Class Methods

new(osc_files, audio_file_type, sample_rate, sample_format) click to toggle source
Calls superclass method Musicality::Tasks::FileRaker::new
# File lib/musicality/project/file_raker.rb, line 83
def initialize osc_files, audio_file_type, sample_rate, sample_format
  super(osc_files, audio_file_type, ".#{audio_file_type}") do |t|
    check_sample_format audio_file_type, sample_format

    osc_fpath = t.sources[0]
    out_fpath = File.join(File.dirname(osc_fpath), File.basename(osc_fpath, File.extname(osc_fpath)) + ".#{audio_file_type}")

    cmd_line = "scsynth -N \"#{osc_fpath}\" _ \"#{out_fpath}\" #{sample_rate} #{audio_file_type} #{sample_format}"
    IO.popen(cmd_line) do |pipe|
      while response = pipe.gets
        puts response
        if /Couldn't open non real time command file/ =~ response
          puts "The #{sample_format} sample format is not compatible with file format"
          File.delete(out_fpath)
          break
        end
      end
    end
  end
end

Public Instance Methods

check_sample_format(audio_file_type, sample_format) click to toggle source
# File lib/musicality/project/file_raker.rb, line 68
def check_sample_format audio_file_type, sample_format
  combination_okay = case audio_file_type
  when :wav
    sample_format != "int8"
  when :flac
    !["int32","float","mulaw","alaw"].include?(sample_format)
  else
    true
  end

  unless combination_okay
    raise ConfigError, "#{audio_file_type} file format can not be used with #{sample_format} sample format"
  end
end