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

require 'rubygems'
require 'wav-file'

y = 0

f = open("hoge.wav")
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)

#for x in wavs do
#  if x.abs.to_s.length > 3
#  puts x
#  owavs.push(x)
#  end
#end

while wavs.length > y
  if y <= 100000
    owavs.push(wavs[y])
  end
y += 1
end

dataChunk.data = owavs.pack(bit)

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

p wavs.length
