Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions CHANGELOG.rst
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHANGED: replaced assert.h with xcore/assert.h

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
lib_mic_array change log
========================

UNRELEASED
----------
6.0.0
-----

* ADDED: A new API to replace vanilla that is the default recommended way
of using the mic array.
* ADDED: Support for mic array shutdown which causes the mic arry thread(s)
* ADDED: A new API to replace vanilla that is the default recommended way of
using the mic array.
* ADDED: Support for mic array shutdown which causes the mic array thread(s)
to return.
* ADDED: Test for mic array shutdown
* ADDED: API to support initialising the mic array with custom decimation
filters
* CHANGED: BasicMicArray tests to test the default API
* CHANGED: app_measure_mips example to run the default API
* CHANGED: Documentation improvements
* CHANGED: replaced assert.h with xcore/assert.h
* FIXED: PDM RX ISR deadlock bug
* REMOVED: Vanilla API and configuration
* REMOVED: Prefab API
Comment thread
shuchitak marked this conversation as resolved.
* REMOVED: lib_xassert dependency

5.5.0
-----
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ lib_mic_array: PDM microphone array library
###########################################

:vendor: XMOS
:version: 5.5.0
:version: 6.0.0
:scope: General Use
:description: PDM microphone array library
:category: Audio
Expand Down
2 changes: 2 additions & 0 deletions doc/rst/src/examples.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

.. _examples:

********
Examples
********
Expand Down
21 changes: 11 additions & 10 deletions doc/rst/src/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
Introduction
************

``lib_mic_array`` is a library for interfacing with one or more PDM microphones
on an XMOS device.
``lib_mic_array`` provides microphone array processing support on XMOS devices.
It interfaces with one or more PDM (Pulse Density Modulation) microphones, capturing and converting their
output into high-quality PCM audio suitable for downstream voice and audio
processing pipelines.

Version 5.0 of this library has been redesigned from scratch to leverage the
`Vector unit in the XMOS XS3 architecture <https://www.xmos.com/documentation/XM-014007-PS/html/doc/rst/xs3-arch-inst.html#vector-unit>`_.
PDM microphones produce a high-rate, 1-bit digital bitstream. The library
captures these PDM streams on the device and performs the required filtering
and decimation to produce 32-bit PCM audio samples.

See :ref:`using_mic_array` to get started.
For high level description of mic array processing and the library capabilities, refer to :ref:`overview`.
To get started with using the library, see :ref:`using_mic_array` and :ref:`examples`.

.. note::

Version 5.0 does not currently support XS2 or XS1 devices. Please use version 4.5.0 if you need support for these devices: https://github.com/xmos/lib_mic_array/releases/tag/v4.5.0

.. note::

Find the latest version of ``lib_mic_array`` on `GitHub
<https://github.com/xmos/lib_mic_array>`_.
From Version 5.0 onwards, the library does not support XS2 or XS1 devices. Please use version 4.5.0 if you need support for these devices: https://github.com/xmos/lib_mic_array/releases/tag/v4.5.0

2 changes: 2 additions & 0 deletions doc/rst/src/overview.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

.. _overview:

********
Overview
********
Expand Down
2 changes: 1 addition & 1 deletion examples/app_custom_filter/src/app_i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <xcore/channel_streaming.h>
#include <stdint.h>
#include <stdio.h>
#include <assert.h>
#include <xcore/assert.h>
#include <stdlib.h>
#include <string.h>
#include <platform.h>
Expand Down
1 change: 0 additions & 1 deletion examples/app_custom_filter/src/main.xc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include "xk_voice_l71/board.h"
#include "app_config.h"
#include "mic_array.h"
Expand Down
2 changes: 1 addition & 1 deletion examples/app_mic_array/src/app_i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <xcore/channel_streaming.h>
#include <stdint.h>
#include <stdio.h>
#include <assert.h>
#include <xcore/assert.h>
#include <stdlib.h>
#include <string.h>
#include <platform.h>
Expand Down
1 change: 0 additions & 1 deletion examples/app_mic_array/src/main.xc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include "xk_voice_l71/board.h"
#include "app_config.h"
#include "mic_array.h"
Expand Down
2 changes: 1 addition & 1 deletion examples/app_par_decimator/src/app_i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <xcore/channel_streaming.h>
#include <stdint.h>
#include <stdio.h>
#include <assert.h>
#include <xcore/assert.h>
#include <stdlib.h>
#include <string.h>
#include <platform.h>
Expand Down
1 change: 0 additions & 1 deletion examples/app_par_decimator/src/main.xc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include "app_config.h"

#include "app.h"
Expand Down
2 changes: 1 addition & 1 deletion examples/app_shutdown/src/app_i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <stdint.h>
#include <stdio.h>
#include <assert.h>
#include <xcore/assert.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
Expand Down
1 change: 0 additions & 1 deletion examples/app_shutdown/src/main.xc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include "xk_voice_l71/board.h"
#include "app_config.h"
#include "mic_array.h"
Expand Down
3 changes: 1 addition & 2 deletions examples/deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ endif()

set(APP_DEPENDENT_MODULES "lib_mic_array"
"i2s"
"lib_xassert"
"lib_board_support(develop)")
"lib_board_support(1.5.0)")
7 changes: 2 additions & 5 deletions lib_mic_array/api/mic_array/etc/filters_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@ C_API_START
* @brief Macro indicating Stage 1 Decimation Factor
*
* This is the ratio of input sample rate to output sample rate for the first
* filter stage.
* filter stage. This value is fixed, even when using custom filter coefficients.
*
* @note In version 5.0 of lib_mic_array, this value is fixed (even if you
* choose not to use the default filter coefficients).
*/
#define STAGE1_DEC_FACTOR 32

/**
* @brief Macro indicating Stage 1 Filter Tap Count
*
* This is the number of filter taps in the first stage filter.
* This value is fixed, even when using custom filter coefficients.
*
* @note In version 5.0 of lib_mic_array, this value is fixed (even if you
* choose not to use the default filter coefficients).
*/
#define STAGE1_TAP_COUNT 256

Expand Down
6 changes: 3 additions & 3 deletions lib_mic_array/api/mic_array/etc/xcore_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#pragma once

/**
* The `<xcore/>` headers cannot be safely included from XC files, but
* several of the types defined in those headers need to be available in XC.
* The `<xcore/>` headers cannot be safely included from XC files, but
* several of the types defined in those headers need to be available in XC.
* This header is a work-around which defines those types for XC but includes
* them for C or CPP files.
*/
Expand All @@ -22,7 +22,7 @@ extern "C" {
unsigned end_a;
unsigned end_b;
} streaming_channel_t;

typedef struct {
unsigned end_a;
unsigned end_b;
Expand Down
15 changes: 9 additions & 6 deletions lib_mic_array/api/mic_array/mic_array_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ C_API_START
* is not created (when running in thread context) so the received PDM samples are
* ignored.
*
* @param pdm_res Pointer to the pdm_rx_resources_t struct containing hardware resources
* required by the mic array module.
* @param channel_map Array containing MIC_ARRAY_CONFIG_MIC_IN_COUNT to MIC_ARRAY_CONFIG_MIC_COUNT mapping.
* array dimension should be MIC_ARRAY_CONFIG_MIC_COUNT, and the i<sup>th</sup> entry is the
* input pdm pin index mapped to mic array output index i
* @param output_samp_freq output PCM sampling frequency (supported values are 16, 32 and 48KHz)
* @param pdm_res Pointer to the pdm_rx_resources_t struct containing hardware resources
* required by the mic array module.
* @param channel_map Optional mapping from PDM input pin to mic-array output channel index.
* - Array size: MIC_ARRAY_CONFIG_MIC_COUNT
* - channel_map[i] is the PDM pin index that should feed mic output channel i.
* - If channel_map is NULL, a default 1:1 mapping is used: PDM pin i -> mic output channel i.
* - Valid values for channel_map[i] are in [0, MIC_ARRAY_CONFIG_MIC_IN_COUNT-1].
* @param output_samp_freq Target sampling rate (in Hz) for the decimated PCM output stream
* Supported values: 16000, 32000, 48000 (Hz).
*/
MA_C_API
void mic_array_init(pdm_rx_resources_t *pdm_res, const unsigned *channel_map, unsigned output_samp_freq);
Expand Down
4 changes: 2 additions & 2 deletions lib_mic_array/api/mic_array/pdm_resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
#pragma once

#include <stdio.h> // for clock_t
#include <stdint.h>
#include "api.h"
#include "etc/xcore_compat.h"

#include "xmath/xmath.h"

#include <stdint.h>


C_API_START
Expand Down
5 changes: 2 additions & 3 deletions lib_mic_array/lib_build_info.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
set(LIB_NAME lib_mic_array)
set(LIB_VERSION 5.5.0)
set(LIB_DEPENDENT_MODULES "lib_xcore_math(2.4.0)"
"lib_xassert(4.3.2)")
set(LIB_VERSION 6.0.0)
set(LIB_DEPENDENT_MODULES "lib_xcore_math(2.4.0)")
set(LIB_INCLUDES
api
api/mic_array
Expand Down
5 changes: 2 additions & 3 deletions lib_mic_array/module_build_info
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
VERSION = 5.5.0
VERSION = 6.0.0

DEPENDENT_MODULES = lib_xcore_math(>=2.4.0) \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice getting rid of external lib and using lib_xcore

lib_xassert(>=4.3.2)
DEPENDENT_MODULES = lib_xcore_math(>=2.4.0)

MODULE_XCC_FLAGS = $(XCC_FLAGS) -g -Os

Expand Down
31 changes: 1 addition & 30 deletions lib_mic_array/src/frame_transfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,7 @@ unsigned ma_frame_tx(
const unsigned sample_count)
{
unsigned shutdown = 0;
#if 0
transacting_chanend_t ct_frame = chan_init_transaction_master(c_frame_out);
t_chan_out_buf_word(&ct_frame,
(uint32_t*) frame,
channel_count * sample_count);
chan_complete_transaction(ct_frame);
#else
chanend_out_control_token(c_frame_out, XS1_CT_END);
//asm volatile("testct %0, res[%1]" : "=r"(shutdown) : "r"(c_frame_out));
shutdown = chanend_test_control_token_next_byte(c_frame_out);
if(shutdown)
{
Expand All @@ -41,8 +33,6 @@ unsigned ma_frame_tx(
chanend_out_control_token(c_frame_out, XS1_CT_END); // close the channel only when not shutting down
chanend_check_control_token(c_frame_out, XS1_CT_END);
}

#endif
return shutdown;
}

Expand All @@ -52,22 +42,13 @@ void ma_frame_rx(
const unsigned channel_count,
const unsigned sample_count)
{
#if 0
transacting_chanend_t ct_frame = chan_init_transaction_slave(c_frame_in);
t_chan_in_buf_word(&ct_frame,
(uint32_t*) frame,
channel_count * sample_count);
chan_complete_transaction(ct_frame);
#else
chanend_check_control_token(c_frame_in, XS1_CT_END);
chanend_out_byte(c_frame_in, 0); //dummy indicating wish to proceed with data transfer
for(int i=0; i<channel_count*sample_count; i++) {
frame[i] = chanend_in_word(c_frame_in);
}
chanend_check_control_token(c_frame_in, XS1_CT_END);
chanend_out_control_token(c_frame_in, XS1_CT_END);

#endif
}


Expand All @@ -77,15 +58,6 @@ void ma_frame_rx_transpose(
const unsigned channel_count,
const unsigned sample_count)
{
#if 0
transacting_chanend_t ct_frame = chan_init_transaction_slave(c_frame_in);
for(int ch = 0; ch < channel_count; ch++){
for(int smp = 0; smp < sample_count; smp++){
frame[smp*channel_count+ch] = t_chan_in_word(&ct_frame);
}
}
chan_complete_transaction(ct_frame);
#else
chanend_check_control_token(c_frame_in, XS1_CT_END);
chanend_out_byte(c_frame_in, 0); //dummy indicating wish to proceed with data transfer

Expand All @@ -96,10 +68,9 @@ void ma_frame_rx_transpose(
}
chanend_check_control_token(c_frame_in, XS1_CT_END);
chanend_out_control_token(c_frame_in, XS1_CT_END);
#endif
}

void ma_shutdown(const chanend_t c_frame_in) //same chanend as whats used in ma_frame_rx()
void ma_shutdown(const chanend_t c_frame_in) //same chanend as the one used in ma_frame_rx()
{
chanend_check_control_token(c_frame_in, XS1_CT_END);
chanend_out_control_token(c_frame_in, XS1_CT_END); // indicate shutdown to ma_frame_tx()
Expand Down
21 changes: 13 additions & 8 deletions lib_mic_array/src/mic_array_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,35 @@ void mic_array_resources_configure(
port_clear_buffer(pdm_res->p_pdm_mics);
}

static inline
void mic_array_inpw8(const port_t p_pdm_mics)
{
uint32_t tmp;
asm volatile("inpw %0, res[%1], 8" : "=r"(tmp)
: "r" (p_pdm_mics));
}

void mic_array_pdm_clock_start(
pdm_rx_resources_t* pdm_res)
{
if( pdm_res->clock_b != 0 ) {
uint32_t tmp;


port_clear_buffer(pdm_res->p_pdm_mics);

/* start the faster capture clock */
clock_start(pdm_res->clock_b);

/* wait for a rising edge on the capture clock */
// (this ensures the rising edges of the two
// (this ensures the rising edges of the two
// clocks are not in phase)
asm volatile("inpw %0, res[%1], 8" : "=r"(tmp)
: "r" (pdm_res->p_pdm_mics));
mic_array_inpw8(pdm_res->p_pdm_mics);

/* start the slower output clock */
clock_start(pdm_res->clock_a);
} else {
// You'd think that we could move the `clock_start(pdm_res->clock_a)` to be
// after the if..else block instead of duplicating it. But no, if I try
// that, the compiler screws something up and the output audio is all
// after the if..else block instead of duplicating it. But no, if I try
// that, the compiler screws something up and the output audio is all
// messed up.
clock_start(pdm_res->clock_a);
}
Expand Down
Loading