Skip to content

Commit

Permalink
Added a basic ADM renderer to handle Object, DirectSpeaker and HOA st…
Browse files Browse the repository at this point in the history
…reams
  • Loading branch information
peterStitt authored and chouquette committed Oct 14, 2020
1 parent 06c4800 commit 8306cdc
Show file tree
Hide file tree
Showing 17 changed files with 3,642 additions and 0 deletions.
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ list(APPEND headers
include/AmbisonicDecoder.h
include/AmbisonicMicrophone.h
include/AmbisonicSource.h
include/AdmDecorrelate.h
include/AdmDirectSpeakerGainCalc.h
include/AdmLayouts.h
include/AdmMappingRules.h
include/AdmMetadata.h
include/AdmPointSourcePanner.h
include/AdmPointSourcePannerGainCalc.h
include/AdmRegionHandlers.h
include/AdmRenderer.h
include/AdmUtils.h
include/BFormat.h
include/mit_hrtf_lib.h
include/hrtf/hrtf.h
Expand Down Expand Up @@ -69,6 +79,12 @@ list(APPEND sources
source/AmbisonicSpeaker.cpp
source/AmbisonicEncoderDist.cpp
source/AmbisonicZoomer.cpp
source/AdmDecorrelate.cpp
source/AdmDirectSpeakerGainCalc.cpp
source/AdmPointSourcePanner.cpp
source/AdmPointSourcePannerGainCalc.cpp
source/AdmRegionHandlers.cpp
source/AdmRenderer.cpp
)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
Expand Down
103 changes: 103 additions & 0 deletions include/AdmDecorrelate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*############################################################################*/
/*# #*/
/*# A renderer for ADM streams. #*/
/*# CAdmRenderer - ADM Renderer #*/
/*# Copyright © 2020 Peter Stitt #*/
/*# #*/
/*# Filename: AdmRenderer.h #*/
/*# Version: 0.1 #*/
/*# Date: 23/06/2020 #*/
/*# Author(s): Peter Stitt #*/
/*# Licence: LGPL + proprietary #*/
/*# #*/
/*############################################################################*/

#pragma once

#include "AdmLayouts.h"
#include "AdmUtils.h"
#include "kiss_fftr.h"

namespace admrender {

/**
This class applied decorrelation to the output speaker layouts.
It allows allows for compensation delay to be applied to the direct signal
*/

class CAdmDecorrelate
{
public:
/*
layout is the target loudspeaker layout
nSamples is the maximum block size expected
*/
CAdmDecorrelate();
~CAdmDecorrelate();

/**
Re-create the object for the given configuration. Previous data is
lost. Returns true if successful.
*/
bool Configure(Layout layout, unsigned int nBlockSize);
/**
Not implemented.
*/
void Reset();
/**
Filter otate B-Format stream.
*/
void Process(std::vector<std::vector<float>> &ppInDirect, std::vector<std::vector<float>> &ppInDiffuse, unsigned int nSamples);

private:
// The time-domain decorrelation filters
std::vector<std::vector<float>> decorrelationFilters;
// Output layout
Layout m_layout;
// The number of channels in the output array
unsigned int m_nCh;

// According to Rec. ITU-R BS.2127-0 sec. 7.4 the decorrelation filter length is 512 samples
const unsigned int m_nDecorrelationFilterSamples = 512;

kiss_fftr_cfg m_pFFT_decor_cfg;
kiss_fftr_cfg m_pIFFT_decor_cfg;

float* m_pfScratchBufferA;
float** m_pfOverlap;
unsigned m_nFFTSize;
unsigned m_nBlockSize;
unsigned m_nTaps;
unsigned m_nOverlapLength;
unsigned m_nFFTBins;
float m_fFFTScaler;

kiss_fft_cpx** m_ppcpDecorFilters;
kiss_fft_cpx* m_pcpScratch;

// Buffers to hold the delayed direct signals
float** m_ppfDirectDelay;
unsigned int m_nDelayLineLength;
int m_nDelay = (m_nDecorrelationFilterSamples - 1) / 2;
int m_nReadPos = 0;
int m_nWritePos = 0;

/**
Read and write data to delay lines
*/
void WriteToDelayLine(float* pDelayLine, float* pIn, int nWritePos, int nSamples);
void ReadFromDelayLine(float* pDelayLine, float* pOut, int nReadPos, int nSamples);

/**
Calculate decorrelation filters using the method described in Rec. ITU-R BS.2127-0 sec. 7.4
The filters depend on the layout set at construction
*/
std::vector<std::vector<float>> CalculateDecorrelationFilterBank();

/**
Calculate the time-domain decorrelation filter for the a particular channel index seed
*/
std::vector<float> CalculateDecorrelationFilter(unsigned int seedIndex);
};

}
58 changes: 58 additions & 0 deletions include/AdmDirectSpeakerGainCalc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*############################################################################*/
/*# #*/
/*# Calculate the gain vector to spatialise a DirectSpeaker channel. #*/
/*# CAdmDirectSpeakersGainCalc #*/
/*# Copyright © 2020 Peter Stitt #*/
/*# #*/
/*# Filename: AdmDirectSpeakersGainCalc.h #*/
/*# Version: 0.1 #*/
/*# Date: 23/06/2020 #*/
/*# Author(s): Peter Stitt #*/
/*# Licence: LGPL + proprietary #*/
/*# #*/
/*############################################################################*/

#pragma once

#include "AdmMetadata.h"
#include "AdmLayouts.h"
#include "AdmUtils.h"
#include "AdmMappingRules.h"
#include "AdmPointSourcePannerGainCalc.h"

namespace admrender {

/**
A class to calculate the gains to be applied to a set of loudspeakers for DirectSpeaker processing
*/
class CAdmDirectSpeakersGainCalc
{
public:
CAdmDirectSpeakersGainCalc(Layout layoutWithLFE);
~CAdmDirectSpeakersGainCalc();

/**
Calculate the gain vector corresponding to the metadata input
*/
std::vector<double> calculateGains(DirectSpeakerMetadata metadata);

private:
unsigned int m_nCh = 0;
Layout m_layout;
CAdmPointSourcePannerGainCalc m_pointSourcePannerGainCalc;

bool isLFE(DirectSpeakerMetadata metadata);

/**
Find the closest speaker in the layout within the tolerance bounds
set
*/
int findClosestWithinBounds(DirectSpeakerPolarPosition direction, double tol);

/**
Determine if a given mapping rule applies for input layout, speaker label and output layout.
See Rec. ITU-R BS.2127-0 sec 8.4
*/
bool MappingRuleApplies(const MappingRule& rule, const std::string& input_layout, const std::string& speakerLabel, admrender::Layout& output_layout);
};
}
Loading

0 comments on commit 8306cdc

Please sign in to comment.