module Castaway::Production::Audio
Public Instance Methods
_build_intro(clip, state)
click to toggle source
# File lib/castaway/production/audio.rb, line 78 def _build_intro(clip, state) Chaussettes::Clip.new do |c| c.in(state[:input]) c.out(device: :stdout).type(:aiff).rate(48_000).channels(2) c.chain.fade(0, state[:at] + state[:right_delay], state[:speed], type: :linear) clip.in(c).type :aiff end 1 end
_build_last(clip, state)
click to toggle source
# File lib/castaway/production/audio.rb, line 106 def _build_last(clip, state) return 0 unless state[:at] + state[:info].duration < duration Chaussettes::Clip.new do |c| c.in(state[:input]) c.out(device: :stdout).type(:aiff).rate(48_000).channels(2) c.chain.trim(state[:at] + state[:info].duration - state[:left_delay]). fade(state[:speed], type: :linear). pad(state[:at] + state[:info].duration - state[:left_delay]) clip.in(c).type :aiff end 1 end
_build_middle(clip, state)
click to toggle source
# File lib/castaway/production/audio.rb, line 91 def _build_middle(clip, state) Chaussettes::Clip.new do |c| c.in(state[:input]) c.out(device: :stdout).type(:aiff).rate(48_000).channels(2) c.chain. trim(state[:at], state[:info].duration). vol(state[:adjust]). pad(state[:at]) clip.in(c).type :aiff end 1 end
_build_overlay(clip, state)
click to toggle source
# File lib/castaway/production/audio.rb, line 122 def _build_overlay(clip, state) Chaussettes::Clip.new do |c| c.in(state[:overtrack]) c.out(device: :stdout).type(:aiff).rate(48_000).channels(2) c.chain.pad(state[:at]) clip.in(c).type :aiff end 1 end
_duck(clip, basis, options)
click to toggle source
# File lib/castaway/production/audio.rb, line 60 def _duck(clip, basis, options) adjust = options[:adjust] || 0.5 speed = options[:speed] || 0.5 state = { input: basis, overtrack: options[:clip], at: options[:at] || 0, adjust: adjust, speed: speed, info: Chaussettes::Info.new(options[:clip]), right_delay: adjust * speed, left_delay: (1 - adjust) * speed } count = _build_intro(clip, state) count += _build_middle(clip, state) count += _build_last(clip, state) count + _build_overlay(clip, state) end
_produce_soundtrack(range)
click to toggle source
# File lib/castaway/production/audio.rb, line 134 def _produce_soundtrack(range) block = self.class.soundtrack return nil unless block _next_filename('.aiff').tap do |filename| real_filename = filename filename = range.truncated? ? _next_filename('.aiff') : real_filename Chaussettes::Clip.new do |clip| instance_exec(clip, &block) clip.out(filename) clip.run end if range.truncated? Chaussettes::Clip.new do |clip| clip.in(filename) clip.chain.trim range.start_time, range.end_time - range.start_time clip.out(real_filename) clip.run end end end end
duck(basis, *overlays)
click to toggle source
Ducks the `basis` audio beneath the given `overlays`. Each overlay should be a hash containing at least a `:clip` key, corresponding to a filename to be used for the overlay clip. Additional keys are:
-
`:at` (default 0, where in `basis` the overlay should be applied)
-
`:adjust` (default 0.5, how much the basis audio should be reduced)
-
`:speed` (default 0.5, how many seconds the fade in/out should take)
Returns a new filename representing the results of the duck operation.
# File lib/castaway/production/audio.rb, line 43 def duck(basis, *overlays) _next_filename('.aiff').tap do |result| Chaussettes::Clip.new do |clip| clip.mix.out result count = overlays.reduce(0) do |total, options| total + _duck(clip, basis, options) end # restore volume clip.chain.vol count clip.run end end end
soundclip(id)
click to toggle source
Returns the filename associated with the soundclip with the given id. If the soundclip was declared with a block, the block will be evaluated with a new `Chaussettes::Clip` instance, and the a temporary filename containing the resulting audio will be returned,
# File lib/castaway/production/audio.rb, line 11 def soundclip(id) @soundclips ||= {} @soundclips[id] ||= begin definition = self.class.soundclip(id) raise "no soundclip #{id.inspect}" unless definition case definition when String then definition when Proc then _next_filename('.aiff').tap do |filename| Chaussettes::Clip.new do |clip| instance_exec(clip, &definition) clip.out(filename) clip.run end end else raise ArgumentError, "can't use #{definition.inspect} as soundclip" end end end