Class: MusicMaster::Formats::Wave

Inherits:
Object
  • Object
show all
Defined in:
lib/MusicMaster/Formats/Wave.rb

Overview

Wave file format. Take the following parameters:

  • :Dither (Boolean): Do we apply dither while converting ?

  • :SampleRate (Integer): Sample rate in Hz (ie 44100, 192000 …)

  • :BitDepth (Integer): Number of bits used to encode 1 sample on 1 channel (ie 8, 16, 24…)

Instance Method Summary collapse

Instance Method Details

#deliver(iSrcFileName, iDstFileName, iFormatConf, iMetadata) ⇒ Object

Deliver a file. The delivered file can be a shortcut to the source one.

Parameters
  • iSrcFileName (String): The source file to deliver from

  • iDstFileName (String): The destination file to be delivered

  • iFormatConf (map<Symbol,Object>): The format configuration

  • iMetadata (map<Symbol,Object>): The metadata that can be used while delivering the file



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/MusicMaster/Formats/Wave.rb', line 33

def deliver(iSrcFileName, iDstFileName, iFormatConf, )
  # Check if we can just make a shortcut
  lShortcut = true
  if (!iFormatConf.empty?)
    if (iFormatConf[:Dither])
      lShortcut = false
    else
      # Need to get the source file attributes (sample rate and bit depth)
      require 'WSK/Common'
      self.class.module_eval('include WSK::Common')
      accessInputWaveFile(iSrcFileName) do |iHeader, iInputData|
        lShortcut = !(((iFormatConf[:SampleRate] != nil) and
                       (iFormatConf[:SampleRate] != iHeader.SampleRate)) or
                      ((iFormatConf[:BitDepth] != nil) and
                       (iFormatConf[:BitDepth] != iHeader.NbrBitsPerSample)))
        next nil
      end
    end
  end
  if (lShortcut)
    # Just create a shortcut
    createShortcut(iSrcFileName, iDstFileName)
  else
    # We need to convert the Wave file: call SSRC
    lTranslatedParams = [ '--profile standard', '--twopass' ]
    iFormatConf.each do |iParam, iValue|
      case iParam
      when :SampleRate
        lTranslatedParams << "--rate #{iValue}"
      when :BitDepth
        lTranslatedParams << "--bits #{iValue}"
      when :Dither
        lTranslatedParams << '--dither 4' if (iValue == true)
      else
        log_warn "Unknown Wave format parameter: #{iParam} (value #{iValue.inspect}). Ignoring it."
      end
    end
    lCmd = "#{@MusicMasterConf[:Formats]['Wave'][:SRCCmdLine]} #{lTranslatedParams.sort.join(' ')} \"#{iSrcFileName}\" \"#{iDstFileName}\""
    log_info "=> #{lCmd}"
    raise "Error while executing SSRC command \"#{lCmd}\": error code #{$?.exitstatus}" if (!system(lCmd)) or ($?.exitstatus != 0)
  end
end

#getFileExtObject

Give the file extension

Return
  • String: The file extension (without .)



21
22
23
# File 'lib/MusicMaster/Formats/Wave.rb', line 21

def getFileExt
  return 'wav'
end