This repository has been archived on 2025-04-28. You can view files and clone it, but cannot push or open issues or pull requests.
computers-sound-music-portf.../code/tuner
David Westgate baa909c79d tuner entry
2024-11-15 17:20:15 -08:00
..
bass-demo.mkv tuner entry 2024-11-15 17:20:15 -08:00
key-demo.mkv tuner entry 2024-11-15 17:20:15 -08:00
main.py tuner code 2024-11-15 15:50:44 -08:00
README.md tuner entry 2024-11-15 17:20:15 -08:00
requirements.txt tuner entry 2024-11-15 17:20:15 -08:00
trumpet-demo.mkv tuner entry 2024-11-15 17:20:15 -08:00

Background

Here is a simple python instrument tuner. The idea is that you connect your instrument to your computers audio input, and the python script will tell you what note is being played (the note associated with the dominant frequency).

I decided to build this application because my bass tuner has gone missing. I believe someone has taken it from me and a mild sense of pride has kept me from acknowledging it is gone, so I am therefor reluctant to buy a new one. However, this program I have written is free and I hope it will do the job.

Setup

Potential libraries needed for debian-based gnu+linux

sudo apt-get install libportaudio2

Install python libraries

pip install -r requirnments.txt

You will need to tweak the code to choose the correct device number. Of course, this could be abstracted to a python argument with a default value.

Run

python3 main.py

View Source

main.py

Demo

Keyboard

Bass

Trumpet

Reflection

This app works ok in some circumstances. Specifically, it seems to do well with mid range and high range frequencies, but was not very helpful for bass tuning. This could be for a variety of reasons including improper use of my bass amplifier, or sub-standard instrument, but I also suspect I could re-work my calculation of dominant frequenceies to better accomodate low ranges.

Getting the results I have took some work. I did understand I would need to use an FFT to recover the frequencies from the signal, but understanding how to properly apply a window (hanning) and the chunk size took more work. In addition to reviewing the course notes, ChatGPT was consulted to help debug and refine the function dominant_frequency. Deriving the note and octave values from the frequencies was rather straightforward algebra from the notes lecture.

Consultation

Python Sounddevice documentation. This was my first time capturing audio from a PC audio input, rather than a wav file

Tuner example. This is a similar application, but using pyaudio rather than sounddevice. Some inspiration was taken from this.