Microphone_PDM
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
Microphone_PDM_Base Class Reference

#include <Microphone_PDM.h>

Inheritance diagram for Microphone_PDM_Base:
Microphone_PDM_RTL872x Microphone_PDM_nRF52 Microphone_PDM_MCU Microphone_PDM_MCU Microphone_PDM Microphone_PDM

Public Types

enum class  OutputSize { UNSIGNED_8 , SIGNED_16 , RAW_SIGNED_16 }
 
enum class  Range {
  RANGE_128 = 0 , RANGE_256 , RANGE_512 , RANGE_1024 ,
  RANGE_2048 , RANGE_4096 , RANGE_8192 , RANGE_16384 ,
  RANGE_32768
}
 

Public Member Functions

int getSampleRate () const
 

Protected Member Functions

 Microphone_PDM_Base (size_t numSamples)
 
virtual ~Microphone_PDM_Base ()
 
void copySamplesInternal (const int16_t *src, uint8_t *dst) const
 
virtual size_t copySrcIncrement () const
 

Protected Attributes

pin_t clkPin = A0
 
pin_t datPin = A1
 
bool stereoMode = false
 
int sampleRate
 
OutputSize outputSize = OutputSize::SIGNED_16
 
Range range = Range::RANGE_2048
 
size_t numSamples
 

Detailed Description

Class used for settings. You will not instantiate one of these; it's a base class of Microphone_PDM_MCU.

There are accessor methods for setting these settings in the Microphone_PDM class.

Member Enumeration Documentation

◆ OutputSize

Configuration for the size of the output data.

Enumerator
UNSIGNED_8 

Output unsigned 8-bit values (adjusted by PDMRange)

SIGNED_16 

Output signed 16-bit values (adjusted by PDMRange) (default)

RAW_SIGNED_16 

Output values as signed 16-bit values as returned by MCU (unadjusted)

◆ Range

enum class Microphone_PDM_Base::Range
strong

Adjustment value so samples fill most of an 8 or 16 bit output size.

The setting is dependent on your microphone. The Adafruit microphone is 12-bit, so the default value of RANGE_2048 is correct.

Enumerator
RANGE_128 

From -128 to 127 (8 bits)

RANGE_256 

From -256 to 255 (9 bits)

RANGE_512 

From -512 to 511 (10 bits)

RANGE_1024 

From -1024 to 1023 (11 bits)

RANGE_2048 

From -2048 to 2047 (12 bits) (default)

RANGE_4096 

From -4096 to 4095 (13 bits)

RANGE_8192 

From -8192 to 8191 (14 bits)

RANGE_16384 

From -16384 to 16383 (15 bits)

RANGE_32768 

From -32768 to 32767 (16 bits) (same as raw mode)

Constructor & Destructor Documentation

◆ Microphone_PDM_Base()

Microphone_PDM_Base::Microphone_PDM_Base ( size_t  numSamples)
inlineprotected

You cannot instantiate one of these, it's only done by the subclass, which is a Microphone_PDM_* MCU-specific class.

Parameters
numSamplesThe value of BUFFER_SIZE_SAMPLES defined in the MCU-specific subclass

Member Function Documentation

◆ copySamplesInternal()

void Microphone_PDM_Base::copySamplesInternal ( const int16_t *  src,
uint8_t *  dst 
) const
protected

Used internally. Use copySamples() externally.

Parameters
srcPointer to the internal DMA buffer, which is always 16-bit samples
dstPointer to the destination buffer, which will be 8 or 16-bit samples, depending on outputSize

Also pays attention to range to determine how much to shift the samples, unless the output size is RAW_SIGNED_16, which does not do any transformation.

src and dst can be the same buffer to transform the data range in place.

◆ copySrcIncrement()

virtual size_t Microphone_PDM_Base::copySrcIncrement ( ) const
inlineprotectedvirtual

How much to increment src in copySamplesInternal. Used internally.

Returns
size_t number of bytes

This is almost always 1. The exception is if you are using 8000 Hz sampling on the nRF52. In this case, every other sample is skipped and the subclass overrides this to return 2.

Reimplemented in Microphone_PDM_nRF52.

◆ getSampleRate()

int Microphone_PDM_Base::getSampleRate ( ) const
inline

Return the sample rate (16000 or 32000) in samples per second.

Returns
int

The documentation for this class was generated from the following files: