class RSGuitarTech::WWiseConverter

Constants

TEMPLATE_TAR_BZ

Attributes

chorus[RW]
dir[RW]
quality[RW]
source_file[RW]
wwise_version[RW]

Public Class Methods

new(source_file, opts = {}) click to toggle source
# File lib/rsgt/wwise_converter.rb, line 8
def initialize(source_file, opts = {})
  @source_file   = source_file
  @wwise_version = opts[:wwise_ver]
  @quality       = opts[:quality]
  @chorus        = opts[:chorus]
end

Public Instance Methods

convert!() { |self| ... } click to toggle source
# File lib/rsgt/wwise_converter.rb, line 15
def convert!
  Dir.mktmpdir do |dir|
    @dir = dir

    extract_base_template
    prepare_template
    copy_source
    ffmpeg_preview
    run_wwise
    if wwise_version[0..3].to_i >= 2016
      downgrade_headers "#{template_dir}/GeneratedSoundBanks/Windows/144151451.wem"
      downgrade_headers "#{template_dir}/GeneratedSoundBanks/Windows/309608343.wem"
    end
    yield self
  end
end
copy_source() click to toggle source
# File lib/rsgt/wwise_converter.rb, line 44
def copy_source
  FileUtils.cp source_file, "#{template_dir}/Originals/SFX/Audio.wav"
end
downgrade_headers(file) click to toggle source
# File lib/rsgt/wwise_converter.rb, line 67
def downgrade_headers(file)
  CommandRunner.run! %Q{printf "$(printf '\\x%02X' 03)" | dd of=#{file} bs=1 seek=40 count=1 conv=notrunc}, skip_escaping: true
  CommandRunner.run! %Q{printf "$(printf '\\x%02X' 00)" | dd of=#{file} bs=1 seek=41 count=1 conv=notrunc}, skip_escaping: true
  CommandRunner.run! %Q{printf "$(printf '\\x%02X' 00)" | dd of=#{file} bs=1 seek=42 count=1 conv=notrunc}, skip_escaping: true
  CommandRunner.run! %Q{printf "$(printf '\\x%02X' 00)" | dd of=#{file} bs=1 seek=43 count=1 conv=notrunc}, skip_escaping: true
end
extract_base_template() click to toggle source
# File lib/rsgt/wwise_converter.rb, line 32
def extract_base_template
  just_tar = template_tar_bz.gsub(".bz2", "")
  CommandRunner.run! ["bunzip2", "-k", template_tar_bz]     # Unzip Wwise2016.tar.bz2 to Wwise2016.tar
  CommandRunner.run! ["tar", "-xzvf", just_tar, "-C", dir]  # Untar Wwise2016.tar to the workdir
end
ffmpeg_preview() click to toggle source
# File lib/rsgt/wwise_converter.rb, line 48
def ffmpeg_preview
  CommandRunner.run! ["ffmpeg", "-i", source_file, "-ss", chorus, "-t", "30", "#{template_dir}/Originals/SFX/Audio_preview.wav"]
end
prepare_template() click to toggle source
# File lib/rsgt/wwise_converter.rb, line 38
def prepare_template
  CommandRunner.run! ["mkdir", "-p", "#{template_dir}/.cache/Windows/SFX"]
  CommandRunner.run! ["sed", "-i.bak", "'s/%QF1%/#{quality}/'", default_work_unit.shellescape], skip_escaping: true
  CommandRunner.run! ["sed", "-i.bak", "'s/%QF2%/#{quality}/'", default_work_unit.shellescape], skip_escaping: true
end
results() click to toggle source
# File lib/rsgt/wwise_converter.rb, line 74
def results
  {
    main:    "#{template_dir}/GeneratedSoundBanks/Windows/144151451.wem",
    preview: "#{template_dir}/GeneratedSoundBanks/Windows/309608343.wem"
  }
end
run_wwise() click to toggle source
# File lib/rsgt/wwise_converter.rb, line 52
def run_wwise
  wwise_cmd = [
    wwise_cli,
    "#{template_dir}/Template.wproj",
    "-GenerateSoundBanks",
    "-Platform",
    "Windows",
    "-NoWwiseDat",
    "-ClearAudioFileCache",
    "-Save"
  ]
  wwise_cmd << "-Verbose" if RSGuitarTech.verbose
  CommandRunner.run! wwise_cmd
end

Private Instance Methods

default_work_unit() click to toggle source
# File lib/rsgt/wwise_converter.rb, line 95
def default_work_unit
  "#{template_dir}/Interactive Music Hierarchy/Default Work Unit.wwu"
end
template_dir() click to toggle source
# File lib/rsgt/wwise_converter.rb, line 83
def template_dir
  "#{dir}/Template"
end
template_tar_bz() click to toggle source
# File lib/rsgt/wwise_converter.rb, line 87
def template_tar_bz
  TEMPLATE_TAR_BZ.dup.gsub "YEAR", wwise_version[0..3]
end
wwise_cli() click to toggle source
# File lib/rsgt/wwise_converter.rb, line 91
def wwise_cli
  "/Applications/Audiokinetic/Wwise #{wwise_version}/Wwise.app/Contents/Tools/WwiseCLI.sh"
end