Looper device

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Giovanni1982
 
Posts: 16
Joined: Thu Jun 03, 2021 7:48 pm

Looper device

Post by Giovanni1982 »

Hello, I have been thinking about putting together a little recording device/looper. I got the idea from existing products out there, but I wanted to make one myself for my kids. It needs a microphone, a built in speaker, battery power and a few buttons and knobs to start/stop recording and adjust the playback speed and maybe add some digital effects if possible. Looking around on the store, I found this mic breakout board: https://www.adafruit.com/product/3421 and this mono amp: https://www.adafruit.com/product/2130 which I think would work with any Feather boards. Plus there are several speaker, battery, buttons and knobs choices available.
I assume my plan should work, but I’m wondering which Feather board would work best for this. I don’t need the looper to have a ton of available recording space and it doesn’t need to persist the audio after it shuts off. I would prefer C/C++ since it’s the language I’m most familiar with (I use it for work).
Any suggestions will be appreciated!

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Looper device

Post by adafruit_support_mike »

The Feather M4 should work for that:

https://www.adafruit.com/product/3857

It can handle I2S input and can produce audio output. It also runs CircuitPython, which has features for recording and playing back audio.

You might also want to look at the Teensy, which has an impressive collection of audio tools:

https://www.adafruit.com/?q=Teensy&sort=BestMatch
https://www.pjrc.com/teensy/td_libs_Audio.html

User avatar
Giovanni1982
 
Posts: 16
Joined: Thu Jun 03, 2021 7:48 pm

Re: Looper device

Post by Giovanni1982 »

Thank you for the suggestion. For my own understanding, how can I navigate the different options? Is there a comparison chart or something? I see so many variations on the site and it’s a bit overwhelming. Granted, I’m relatively new to this stuff (I have an Arduino Uno that I got years ago but never did much with it).
Thank you!

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Looper device

Post by adafruit_support_mike »

Giovanni1982 wrote:For my own understanding, how can I navigate the different options? Is there a comparison chart or something?
No, that's something you have to build for each project.

Every project starts with a wish list: the set of things it would do if there were no limits on what's possible. From those, you make two lists: one of measureable properties an acceptable solution has to meet, called the 'requirements', and one of devices that look like they could provide some collection of features from the wish list, called the 'candidate solutions'.

The candidate solutions will have things they need, like power, physical space, signal connections, and cost. For any candidate you include in the project, you have to add those things to the list of requirements.

In most cases, you'll end up with something impossible. That's when the design process starts: making tradeoffs to bring your wish list, requirements, and candidate solutions together until you have something physically possible.

Along the way, you develop a more detailed understanding of what you want the final solution to do. That often leads you to candidates you wouldn't have considered at first.

Eventually you end up choosing a specific group of candidates to build. And in most cases, actually using that system gives you new ideas for things to do next time.

Every project has a different wish list, and evolves a different set of requirements. Two designers starting from the same wish list will probably choose different candidates and wind up with different final solutions. You never have complete information, and the set of available candidates changes over time. Trying to find every possible candidate is a trap that leads to never building anything, so it's more effective to use the information you have at the time and keep iterating.

User avatar
Giovanni1982
 
Posts: 16
Joined: Thu Jun 03, 2021 7:48 pm

Re: Looper device

Post by Giovanni1982 »

Maybe a better question then is how did you decide to recommend that particular board? :)
I found one of the articles explaining the differences between various boards and it now makes a lot more sense to me. Thank you again!

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Looper device

Post by adafruit_support_mike »

In this case, it's a matter of throwing hardware at a problem to get ease of use.

The SAMD51 is a fast microcontroller with hardware support for floating-point math a DAC for analog output voltage. Both of those features make it good for audio processing. It can run CircuitPython, which is a popular language for beginners and has existing code to support audio.

The Teensy series of dev boards are even more powerful, and the Teensy audio library is incredibly good. The code is written in C++ though, and is a better fit for more experienced programmers.

The other microcontrollers with as much number crunching power as the SAMD51 are mostly System-on-Chip devices (SoCs) that devote processing resources to things like Bluetooth and Wifi.

You can do audio processing with microcontrollers less powerful than the SAMD51, but you're more likely to run into hardware limits while you do. Working around those limits requires more theoretical background in signal processing and programming.

User avatar
Giovanni1982
 
Posts: 16
Joined: Thu Jun 03, 2021 7:48 pm

Re: Looper device

Post by Giovanni1982 »

Got the Feather M4 and trying to get the I2S MEMS mic breakout board to work now (got the amp/speaker to work already). My code is failing at this line:

Code: Select all

mic = audiobusio.PDMIn(clock_pin=board.TX, data_pin=board.D11, sample_rate=16000, bit_depth=16, mono=True, startup_delay=0.5)
Where I get the error:

Code: Select all

ValueError: Invalid data pin
I was under the impression the D11 is the I2S data pin for the Feather M4 (per https://learn.adafruit.com/adafruit-fea ... 51/pinouts), is that not the case?

Thank you!

User avatar
Giovanni1982
 
Posts: 16
Joined: Thu Jun 03, 2021 7:48 pm

Re: Looper device

Post by Giovanni1982 »

Answering my own question: found the CircuitPython example for the mic today (not sure why I couldn’t find it yesterday) and it uses D12 instead of D11. I’m still confused why it doesn’t work over I2S? Is that just for output?

User avatar
Giovanni1982
 
Posts: 16
Joined: Thu Jun 03, 2021 7:48 pm

Re: Looper device

Post by Giovanni1982 »

I managed to get the M4 set up to record and play back.

Connections:

Speaker breakout:

Code: Select all

A+ -> Feather A0
A- -> ground
Mic breakout:

Code: Select all

BCLK -> Feather TX
DOUT -> Feather D12
And the code below works:

Code: Select all

import time
import array
import math
import board
import digitalio
import audiobusio
from audiocore import RawSample

try:
    from audioio import AudioOut
except ImportError:
    try:
        from audiopwmio import PWMAudioOut as AudioOut
    except ImportError:
        pass  # not always supported by every board!

audio = AudioOut(board.A0)
recording_rate = 16000
num_samples = 24000
mic = audiobusio.PDMIn(clock_pin=board.TX, data_pin=board.D12, sample_rate=recording_rate, bit_depth=16, mono=True, startup_delay=0.5)
samples = array.array('H', [0] * num_samples)

while True:
    print("Recording...")
    mic.record(samples, len(samples))
    time.sleep(1.1)
    print("Playing...")
    audio.play(RawSample(samples, sample_rate = recording_rate), loop=False)
    time.sleep(2)
    audio.stop()
    time.sleep(1)
Besides the fact that I am unable to allocate more memory than 24K in the array (32K fails), the setup seems to work.

However, the recorded sound is extremely noisy, with white noise drowning the recorded sound, for the most part (I can hear it if very loud, but still drowned in noise). Unfortunately the breakout is mounted on the breadboard with the mic facing down (that's how I soldered the headers), so that could be part of the problem, but I wonder if there's anything I did wrong in my setup?

User avatar
Giovanni1982
 
Posts: 16
Joined: Thu Jun 03, 2021 7:48 pm

Re: Looper device

Post by Giovanni1982 »

I tried my setup again, using jumper cables so I could talk directly into the mic. Now I am getting no input from the mic at all. I verified that the speaker works properly by playing a tone right before it's supposed to play back the audio recorded by the mic. Here's a pic of my breadboard setup.

Here's the code I have right now:

Code: Select all

import time
import array
import math
import board
import digitalio
import audiobusio
from audiocore import RawSample

try:
    from audioio import AudioOut
except ImportError:
    try:
        from audiopwmio import PWMAudioOut as AudioOut
    except ImportError:
        pass  # not always supported by every board!

audio = AudioOut(board.A0)
tone_volume = 0.1  # Increase this to increase the volume of the tone.
frequency = 440  # Set this to the Hz of the tone you want to generate.
length = 8000 // frequency
sine_wave = array.array("H", [0] * length)
for i in range(length):
    sine_wave[i] = int((1 + math.sin(math.pi * 2 * i / length)) * tone_volume * (2 ** 15 - 1))
sine_wave_sample = RawSample(sine_wave)

recording_rate = 16000
num_samples = 24000
mic = audiobusio.PDMIn(clock_pin=board.TX, data_pin=board.D12, sample_rate=recording_rate, bit_depth=16, mono=True, startup_delay=1)
samples = array.array('H', [0] * num_samples)

while True:
    print("Recording...")
    mic.record(samples, len(samples))
    time.sleep(1.1)
    print((samples[:10],))
    print("Playing...")
    audio.play(sine_wave_sample, loop=True)
    time.sleep(0.2)
    audio.stop()
    audio.play(RawSample(samples, sample_rate = recording_rate), loop=False)
    time.sleep(2)
    audio.stop()
    time.sleep(1)
and serial output example:

Code: Select all

(array('H', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),)
Playing...
Recording...
(array('H', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),)
Playing...
Recording...
(array('H', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),)
Playing...
Recording...
(array('H', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),)
Playing...
Recording...
(array('H', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),)
Playing...
Recording...
(array('H', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),)
Playing...
Recording...
(array('H', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),)
Playing...
Recording...
(array('H', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),)
Playing...
Recording...
(array('H', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),)
I am concerned that the mic board may be defective. Any way for me to verify?
Thank you!

User avatar
Giovanni1982
 
Posts: 16
Joined: Thu Jun 03, 2021 7:48 pm

Re: Looper device

Post by Giovanni1982 »

Any help on this please?

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”