Skip to content

File ns_audio.h

FileList > includes-api > ns_audio.h

Go to the source code of this file

API Definition for NeuralSPOT Audio library. More...

  • #include "am_bsp.h"
  • #include "am_mcu_apollo.h"
  • #include "am_util.h"
  • #include "ns_core.h"
  • #include "ns_ipc_ring_buffer.h"

Classes

Type Name
struct ns_audadc_cfg_t
AUDADC Configuration.
struct ns_audio_cfg
struct ns_pdm_cfg_t
PDM Configuration.

Public Types

Type Name
enum ns_audio_api_mode_e
Audio IPC Modes.
typedef void(* ns_audio_callback_cb
Invoked by IRQ when audio buffer is ready.
enum ns_audio_clksel_e
Audio Clock Source.
typedef struct ns_audio_cfg ns_audio_config_t
enum ns_audio_pdm_clock_e
PDM Clock Frequency.
enum ns_audio_pdm_micsel_e
PDM Microphone Selection.
enum ns_audio_source_e
Audio Source (current only AUDADC and PDM are supported)

Public Attributes

Type Name
ns_audio_config_t * g_ns_audio_config
Audio Configuration and State.
const ns_core_api_t ns_audio_V0_0_1
const ns_core_api_t ns_audio_V1_0_0
const ns_core_api_t ns_audio_V2_0_0
const ns_core_api_t ns_audio_V2_1_0
const ns_core_api_t ns_audio_current_version
const ns_core_api_t ns_audio_oldest_supported_version

Public Functions

Type Name
void ns_audio_getPCM (int16_t * pcm, uint32_t * raw, int16_t len)
Extract int16 PCM from data collected by ADC.
void ns_audio_getPCM_v2 (ns_audio_config_t * config, void * pcm)
Extract int16 PCM from AUDADC or PDM sources.
uint32_t ns_audio_init (ns_audio_config_t * cfg)
Initialize NeuralSPOT audio capture library.
uint32_t ns_audio_set_gain (int left_gain, int right_gain)
Set gain of audio source.
uint32_t ns_end_audio (ns_audio_config_t * cfg)
Stop audio capture.
uint32_t ns_start_audio (ns_audio_config_t * cfg)
Start audio capture, must be called after ns_audio_init.

Macros

Type Name
define NS_AUDIO_API_ID 0xCA0001
define NS_AUDIO_CURRENT_VERSION NS\_AUDIO\_V2\_1\_0
define NS_AUDIO_DMA_BUFFER_SIZE 480
define NS_AUDIO_OLDEST_SUPPORTED_VERSION NS\_AUDIO\_V0\_0\_1
define NS_AUDIO_V0_0_1 { .major = 0, .minor = 0, .revision = 1 }
define NS_AUDIO_V1_0_0 { .major = 1, .minor = 0, .revision = 0 }
define NS_AUDIO_V2_0_0 { .major = 2, .minor = 0, .revision = 0 }
define NS_AUDIO_V2_1_0 { .major = 2, .minor = 1, .revision = 0 }

Detailed Description

Author:

Carlos Morales

Version:

0.1

Date:

2022-08-12

Copyright:

Copyright (c) 2022

Public Types Documentation

enum ns_audio_api_mode_e

Audio IPC Modes.

enum ns_audio_api_mode_e {
    NS_AUDIO_API_CALLBACK,
    NS_AUDIO_API_RINGBUFFER,
    NS_AUDIO_API_TASK
};


typedef ns_audio_callback_cb

Invoked by IRQ when audio buffer is ready.

typedef void(* ns_audio_callback_cb) (struct ns_audio_cfg *, uint16_t);


enum ns_audio_clksel_e

Audio Clock Source.

enum ns_audio_clksel_e {
    NS_CLKSEL_XTHS,
    NS_CLKSEL_HFXTAL,
    NS_CLKSEL_HFRC,
    NS_CLKSEL_HFRC2,
    NS_CLKSEL_HFRC2_ADJ,
    NS_CLKSEL_PLL
};


typedef ns_audio_config_t

typedef struct ns_audio_cfg ns_audio_config_t;

NeuralSPOT Audio API Configuration Struct

Audio configuration is via this struct, which also serves as a handle after ns_audio_init() has been invoked


enum ns_audio_pdm_clock_e

PDM Clock Frequency.

enum ns_audio_pdm_clock_e {
    NS_AUDIO_PDM_CLK_750KHZ,
    NS_AUDIO_PDM_CLK_1_5MHZ
};


enum ns_audio_pdm_micsel_e

PDM Microphone Selection.

enum ns_audio_pdm_micsel_e {
    NS_AUDIO_PDM_MICBOARD_0 = 0,
    NS_AUDIO_PDM_MICBOARD_1 = 2,
    NS_AUDIO_PDM_MICBOARD_2 = 1
};


enum ns_audio_source_e

Audio Source (current only AUDADC and PDM are supported)

enum ns_audio_source_e {
    NS_AUDIO_SOURCE_AUDADC,
    NS_AUDIO_SOURCE_PDM
};


Public Attributes Documentation

variable g_ns_audio_config

Audio Configuration and State.

ns_audio_config_t* g_ns_audio_config;


variable ns_audio_V0_0_1

const ns_core_api_t ns_audio_V0_0_1;

variable ns_audio_V1_0_0

const ns_core_api_t ns_audio_V1_0_0;

variable ns_audio_V2_0_0

const ns_core_api_t ns_audio_V2_0_0;

variable ns_audio_V2_1_0

const ns_core_api_t ns_audio_V2_1_0;

variable ns_audio_current_version

const ns_core_api_t ns_audio_current_version;

variable ns_audio_oldest_supported_version

const ns_core_api_t ns_audio_oldest_supported_version;

Public Functions Documentation

function ns_audio_getPCM

Extract int16 PCM from data collected by ADC.

void ns_audio_getPCM (
    int16_t * pcm,
    uint32_t * raw,
    int16_t len
) 

Parameters:

  • pcm - resulting PCM data
  • raw - incoming data from ADC engine
  • len - number of sample words to convert

function ns_audio_getPCM_v2

Extract int16 PCM from AUDADC or PDM sources.

void ns_audio_getPCM_v2 (
    ns_audio_config_t * config,
    void * pcm
) 

Parameters:

  • config - ns audio config
  • pcm - resulting PCM data

function ns_audio_init

Initialize NeuralSPOT audio capture library.

uint32_t ns_audio_init (
    ns_audio_config_t * cfg
) 

Parameters:

  • cfg : desired configuration

function ns_audio_set_gain

Set gain of audio source.

uint32_t ns_audio_set_gain (
    int left_gain,
    int right_gain
) 

Parameters:

  • left_gain - left channel gain
  • right_gain - right channel gain

function ns_end_audio

Stop audio capture.

uint32_t ns_end_audio (
    ns_audio_config_t * cfg
) 

Parameters:

  • cfg : desired configuration

function ns_start_audio

Start audio capture, must be called after ns_audio_init.

uint32_t ns_start_audio (
    ns_audio_config_t * cfg
) 

Parameters:

  • cfg : desired configuration

Macro Definition Documentation

define NS_AUDIO_API_ID

#define NS_AUDIO_API_ID `0xCA0001`

define NS_AUDIO_CURRENT_VERSION

#define NS_AUDIO_CURRENT_VERSION `NS_AUDIO_V2_1_0`

define NS_AUDIO_DMA_BUFFER_SIZE

#define NS_AUDIO_DMA_BUFFER_SIZE `480`

define NS_AUDIO_OLDEST_SUPPORTED_VERSION

#define NS_AUDIO_OLDEST_SUPPORTED_VERSION `NS_AUDIO_V0_0_1`

define NS_AUDIO_V0_0_1

#define NS_AUDIO_V0_0_1 `{ .major = 0, .minor = 0, .revision = 1 }`

define NS_AUDIO_V1_0_0

#define NS_AUDIO_V1_0_0 `{ .major = 1, .minor = 0, .revision = 0 }`

define NS_AUDIO_V2_0_0

#define NS_AUDIO_V2_0_0 `{ .major = 2, .minor = 0, .revision = 0 }`

define NS_AUDIO_V2_1_0

#define NS_AUDIO_V2_1_0 `{ .major = 2, .minor = 1, .revision = 0 }`


The documentation for this class was generated from the following file neuralSPOT/neuralspot/ns-audio/includes-api/ns_audio.h