Pitch
Pitch is a Ruby gem that provides a way to generate audio tones, writes them to files, and detects those tones. It can be used in applications that need to test whether audio data is being written properly. For example, it is used in the HD24Dig gem to build a test harness for testing audio extraction from a multitrack digital recorder.
Pitches can be created from scientific pitch notation (SPN), where 'C4' is designated to be middle C. Or from MIDI notation where either the string 'C3' or the value 60 is middle C. Pitches can be converted between various forms, as well as added to or subtracted from. Finally, pitches can be written to files as audio tones, and generated by analyzing files with audio tones.
Usage
require 'pitch'
pitch = Pitch.new_from_spn('C4')
pitch.write_to_file('tone.wav', rate: 48000, depth: 24)
pitch = Pitch.read_from_file('tone.wav')
Installation
Install as a gem:
gem install pitch
...or add to your Gemfile
or .gemspec
file as needed.
Requirements
This gem was written to use Ruby 3.3. It should work with versions of Ruby that are close to that.
Under the hood, Pitch uses SoX to generate tones and write audio files, and Aubio to analyze and detect tones from those files. You will need to install the appropriate package in order for the write_to_file
and read_from_file
methods to work properly. On macOS using Homebrew, that looks like this:
brew install sox
brew install aubio
References