XCORE SDK
XCORE Software Development Kit
Prefab.hpp
1 // Copyright 2022 XMOS LIMITED.
2 // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 
4 #pragma once
5 
6 #include <type_traits>
7 
8 #include "MicArray.hpp"
9 #include "mic_array/etc/filters_default.h"
10 
11 // This has caused problems previously, so just catch the problems here.
12 #if defined(MIC_COUNT) || defined(MICS_IN) || defined(FRAME_SIZE) || defined(USE_DCOE)
13 # error Application must not define the following as precompiler macros: MIC_COUNT, MICS_IN, FRAME_SIZE, USE_DCOE.
14 #endif
15 
16 namespace mic_array {
17 
29  namespace prefab {
30 
311  template <unsigned MIC_COUNT, unsigned FRAME_SIZE, bool USE_DCOE, unsigned MICS_IN=MIC_COUNT>
313  : public MicArray<MIC_COUNT,
314  TwoStageDecimator<MIC_COUNT, STAGE2_DEC_FACTOR,
315  STAGE2_TAP_COUNT>,
316  StandardPdmRxService<MICS_IN,MIC_COUNT,STAGE2_DEC_FACTOR>,
317  // std::conditional uses USE_DCOE to determine which
318  // sample filter is used.
319  typename std::conditional<USE_DCOE,
320  DcoeSampleFilter<MIC_COUNT>,
321  NopSampleFilter<MIC_COUNT>>::type,
322  FrameOutputHandler<MIC_COUNT, FRAME_SIZE,
323  ChannelFrameTransmitter>>
324  {
325 
326  public:
327 
328  using TParent = MicArray<MIC_COUNT,
332  typename std::conditional<USE_DCOE,
335  FrameOutputHandler<MIC_COUNT, FRAME_SIZE,
337 
338 
351  constexpr BasicMicArray() noexcept {}
352 
356  void Init();
357 
372  port_t p_pdm_mics,
373  chanend_t c_frames_out);
374 
384  void SetPort(
385  port_t p_pdm_mics);
386 
397  void SetOutputChannel(
398  chanend_t c_frames_out);
399 
407  void PdmRxThreadEntry();
408 
414  void InstallPdmRxISR();
415 
421  void UnmaskPdmRxISR();
422 
423 
424  };
425 
426  }
427 }
428 
430 // Template function implementations below. //
432 
433 
434 template <unsigned MIC_COUNT, unsigned FRAME_SIZE, bool USE_DCOE, unsigned MICS_IN>
436 {
437  this->Decimator.Init((uint32_t*) stage1_coef, stage2_coef, stage2_shr);
438 }
439 
440 
441 template <unsigned MIC_COUNT, unsigned FRAME_SIZE, bool USE_DCOE, unsigned MICS_IN>
444  port_t p_pdm_mics,
445  chanend_t c_frames_out) : TParent(
446  StandardPdmRxService<MICS_IN, MIC_COUNT, STAGE2_DEC_FACTOR>(p_pdm_mics),
447  FrameOutputHandler<MIC_COUNT, FRAME_SIZE,
449  ChannelFrameTransmitter<MIC_COUNT, FRAME_SIZE>(
450  c_frames_out)))
451 {
452  this->Decimator.Init((uint32_t*) stage1_coef, stage2_coef, stage2_shr);
453 }
454 
455 
456 template <unsigned MIC_COUNT, unsigned FRAME_SIZE, bool USE_DCOE, unsigned MICS_IN>
458  ::SetOutputChannel(chanend_t c_frames_out)
459 {
460  this->OutputHandler.FrameTx.SetChannel(c_frames_out);
461 }
462 
463 
464 template <unsigned MIC_COUNT, unsigned FRAME_SIZE, bool USE_DCOE, unsigned MICS_IN>
466  ::SetPort(port_t p_pdm_mics)
467 {
468  this->PdmRx.Init(p_pdm_mics);
469 }
470 
471 
472 template <unsigned MIC_COUNT, unsigned FRAME_SIZE, bool USE_DCOE, unsigned MICS_IN>
475 {
476  this->PdmRx.ThreadEntry();
477 }
478 
479 
480 template <unsigned MIC_COUNT, unsigned FRAME_SIZE, bool USE_DCOE, unsigned MICS_IN>
483 {
484  this->PdmRx.InstallISR();
485 }
486 
487 
488 template <unsigned MIC_COUNT, unsigned FRAME_SIZE, bool USE_DCOE, unsigned MICS_IN>
491 {
492  this->PdmRx.UnmaskISR();
493 }
Frame transmitter which transmits frame over a channel.
Definition: OutputHandler.hpp:175
Filter which applies DC Offset Elimination (DCOE).
Definition: SampleFilter.hpp:49
OutputHandler for grouping samples into frames and sending frames to subsequent processing stages.
Definition: OutputHandler.hpp:104
Represents the microphone array component of an application.
Definition: MicArray.hpp:48
Filter which does nothing.
Definition: SampleFilter.hpp:34
PDM rx service which uses a streaming channel to send a block of data by pointer.
Definition: PdmRx.hpp:251
First and Second Stage Decimator.
Definition: Decimator.hpp:44
Class template for a typical bare-metal mic array unit.
Definition: Prefab.hpp:324
void Init()
Initialize the decimator.
Definition: Prefab.hpp:435
void InstallPdmRxISR()
Install the PDM rx ISR on the calling thread.
Definition: Prefab.hpp:482
void SetOutputChannel(chanend_t c_frames_out)
Set the audio frame output channel.
Definition: Prefab.hpp:458
void PdmRxThreadEntry()
Entry point for PDM rx thread.
Definition: Prefab.hpp:474
void UnmaskPdmRxISR()
Unmask interrupts on the calling thread.
Definition: Prefab.hpp:490
void SetPort(port_t p_pdm_mics)
Set the PDM data port.
Definition: Prefab.hpp:466
constexpr BasicMicArray() noexcept
No-argument constructor.
Definition: Prefab.hpp:351
#define STAGE2_DEC_FACTOR
Definition: filters_default.h:142
#define STAGE2_TAP_COUNT
Definition: filters_default.h:152
const int32_t stage2_coef[STAGE2_TAP_COUNT]
const uint32_t stage1_coef[STAGE1_WORDS]
const right_shift_t stage2_shr