How to Play Music on a CNC Machine
A CNC machine can turn a part into an instrument. You map musical notes to spindle speed and axis motion, write the G-code, and the machine sings while it cuts. This guide is for engineers who want the exact steps, safe parameter ranges, and the mistakes that ruin the tune.

Key takeaways
How a CNC Machine Makes Sound
A CNC machine does not have a speaker. It makes sound through its spindle, its axes, and the workpiece. When the spindle spins, the motor and bearings produce a tone. When an axis moves, the servo and ball screw add a lower-frequency hum. When the tool touches material, you get a loud broadband noise that masks everything else.
To play music on a CNC machine, you control the tone-producing parts and suppress the noise-producing part. That means the tool stays clear of the workpiece for most of the performance. The spindle speed becomes your pitch control. The axis motion becomes your rhythm and note duration.
The frequency you hear is tied to rotational speed. A spindle running at 6,000 RPM produces a fundamental around 100 Hz, depending on motor pole count and drive settings. At 12,000 RPM that fundamental roughly doubles. The relationship is not perfectly linear across all machines, so you have to measure your own spindle first.
- 1Spindle toneThe dominant musical voice. Controlled by the S word.
- 2Axis humLower pitch, useful for bass lines or percussion.
- 3Cutting noiseLoud and non-musical. Keep the tool out of the material.
Map Musical Notes to Spindle RPM
Standard tuning puts A4 at 440 Hz. Each semitone up multiplies frequency by about 1.0595. To find the RPM for a note, you need to know your spindle's frequency-to-RPM ratio. Run the spindle at a few known speeds, record the tone with a microphone or phone app, and read the frequency. Divide RPM by Hz to get your machine constant.
Say your constant is 60 RPM per Hz. A4 at 440 Hz needs 26,400 RPM. That is above most machining center spindles. You have two options: transpose the melody down an octave or two, or use a lower RPM range and accept a bass-heavy arrangement. A 12,000 RPM spindle can comfortably reach about 200 Hz, which is roughly G3.
Do not chase exact concert pitch if it pushes the spindle past its rated maximum. A melody shifted down an octave still reads as the same tune to almost every listener. Safety and spindle life come first.
- 1Measure your constantRPM divided by measured Hz. Do this before writing any code.
- 2Transpose downShift the whole melody to fit your spindle's safe range.
- 3Avoid micro-adjustmentsTiny RPM changes may not produce a clean pitch shift. Use semitone steps.
Choose the Right Workpiece and Setup
The workpiece acts as the soundboard. A thin plate of aluminum, brass, or acrylic rings clearly and sustains notes. A thick steel block absorbs vibration and gives a dull thud. For a musical result, use a thin resonant plate clamped at one or two points, not fully bolted down.
Clamping matters as much as material. Over-tighten the vise and you kill the vibration. Use soft jaws or a light clamp force so the plate can flex. If the part is small, mount it on a thin fixture plate that also rings. The fixture becomes part of the instrument.
Tool choice affects the sound too. A large face mill adds mass and damps vibration. A small end mill or no tool at all gives a cleaner tone. For pure music, remove the tool or keep it far from the work. For a performance that also cuts, use a small diameter tool and light depths of cut.
- 1Thin plates ring best2–6 mm aluminum or brass. Acrylic works for softer tones.
- 2Light clampingLet the plate flex. Heavy clamping kills sustain.
- 3Small tool or no toolLess mass means clearer pitch.
Write the G-code Score
Each note becomes a block of G-code. The S word sets spindle speed. A dwell (G4) holds the note for a set time. Then the next S word changes pitch. You do not need to move any axis to play a note, but adding a small X or Y move gives the note a pluck or attack.
Here is the pattern: S6000, G4 P0.5, S8000, G4 P0.5. That plays two notes, each half a second long. The P value is in seconds on most controls. Check your controller manual because some machines use milliseconds. A wrong unit turns a melody into a blur.
For rhythm, vary the dwell time. Quarter notes might be P0.5, eighth notes P0.25. For rests, insert a dwell with the spindle stopped or at a neutral speed. Do not use M5 to stop the spindle between every note; too many stop-start cycles heat the drive and shorten motor life.
- 1S word = pitchSets the note. Keep changes in semitone steps.
- 2G4 = durationP value holds the note. Check seconds vs milliseconds.
- 3Small moves = attackA short X or Y jog gives the note a pluck.
Common Mistakes and How to Avoid Them
The most common mistake is trying to play notes while the tool is cutting. The cutting noise is 20–30 dB louder than the spindle tone. Nobody hears the melody. Keep the tool clear of the work for the musical sections, or accept that the tune is a background effect.
The second mistake is dwell units. If your controller reads G4 P in milliseconds rather than seconds, a P0.5 note lasts half a millisecond. You hear a click, not a note. Always run a single-note test and time it with a stopwatch before writing the full score.
The third mistake is pushing the spindle past its safe speed. Some programmers transpose a melody up instead of down. That can command 20,000 RPM on a 12,000 RPM spindle. The drive will fault or the bearings will suffer. Transpose down, never up.
- 1Cutting masks toneKeep the tool out of the material during musical passages.
- 2Dwell units varyTest one note and time it. Never assume.
- 3Never exceed rated RPMShift the melody down to fit your spindle.
Step by Step: Play Music on a CNC Machine
- 1Measure your spindle's pitch constantCommand S3000, S6000, and S9000. Record each tone with a phone app or microphone. Divide RPM by Hz for each. Average the three values. Typical machining centers land between 40 and 80 RPM per Hz.
- 2Pick a melody and transpose itTake a simple tune like Ode to Joy or a scale. Convert note names to frequencies. Divide by your constant to get RPM. Shift the whole melody down until every note fits under your spindle's rated maximum.
- 3Choose a resonant workpieceUse a 2–6 mm aluminum or brass plate at least 100 mm across. Clamp it lightly at two edges. Avoid heavy vises. If you must cut, use a 3–6 mm end mill at 0.2–0.5 mm depth.
- 4Write the G-code blocksFor each note: an S word, a G4 dwell, and optionally a 1–2 mm X or Y move for attack. Use P0.5 for quarter notes and P0.25 for eighths. Verify the dwell unit in your controller manual.
- 5Add rests and phrasingInsert a G4 dwell at a neutral RPM between phrases. Do not stop the spindle. A 0.25–0.5 s pause at 3,000–4,000 RPM reads as silence to the ear without cycling the motor.
- 6Dry-run the program firstRun with the tool clear of the work and the feed override at 100%. Listen for the melody. Check that no S value exceeds the spindle rating. Fix any wrong notes before cutting.
- 7Record and fine-tuneRecord the run. Compare against the target melody. Adjust RPM values by ±2–5% if a note sounds sharp or flat. Small changes are enough; large jumps break the scale.
Which Method Fits Your Goal
Pick the approach that matches what you want to hear and cut.
| Method | Best for | Parameter range | Watch out for |
|---|---|---|---|
| Spindle-only melody | Pure music, no cutting | S 3,000–12,000, G4 P0.25–0.5 | Spindle heating on long programs |
| Axis hum bass line | Low notes, rhythm | Feed 500–2,000 mm/min | Servo noise masks quiet notes |
| Cutting performance | Part plus tune | 0.2–0.5 mm depth, 3–6 mm tool | Cutting noise drowns the pitch |
| Thin plate resonance | Sustained notes | Plate 2–6 mm, light clamp | Over-clamping kills sustain |
| Heavy block | Percussive clicks | Any S value | Little pitch, mostly thud |
Music Is a Programming Exercise, Not a Machine Feature
If you can control spindle speed and dwell, you can play music on a CNC machine. Keep the tool clear, stay inside the rated RPM, and transpose the melody to fit your spindle. The rest is G-code.
Frequently Asked Questions
Can any CNC machine play music?
Any machine with a controllable spindle speed and G-code dwell can produce notes. Mills, lathes, and routers all work. The quality depends on the spindle drive and the workpiece resonance.
Machines with a fixed-speed spindle or no spindle control cannot change pitch. You would need to use axis motion alone, which gives a much narrower range.
Do I need special software?
No. You can write the G-code by hand for a short melody. For longer pieces, use a spreadsheet to convert note frequencies to RPM, then export the S and G4 blocks.
Some hobbyists write a small script in Python or a macro to generate the code. That is faster for multi-minute songs.
Will playing music damage the spindle?
Not if you stay within the rated speed range and avoid rapid stop-start cycles. Continuous speed changes within the safe range are normal for a machining center.
The risk comes from exceeding maximum RPM or commanding thousands of M3/M5 cycles per minute. Keep the spindle running and vary only the S word.
Can I cut a part and play music at the same time?
You can, but the cutting noise will dominate. The melody becomes a faint background tone. For a clear performance, separate the musical moves from the cutting moves.
A practical compromise is to cut the part first, then run a musical pass with the tool clear of the work.
What is the best material for a musical workpiece?
Thin aluminum and brass plates ring clearly and sustain notes. Acrylic gives a softer, warmer tone. Steel blocks damp vibration and produce mostly percussive clicks.
Plate thickness between 2 mm and 6 mm works well. Thicker plates shift the resonance down and reduce sustain.
How do I get accurate pitch from the spindle?
Measure your spindle's RPM-to-Hz constant first. Use a phone tuner app or microphone. Then calculate RPM for each note by multiplying the target frequency by that constant.
Expect some drift. Spindle speed varies with load and temperature. Fine-tune each note by ±2–5% after recording a test run.
Need Precision Parts for Your Next Project?
Upload your CAD file and get a quote with free DFM analysis within 12 hours. No minimum order quantity, from one prototype to 10,000+ parts.
12-hour quoteNo MOQ100% inspectionNDA available