basic-pitch developer on retainer: note_events pitch field is a MIDI note number 0–127 not Hz — developer passes MIDI 60 to synthesizer expecting 261.63 Hz — all transcribed melodies rendered 2–3 octaves too low — 15 000 recordings per month — 3 weeks — basic-pitch developer on monthly retainer

basic-pitch 0.2.5 • Python 3.10 • Spotify automatic music transcription; note_events[i][2] is pitch_midi — MIDI note number integer 0–127, not Hz; developer passes MIDI 60 as frequency=60.0 Hz (B1 sub-bass); all synthesized melodies 2–3 octaves below source; • Northfield Basicpitch Ltd. (vocal melody re-synthesis pipeline; 15,000 recordings/month; notes below MIDI 44 inaudible on consumer speakers; 3 weeks; fix: 440.0 * 2**((pitch_midi − 69) / 12); 1.5h retainer engagement)

Northfield Basicpitch Ltd. built an automatic melody transcription and re-synthesis pipeline that accepted vocal and melodic instrument recordings, transcribed the melody to note events using basic-pitch 0.2.5, and re-rendered the melody through a custom synthesizer for use in music production software. The pipeline processed 15,000 recordings per month from 200 music production studios. The developer called model_output, midi_data, note_events = predict(audio_path) and built a synthesis adapter that iterated over note_events, reading note_events[i][2] as the pitch. The variable was named frequency_hz in the synthesis code, and its value was passed directly to synthesizer.render(start=start_s, end=end_s, frequency=frequency_hz). The pipeline ran without raising any exception and produced valid audio files. Three weeks after deployment, a customer submitted a soprano vocal recording and reported that the re-synthesized output “sounds like a bass trombone, not a soprano voice.” Listening to the output confirmed that the entire melody had been transposed 2–3 octaves below the original.

basic-pitch 0.2.5 basic_pitch.inference.predict(audio_path_or_array) returns a 3-tuple: (model_output, midi_data, note_events). note_events is a list of tuples where each tuple has the form (start_time_seconds, end_time_seconds, pitch_midi, amplitude, pitch_bends). The pitch_midi field is an integer MIDI note number in [0, 127], following the standard MIDI specification where MIDI 69 = A4 = 440 Hz and MIDI 60 = C4 (middle C) = 261.63 Hz. MIDI note numbers and Hz are related by the equation Hz = 440.0 × 2((MIDI − 69) / 12). When the developer passes pitch_midi directly to the synthesizer’s frequency parameter: MIDI 60 (middle C, 261.63 Hz) becomes frequency=60.0 Hz — a B1, 2.07 octaves below middle C; MIDI 69 (A4, 440 Hz) becomes frequency=69.0 Hz — a C♯2, 2.09 octaves below A4; MIDI 72 (C5, 523.25 Hz) becomes frequency=72.0 Hz. The entire melody is shifted down by approximately 2.1–2.9 octaves. Notes with MIDI numbers below 44 (G♯2, 103.8 Hz), which map to frequency values below 44 Hz, fall outside the audible range of consumer speakers and are absent from the rendered output entirely. The developer verified correctness by checking the midi_data return value — midi_data.write(‘output.mid’) and listening in a DAW — and heard the correct pitch. Because midi_data is a pretty_midi.PrettyMIDI object that stores MIDI note numbers natively (not Hz), the MIDI file export was always correct. This led the developer to attribute the pitch error to the synthesis layer and spend three weeks investigating the synthesizer before identifying the unit mismatch in the note_events parsing code.

The annotated buggy and fixed basic-pitch synthesis adapter, with MIDI-to-Hz conversion and pitch range validation:

# Northfield Basicpitch Ltd. — basic-pitch 0.2.5 pitch unit fix
# basic-pitch 0.2.5; Python 3.10
# Vocal melody re-synthesis pipeline; 15,000 recordings/month
#
# Problem: note_events[i][2] is pitch_midi — MIDI note number 0-127
#          Developer passes pitch_midi directly as frequency in Hz
#          MIDI 60 (middle C, 261.63 Hz) → synthesizer renders at 60.0 Hz (B1)
#          All melodies 2-3 octaves too low; notes below MIDI 44 inaudible
# Fix:     Convert pitch_midi to Hz: 440.0 * 2**((pitch_midi - 69) / 12)

import numpy as np
from basic_pitch.inference import predict


def midi_note_to_hz(pitch_midi: int) -> float:
    """Convert MIDI note number to Hz. MIDI 69 = A4 = 440 Hz."""
    return 440.0 * 2.0 ** ((pitch_midi - 69) / 12.0)


# ── BUGGY synthesis adapter ───────────────────────────────────────────────────

def synthesize_buggy(audio_path: str, synthesizer) -> None:
    """Transcribe and re-synthesize melody — BUGGY: pitch_midi used as Hz."""
    model_output, midi_data, note_events = predict(audio_path)

    for start_s, end_s, pitch_midi, amplitude, pitch_bends in note_events:
        # BUG: pitch_midi is an integer MIDI note number (0-127), NOT Hz
        # For middle C (MIDI 60): pitch_midi=60; synthesizer renders at 60 Hz (B1)
        # For A4 (MIDI 69, 440 Hz): renders at 69 Hz (C#2)
        # Melody is 2-3 octaves too low; notes below MIDI 44 render below 44 Hz
        frequency_hz = pitch_midi   # WRONG — this is a MIDI note number, not Hz
        synthesizer.render(
            start=start_s,
            end=end_s,
            frequency=frequency_hz,  # receives 60.0, should receive 261.63
            amplitude=amplitude,
        )


# ── FIXED synthesis adapter ───────────────────────────────────────────────────

def synthesize_fixed(audio_path: str, synthesizer) -> None:
    """Transcribe and re-synthesize melody — FIXED: convert pitch_midi to Hz."""
    # Startup check: verify basic-pitch returns MIDI note numbers as expected
    # Create a 1-second A4 (440 Hz) sine wave and confirm transcription returns MIDI 69
    _validate_pitch_unit()

    model_output, midi_data, note_events = predict(audio_path)

    for start_s, end_s, pitch_midi, amplitude, pitch_bends in note_events:
        # FIX: convert MIDI note number to Hz
        # MIDI 60 (middle C) → 261.63 Hz; MIDI 69 (A4) → 440.0 Hz
        frequency_hz = midi_note_to_hz(pitch_midi)

        # Sanity: rendered frequency should be in human hearing range
        if not (20.0 <= frequency_hz <= 20000.0):
            import warnings
            warnings.warn(
                f"Rendered frequency {frequency_hz:.1f} Hz (MIDI {pitch_midi}) "
                "outside human hearing range [20, 20000] Hz. "
                "Sub-20 Hz notes will be inaudible on consumer speakers."
            )

        synthesizer.render(
            start=start_s,
            end=end_s,
            frequency=frequency_hz,   # 261.63 Hz for middle C — correct
            amplitude=amplitude,
        )


def _validate_pitch_unit() -> None:
    """Confirm that basic-pitch returns MIDI note numbers, not Hz."""
    import numpy as np
    sr = 22050
    t = np.linspace(0, 1.0, sr, endpoint=False)
    # A4 sine wave at 440 Hz
    a4_audio = (np.sin(2 * np.pi * 440.0 * t) * 0.5).astype(np.float32)

    _, _, note_events = predict(a4_audio, sr)
    if note_events:
        pitch_val = note_events[0][2]
        # If pitch is MIDI, it should be ~69 (A4). If it were Hz, it would be ~440.
        if pitch_val > 200:
            raise RuntimeError(
                f"basic-pitch returned pitch_midi={pitch_val}, which appears to be in Hz "
                "rather than MIDI note number. This should not happen in basic-pitch 0.2.5; "
                "check library version. Expected MIDI 69 (A4), not 440 Hz."
            )
        assert 65 <= pitch_val <= 73, (
            f"A4 sine wave transcribed as MIDI {pitch_val} (expected ~69). "
            "Check audio input format and sample rate."
        )


def batch_synthesize_fixed(audio_paths: list, synthesizer) -> dict:
    """Transcribe and re-synthesize a batch of recordings; return per-file status."""
    results = {}
    for path in audio_paths:
        try:
            synthesize_fixed(path, synthesizer)
            results[path] = 'ok'
        except Exception as exc:
            results[path] = f'error: {exc}'
    return results

How a MIDI note number named frequency_hz, a MIDI file that always sounds correct, and a synthesis layer investigated for three weeks combine to mask a unit mismatch in note_events parsing — and the correct basic-pitch pattern for melody synthesis

The core failure combines three independent factors: the note_events tuple field is not documented inline in the return value (the developer must read the basic-pitch source or README to learn that element 2 is pitch_midi in MIDI note number format, not Hz); the developer named the variable frequency_hz, which makes the code appear correct on code review; and the MIDI file export path (midi_data.write()) is always correct because pretty_midi.PrettyMIDI stores pitches as MIDI note numbers natively — this created a misleading “basic-pitch is working correctly, the problem is downstream” diagnostic trail that sent the investigation in the wrong direction for three weeks. The correct conversion is frequency_hz = 440.0 * 2.0 ** ((pitch_midi - 69) / 12.0): MIDI 69 (A4) → 440.0 Hz; MIDI 60 (C4, middle C) → 261.63 Hz; MIDI 48 (C3) → 130.81 Hz; MIDI 72 (C5) → 523.25 Hz. The startup validation approach — generating a known-frequency sine wave, running it through predict(), and asserting that the returned pitch_midi is near 69 for a 440 Hz input — would have caught the unit mismatch within the first few minutes of development. The range check — asserting 20 <= frequency_hz <= 20000 before every synthesizer.render() call — would have caught the error on the first note of the first recording. Neither check was present. The recovery effort was 1.5h: 0.25h triage (MIDI file correct; synthesis log shows frequency=69.0 for A4; confirms unit error); 0.5h root cause (note_events[i][2] is MIDI note number; MIDI-to-Hz conversion required; MIDI file uses MIDI natively, explaining why that path was always correct); 0.25h fix (midi_note_to_hz() conversion; startup A4 validation; frequency range assertion; re-synthesize 3-week backlog); 0.5h validation (100-recording test; rendered pitch within 10 cents of reference; min/max/mean frequency distribution matches source audio; 1.5h total). Hours logged to HourTab with per-session breakdown.

Related retainer posts


Track retainer hours without a client portal

HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.

See pricing →