Realtime Adjustment of Sampling Rate and Bit Resolution

This Audio Hacker shield project lets you dynamically adjust the audio sampling rate and bit resolution so that you can listen to the effect they have on audio quality. With an Arduino and this simple shield, we can sample audio and manipulate the signal in many different ways.

Sampling rate is how often we measure the input voltage of an audio signal. The more often we measure it, the more faithfully we can reproduce the signal. According to the Nyquist Sampling Theorem, to reproduce a signal with frequency f, we must sample at a rate of 2f. So higher sample rates will allow us to reproduce higher frequencies and have less noise in the signal.

Bit resolution, or audio bit depth, refers to how accurately we measure the input voltage. A resolution of 8 bits means that each measurement has 8 bits of precision, giving us values in the range of 0-255. A resolution of 12 bits is more accurate and gives us values in the range 0-4095.

CD quality audio is 44.1 kHz sample rate with 16 bits of resolution. The Audio Hacker ADC (analog to digital converter) and DAC (digital to analog converter) are only capable of 12-bit resolution.

But how do these parameters affect the quality of audio? You can listen for yourself by connecting two potentiometers to the Arduino+Audio Hacker shield so we can adjust the sample rate and bit resolution while we are listening to an audio signal!

Load the Audio Hacker example sketch File->Examples->Audio Hacker->DynamicSampleRate onto your Arduino. Connect two potentiometers to pins A0 and A1. If you are unsure how to wire it, see analog input tutorial. A0 will control the sample rate and A1 will control the bit resolution. Set the pots both to their highest values and open the Arduino serial monitor (rate=115200) so you can see the output of the program. Play an audio signal into your Audio Hacker (e.g. from an MP3 player or from your music library on your computer). Now adjust the sampling rate downward until you hear the quality start to suffer. At what sample rate does it seem to start introducing noise? What does the noise sound like?

Now use the second potentiometer to adjust the resolution down from 12 bits to 11, then 10, then lower. Can you tell the difference between 12 bit resolution and 10 bit resolution? How about 8 bit resolution? Lowering the bandwidth of the signal is called “bitcrushing”. What happens when you crush it all the way down to 1-bit resolution? You might be surprised at how intelligible speech can be even with one bit of resolution!

This experiment isn’t a perfect test for sampling rate because there is a low pass filter on the input, so you may not hear much difference in audio quality as the sampling rate goes above 30 kHz. This project is good for hearing how things degrade at lower sampling rates and bit resolutions.

Now, which do you think is more important for audio quality: sample rate or bit resolution?

Full info about the Audio Hacker is here.

For lots more great Audio Hacker experiments, see the Audio Hacker project page.

The Audio Hacker is available as a kit or fully assembled in the nootropic design store.

Published by Michael, on July 5th, 2013 at 6:10 am. Filed under: Audio. | No Comments |

Battery Backup for Audio Hacker Samples

When you record audio samples to the serial SRAM on the Audio Hacker, the data will be lost when power is disconnected. However, the Audio Hacker uses SRAM chips that allow a small voltage to maintain their contents. The Audio Hacker board has pads where you can connect a small battery.


A 3V coin cell battery (like a CR2032) is sufficient to maintain the contents of the memory:


Now you can disconnect power without losing your awesome samples. There is one problem though: your sampling program on the Arduino was probably keeping track of which memory address your sample began/ended at, so now your program has “forgotten” where the sample boundaries are. One way to fix that is to write your sample address information to a header in SRAM. Another easy approach is to store the address info in the Arduino’s EEPROM. There is code in the Four Sample 12-bit Sampler project, as well as the 3-Track Looper project. These sketches store each sample’s end address in EEPROM whenever a sample is recorded. At sketch startup, these addresses are read from EEPROM. The code is simple, so just look for lines that use the EEPROM library.

Published by Michael, on July 5th, 2013 at 6:09 am. Filed under: Audio. | No Comments |

Playing Audio Hacker Samples in Reverse

This simple example project is the same as the 12-bit Sampler, but the audio sample is played in reverse. In the Arduino menu, choose File->Examples->Audio Hacker->SamplerReverse. Record your audio sample with button S1 on the Audio Hacker (top button), and play it back in reverse using the S2 button. Just as with the 12-bit Sampler, you can connect a potentiometer to A0 to adjust the playback speed. If you are unsure how to wire the potentiometer, see analog input tutorial. To enable this feature, make a minor code change to set adjustablePlaybackSpeed = true;. Arduino will prompt you to save your changed sketch to another location.

Published by Michael, on July 5th, 2013 at 6:08 am. Filed under: Audio. | No Comments |

Connecting an Electret Microphone to the Audio Hacker

I like to use my computer’s microphone and audio output when I want to record my voice in the Audio Hacker, but you can also connect an electret microphone using a simple circuit. An electret microphone is handy for applications where you don’t want a computer. Electret microphones have polarity, so make sure you connect the positive/negative leads correctly in the circuit.


Since the output of the microphone is very weak, turn up the preamp gain on the Audio Hacker shield until you are happy with the level (probably all the way up!). The preamp provides up to 100X gain. Connect the microphone’s positive lead to one of the input pads. It doesn’t matter if you pick ‘L’ or ‘R’, or connect the microphone to both.


Another approach is to use this handy microphone breakout board from Sparkfun. It includes a 100X amp so you don’t need to amplify its signal with the Audio Hacker preamp.

Published by Michael, on July 5th, 2013 at 6:07 am. Filed under: Audio. | No Comments |