Skip to content

Enable resampling #1

Description

@padde

Consider the following code:

require 'wavefile'
include WaveFile

#1 second 440 Hz square wave
format = Format.new(:mono, 16, 44100)
writer = Writer.new("square.wav", format)
cycle = ([2**15] * 50) + ([-2**15] * 50)
buffer = Buffer.new(cycle, format)
441.times do 
  writer.write(buffer)
end
writer.close()

# square.wav now has 44100 samples

# read square wave in at half the sampling rate
samples = []
format = Format.new(:mono, 16, 22050)
reader = Reader.new("square.wav", format).each_buffer(1024) do |buffer|
  samples += buffer.samples
end

puts "#{samples.length} samples read"
# outputs "44100 samples read"

I would assume to get 22050 samples instead of 44100, thus a resampled version of the file. Am i the only one feeling this way?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions