SAF
Loading...
Searching...
No Matches
afSTFTlib.c File Reference

A modified version of afSTFTlib. More...

#include "afSTFTlib.h"
#include "afSTFT_internal.h"

Go to the source code of this file.

Data Structures

struct  afSTFT_data
 Data structure for the afSTFT filterbank. More...
 

Functions

static void afAnalyse (float *inTD, int nSamplesTD, int nCH, int hopSize, int LDmode, int hybridmode, float_complex *outTF)
 Passes input time-domain data through the afSTFT filterbank.
 
void afSTFT_create (void **const phSTFT, int nCHin, int nCHout, int hopsize, int lowDelayMode, int hybridmode, AFSTFT_FDDATA_FORMAT format)
 Creates an instance of afSTFT.
 
void afSTFT_destroy (void **const phSTFT)
 Destroys an instance of afSTFT.
 
void afSTFT_forward (void *const hSTFT, float **dataTD, int framesize, float_complex ***dataFD)
 Performs forward afSTFT transform.
 
void afSTFT_forward_knownDimensions (void *const hSTFT, float **dataTD, int framesize, int dataFD_nCH, int dataFD_nHops, float_complex ***dataFD)
 Performs forward afSTFT transform (dataFD dimensions are known)
 
void afSTFT_forward_flat (void *const hSTFT, float *dataTD, int framesize, float_complex *dataFD)
 Performs forward afSTFT transform (flattened arrays)
 
void afSTFT_backward (void *const hSTFT, float_complex ***dataFD, int framesize, float **dataTD)
 Performs backward afSTFT transform.
 
void afSTFT_backward_knownDimensions (void *const hSTFT, float_complex ***dataFD, int framesize, int dataFD_nCH, int dataFD_nHops, float **dataTD)
 Performs backward afSTFT transform (dataFD dimensions are known)
 
void afSTFT_backward_flat (void *const hSTFT, float_complex *dataFD, int framesize, float *dataTD)
 Performs backward afSTFT transform (flattened arrays)
 
void afSTFT_channelChange (void *const hSTFT, int new_nCHin, int new_nCHout)
 Re-allocates memory to support a change in the number of input/output channels.
 
void afSTFT_clearBuffers (void *const hSTFT)
 Flushes time-domain buffers with zeros.
 
int afSTFT_getNBands (void *const hSTFT)
 Returns number of frequency bands.
 
int afSTFT_getProcDelay (void *const hSTFT)
 Returns current processing delay, in samples.
 
void afSTFT_getCentreFreqs (void *const hSTFT, float fs, int nBands, float *freqVector)
 Returns current frequency vector.
 
void afSTFT_FIRtoFilterbankCoeffs (float *hIR, int N_dirs, int nCH, int ir_len, int hopSize, int LDmode, int hybridmode, float_complex *hFB)
 Converts FIR filters into Filterbank Coefficients by passing them through the afSTFT filterbank.
 

Variables

static const double __afCenterFreq48e3 [133]
 afSTFT centre frequencies for 128 hop size, hybrid-mode enabled, 48kHz
 
static const double __afCenterFreq44100 [133]
 afSTFT centre frequencies for 128 hop size, hybrid-mode enabled, 44.1kHz
 
static const float __stft2hybCentreFreq [9][5]
 Matrix for converting the centre frequencies of the first 5 stft bins into the centre frequencies for the 9 hybrid bands.
 

Detailed Description

A modified version of afSTFTlib.

The original afSTFT code (by Juha Vilkamo) can be found here: https://github.com/jvilkamo/afSTFT This version is slightly modified to be more in-line with how the rest of SAF is structured. The files afSTFTlib.h/.c act as the interface to afSTFT, which is then implemented in afSTFT_internal.h/.c.

This version also adds functionality to change the number of channels on the fly, flush the run-time buffers with zeros, return the current frequency vector and the current processing delay. It also incorporates SAF utilities (for the vectorisation and FFT).

The afSTFT design is also described in more detail in [1]

See also
[1] Vilkamo, J., & Ba"ckstro"m, T. (2018). Time–Frequency Processing: Methods and Tools. In Parametric Time–Frequency Domain Spatial Audio. John Wiley & Sons.
Author
Juha Vilkamo
Date
08.04.2015
License
MIT

Definition in file afSTFTlib.c.

Function Documentation

◆ afAnalyse()

static void afAnalyse ( float * inTD,
int nSamplesTD,
int nCH,
int hopSize,
int LDmode,
int hybridmode,
float_complex * outTF )
static

Passes input time-domain data through the afSTFT filterbank.

Copyright (c) 2015 Juha Vilkamo, MIT license

Definition at line 78 of file afSTFTlib.c.

◆ afSTFT_backward()

void afSTFT_backward ( void *const hSTFT,
float_complex *** dataFD,
int framesize,
float ** dataTD )

Performs backward afSTFT transform.

Parameters
[in]hSTFTafSTFT handle
[in]dataFDFrequency-domain input; AFSTFT_FDDATA_FORMAT
[in]framesizeFrame size of time-domain data
[out]dataTDTime-domain output; nCHout x framesize

Definition at line 347 of file afSTFTlib.c.

◆ afSTFT_backward_flat()

void afSTFT_backward_flat ( void *const hSTFT,
float_complex * dataFD,
int framesize,
float * dataTD )

Performs backward afSTFT transform (flattened arrays)

Parameters
[in]hSTFTafSTFT handle
[in]dataFDFrequency-domain input; FLAT: AFSTFT_FDDATA_FORMAT
[in]framesizeFrame size of time-domain data
[out]dataTDTime-domain output; FLAT: nCHout x framesize

Definition at line 433 of file afSTFTlib.c.

◆ afSTFT_backward_knownDimensions()

void afSTFT_backward_knownDimensions ( void *const hSTFT,
float_complex *** dataFD,
int framesize,
int dataFD_nCH,
int dataFD_nHops,
float ** dataTD )

Performs backward afSTFT transform (dataFD dimensions are known)

Note
If the dimensions of dataFD are known, then this function will use the same dataFD format as used by afSTFT_backward(), but with the speed of afSTFT_backward_flat()
Parameters
[in]hSTFTafSTFT handle
[in]dataFDFrequency-domain input; AFSTFT_FDDATA_FORMAT
[in]framesizeFrame size of time-domain data
[in]dataFD_nCHNumber of channels dataFD is allocated (the max)
[in]dataFD_nHopsNumber of timeslots dataFD is allocated (the max)
[out]dataTDTime-domain output; nCHout x framesize

Definition at line 390 of file afSTFTlib.c.

◆ afSTFT_channelChange()

void afSTFT_channelChange ( void *const hSTFT,
int new_nCHin,
int new_nCHout )

Re-allocates memory to support a change in the number of input/output channels.

Parameters
[in]hSTFTafSTFT handle
[in]new_nCHinNew number of input channels
[in]new_nCHoutNew number of output channels

Definition at line 476 of file afSTFTlib.c.

◆ afSTFT_clearBuffers()

void afSTFT_clearBuffers ( void *const hSTFT)

Flushes time-domain buffers with zeros.

Definition at line 518 of file afSTFTlib.c.

◆ afSTFT_create()

void afSTFT_create ( void **const phSTFT,
int nCHin,
int nCHout,
int hopsize,
int lowDelayMode,
int hybridmode,
AFSTFT_FDDATA_FORMAT format )

Creates an instance of afSTFT.

Test
test__afSTFT()
Parameters
[in]phSTFT(&) address of afSTFT handle
[in]nCHinNumber of input channels
[in]nCHoutNumber of output channels
[in]hopsizeHop size, in samples
[in]lowDelayMode0: disabled, 1: low-delay mode enabled
[in]hybridmode0: disabled, 1: hybrid-filtering enabled
[in]formatFrequency-domain frame format, see AFSTFT_FDDATA_FORMAT enum

Definition at line 142 of file afSTFTlib.c.

◆ afSTFT_destroy()

void afSTFT_destroy ( void **const phSTFT)

Destroys an instance of afSTFT.

Parameters
[in]phSTFT(&) address of afSTFT handle

Definition at line 198 of file afSTFTlib.c.

◆ afSTFT_FIRtoFilterbankCoeffs()

void afSTFT_FIRtoFilterbankCoeffs ( float * hIR,
int N_dirs,
int nCH,
int ir_len,
int hopSize,
int LDmode,
int hybridmode,
float_complex * hFB )

Converts FIR filters into Filterbank Coefficients by passing them through the afSTFT filterbank.

Parameters
[in]hIRTime-domain FIR; FLAT: N_dirs x nCH x ir_len
[in]N_dirsNumber of FIR sets
[in]nCHNumber of channels per FIR set
[in]ir_lenLength of the FIR
[in]hopSizeHop size
[in]LDmode0: disabled, 1:enabled
[in]hybridmode0: disabled, 1:enabled
[out]hFBThe FIRs as Filterbank coefficients; FLAT: N_bands x nCH x N_dirs

Definition at line 592 of file afSTFTlib.c.

◆ afSTFT_forward()

void afSTFT_forward ( void *const hSTFT,
float ** dataTD,
int framesize,
float_complex *** dataFD )

Performs forward afSTFT transform.

Parameters
[in]hSTFTafSTFT handle
[in]dataTDTime-domain input; nCHin x framesize
[in]framesizeFrame size of time-domain data
[out]dataFDFrequency-domain output; AFSTFT_FDDATA_FORMAT

Definition at line 229 of file afSTFTlib.c.

◆ afSTFT_forward_flat()

void afSTFT_forward_flat ( void *const hSTFT,
float * dataTD,
int framesize,
float_complex * dataFD )

Performs forward afSTFT transform (flattened arrays)

Parameters
[in]hSTFTafSTFT handle
[in]dataTDTime-domain input; FLAT: nCHin x framesize
[in]framesizeFrame size of time-domain data
[out]dataFDFrequency-domain output; FLAT: AFSTFT_FDDATA_FORMAT

Definition at line 310 of file afSTFTlib.c.

◆ afSTFT_forward_knownDimensions()

void afSTFT_forward_knownDimensions ( void *const hSTFT,
float ** dataTD,
int framesize,
int dataFD_nCH,
int dataFD_nHops,
float_complex *** dataFD )

Performs forward afSTFT transform (dataFD dimensions are known)

Note
If the dimensions of dataFD are known, then this function will use the same dataFD format as used by afSTFT_forward(), but with the speed of afSTFT_forward_flat()
Parameters
[in]hSTFTafSTFT handle
[in]dataTDTime-domain input; nCHin x framesize
[in]framesizeFrame size of time-domain data
[in]dataFD_nCHNumber of channels dataFD is allocated (the max)
[in]dataFD_nHopsNumber of timeslots dataFD is allocated (the max)
[out]dataFDFrequency-domain output; AFSTFT_FDDATA_FORMAT

Definition at line 267 of file afSTFTlib.c.

◆ afSTFT_getCentreFreqs()

void afSTFT_getCentreFreqs ( void *const hSTFT,
float fs,
int nBands,
float * freqVector )

Returns current frequency vector.

Definition at line 545 of file afSTFTlib.c.

◆ afSTFT_getNBands()

int afSTFT_getNBands ( void *const hSTFT)

Returns number of frequency bands.

Definition at line 527 of file afSTFTlib.c.

◆ afSTFT_getProcDelay()

int afSTFT_getProcDelay ( void *const hSTFT)

Returns current processing delay, in samples.

Note
The afSTFT filterbank delay is broken down into the following: analysis delay: 5*hopsize
  • hybrid-filtering delay: 3*hopsize (or 0, if it is disabled)
  • synthesis delay 4*hopsize

If the low-delay mode is enabled, it is instead: analysis delay: 2*hopsize

  • hybrid-filtering delay: 3*hopsize (or 0, if it is disabled)
  • synthesis delay 2*hopsize

Definition at line 536 of file afSTFTlib.c.

Variable Documentation

◆ __afCenterFreq44100

const double __afCenterFreq44100[133]
static
Initial value:
=
{ 0.000000000, 129.216965656, 215.314095512, 301.482605287, 387.579738729, 473.748225285, 559.845379541, 646.013853751, 732.111030944, 861.328154418, 1033.593765929, 1205.859407569, 1378.125069596, 1550.390654200, 1722.656272269, 1894.921852124, 2067.187549340, 2239.453165674, 2411.718752127, 2583.984393174, 2756.250038304, 2928.515610236, 3100.781245532, 3273.046869646, 3445.312517049, 3617.578144885, 3789.843759058, 3962.109385592, 4134.375009576, 4306.640638272, 4478.906262484, 4651.171887467, 4823.437506959, 4995.703134452, 5167.968753839, 5340.234378143, 5512.500004739, 5684.765628127, 5857.031253205, 6029.296881607, 6201.562505487, 6373.828132809, 6546.093756373, 6718.359382855, 6890.625004623, 7062.890629479, 7235.156254481, 7407.421881970, 7579.687505713, 7751.953124821, 7924.218750103, 8096.484373148, 8268.750008140, 8441.015629043, 8613.281251405, 8785.546881031, 8957.812505821, 9130.078124593, 9302.343752690, 9474.609377190, 9646.875004048, 9819.140627591, 9991.406251289, 10163.671877038, 10335.937501008, 10508.203126187, 10680.468750748, 10852.734375129, 11025.000000000, 11197.265624618, 11369.531249516, 11541.796874351, 11714.062498897, 11886.328122716, 12058.593748662, 12230.859372797, 12403.124996237, 12575.390622207, 12747.656246830, 12919.921875455, 13092.187494451, 13264.453118973, 13436.718748035, 13608.984370830, 13781.249991857, 13953.515626614, 14125.781249475, 14298.046875918, 14470.312494312, 14642.578118001, 14814.843746034, 14987.109370627, 15159.374994823, 15331.640617057, 15503.906242865, 15676.171867063, 15848.437494762, 16020.703118027, 16192.968746288, 16365.234371274, 16537.499995256, 16709.765622164, 16882.031246440, 17054.296865897, 17226.562492526, 17398.828113024, 17571.093736919, 17743.359361459, 17915.624990597, 18087.890614243, 18260.156240676, 18432.421855285, 18604.687483097, 18776.953130401, 18949.218754459, 19121.484389530, 19293.749961692, 19466.015606863, 19638.281247918, 19810.546834386, 19982.812450661, 20155.078147972, 20327.343727455, 20499.609346121, 20671.874930324, 20844.140592387, 21016.406233899, 21188.671845644, 21360.937478510, 21533.203108994, 21705.468678356, 21877.734276834, 22050.000000000 }

afSTFT centre frequencies for 128 hop size, hybrid-mode enabled, 44.1kHz

Definition at line 58 of file afSTFTlib.c.

◆ __afCenterFreq48e3

const double __afCenterFreq48e3[133]
static
Initial value:
=
{ 0.000000000, 140.644316361, 234.355478108, 328.144332285, 421.855497937, 515.644326841, 609.355515147, 703.144330614, 796.855543885, 937.500032020, 1125.000017338, 1312.500035449, 1500.000075751, 1687.500031782, 1875.000024239, 2062.499975101, 2250.000053703, 2437.500044271, 2625.000002315, 2812.500019782, 3000.000041692, 3187.499983930, 3374.999995137, 3562.499994173, 3750.000018557, 3937.500021643, 4125.000009859, 4312.500011528, 4500.000010423, 4687.500014446, 4875.000013588, 5062.500013570, 5250.000007575, 5437.500010288, 5625.000004178, 5812.500003421, 6000.000005158, 6187.500003404, 6375.000003488, 6562.500007191, 6750.000005972, 6937.500008499, 7125.000006936, 7312.500008549, 7500.000005032, 7687.500004875, 7875.000004878, 8062.500007586, 8250.000006218, 8437.499999805, 8625.000000113, 8812.499997984, 9000.000008860, 9187.500004401, 9375.000001529, 9562.500006565, 9750.000006335, 9937.499999557, 10125.000002928, 10312.500002384, 10500.000004406, 10687.500002820, 10875.000001403, 11062.500002219, 11250.000001097, 11437.500001292, 11625.000000815, 11812.500000140, 12000.000000000, 12187.499999584, 12374.999999473, 12562.499999294, 12749.999998799, 12937.499997514, 13124.999998543, 13312.499997602, 13499.999995904, 13687.499996961, 13874.999996550, 14062.500000495, 14249.999993960, 14437.499993440, 14624.999997861, 14812.499995461, 14999.999991137, 15187.500001756, 15374.999999428, 15562.500000999, 15749.999993809, 15937.499992382, 16124.999995683, 16312.499995240, 16499.999994365, 16687.499991354, 16874.999992234, 17062.499991361, 17249.999994298, 17437.499992410, 17624.999995960, 17812.499995945, 17999.999994836, 18187.499996913, 18374.999996125, 18562.499990092, 18749.999991865, 18937.499986965, 19124.999985762, 19312.499985261, 19499.999989766, 19687.499988292, 19874.999989851, 20062.499978542, 20249.999981602, 20437.500005879, 20625.000004853, 20812.500015815, 20999.999958305, 21187.499980259, 21374.999997733, 21562.499955794, 21749.999946298, 21937.500025004, 22124.999975461, 22312.499968567, 22499.999924162, 22687.499964503, 22874.999982475, 23062.499968048, 23249.999976609, 23437.499982579, 23624.999922020, 23812.499893152, 24000.000000000 }

afSTFT centre frequencies for 128 hop size, hybrid-mode enabled, 48kHz

Definition at line 54 of file afSTFTlib.c.

◆ __stft2hybCentreFreq

const float __stft2hybCentreFreq[9][5]
static
Initial value:
=
{ { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.7501f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 1.2499f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.8751f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 1.1249f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 0.9167f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 1.0833f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 0.0f, 0.9375f },
{ 0.0f, 0.0f, 0.0f, 0.0f, 1.0625f } }

Matrix for converting the centre frequencies of the first 5 stft bins into the centre frequencies for the 9 hybrid bands.

Definition at line 65 of file afSTFTlib.c.