Documentation
¶
Overview ¶
Package piezotone turns MIDI and one-voice audio into note events for a piezo buzzer. The core knows no device. The packages rtttl, midi and opendisplay write the notes in an output format.
Index ¶
Constants ¶
const Rest = -1
Rest is the MIDI value of a note that plays no tone.
const TickMIDI = 96
TickMIDI is the pitch of a drum tick in a rest (C7).
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode reads a WAV, MP3, FLAC or Ogg Vorbis file. It finds the format from the first bytes, mixes the channels down to mono and returns the samples and the sample rate. Integer PCM is in [-1, 1]; float WAV and lossy data can go past it.
Types ¶
type MIDIOptions ¶
MIDIOptions picks the notes to play. A value of -1 means "any". When both are -1, FromMIDI picks the track and channel pair with the most notes.
type NoNotesError ¶
type NoNotesError struct {
Seconds float64 // length of the audio
PeakDB, RMSDB float64 // loudness in dBFS
Frames int // 10 ms analysis frames
Voiced int // frames with a pitch
BestContrast float64 // highest ratio of best pitch to mean pitch of all frames that are not silent; 0 if all are silent
Voicing float64 // voicing threshold in use
}
NoNotesError tells why FromPCM found no note.
func (*NoNotesError) Error ¶
func (e *NoNotesError) Error() string
type Note ¶
Note is one step of a melody: a MIDI note number (69 is A4, 440 Hz) or Rest, its start time and its duration. A melody has no gaps: each note starts where the note before it ends.
func FromMIDI ¶
func FromMIDI(r io.Reader, o MIDIOptions) ([]Note, error)
FromMIDI reads a standard MIDI file and returns one voice: when notes overlap, the highest note sounds.
func FromPCM ¶
func FromPCM(samples []float32, rate int, o PCMOptions) ([]Note, error)
FromPCM finds the main melody of mono samples and cuts it into notes. For each 10 ms frame it sums the spectrum at the first partials of every semitone (harmonic summation, Klapuri, ISMIR 2006), then picks the smoothest strong path through the frames (Viterbi). This keeps the melody over a quieter backing chord or bass. It does not work for music in which no one voice is clearly the loudest. When it finds no pitched note, the error is a *NoNotesError. A sample that is NaN or infinite counts as 0.
type PCMOptions ¶
type PCMOptions struct {
MinHz, MaxHz float64 // pitch search range [80, 5000]
Voicing float64 // a frame whose best pitch is less than this many times the mean is unvoiced [3]
SilenceDB float64 // a frame this far below the loudest frame is silent [-30]
MinNoteMS int // shorter segments join the segment before them [60]
Drums bool // strike held notes again on drum hits and put a tick on hits in rests
}
PCMOptions tunes FromPCM. Zero values use the defaults in brackets.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
piezotone
command
Command piezotone turns a MIDI or audio file into a one-voice melody for a piezo buzzer.
|
Command piezotone turns a MIDI or audio file into a one-voice melody for a piezo buzzer. |
|
Package midi writes notes as a monophonic standard MIDI file (SMF type 0).
|
Package midi writes notes as a monophonic standard MIDI file (SMF type 0). |
|
Package opendisplay fits notes to the buzzer of an OpenDisplay device and writes the melody notation that "opendisplay buzz -melody" of github.com/cr2007/go-opendisplay accepts.
|
Package opendisplay fits notes to the buzzer of an OpenDisplay device and writes the melody notation that "opendisplay buzz -melody" of github.com/cr2007/go-opendisplay accepts. |
|
Package rtttl writes notes in the Nokia RTTTL (Ring Tone Text Transfer Language) format, for example "JingleBell:d=8,o=5,b=112:32p,a,a,4a".
|
Package rtttl writes notes in the Nokia RTTTL (Ring Tone Text Transfer Language) format, for example "JingleBell:d=8,o=5,b=112:32p,a,a,4a". |