CC Blog • Projects • Research & Design Hub

Play Harmonies on a Single Trumpet

Using a Capacitive Touch Slider, Raspberry Pi 4, and
Arduino Uno

  • How can a trumpet play harmony with itself?
  • How does a capacitive touch slider control musical intervals?
  • How is FFT used to detect and shift pitch in real time?
  • Why combine Arduino and Raspberry Pi in audio processing?
  • What limits latency and sound quality in pitch-shifting systems?
  • Capacitive touch sensing
  • Digital signal processing
  • Fast Fourier Transform
  • Pitch shifting
  • Embedded audio processing
  • Raspberry Pi | raspberrypi.com
  • Arduino | arduino.cc
  • TinyCircuits | tinycircuits.com
  • Circuit Cellar | circuitcellar.com

While many instruments such as the piano or similarly organized mallet percussion instruments have the capability to play in harmony, brass instruments do not. These Cornell University students created the Trumpet Harmonizer, a pitch shifter that enables musicians to harmonize with themselves in real time. With the touch of a finger, the musician can turn solo music into a duet, which provides endless possibilities for creativity and music transformation.

While many instruments such as the piano or similarly organized mallet percussion instruments (xylophone) and string instruments that are played with a bow (violin, cello) or plucked or strummed (guitar, banjo) have the capability to play in harmony, brass instruments do not The mechanics of our device, the “Trumpet Harmonizer,” make it as easy as possible for a musician to add harmony to playing a brass instrument—in our case, a trumpet—and to dynamically control that harmony.

A capacitive touch slider is mounted to the side of a trumpet, so that a musician can control the interval at which the harmonizer pitch-shifts the sound. The touch slider is placed vertically in front of the valves (Figure 1), so that players can easily use their right thumb, which typically doesn’t have a function when playing the trumpet, to control the harmony interval, while they press the valves. This extra control will take practice for a musician to master, but once familiarity with the technique has been acquired, the additional motion does not interfere with the ability to otherwise play the instrument, and is intuitive for the player.

Figure 1
Capacitive touch slider attached to the trumpet. An ElectroCookie solderable breadboard and wires to an Arduino are also shown (see “Hardware Overview”).
Figure 1
Capacitive touch slider attached to the trumpet. An ElectroCookie solderable breadboard and wires to an Arduino are also shown (see “Hardware Overview”).

A microphone attached to the bell of the trumpet captures the sound it produces, and the audio is processed and pitch-shifted based on the interval selected on the touch slider. The pitch-shifted notes are played on speakers in real time so that the harmony effect is created.

MUSIC THEORY

The concept of pitch-shifting relies upon the idea of a musical interval. An interval is defined as the distance between two musical notes, and this distance is expressed in units of “semitones,” which are the number of notes on a piano keyboard (whether black or white) between the two notes. The most basic interval is an octave, which is defined as two notes whose frequencies are separated by a factor of two. In Western music, an octave is divided into 12 different pitches; thus, there are 12 different types of intervals, because once an octave has been reached, the list of intervals repeats.

Out of the 12 possible intervals, we knew we would only be able to choose a subset of them to use with the touch slider, so that the device would not be overly complex to use. To achieve this, we chose six of the most common intervals for playing consonant harmony (see Table 1). The most obvious choice was the octave, since duplicating a pitch in octaves is common, and is more of a pitch effect than an actual harmony. The “perfect fifth” (an interval spanning five semitones) was chosen, so that the user can play in parallel fifths, as if mimicking a rock guitarist. The “minor third” (interval spanning three semitones), “major third” (interval spanning four semitones), and “perfect fourth” (interval spanning five semitones) were all chosen with the intent of being able to play a harmony that is a “third above.” The “major second” (interval spanning two semitones) was chosen to be useful in jazz.

TABLE 1
A list of all standard music intervals; the ones we implemented are highlighted in green
TABLE 1
A list of all standard music intervals; the ones we implemented are highlighted in green
HARDWARE OVERVIEW

The fully assembled system is shown in Figure 2. It includes a trumpet, Arduino Uno, Raspberry Pi 4, a solderable breadboard, a microphone, and speakers.

Figure 2
The entire system, comprising the trumpet, touch slider, microphone, Raspberry Pi 4, Arduino Uno, breadboard wired to the Arduino, and speakers. A lab bench is still needed to hold the speaker, Raspberry Pi, and Arduino because they were not mounted on the trumpet as originally intended.
Figure 2
The entire system, comprising the trumpet, touch slider, microphone, Raspberry Pi 4, Arduino Uno, breadboard wired to the Arduino, and speakers. A lab bench is still needed to hold the speaker, Raspberry Pi, and Arduino because they were not mounted on the trumpet as originally intended.

The main hardware component we use is a touch slider, which is used to control the interval at which the incoming sound from the trumpet is pitch-shifted. We chose the AST1003 Capacitive Touch Slider from TinyCircuits [1], because its length is similar to the distance between the lead pipe and first valve slide of a trumpet, and therefore would be easy to fasten. Additionally, our touch slider of choice communicates via I2C, which is a reliable and standardized communication protocol.

The dimensions of the touch slider allow it to rest on the side of the trumpet such that when playing the instrument, the musician can comfortably press on the slider with their right thumb and not have to contort their hand. The touch slider also had small holes in each corner of its PCB, so we were able to secure it to the upper and lower pipes of the instrument.

The wiring from the touch slider is simple, since it is equipped with a 5-pin JST connector. Four pins are used: SCL and SDA for the I2C data transfer, alongside VCC and GND to properly power the PCB. We use TinyCircuits’ ASR00009 (a 5-pin cable that fits in the JST connector mounted on the touch slider) to bring I2C data from the touch slider to our microcontroller, and power from the microcontroller to the touch slider. To neatly route the data and power, we use an ElectroCookie solderable breadboard, which we also mounted to the trumpet.

The Arduino Uno and the Raspberry Pi are simply connected with a USB-A-to-USB-B cable to facilitate the UART connection between the two devices. Asynchronous communication is a simple and inexpensive way to move data quickly from one device to another, and with a lot happening on both sides, it was the most efficient. Once the Arduino Uno reads from its I2C connection with the capacitive touch slider, it pushes the value to the serial port, and can do this continuously without having to wait for the Raspberry Pi to read the incoming data.

RASPBERRY PI 4 SOFTWARE OVERVIEW

Code for this project can be downloaded from the Circuit Cellar Article Code and Files webpage.

Our Raspberry Pi 4 pitch-shifts incoming audio from our USB microphone, and plays the generated samples. To reduce latency, our code is all written in C. As a compiled language, C is much faster than popular interpreted languages such as Python.

Initially, we create a stream of audio through the “PortAudio” C library, which repeatedly takes in audio samples at a frequency of 44.1kHz in windows of 4,096 data values to be processed. PortAudio uses a callback function, which is repeatedly invoked by the stream, making it run effectively as a while loop. Rather than the incoming samples from the microphone being directly inserted into the output buffer to be played by the speakers, our audio samples are diverted, and instead go through processing stages (Figure 3).

Figure 3
Diagram of the logical flow of the software of the system. Incoming samples are diverted and go through various processing stages, beginning at the microphone input and ending at the speakers output.
Figure 3
Diagram of the logical flow of the software of the system. Incoming samples are diverted and go through various processing stages, beginning at the microphone input and ending at the speakers output.
Frequency Detection

The first stage that audio samples enter is frequency detection, which allows us to identify the note currently being played by the trumpet. Any note played by a trumpet is made up of several frequencies due to the vibrational characteristics of the instrument. The frequency that is the most prominent in the sound is the “fundamental frequency”, which it is our goal to detect. To isolate the trumpet’s frequencies and identify the fundamental frequency (the note identifiable by a tuning device or human ear), we select the frequency with the highest magnitude in a given sample window.

To detect all the frequencies in a note, we implement a Fast Fourier Transform (FFT) using the Cooley-Tukey Fast Fourier Transform algorithm [2], which is capable of efficiently performing a Discrete Fourier Transform (DFT) on a window of incoming audio samples. The DFT is an algorithm that takes a vector of equally-spaced samples in the time domain and translates them into a frequency spectrum. Thus, the FFT allows us to isolate the frequencies embedded in each audio window by converting the time-domain measurements to the frequency-domain.

The first consideration when performing an FFT is to decide the window size on which the FFT is calculated. The FFT algorithm needs a number of samples that is a power of 2. We require the resolution of the FFT to be roughly 10Hz—which is the smallest gap between notes at the low end of the trumpet’s range—so we use a window of 4,096 data points. Had we chosen a smaller-sized window, it would have been impossible to differentiate between notes at the lower end of the trumpet’s range. This allows us to define ~10Hz “bins” and map them to notes.

Finding the Fundamental Frequency

Next, based on the result of the FFT calculation, we find the fundamental frequency by picking the frequency value of highest magnitude. While this seems simple, our detection algorithm occasionally runs into problems. First, we often detect the first harmonic (the same note but an octave higher) as the fundamental frequency. To solve this, we limit the range of accepted values to within one octave, so that the harmonics are not under consideration for being the fundamental frequency. Additionally, we are often off by one frequency bin that we pre-defined, even if the sound of the input note was seemingly unchanged. To fix this issue, we detect frequencies within one bin of each other as the same frequency, and then compute the mode out of the five most recent detections to average out any irregularities.

Polling a UART Line

After performing our initial frequency-detection calculation, we use the poll() function to poll a UART line connected to our Arduino Uno (which is connected to our touch slider via I2C) for 20ms to determine if the touch slider is being touched or not. If a touch event is recognized by the Arduino, it sends data points ranging from 1 to 100, depending on the location of the touch through the UART line. To report the status of the UART line, the poll() function returns either a “1” if there is data ready or a “0” if the line is idle.

If the user is not making contact with the touch slider, we discard the incoming values from the microphone and the FFT, and don’t proceed with our harmonization logic, which allows the musician to play without any sound from our device. We send zeros to the output buffer to play nothing through the speakers, and restart the callback function. If the poll function tells us that there is something to read, we call read(), which receives data waiting on the asynchronous UART line. After this, we move to the next phase of our audio processing—pitch-shift mapping.

Pitch-shift Mapping

Our pitch shift mapping relies on the value that our FFT detects as the pitch coming from the instrument, along with the value that we read from the touch slider. To simplify things, we discretize the touch slider data between 1 and 100 into a value between 1 and 6. This allows us to pitch-shift into six real harmonic intervals, instead of arbitrary numbers that our algorithm would come up with otherwise.

Since the frequencies of notes in a scale do not increase linearly, no simple calculation can be used to determine a number of bins to shift. The simplest method to identify the difference is direct mapping. This approach matches each pair of incoming frequencies and shift amounts to a specific frequency difference. Once the difference of the pitch shift is determined, we shift the entire result of the FFT by that much, so that the fundamental frequency and all the overtones are included and are at their new correct values. We also zero out the bins with the lowest frequencies, because we found that they contain a lot of unwanted noise.

Audio Generation

Finally, we move to the last audio processing stage—audio generation. This stage converts the newly obtained frequency values back into audio values in the time domain. To do this, we perform an Inverse Fast Fourier Transform (iFFT), which converts our shifted FFT back into the time domain. The iFFT algorithm closely resembles the FFT algorithm, with minor adjustments to accommodate the reverse direction of the computation, so it is equally fast and does not introduce much latency into our processing time. Once the audio window has been pitch-shifted, the result is sent to the PortAudio stream’s output buffer, which is played by the speakers connected to the Raspberry Pi’s audio jack.

RESULTS

Our final prototype exhibited the basic functionality that we set out to achieve. Using a capacitive touch slider, an Arduino, and a Raspberry Pi 4, we were able to create two-note harmonies on a trumpet—a brass instrument that otherwise is incapable of playing multiple notes at the same time. As you can hear in the demonstration video [3].

Our system had some shortcomings, however. Notably, the current pitch-shifting method has inherent limitations on the amount of pitch shift, and also significant latency—approximately 400ms from input to output.

Aside from those limitations, the process of pitch-shifting the audio had a noticeable effect on the timbre of the trumpet sound. The output sound had a distinct metallic and robotic quality, such that it did not blend with the natural trumpet sound as well as we had envisioned.

FUTURE IMPROVEMENTS

Several areas of improvement are possible. The most significant area lies in the method of pitch-shifting that we used. The simpler possibility would be to change the way the DFT is performed. Rather than taking a buffer of 4,096 samples, computing the DFT, and throwing those samples away, there could be a sliding window of which samples are put into the DFT, such that the DFT can be computed more frequently and it is not necessary to wait for another 4,096 samples before computing the next one.

It might be possible to utilize the quad-core capability of the Raspberry Pi to parallelize the computation of these overlapping DFTs. Moreover, in conjunction with this, there could be a smoothing window applied to each group of samples being fed into the DFT. Currently, the system employs a rectangular window, which is likely causing distortions when taking the DFT, due to the sudden transitions at the edges of the window. Using a window function, such as a Hann function, might lessen some of these effects and create an output sound with less distortion.

A possible alternative to the DFT algorithm altogether is the phase vocoder [4], which we discovered in our research but decided not to attempt, given our time constraints. The phase vocoder would handle pitch-shifting completely in the time domain, and would enable pitch-shifting by any arbitrary amount. Also, the pitch-shifting calculation would not depend on the pitch of the note being played, so there would not need to be any frequency detection at all. Moreover, due to the phase vocoder’s successful use in guitar pedals, we know it has the potential for not having latency issues, unlike the DFT algorithm.

On the topic of frequency detection, a second major area of improvement would be to handle the issue of accidentally detecting the pitch an octave higher than the pitch actually played. We handled this issue by restricting the functional range of the harmonizer to just within a one-octave input range, but this imposes stringent constraints on what can be played using the system. It may be possible to devise an algorithm that could detect several peak frequencies corresponding to several present harmonics, and then identify which one is the fundamental, rather than only finding the peak. The phase vocoder would also not have this issue.

There are a few more areas of possible improvement related to the touch slider and pitch-shifting. For one, there would ideally be more than six possible pitch shift intervals to choose from; however, it would be difficult to design a physical system such that more than six shift intervals would be accessible via one-finger operation. A system improvement that would be helpful for this would be to design a custom capacitive touch slider with thin, smooth frets to clearly indicate the barriers between intervals to the user.

Moreover, another desired mode of operation would be to pitch-shift to a lower pitch than the one being played, which would not require any different mathematics than pitch-shifting upward. It could be possible to simply flip a switch between positive and negative pitch-shift intervals, or perhaps the pitch-shift intervals could be more customizable overall.

There could also be a user interface, perhaps in a form such as a PiTFT touchscreen, wherein the user can select exactly what interval each section of the touch slider could represent, both positive and negative. In a more advanced system, there could even be settings to modify the timbre and equalization of the output sound.

Thinking more broadly, there are possible hardware options to the Raspberry Pi—such as a Field-Programmable Gate Array (FPGA)—that could be better suited to accomplishing this task. An FPGA would be well-suited to this type of computational task, since it mainly consists of FFT calculations and other surrounding logic. Developing a custom PCB with an FPGA to handle such logic, and a microcontroller to manage the user interface/IO would streamline this.

Finally, the ideal final version of this product would be mounted onto the trumpet itself, rather than sitting on a table nearby. To accomplish this, it would be beneficial to eliminate the Arduino from the system, since its only purpose is to allow the touch slider to communicate with the Raspberry Pi. If the slider and Pi could be configured to communicate directly, then there would no longer be a need for the Arduino, and thus the overall system would be smaller in size and easier to mount.

REFERENCES
[1] TinyCircuits Capacitive Touch Slider AST1003: https://www.mouser.com/ProductDetail/TinyCircuits/AST1003?qs=vHuUswq2%252BsxRIfzR2nVB9g%3D%3D&srsltid= AfmBOooXs1OUGlTu3is7HrAchNKkp7dzwFaKcs3z4hKzy4JHpivAozhh
[2] Professor Hunter Adams’ FFT Implementation in C. “Understanding the Cooley-Tukey FFT: https://vanhunteradams.com/FFT/FFT.html
[3] Demonstraton video https://www.youtube.com/watch?v=Sx0tuqZjzUk
[4] Phase Vocoder: https://en.wikipedia.org/wiki/Phase_vocoder

Code and Supporting Files 

PUBLISHED IN CIRCUIT CELLAR MAGAZINE • JULY 2025 #420 – Get a PDF of the issue

Keep up-to-date with our FREE Weekly Newsletter!

Don't miss out on upcoming issues of Circuit Cellar.


Note: We’ve made the Dec 2022 issue of Circuit Cellar available as a free sample issue. In it, you’ll find a rich variety of the kinds of articles and information that exemplify a typical issue of the current magazine.

Would you like to write for Circuit Cellar? We are always accepting articles/posts from the technical community. Get in touch with us and let's discuss your ideas.

Sponsor this Article
+ posts

Robert Haig graduated from Cornell University in May 2025 with a BS in Electrical and Computer Engineering, and he is now an FPGA engineer for Owl Cyber Defense. He is also a jazz musician, and seeks to combine his passions for music and engineering. He can be reached at rdh247@cornell.edu and linkedin.com/in/robert-haig-ece.

Henry Geller graduated from Cornell University in May 2025 with a BS in Electrical and Computer Engineering, and is an incoming Electrical Engineer at Lockheed Martin. He can be reached at hng8@cornell.edu and
linkedin.com/in/henry-geller.

Supporting Companies

Upcoming Events


Copyright © KCK Media Corp.
All Rights Reserved

Copyright © 2026 KCK Media Corp.

Play Harmonies on a Single Trumpet

by Robert Haig Henry Geller time to read: 13 min