Microphone Array
Device Compatibility
Overview
The microphone array interface supports:
- Accepting input from individual microphones
- Accepting input from beamformed microphone
References
Below is the overview of the microphone array implementation. Code examples can be found here.
These header files are required to use the microphone array.
// Interfaces with microphone array #include "matrix_hal/microphone_array.h" // Enables using FIR filter with microphone array #include "matrix_hal/microphone_core.h" // Communicates with MATRIX device #include "matrix_hal/matrixio_bus.h"
MicrophoneArray
MicrophoneArray
is a required object that contains functions to interface with the microphone array.
// Create MicrophoneArray object matrix_hal::MicrophoneArray microphone_array;
The functions below are part of MicrophoneArray
.
.Setup
Setup
is a function that takes a MatrixIOBus
object as a parameter and sets that object as the bus to use for communicating with MATRIX device.
// Function declaration in header file void Setup(MatrixIOBus *bus);
// Set microphone_array to use MatrixIOBus bus microphone_array.Setup(&bus);
.Read
Read
is a function that outputs microphone array data to the delayed_data_
array and the beamformed_
array in the MicrophoneArray
object.
// Function declaration in header file bool Read();
// Reading 8-mics buffer from the FPGA microphone_array.Read();
.SamplingRate
SamplingRate
is a function that returns the sampling_frequency_
value in the MicrophoneArray
object.
// Function declaration in header file uint32_t SamplingRate() { return sampling_frequency_; }
// Return the stored sampling rate uint32_t SamplingRate = microphone_array.SamplingRate();
.Gain
Gain
is a function that returns the gain_
value in the MicrophoneArray
object.
// Function declaration in header file uint16_t Gain() { return gain_; }
// Return the stored gain uint32_t Gain = microphone_array.Gain();
.SetSamplingRate
SetSamplingRate
is a function that sets the sampling_frequency_
value in the MicrophoneArray
object and sends it to the microphone array.
// Function declaration in header file bool SetSamplingRate(uint32_t sampling_frequency);
// Set the sampling rate microphone_array.SetSamplingRate(sampling_rate);
.SetGain
SetGain
is a function that sets the gain_
value in the MicrophoneArray
object and sends it to the microphone array.
// Function declaration in header file bool SetGain(uint16_t gain);
// Set the gain microphone_array.SetGain(gain);
.GetSamplingRate
GetSamplingRate
is a function that gets the sampling rate value from the microphone array and saves it in the MicrophoneArray
object as value sampling_frequency_
.
// Function declaration in header file bool GetSamplingRate();
// Update sampling_frequency_ from microphone array microphone_array.GetSamplingRate();
.GetGain
GetGain
is a function that gets the gain value from the microphone array and saves it in the MicrophoneArray
object as value gain_
.
// Function declaration in header file bool GetGain();
// Update gain_ from microphone array microphone_array.GetGain();
.ReadConfValues
ReadConfValues
is a function that runs both the GetGain
and GetSamplingRate
functions.
This updates the gain_
and the sampling_frequency_
values in the MicrophoneArray
object with values from the microphone array.
// Function declaration in header file void ReadConfValues();
// Update values from microphone array microphone_array.ReadConfValues();
.ShowConfiguration
ShowConfiguration
is a function that outputs the gain_
and sampling_frequency_
values in the MicrophoneArray
object.
// Function declaration in header file void ShowConfiguration();
// Output `gain_` and `sampling_frequency_` values microphone_array.void ShowConfiguration();
// Style of output std::cout << "Audio Configuration: " << std::endl; std::cout << "Sampling Frequency: " << sampling_frequency_ << std::endl; std::cout << "Gain : " << gain_ << std::endl;
.Channels
Channels
is a function that returns the number of microphone channels.
// Function declaration in header file uint16_t Channels() { return kMicrophoneChannels; }
// Return the number of channels uint16_t Channels = microphone_array.Channels();
.NumberOfSamples
NumberOfSamples
is a function that returns the number of samples.
// Function declaration in header file uint32_t NumberOfSamples() { return kMicarrayBufferSize / kMicrophoneChannels; }
// Return the number of samples uint16_t SampleAmount = microphone_array.NumberOfSamples();
.At
At
is a function that returns microphone data from the delayed_data_
array. The Read
function populates the delayed_data_
array.
// Function declaration in header file int16_t &At(int16_t sample, int16_t channel) { return delayed_data_[sample * kMicrophoneChannels + channel]; }
// Return a single sample int16_t sample = microphone_array.At(s, c);
.Beam
Beam
is a function that returns beamformed microphone data from the beamformed_
array. The Read
function populates the beamformed_
array.
// Function declaration in header file int16_t &Beam(int16_t sample) { return beamformed_[sample]; }
// Return a single sample int16_t sample = microphone_array.Beam(s);
.CalculateDelays
CalculateDelays
is a function that calculates and sets up delays for beamforming.
// Function declaration in header file void CalculateDelays(float azimutal_angle, float polar_angle, float radial_distance_mm = 100.0, float sound_speed_mmseg = 320 * 1000.0);
// Calculate and set up beamforming delays microphone_array.CalculateDelays(0, 0, 1000, 320 * 1000);
MicrophoneCore
MicrophoneCore
is an optional object that contains functions to enable using a FIR filter with microphone array. It accepts a MicrophoneArray
object in it's constructor.
// Constructor declaration in header file MicrophoneCore(MicrophoneArray µphone_array);
// Create MicrophoneCore object matrix_hal::MicrophoneCore microphone_core(microphone_array);
The functions below are part of MicrophoneCore
.
.Setup
Setup
is a function that takes a MatrixIOBus
object as a parameter and sets that object as the bus to use for communicating with MATRIX device. It also sets up the FIR filter by calling SelectFIRCoeff(&FIR_default[0])
.
// Function declaration in header file void Setup(MatrixIOBus *bus);
// Set microphone_core to use MatrixIOBus bus microphone_core.Setup(&bus);
.SetFIRCoeff
SetFIRCoeff
is a function that sends the fir_coeff_
array in the MicrophoneCore
object to the FPGA.
// Function declaration in header file bool SetFIRCoeff();
// Sends fir_coeff_ to FPGA microphone_core.SetFIRCoeff();
.SetCustomFIRCoeff
SetCustomFIRCoeff
is a function that sets the fir_coeff_
array in the MicrophoneCore
object.
If input is valid then the function also calls SetFIRCoeff
to send the fir_coeff_
array in the MicrophoneCore
object to the FPGA.
bool SetCustomFIRCoeff(const std::valarray<int16_t> custom_fir);
// Sets fir_coeff_ to custom_fir microphone_core.SetCustomFIRCoeff(custom_fir);
.SelectFIRCoeff
SelectFIRCoeff
is a function that sets the fir_coeff_
array in the MicrophoneCore
object.
If input is valid then the function also calls SetFIRCoeff
to send the fir_coeff_
array in the MicrophoneCore
object to the FPGA.
This function accepts a FIRCoeff struct, which is defined below.
// FIRCoeff definition in header file struct FIRCoeff { uint32_t rate_; std::valarray<int16_t> coeff_; };
bool SelectFIRCoeff(FIRCoeff *FIR_coeff);
// Sets fir_coeff_ from FIR_default[0] microphone_core.SelectFIRCoeff(&FIR_default[0]);
Provided FIR Filters
A FIR filter is provided in matrix_hal/microphone_core_fir.h
.
This filter provided is in the form of a FIRCoeff struct, which is defined below.
// FIRCoeff definition in header file struct FIRCoeff { uint32_t rate_; std::valarray<int16_t> coeff_; };
To use the provided FIR filter the SelectFIRCoeff
function is used to set it, then the SetFIRCoeff
function is used to send it to the FPGA.
// Sets fir_coeff_ from FIR_default[0] microphone_core.SelectFIRCoeff(&FIR_default[0]); // Sends FIR filter in fir_coeff_ to FPGA microphone_core.SetFIRCoeff();