# WAV → MIDI → Geometry → STL SOP

## Purpose

Convert a clear monophonic or lightly polyphonic WAV into a defensible MIDI transcription, then turn the note events into a geometric image and a watertight STL suitable for later slicing.

## Source selection

Prefer a short, clean recording with distinct note attacks. For the first pass, use:

`Projects/audio-sonar/uploads/1782788980348-page1_piano_105bpm.wav`

It is 4.57 seconds long and contains a simple piano phrase.

## Pipeline

1. Inspect the WAV: duration, sample rate, channels, loudness.
2. Detect note attacks with an onset-strength envelope.
3. Track fundamental frequency with probabilistic YIN.
4. At each onset, sample the nearest stable pitch and quantize it to the nearest MIDI note.
5. Estimate each note's end at the next onset; preserve the original timing in seconds.
6. Write a standard MIDI file without requiring a third-party MIDI package.
7. Create a geometric image:
   - time → horizontal position
   - pitch → vertical position
   - velocity → marker size and opacity
   - duration → marker width
   - note sequence → connecting contour
8. Create a watertight extruded note-landscape mesh:
   - time → X position
   - pitch → column height
   - velocity → column radius
   - each note → a capped cylinder joined to a base plate
9. Export STL and validate the mesh for finite coordinates, positive dimensions, and closed edge usage.
10. Slice only after a printer profile and material are known. Do not invent printer-specific G-code from the raw MIDI geometry.
11. Before physical printing, run the slicer's safety checks and inspect the first-layer and travel plan.

## Important limits

This is an interpreted transcription, not recovery of the original MIDI. Audio pitch tracking can confuse harmonics, chords, resonance, and noise. A clean piano phrase is an appropriate first test; dense drones should be represented as selected dominant pitches rather than presented as exact scores.

## Output set

- MIDI transcription
- JSON note/event record
- SVG geometric image
- PNG geometric image
- STL note-landscape mesh
- validation report

## Reproducibility

Record the source path, analysis settings, detected notes, mapping, mesh dimensions, and validation result beside the generated artifacts. Keep the source WAV unchanged.

## First completed run — 2026-07-15

Source: `Projects/audio-sonar/uploads/1782788980348-page1_piano_105bpm.wav`.

Results: 15 onset events transcribed with spectral fallback; MIDI, SVG, PNG, and a 120 × 34 × 76 mm ASCII STL generated. The STL passed closed-manifold validation with 972 facets and zero boundary edges. A generic PLA FFF slice was generated with PrusaSlicer at 0.20 mm layers, 205 °C nozzle, 60 °C bed, and 15% infill. The G-code is process-validated but not printer-specific; select a real printer profile before physical printing. The generic slice estimates 6 h 4 m and 12,678 mm filament, so the geometry/profile should be optimized before printing.
