Open Speech Platform
osp_process.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "logger.h"
#include "osp_process.h"
#include "utilities.h"
#include "filter.h"
#include "coeffs.h"
#include "afc.h"
#include "delay_line.h"
#include "array_utilities.h"
#include "peak_detect.h"
#include "wdrc.h"
#include "wdrc_mpo_support.h"
#include "mpo.h"
Include dependency graph for osp_process.c:

Macros

#define FEEDBACK_EST_DELAY   100
 Feedback delay in samples. For file loopback its 0. For real-time processing one needs to account for I/O delay. More...
 
#define STEREO
 Toggle for stereo and mono. More...
 

Functions

static void osp_process_ha (osp_user_data *osp, Filter *filter, Peak_detect pd, float *e_n, float *s_n, size_t len)
 Function that performs basic Hearing Aid (HA) processing on a single channel. More...
 
int osp_init (unsigned int frame_size, int sample_rate, unsigned char afc_adaptation_type)
 This file groups all of the different OSP library calls in one place. This is more of an example way of using the different parts of the OSP libraries to implement a hearing aid algorith with MHA and AFC all in one place. More...
 
void osp_process_audio (osp_user_data *osp, float *x_nL, float *x_nR, float *outL, float *outR, size_t len)
 Function to perform Master Hearing Aid (MHA) processing on the input signal for both channels. More...
 
unsigned int osp_get_num_bands ()
 Function to get the number of Sub-Bands. More...
 
void osp_close ()
 Wrapper function to free all the modules of Master Hearing Aid (MHA) More...
 
void osp_dump_afc_filter ()
 Function to dump AFC filter taps for both left and right channels. More...
 
void osp_data_init (osp_user_data *user_data)
 Helper function for initializing Master Hearing Aid (MHA) parameters. More...
 
void osp_data_set_gain (osp_user_data *user_data, int gain)
 Helper function for initializing gain parameters for WDRC with a constant gain. More...
 
void osp_data_set_nh (osp_user_data *user_data)
 Helper function for initializing gain parameters for WDRC with NH audiogram. More...
 
void osp_data_set_n2 (osp_user_data *user_data)
 Helper function for initializing gain parameters for WDRC with N2 audiogram. More...
 
void osp_data_set_n4 (osp_user_data *user_data)
 Helper function for initializing gain parameters for WDRC with N4 audiogram. More...
 
void osp_data_set_s2 (osp_user_data *user_data)
 Helper function for initializing gain parameters for WDRC with S2 audiogram. More...
 

Variables

static Filter filterL [NUM_BANDS]
 
static Filter filterR [NUM_BANDS]
 
static Filter synthetic_feedback_filter_left
 
static Filter synthetic_feedback_filter_right
 
static Peak_detect pdL
 
static Peak_detect pdR
 
static Afc afc_left
 
static Afc afc_right
 
static Delay_Line delay_line_left
 
static Delay_Line delay_line_right
 

Macro Definition Documentation

◆ FEEDBACK_EST_DELAY

#define FEEDBACK_EST_DELAY   100

Feedback delay in samples. For file loopback its 0. For real-time processing one needs to account for I/O delay.

◆ STEREO

#define STEREO

Toggle for stereo and mono.

Function Documentation

◆ osp_close()

void osp_close ( )

Wrapper function to free all the modules of Master Hearing Aid (MHA)

◆ osp_data_init()

void osp_data_init ( osp_user_data user_data)

Helper function for initializing Master Hearing Aid (MHA) parameters.

See also
osp_user_data
osp_data_set_gain, osp_data_set_nh, osp_data_set_n2 ,osp_data_set_n4 ,osp_data_set_s2
Parameters
user_dataPointer to an osp_user_data instance which will be allocated in the function

◆ osp_data_set_gain()

void osp_data_set_gain ( osp_user_data user_data,
int  gain 
)

Helper function for initializing gain parameters for WDRC with a constant gain.

See also
osp_user_data
osp_data_set_gain, osp_data_set_nh, osp_data_set_n2 ,osp_data_set_n4 ,osp_data_set_s2
Parameters
user_dataPointer to the instance of osp_user_data initialized by osp_data_init
gainThe constant gain value

◆ osp_data_set_n2()

void osp_data_set_n2 ( osp_user_data user_data)

Helper function for initializing gain parameters for WDRC with N2 audiogram.

See also
osp_user_data
osp_data_set_gain, osp_data_set_nh, osp_data_set_n2 ,osp_data_set_n4 ,osp_data_set_s2
Parameters
user_dataPointer to the instance of osp_user_data initialized by osp_data_init

◆ osp_data_set_n4()

void osp_data_set_n4 ( osp_user_data user_data)

Helper function for initializing gain parameters for WDRC with N4 audiogram.

See also
osp_user_data
osp_data_set_gain, osp_data_set_nh, osp_data_set_n2 ,osp_data_set_n4 ,osp_data_set_s2
Parameters
user_dataPointer to the instance of osp_user_data initialized by osp_data_init

◆ osp_data_set_nh()

void osp_data_set_nh ( osp_user_data user_data)

Helper function for initializing gain parameters for WDRC with NH audiogram.

See also
osp_user_data
osp_data_set_gain, osp_data_set_nh, osp_data_set_n2 ,osp_data_set_n4 ,osp_data_set_s2
Parameters
user_dataPointer to the instance of osp_user_data initialized by osp_data_init

◆ osp_data_set_s2()

void osp_data_set_s2 ( osp_user_data user_data)

Helper function for initializing gain parameters for WDRC with S2 audiogram.

See also
osp_user_data
osp_data_set_gain, osp_data_set_nh, osp_data_set_n2 ,osp_data_set_n4 ,osp_data_set_s2
Parameters
user_dataPointer to the instance of osp_user_data initialized by osp_data_init

◆ osp_dump_afc_filter()

void osp_dump_afc_filter ( )

Function to dump AFC filter taps for both left and right channels.

File names can be changed by changing AFC_FILTER_TAP_FILE_L, AFC_FILTER_TAP_FILE_R in constants.h

◆ osp_get_num_bands()

unsigned int osp_get_num_bands ( )

Function to get the number of Sub-Bands.

Returns
int Number of Sub-Bands give by NUM_BANDS

◆ osp_init()

int osp_init ( unsigned int  frame_size,
int  sample_rate,
unsigned char  afc_adaptation_type 
)

This file groups all of the different OSP library calls in one place. This is more of an example way of using the different parts of the OSP libraries to implement a hearing aid algorith with MHA and AFC all in one place.

Wrapper function to initalize all the modules of Master Hearing Aid (MHA)

Parameters
frame_sizeThe number of samples in a frame. i.e. the number of samples to process
sample_rateThe sample rate at which all MHA processing will be done
afc_adaptation_typeThe type of AFC adaptation
Returns
0 if successful initialization. -1 otherwise

◆ osp_process_audio()

void osp_process_audio ( osp_user_data osp,
float *  x_nL,
float *  x_nR,
float *  outL,
float *  outR,
size_t  len 
)

Function to perform Master Hearing Aid (MHA) processing on the input signal for both channels.

If STEREO is false, only the right channel is processed

See also
osp_user_data
Parameters
ospThe instance of the osp_user_data structure that was initialized in osp_data_init. This contains all the MHA parameters.
x_nLPointer to the array containing left channel input
x_nRPointer to the array containing right channel input
outLPointer to the array to store the output of MHA processing on left channel input
outRPointer to the array to store the output of MHA processing on right channel input
lenThe length of the input signal e_n that is given for processing. i.e. frame length.

◆ osp_process_ha()

static void osp_process_ha ( osp_user_data osp,
Filter filter,
Peak_detect  pd,
float *  e_n,
float *  s_n,
size_t  len 
)
static

Function that performs basic Hearing Aid (HA) processing on a single channel.

The signal is split into Sub-Bands. Peak Detect and WDRC are applied on each Sub-Band. The WDRC outputs are then added across the Sub-Bands. This will be the output of the HA.

See also
osp_user_data
Parameters
ospThe instance of the osp_user_data structure that was initialized in osp_data_init. This contains all the MHA parameters.
filterThe filter data structure instance for that channel
pdThe peak detect data structure instance for that channel
e_nPointer to the input signal of the HA. This will be the sum of desired input signal plus the feedback signal.
s_nPointer to the output signal of the HA. i.e. the output of the HA. This output will be used by AFC to remove feedback.
lenThe length of the input signal e_n that is given for processing. i.e. frame length.

Variable Documentation

◆ afc_left

Afc afc_left
static

◆ afc_right

Afc afc_right
static

◆ delay_line_left

Delay_Line delay_line_left
static

◆ delay_line_right

Delay_Line delay_line_right
static

◆ filterL

Filter filterL[NUM_BANDS]
static

◆ filterR

Filter filterR[NUM_BANDS]
static

◆ pdL

Peak_detect pdL
static

◆ pdR

Peak_detect pdR
static

◆ synthetic_feedback_filter_left

Filter synthetic_feedback_filter_left
static

◆ synthetic_feedback_filter_right

Filter synthetic_feedback_filter_right
static