Code Monkey home page Code Monkey logo

microphone-library-for-pico's People

Contributors

ep1cman avatar sandeepmistry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

microphone-library-for-pico's Issues

Examples refuse to compile

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

What is the maximum sample-rate?

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

Microphone does not work on Windows 10

I appreciated your work, but I have several questions about this project.

  1. Is it correct to change sample rate in this line of code?(for example 16 for 16khz, 48 for 48 kHz)
  2. On my windows computer, the USB microphone only works when the sample rate is 16kHz, I tried many other parameters(32 40 48 80 etc.), but none of them work properly. (Although the microphone seem to be working with these parameters on Ubuntu.)
    I check the error message from Audacity , and it is

{ "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?

for examples/usb_microphone, set Gain to 1 to lower the background noise.

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...

pdm_mic.filter.Fs = config->sample_rate;
pdm_mic.filter.LP_HZ = config->sample_rate / 2;
pdm_mic.filter.HP_HZ = 10;
pdm_mic.filter.In_MicChannels = 1;
pdm_mic.filter.Out_MicChannels = 1;
pdm_mic.filter.Decimation = PDM_DECIMATION;
pdm_mic.filter.MaxVolume = 64;
pdm_mic.filter.Gain = 16;

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.

* a picture of my microphone
photo_2022-08-04_00-09-25

No sound, and not sure what to try

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!

Error on cmake command

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".

Use Micropython With microphone library

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))

Multichannel Analog USB Microphone

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:

  1. Received the same signal across different channels. [I expected it to show different signals from different channels because they are using different ADC pins]
  2. Even if I did not initialize a ADC pin, for example, GPIO26 from rp2040, i could still get the signal from that pin regardless. And this also has the issue I described above issue 1. [I expected it to not be able to read from GPIO26 because I did not initialize that pin to read from]

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!

when is on_usb_microphone_tx_ready() called?

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?

Filtering for PDM Mic

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!

Can it work with?

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

Audio samples being skipped while recording using analog microphone

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

Sample rate lower than 16000 may cause some PDM microphone to stop outputting data

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.

Compile errors: not compatible with TinyUSB 0.10?

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!

Fail to run PDM example

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?

Device cannot start error on Windows 10

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.

  • MicNode does appear under "Sound, video and game devices" in Device Manager, but with a yellow triangle icon (apparently indicating that the device failed to start)
  • right-clicking on MicNode in Device Manager shows device status as "This device cannot start. (Code 10) The specified range could not be found in the range list."

Any advice would be much appreciated.
Thank you

Reading raw PDM data

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!

Support mic array?

Is it possible to support multiple PDM microphone and as USB microphone?

Changing the sample rate

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?

Reducing Gain of the Microphone

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!!

Using with Arduino

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?

Background low-frequency, fluctuating tone in recordings

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

Can I just change the sampling rate?

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.