OpenDAFF C++ API  v1.7
Directional Audio File Format
DAFFReaderImpl.h
Go to the documentation of this file.
1 /*
2  * -------------------------------------------------------------------------------------
3  *
4  * OpenDAFF - A free, open source software package for directional audio data
5  * Copyright 2016 Institute of Technical Acoustics, RWTH Aachen University
6  * OpenDAFF is distributed under the Apache License Version 2.0.
7  *
8  * ------------------------------------------------------------------------------------
9  *
10  */
11 
12 #ifndef IW_DAFF_READERIMPL
13 #define IW_DAFF_READERIMPL
14 
15 #include <DAFFDefs.h>
16 #include <DAFFContent.h>
17 #include <DAFFContentIR.h>
18 #include <DAFFContentMS.h>
19 #include <DAFFContentPS.h>
20 #include <DAFFContentMPS.h>
21 #include <DAFFContentDFT.h>
22 #include "DAFFHeader.h"
23 #include <DAFFProperties.h>
24 #include <DAFFReader.h>
25 #include <DAFFSCTransform.h>
26 
27 class DAFFMetadataImpl;
28 
29 class DAFFReaderImpl : public DAFFReader, public DAFFProperties, public DAFFContentIR, public DAFFContentMS, public DAFFContentPS, public DAFFContentMPS, public DAFFContentDFT {
30 public:
33 
34  bool isFileOpened() const;
35  int openFile( const std::string& );
36  void closeFile();
37  std::string getFilename() const;
38 
39  int deserialize( char* pDAFFDataBuffer );
40  bool isValid() const;
41 
42  int getFileFormatVersion() const;
43  int getContentType() const;
44  DAFFContent* getContent() const;
45  const DAFFMetadata* getMetadata() const;
47 
48  std::string toString() const;
49 
50  // --= Implementation of the interface "DAFFProperties" =--
51 
52  int getQuantization() const;
53  int getNumberOfChannels() const;
54  int getNumberOfRecords() const;
55  std::string getChannelLabel(int iChannel) const;
56 
57  int getAlphaPoints() const;
58  float getAlphaResolution() const;
59  float getAlphaStart() const;
60  float getAlphaEnd() const;
61  float getAlphaSpan() const;
62  int getBetaPoints() const;
63  float getBetaResolution() const;
64  float getBetaStart() const;
65  float getBetaEnd() const;
66  float getBetaSpan() const;
67 
69  void setDefaultOrientation();
70  void getOrientation(DAFFOrientationYPR& o) const;
71  void setOrientation(const DAFFOrientationYPR& o);
72 
73  bool coversFullAlphaRange() const;
74  bool coversFullBetaRange() const;
75  bool coversFullSphere() const;
76 
77  // --= Interface "DAFFContent" =--
78 
79  DAFFReader* getParent() const;
80  const DAFFMetadata* getRecordMetadata(int iRecordIndex) const;
81  int getRecordCoords(int iRecordIndex, int iView, float& fAngle1, float& fAngle2) const;
82  void getNearestNeighbour(int iView, float fAngle1Deg, float fAngle2Deg, int& iRecordIndex) const;
83  void getNearestNeighbour(int iView, float fAngle1Deg, float fAngle2Deg, int& iRecordIndex, bool& bOutOfBounds) const;
84  void getCell(int iView, float fAngle1, float fAngle2, DAFFQuad& qIndices) const;
85  void transformAnglesD2O(float fAlpha, float fBeta, float& fAzimuth, float& fElevation) const;
86  void transformAnglesO2D(float fAzimuth, float fElevation, float& fAlpha, float& fBeta) const;
87 
88  // --= Interface "DAFFContentIR" =--
89 
90  double getSamplerate() const;
91  int getFilterLength() const;
92  int getFilterCoeffs(int iRecordIndex, int iChannel, float* pfDest, float fGain=1.0F) const;
93  int addFilterCoeffs(int iRecordIndex, int iChannel, float* pfDest, float fGain=1.0F) const;
94  int getMinEffectiveFilterOffset() const;
95  int getMaxEffectiveFilterLength() const;
96  int getEffectiveFilterBounds(int iRecordIndex, int iChannel, int& iOffset, int& iLength) const;
97  int getEffectiveFilterCoeffs(int iRecordIndex, int iChannel, float* pfDest, float fGain=1.0F) const;
98  int addEffectiveFilterCoeffs(int iRecordIndex, int iChannel, float* pfDest, float fGain=1.0F) const;
99  float getOverallPeak(); // no const because of lazy initialization
100 
101  // --= Interface "DAFFContentMS" =--
102 
103  int getNumFrequencies() const;
104  const std::vector<float>& getFrequencies() const;
105  float getOverallMagnitudeMaximum() const;
106  int getMagnitudes(int iRecordIndex, int iChannel, float* pfData) const;
107  int getMagnitude(int iRecordIndex, int iChannel, int iFreqIndex, float& fMag) const;
108 
109  // --= Interface "DAFFContentPS" =--
110 
111  int getPhases(int iRecordIndex, int iChannel, float* pfData) const;
112  int getPhase(int iRecordIndex, int iChannel, int iFreqIndex, float& fPhase) const;
113 
114  // --= Interface "DAFFContentMPS" =--
115 
116  int getCoefficientsMP(int iRecordIndex, int iChannel, float* pfDest) const;
117  int getCoefficientsRI(int iRecordIndex, int iChannel, float* pfDest) const;
118 
119  // --= Interface "DAFFContentDFT" =--
120 
121  int getTransformSize() const;
122  int getNumDFTCoeffs() const;
123  bool isSymmetric() const;
124  double getFrequencyBandwidth() const;
125  int getDFTCoeff(int iRecordIndex, int iChannel, int iDFTCoeff, float& fReal, float& fImag) const;
126  int getDFTCoeffs(int iRecordIndex, int iChannel, float* pfDest) const;
127 
128 private:
129  bool m_bDAFFObjectValid;
130  bool m_bDAFFObjectFromFileValid;
131  std::string m_sFilePath;
132  FILE* m_file;
133  DAFFFileHeader m_fileHeader;
134  DAFFMainHeader* m_pMainHeader;
135  DAFFFileBlockEntry* m_pFileBlockTable;
136  DAFFFileBlockEntry* m_pRecordDescriptorTable;
137  DAFFFileBlockEntry* m_pDataFileBlock;
138  void* m_pContentHeader;
139  void* m_pRecordDescriptorBlock;
140  void* m_pDataBlock;
141  int m_iRecordChannelDescSize;
142 
143  DAFFContentHeaderIR* m_pContentHeaderIR;
144  DAFFContentHeaderMS* m_pContentHeaderMS;
145  DAFFContentHeaderPS* m_pContentHeaderPS;
146  DAFFContentHeaderMPS* m_pContentHeaderMPS;
147  DAFFContentHeaderDFT* m_pContentHeaderDFT;
148  std::vector< float > m_vfFreqs;
149 
150  const DAFFMetadataImpl* m_pEmptyMetadata;
151  std::vector< DAFFMetadataImpl* > m_vpMetadata;
152  DAFFProperties* m_pProperties;
153  bool m_bOverallPeakInitialized;
154  float m_fOverallPeak;
155 
156  DAFFOrientationYPR m_orientation;
157  DAFFOrientationYPR m_orientationDefault;
158 
159  float m_fAlphaResolution;
160  float m_fBetaResolution;
161  DAFFSCTransform m_tTrans;
162 
164 
167  int loadFileHeader();
168 
170 
173  int loadFileBlockTable();
174 
176 
179  int loadMainHeader();
180 
182 
185  int loadContentHeader();
186 
188 
191  int loadRecordDescriptor();
192 
194 
197  int loadRecordData();
198 
200 
203  int loadMetadata( char* );
204 
206 
209  void fixAngleRanges();
210 
211 
213  /* @return Total number of matching file blocks)
214  */
215  int getFirstFileBlockByID( int iID, DAFFFileBlockEntry*& pfDest ) const;
216 
218  int getFileBlocksByID( int iID, std::vector< DAFFFileBlockEntry* >& vpfDest ) const;
219 
221  void* getRecordChannelDescPtr( int iRecord, int iChannel ) const;
222 
224  int* getRecordMetadataIndexPtr( int iRecord ) const;
225 
227  void tidyup();
228 };
229 
230 #endif // IW_DAFF_READERIMPL
int getNumberOfRecords() const
Returns the overall number of records.
int getPhases(int iRecordIndex, int iChannel, float *pfData) const
Retrieves phase coefficients.
DAFF file format content header for phase spectra.
Definition: DAFFHeader.h:187
float getBetaResolution() const
float getAlphaEnd() const
void getDefaultOrientation(DAFFOrientationYPR &o) const
Returns the default orientation as stored in the file.
Reader interface for DAFF files.
Definition: DAFFReader.h:116
int getRecordCoords(int iRecordIndex, int iView, float &fAngle1, float &fAngle2) const
Determines the spherical coordinates of a record (grid point on spherical regular grid) ...
int getQuantization() const
Returns the quantization of the data elements.
void closeFile()
Closes an opened DAFF file.
std::string getChannelLabel(int iChannel) const
Returns the label of a channel.
DAFF file format content header for magnitude spectra.
Definition: DAFFHeader.h:169
bool coversFullAlphaRange() const
Indicates whether the data covers the full alpha range [0°, 360°)
void transformAnglesD2O(float fAlpha, float fBeta, float &fAzimuth, float &fElevation) const
Transforms data spherical coordinates into object spherical coordinates.
int getPhase(int iRecordIndex, int iChannel, int iFreqIndex, float &fPhase) const
Retrieves a single phase coefficient.
Common content interface.
Definition: DAFFContent.h:40
Magnitude spectrum content interface.
Definition: DAFFContentMS.h:31
Pure data class that describes the points of a quad by their indices and coordinates.
Definition: DAFFDefs.h:122
int addFilterCoeffs(int iRecordIndex, int iChannel, float *pfDest, float fGain=1.0F) const
Adds filter coefficients for record and channel to a given buffer.
Phase spectrum content interface.
Definition: DAFFContentPS.h:31
int getMinEffectiveFilterOffset() const
Returns the minimal effective filter offset over all records.
int getFilterLength() const
Returns the number of filter coefficients.
void setDefaultOrientation()
Sets/alters the default orientation manually.
float getOverallMagnitudeMaximum() const
Returns the overall greatest magnitude value.
int getMagnitudes(int iRecordIndex, int iChannel, float *pfData) const
Retrieves magnitude coefficients.
int getNumberOfChannels() const
Returns the number of channels.
int getEffectiveFilterBounds(int iRecordIndex, int iChannel, int &iOffset, int &iLength) const
Retrieves the offset and length of the effective part of a filter.
int getTransformSize() const
Returns the size of the transform (number of overall DFT coefficients)
bool isValid() const
int openFile(const std::string &)
Opens a DAFF file for reading.
int getFileFormatVersion() const
Returns the DAFF version of the file format.
const DAFFMetadata * getRecordMetadata(int iRecordIndex) const
Returns the metadata of a record.
int getAlphaPoints() const
int getMaxEffectiveFilterLength() const
Returns the maximum effective filter length over all records.
void transformAnglesO2D(float fAzimuth, float fElevation, float &fAlpha, float &fBeta) const
Transforms object spherical coordinates into data spherical coordinates.
This is the (pre) header of DAFF files.
Definition: DAFFHeader.h:61
DAFF file format content header for discrete Fourier spectra.
Definition: DAFFHeader.h:219
float getBetaEnd() const
Magnitude-phase spectrum content interface.
int getEffectiveFilterCoeffs(int iRecordIndex, int iChannel, float *pfDest, float fGain=1.0F) const
Retrieves effective filter coefficients for record and channel.
double getSamplerate() const
Returns the correspondig sampling rate [in Hertz].
float getAlphaStart() const
void getNearestNeighbour(int iView, float fAngle1Deg, float fAngle2Deg, int &iRecordIndex) const
Determine the nearest neighbour record and return its index.
A file block entry.
Definition: DAFFHeader.h:82
int getDFTCoeffs(int iRecordIndex, int iChannel, float *pfDest) const
Retrieves magnitude coefficients.
int deserialize(char *pDAFFDataBuffer)
Deserializes DAFF content from a byte buffer.
int getNumFrequencies() const
Returns the number of support points (frequencies)
float getOverallPeak()
Get overall peak value.
std::string toString() const
Returns string with information about the reader.
std::string getFilename() const
Returns the name of the opened DAFF file.
float getBetaSpan() const
bool isSymmetric() const
Returns whether the spectrum is complex-conjugated symmetric.
float getBetaStart() const
int getBetaPoints() const
bool isFileOpened() const
Returns whether a file is opened.
Impulse response content interface.
Definition: DAFFContentIR.h:38
const std::vector< float > & getFrequencies() const
Retrieves the frequencies [in Hertz] at which values are defined.
double getFrequencyBandwidth() const
Returns the frequency resolution [in Hertz].
const DAFFMetadata * getMetadata() const
Returns the metadata.
int getMagnitude(int iRecordIndex, int iChannel, int iFreqIndex, float &fMag) const
Retrieves a single magnitude coefficient.
int getCoefficientsRI(int iRecordIndex, int iChannel, float *pfDest) const
Retrieves coefficients in cartesian form.
Metadata interface.
Definition: DAFFMetadata.h:31
float getAlphaResolution() const
Discrete Fourier spectrum content interface.
int getNumDFTCoeffs() const
Returns the number of DFT coefficients.
DAFF file format content header for impulse responses.
Definition: DAFFHeader.h:151
DAFFProperties * getProperties() const
Returns the properties of the file.
Properties of a DAFF file that uses regular sphere grids (or parts of a regular grid) ...
int getContentType() const
Returns the content type.
int getCoefficientsMP(int iRecordIndex, int iChannel, float *pfDest) const
Retrieves coefficients in polar form.
void setOrientation(const DAFFOrientationYPR &o)
Sets the current orientation of the object view.
int getFilterCoeffs(int iRecordIndex, int iChannel, float *pfDest, float fGain=1.0F) const
Retrieves filter coefficients for record and channel.
int getDFTCoeff(int iRecordIndex, int iChannel, int iDFTCoeff, float &fReal, float &fImag) const
Retrieve a single magnitude coefficient.
DAFFContent * getContent() const
Returns the content.
float getAlphaSpan() const
void getCell(int iView, float fAngle1, float fAngle2, DAFFQuad &qIndices) const
Determines the cell of a given direction on the sphere grid and delivers its surrounding record indic...
Data class for orientations in yaw-pitch-roll (YPR) angles (right-handed OpenGL coordinate system) ...
Definition: DAFFDefs.h:138
bool coversFullSphere() const
Indicates whether the data covers the full sphere.
DAFFReader * getParent() const
Returns the parent reader.
void getOrientation(DAFFOrientationYPR &o) const
Returns the current orientation of the object view.
int addEffectiveFilterCoeffs(int iRecordIndex, int iChannel, float *pfDest, float fGain=1.0F) const
Adds effective filter coefficients for record and channel to a given buffer.
DAFF file format content header for magnitude-phase spectra.
Definition: DAFFHeader.h:202
bool coversFullBetaRange() const
Indicates whether the data covers the full beta range [0°, 180°].
OpenDAFF is a project from the Institute of Technical Acoustics, RWTH Aachen University, Germany.