#!/usr/bin/ruby
# -*- coding: utf-8 -*-

require 'rubygems'
require 'wav-file'
require './read_oto.rb'
require './ut.rb'

y = 0
vbpath = "./vb/leilvcv2/"
oto = readOto(vbpath + "oto.ini")

lyric = "- ど"

#切り出しは1番から3番
#ノート頭は4番
#固定範囲は1番から2番
#伸縮範囲は2番から(1番+|3番|)
#オーバーラップの値何に使うんだっけ5番

f = open(vbpath + oto[lyric][0])
format = WavFile::readFormat(f)
dataChunk = WavFile::readDataChunk(f)
f.close

bit = 's*' if format.bitPerSample == 16
bit = 'c*' if format.bitPerSample == 8

wavs = dataChunk.data.unpack(bit)
owavs = Array.new
#dataChunk.data = wavs.reverse.pack(bit)

lblank = oto[lyric][1]
rblank = oto[lyric][3]
vlength = lblank + rblank.abs

vtop = msc2smp(lblank).round
vend = msc2smp(vlength).round

owavs = wavs[vtop..vend]

dataChunk.data = owavs.pack(bit)

open("output.wav", "w"){|out|
  WavFile::write(out, format,[dataChunk])
}

#p wavs.length
