Class: Musicality::Tasks::FileRaker::Audio

Inherits:
Musicality::Tasks::FileRaker show all
Defined in:
lib/musicality/project/file_raker.rb

Instance Attribute Summary

Attributes inherited from Musicality::Tasks::FileRaker

#file_ext, #files, #subdirs, #task_name

Instance Method Summary collapse

Constructor Details

#initialize(osc_files, audio_file_type, sample_rate, sample_format) ⇒ Audio

Returns a new instance of Audio.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# 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

Instance Method Details

#check_sample_format(audio_file_type, sample_format) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# 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