Module: Castaway::Production::Audio
- Included in:
- Castaway::Production
- Defined in:
- lib/castaway/production/audio.rb
Instance Method Summary collapse
- #_build_intro(clip, state) ⇒ Object
- #_build_last(clip, state) ⇒ Object
- #_build_middle(clip, state) ⇒ Object
- #_build_overlay(clip, state) ⇒ Object
- #_duck(clip, basis, options) ⇒ Object
- #_produce_soundtrack(range) ⇒ Object
-
#duck(basis, *overlays) ⇒ Object
Ducks the ‘basis` audio beneath the given `overlays`.
-
#soundclip(id) ⇒ Object
Returns the filename associated with the soundclip with the given id.
Instance Method Details
#_build_intro(clip, state) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# 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) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# 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) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# 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) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/castaway/production/audio.rb', line 122 def (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) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/castaway/production/audio.rb', line 60 def _duck(clip, basis, ) adjust = [:adjust] || 0.5 speed = [:speed] || 0.5 state = { input: basis, overtrack: [:clip], at: [:at] || 0, adjust: adjust, speed: speed, info: Chaussettes::Info.new([: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 + (clip, state) end |
#_produce_soundtrack(range) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# 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) ⇒ Object
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.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/castaway/production/audio.rb', line 43 def duck(basis, *) _next_filename('.aiff').tap do |result| Chaussettes::Clip.new do |clip| clip.mix.out result count = .reduce(0) do |total, | total + _duck(clip, basis, ) end # restore volume clip.chain.vol count clip.run end end end |
#soundclip(id) ⇒ Object
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,
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 |