Skip to content

Instantly share code, notes, and snippets.

@jgoizueta
Created October 13, 2020 16:40
Show Gist options
  • Select an option

  • Save jgoizueta/69945fb6d2a6d95ddc2857648bfd86c7 to your computer and use it in GitHub Desktop.

Select an option

Save jgoizueta/69945fb6d2a6d95ddc2857648bfd86c7 to your computer and use it in GitHub Desktop.
Zoom MRS-1266 File conversion
# Convert Zoom MRS-1266 .DAT files to .WAV
FIXED_HEADER = "52 49 46 46 24 00 5E 00 57 41 56 45 66 6D 74 20 10 00 00 00 01 00 01 00 44 AC 00 00 88 58 01 00 02 00 10 00 64 61 74 61"
input_file = ARGV[0]
data = File.open(input_file, 'rb') { |file| file.read }
data = data[65536..-1]
size = data.size
header = FIXED_HEADER.split.map{ |v| v.to_i(16) }.pack("C*")
output = header + [size].pack("V") + data
output_file = ARGV[1]
File.open(output_file, 'wb') do |file|
file.write output
end
@jgoizueta
Copy link
Author

jgoizueta commented Oct 13, 2020

A proper script zoom2wav:

#!/usr/bin/env ruby

DAT_ID = "ZOOM1D3ZZ0AUD"
HEADER = "52 49 46 46 24 00 5E 00 57 41 56 45 66 6D 74 20 10 00 00 00 01 00 01 00 44 AC 00 00 88 58 01 00 02 00 10 00 64 61 74 61"

input_file = ARGV[0]
output_file = ARGV[1]

def help(exit_code = 0)
  puts "Usage: zoom2wav INPUT-DAT-FILE OUTPUT-WAV-FILE"
  exit exit_code
end

def read_audio_data(input_file)
  data = File.open(input_file, 'rb') { |file| file.read }
  if data[0, DAT_ID.size] != DAT_ID || data.size <= 65536
    puts "Invalid input file #{input_file}"
    exit 3
  end
  data[65536..-1]
end

def write_audio_data(data, output_file)
  header = HEADER.split.map{ |v| v.to_i(16) }.pack("C*")
  output = header + [data.size].pack("V") + data
  File.open(output_file, 'wb') do |file|
    file.write output
  end
end

if input_file.to_s == '' || output_file.to_s == ''
  puts "Missing parameters"
  help 1
end

unless File.exists?(input_file)
  puts "Input file not found: #{input_file}"
  help 2
end

if File.exists?(output_file)
  puts "Output file #{output_file} already exists; delete it if you want to replace it"
  exit
end

write_audio_data(read_audio_data(input_file), output_file)
puts "File sucessfully converted"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment