armdeveloperecosystem / microphone-library-for-pico Goto Github PK
View Code? Open in Web Editor NEWCapture audio from a microphone on your Raspberry Pi Pico or any RP2040 based board. ๐ค
License: Apache License 2.0
Capture audio from a microphone on your Raspberry Pi Pico or any RP2040 based board. ๐ค
License: Apache License 2.0
what is the correct setting for MP34DT05 at Arduino RP2040 Connect?
Pin Data:22,Clk:23 not running.
Microphone 20000Hz?
Thanks.
For some reason the examples don't compile on my computer... It can't find "pico/pdm_microphone.h" even though the library is linked in the cmakelists.txt file... Can you help me please?
/home/ontake/Downloads/pTuna/Firmware/microphone-library-for-pico/examples/usb_microphone/main.c:15:10: fatal error: pico/pdm_microphone.h: No such file or directory
15 | #include "pico/pdm_microphone.h"
| ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/usb_microphone.dir/build.make:76: CMakeFiles/usb_microphone.dir/main.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1328: CMakeFiles/usb_microphone.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
Assuming the PDM-mic is capaple of doing this: What is the maximum audio sample rate for the Pi pico 2040 and this library? Are 192KHz or even 384KHz possible?
Kind regards
I appreciated your work, but I have several questions about this project.
{ "timestamp": 1675922013, "event_id": "de2968e644af2446aafc55d7a0425be4", "platform": "native", "release": "[email protected]", "contexts": { "os": { "type": "os", "name": "Windows", "version": "10.0.19044" } }, "exception": { "values": [ { "type": "Error", "value": "Error opening recording device.\nError code: -9999 Unanticipated host error.", "mechanism": { "type": "runtime_error", "handled": false } } ] } }
I tried to reinstall sound driver mention in this issue, but it does not work. Could you help me to solve this?
Thanks to this project, make me able to make my own microphone with excellent sound quality without having to write code.
At first time, I tested many microphones, SPK0838HT4H has ~ -45dB background noise, MSM26D4040H11 has ~ -35dB, MSM261D4030H1C has ~ 33dB. I checked the DCDC power supply. and ask the resellers why those microphones have so much noise but no useful result
when I decide to port RNNoise to PI2040, I want to add a simple -25dB suppressor first. then I find this...
microphone-library-for-pico/src/pdm_microphone.c
Lines 96 to 103 in a837f63
after add pdm_microphone_set_filter_gain(1);
to the main function in examples/usb_microphone/main.c
all microphones works perfect with < -90dB noise.
So please consider changing the default gain to 1.
I believe I have followed the instructions for the analog mic and then installed the usb example. I could not find the hello_analog_microphone example source to see what it is meant to do. After building and transferring the uf2 file for usb_microphone, unpluging it, and plugging it into the pi4 on my desk in place of the commercial usb mic, it appears under lsusb as "cafe 4010" but when I record a wav file with arecord, I hear (using aplay) a click, but nothing else. I have grepped the code for "cafe" and "4010" to no effect but expect the code is designed to give a slightly more informative usb device description?
issue 1) where is hello_analog_micrphone source and what is it meant to do? I am guessing it tests the mic without going via usb.
2) what should we expect from lsusb?
3) and (of course) it doesn't work as expected on the pi 4!
2 mic => stereo...
How many reworks will it take to make the sound stereo?
I receive an error when compiling ๐ there is no Cmakelists.txt for the source file
cmake .. -DPICO_BOARD=pico
PICO_SDK_PATH is /home/pi/pico-sdk
PICO platform is rp2040.
Build type is Release
PICO target board is pico.
Using board configuration from /home/pi/pico-sdk/src/boards/include/boards/pico.h
TinyUSB available at /home/pi/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040; enabling build support for USB.
BTstack available at /home/pi/pico-sdk/lib/btstack
cyw43-driver available at /home/pi/pico-sdk/lib/cyw43-driver
Pico W Bluetooth build support available.
lwIP available at /home/pi/pico-sdk/lib/lwip
mbedtls available at /home/pi/pico-sdk/lib/mbedtls
CMake Error at CMakeLists.txt:44 (add_subdirectory):
add_subdirectory given source "examples/hello_analog_microphone" which is
not an existing directory.
CMake Error at CMakeLists.txt:45 (add_subdirectory):
add_subdirectory given source "examples/hello_pdm_microphone" which is not
an existing directory.
CMake Error at CMakeLists.txt:46 (add_subdirectory):
add_subdirectory given source "examples/usb_microphone" which is not an
existing directory.
-- Configuring incomplete, errors occurred!
See also "/home/pi/build/CMakeFiles/CMakeOutput.log".
Every time you compile your project you also compile all of the examples.
Hi. How can i use micropython firmware alongside a Max9814 , with this module?
Any Solutions?
I have written the code below but cant hear clear voice in audacity...
from machine import Pin, ADC
import ustruct , time
analog_value = machine.ADC(26)
conversion_factor =3.3/(65536)
samples = []
while True:
reading = analog_value.read_u16()*conversion_factor
samples.append(int(reading)) #print("ADC: ",reading)
time.sleep(0.002)
with open('Voice.bin', 'wb') as output:
for sample in samples:
output.write(struct.pack('<h', sample))
I followed CaydenPierce's four channel PDM usb microphone array format from: https://github.com/CaydenPierce/MSA to create a similar firmware that use Analog microphones instead of PDM microphones.
The board I was using is waveshare_rp2040_lcd_1.28.
I was able to get signals from the ADC pins and receive four channel audio data on my machine via USB.
However, I encountered some issues:
Could anyone provide some feedback on this? It might due to my implementation is wrong but if someone can point me in the right direction, that would be very helpful.
Thanks in advance!
In /examples/usb_microphone/main.c there is a sample_buffer of 256 int16_t that I assume gets passed to the usb tx process with the above call. I was expecting it to get called when the other end of the usb serial connection ran out of data - so about 16000/256 times a second? I have tried using a for loop to fill the sample buffer with rubbish on each call but the usb microphone locks. That is, arecord -d 3 test.wav does not terminate until the usb something or other times out. Can anyone tell me what I am missing here?
Hello,
I would really appreciate if you explained the filtering that is implemented for the PDM microphone. Should I be concerned at all about aliasing when using the PDM microphone for an audio classification task with potential sounds above 8kHz? Thanks!
So Actually I'm trying to create a "Sound card" for my Electric Guitar but it didn't work with this Elektret microphone aka. Sound sensor? isn't it compatible or do I need do something I would use PDM but this sort of microphone modules are much easier to replace or solder on it
I don't get any soundwave on audacity just a straight line
I made the following changes to the main.c file in the hello_analog_microphone sample
/*
* Copyright (c) 2021 Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
*
* This examples captures data from an analog microphone using a sample
* rate of 8 kHz and prints the sample values over the USB serial
* connection.
*/
#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/analog_microphone.h"
#include "tusb.h"
#define AUDIO_SAMPLE_RATE 8000
#define RECORD_LENGTH_S 10
// configuration
const struct analog_microphone_config config = {
// GPIO to use for input, must be ADC compatible (GPIO 26 - 28)
.gpio = 26,
// bias voltage of microphone in volts
.bias_voltage = 0.0,
// sample rate in Hz
// .sample_rate = 8000,
.sample_rate = AUDIO_SAMPLE_RATE,
// number of samples to buffer
.sample_buffer_size = 256,
};
// variables
int16_t sample_buffer[256];
volatile int samples_read = 0;
int16_t full_record[AUDIO_SAMPLE_RATE * RECORD_LENGTH_S];
int full_record_INDEX = 0;
void on_analog_samples_ready()
{
// callback from library when all the samples in the library
// internal sample buffer are ready for reading
samples_read = analog_microphone_read(sample_buffer, 256);
}
int main( void )
{
bool break_while = false;
// initialize stdio and wait for USB CDC connect
stdio_init_all();
while (!tud_cdc_connected()) {
tight_loop_contents();
}
printf("hello analog microphone\n");
// initialize the analog microphone
if (analog_microphone_init(&config) < 0) {
printf("analog microphone initialization failed!\n");
while (1) { tight_loop_contents(); }
}
// set callback that is called when all the samples in the library
// internal sample buffer are ready for reading
analog_microphone_set_samples_ready_handler(on_analog_samples_ready);
// start capturing data from the analog microphone
if (analog_microphone_start() < 0) {
printf("PDM microphone start failed!\n");
while (1) { tight_loop_contents(); }
}
printf("record audio\n");
while (1) {
// store and clear the samples read from the callback
int sample_count = samples_read;
samples_read = 0;
// loop through any new collected samples
for (int i = 0; i < sample_count; i++) {
// printf("%d\n", sample_buffer[i]);
full_record[full_record_INDEX++] = sample_buffer[i];
if(full_record_INDEX >= AUDIO_SAMPLE_RATE*RECORD_LENGTH_S){
break_while = true;
break; // break inner for loop in case this does not happen at end of loop
// at this point AUDIO_SAMPLE_RATE*RECORD_LENGTH_S number of sample should be available in memory
}
}
if(break_while == true) break; // break the while() loop if this happens
}
printf("Recording complete, stop mic\n");
analog_microphone_stop();
analog_microphone_deinit();
printf("Sending recorded data to serial\n");
// send the AUDIO_SAMPLE_RATE*RECORD_LENGTH_S number of audio samples to USB serial
for (int i = 0; i < AUDIO_SAMPLE_RATE*RECORD_LENGTH_S; i++) {
printf("%d: %d\n",i, full_record[i]);
sleep_ms(2);
}
printf("dummy loop --- \n");
while(1){
}
return 0;
}
I am using a different analog microphone, not the one suggested in this example. Note that I have changed
.bias_voltage = 0.0,
I am recording 10 seconds of audio at 8000 Hz entirely in memory, then sending all the recorded audio samples to USB serial port, where I display all the data in putty as well as save as putty log file. I use this log file to regenerate audio in the PC.
If I play back the audio samples in matlab the sound is very fast (only high speed, not high pitch), and sounds as though some audio samples are being skipped. Since the number of audio samples matches what I expect, it seems the skipping is happening at the ADC itself. Could you please give me some hints on how to fix this?
I have uploaded a sample of my recording here: https://soundcloud.com/user-202091011/pico-mic-rec-01-samsung-galaxy-s7-over-the-horizon-2016
The sound volume is a bit low but my main problem is the speed of the playback and the audio frames being skipped
The original sound is Samsung galaxy s7 over the horizon (2016): https://www.youtube.com/watch?v=SyJyB2niF3s
The output frequency of the clk pin is calculated by the sample rate, and some PDM microphone has a limited frequency range for clock speed (Like MP34Dxxx has a clock rate limit from1 to 3.25 MHz), which causes the sample rate below 16000(Corresponding to the clk frequency of 1.024MHz) to sometimes fail to make the microphone work.
Hi,
When building the project I get a lot of errors related to TinyUSB -- see below.
Version 1.2 of the Pico SDK updated TinyUSB from 0.8.0 to 0.10.1, and the release notes mention:
"Note also that moving from TinyUSB 0.8.0 to TinyUSB 0.10.1 may require some minor changes to your USB code."
I'm guessing that these errors are caused by the TinyUSB update, and changes are required tusb_config.h and usb_descriptors.c -- perhaps main.c as well. I noticed that the TinyUSB audio_test example has quite a few changes to these files.
Can someone please confirm that this project isn't compatible with TinyUSB 0.10.1?
Thanks,
Dan
Errors from build of usb_microphone:
[ 69%] Building C object examples/usb_microphone/CMakeFiles/usb_microphone.dir/main.c.obj
In file included from C:\Users\gigam\Pico\pico-sdk\lib\tinyusb\src/tusb.h:80,
from C:\Users\gigam\source\repos\pico\pico-microphone-v1\examples\usb_microphone\usb_microphone.h:11,
from C:\Users\gigam\source\repos\pico\pico-microphone-v1\examples\usb_microphone\main.c:17:
C:\Users\gigam\Pico\pico-sdk\lib\tinyusb\src/class/audio/audio_device.h:40:2: error: #error You must tell the driver the length of the audio function descriptor including IAD descriptor
40 | #error You must tell the driver the length of the audio function descriptor including IAD descriptor
| ^~~~~
In file included from C:\Users\gigam\Pico\pico-sdk\lib\tinyusb\src/tusb.h:80,
from C:\Users\gigam\source\repos\pico\pico-microphone-v1\examples\usb_microphone\usb_microphone.h:11,
from C:\Users\gigam\source\repos\pico\pico-microphone-v1\examples\usb_microphone\main.c:17:
C:\Users\gigam\Pico\pico-sdk\lib\tinyusb\src/class/audio/audio_device.h:55:2: error: #error You must tell the driver the number of Standard AS Interface Descriptors you have defined in the audio function descriptor!
55 | #error You must tell the driver the number of Standard AS Interface Descriptors you have defined in the audio function descriptor!
| ^~~~~
C:\Users\gigam\Pico\pico-sdk\lib\tinyusb\src/class/audio/audio_device.h:70:2: error: #error You must define an audio class control request buffer size!
70 | #error You must define an audio class control request buffer size!
Thanks for your great work. While I fall in trouble running the PDM example. I've examined the GPIO output and found the CLK output nothing.
And I tried the official pico-examples/clocks/hello_gpout, it works with GPIO 21 output rectangular wave. Other official examples' codes also work well.
Could you please help me?
Hi,
thank you for the sample code. I tried it on Ubuntu 18.04 and Windows. While Ubuntu 18.04 finds MicNode and shows it in Audacity, the device fails to start in Windows 10.
Any advice would be much appreciated.
Thank you
Hi,
Is it possible to output the raw PDM data directly to the serial monitor using these examples? I would like to implement my own filter on the incoming PDM signal in post processing, but I'm not proficient in C so struggling a bit to get the raw data easily.
Thanks!
Is it possible to support multiple PDM microphone and as USB microphone?
Hi,
I tried to change the sample rate without success (tested only in windows 10).
I only changed tusb_config.h to:
#define CFG_TUD_AUDIO_EP_SZ_IN (48+1) * CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX * CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX // 16 Samples (16 kHz) x 2 Bytes/Sample x 1 Channel
and usb_microphone.h :
#define SAMPLE_RATE 48000
any ideas what else need to be modified?
Hi, I was trying to record some audio using the same microphone setup as you instructed. It was a loud audio and for the same reason clipping was observed when the recording was analyzed. I tried to change the "Filter Gain" and "Volume" parameters to reduce the gain but didn't work. It would be great to have some lead on reducing the input gain. Thanks!!
Hey there,
I have been in the midst of (and in over my head with) a project to record voice messages via a handheld, battery-powered device. I designed and built it around the RP2040 and the Adafruit PDM microphone breakout board. I have been attempting to get decent, functional audio out of it via CircuitPython and failing. I came across your USB microphone project and the audio generated sounds great.
I am not a C developer, nor do I have any experience with hardware. Is there an easy way to incorporate this microphone library with, say, an Arduino project?
Hi,
thank you for the sample code. Microphone sound capture works, but there it comes with background low-frequency tone that fluctuates (on/off a few times per second). I've attached a WAV recording - the fluctuating background tone is easy to hear at the end of the recording.
Also, it appears that the audio has some breaks in it (i.e. sound gets missing momentarily).
untitled.wav.zip
Any help would be much appreciated.
Thank you
With the similar set up using SparkFun MicroMod Machine Learning Carrier Board, I wonder if I can just change the default 8000 Hz in examples/hello_pdm_microphone/main.c to 16000 Hz directly?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.