17 #pragma warning(disable: 4996) 22 : m_bDAFFObjectValid( false )
23 , m_bDAFFObjectFromFileValid( false )
25 m_pFileBlockTable(
NULL ),
26 m_pMainHeader(
NULL ),
27 m_pContentHeader(
NULL ),
28 m_pRecordDescriptorBlock(
NULL ),
30 m_bOverallPeakInitialized( false ),
39 delete m_pEmptyMetadata;
44 return ( m_bDAFFObjectFromFileValid && m_bDAFFObjectValid );
49 return m_bDAFFObjectValid;
54 if( m_bDAFFObjectValid )
58 char* pFileHeaderBuffer = (
char* ) &m_fileHeader;
60 pFileHeaderBuffer[ i ] = pDAFFDataBuffer[ i ];
62 int ec = loadFileHeader();
71 char* pFileBlockTableBuffer = (
char* ) m_pFileBlockTable;
73 for(
size_t i = 0; i < nFileBlockTableSize; i++ )
74 pFileBlockTableBuffer[ i ] = pDAFFDataBuffer[ i + nBufferReadPos ];
76 ec = loadFileBlockTable();
84 nBufferReadPos += nFileBlockTableSize;
88 if( getFirstFileBlockByID( FILEBLOCK_DAFF1_MAIN_HEADER_ID, pfbMainHeader ) != 1 )
95 char* pMainHeaderBuffer = (
char* ) m_pMainHeader;
98 pMainHeaderBuffer[ i ] = pDAFFDataBuffer[ i + pfbMainHeader->
ui64Offset ];
100 ec = loadMainHeader();
110 if( getFirstFileBlockByID( FILEBLOCK_DAFF1_CONTENT_HEADER_ID, pfbContentHeader ) != 1 )
117 char* pContentHeaderBuffer = (
char* ) m_pContentHeader;
119 for(
size_t i = 0; i < ( size_t ) pfbContentHeader->
ui64Size; i++ )
120 pContentHeaderBuffer[ i ] = pDAFFDataBuffer[ i + pfbContentHeader->
ui64Offset ];
122 ec = loadContentHeader();
131 if( getFirstFileBlockByID( FILEBLOCK_DAFF1_RECORD_DESC_ID, m_pRecordDescriptorTable ) != 1 )
138 char* pRecordDescriptorBuffer = (
char* ) m_pRecordDescriptorBlock;
140 for(
size_t i = 0; i < ( size_t ) m_pRecordDescriptorTable->
ui64Size; i++ )
141 pRecordDescriptorBuffer[ i ] = pDAFFDataBuffer[ i + m_pRecordDescriptorTable->
ui64Offset ];
143 ec = loadRecordDescriptor();
152 if( getFirstFileBlockByID( FILEBLOCK_DAFF1_DATA_ID, m_pDataFileBlock ) != 1 )
159 char* pDataBlockBuffer = (
char* ) m_pDataBlock;
161 for(
size_t i = 0; i < ( size_t ) m_pDataFileBlock->
ui64Size; i++ )
162 pDataBlockBuffer[ i ] = pDAFFDataBuffer[ i + m_pDataFileBlock->
ui64Offset ];
164 ec = loadRecordData();
174 if( getFirstFileBlockByID( FILEBLOCK_DAFF1_METADATA_ID, pMetadataFileBlock ) > 1 )
180 if( pMetadataFileBlock ==
nullptr )
184 else if( pMetadataFileBlock->
ui64Size == 0 )
192 char* pMetadataBuffer = (
char* ) pMetadataBuf;
194 for(
size_t i = 0; i < ( size_t ) pMetadataFileBlock->
ui64Size; i++ )
195 pMetadataBuffer[ i ] = pDAFFDataBuffer[ i + pMetadataFileBlock->
ui64Offset ];
197 ec = loadMetadata( pMetadataBuffer );
213 m_bDAFFObjectFromFileValid =
false;
214 m_bDAFFObjectValid =
true;
220 if( m_bDAFFObjectValid )
223 m_file = fopen( sFilePath.c_str(),
"rb" );
234 int ec = loadFileHeader();
241 if( fread( m_pFileBlockTable, 1, iFileBlockTableSize, m_file ) != iFileBlockTableSize )
247 ec = loadFileBlockTable();
253 if( getFirstFileBlockByID( FILEBLOCK_DAFF1_MAIN_HEADER_ID, pfbMainHeader ) != 1 )
260 fseek( m_file, (
long ) pfbMainHeader->
ui64Offset, SEEK_SET );
267 ec = loadMainHeader();
273 if( getFirstFileBlockByID( FILEBLOCK_DAFF1_CONTENT_HEADER_ID, pfbContentHeader ) != 1 )
280 fseek( m_file, (
long ) pfbContentHeader->
ui64Offset, SEEK_SET );
281 if( fread( m_pContentHeader, 1, (
size_t ) pfbContentHeader->
ui64Size, m_file ) != (
size_t ) pfbContentHeader->
ui64Size )
287 ec = loadContentHeader();
292 if( getFirstFileBlockByID( FILEBLOCK_DAFF1_RECORD_DESC_ID, m_pRecordDescriptorTable ) != 1 )
299 fseek( m_file, (
long ) m_pRecordDescriptorTable->
ui64Offset, SEEK_SET );
300 if( fread( m_pRecordDescriptorBlock, 1, (
size_t ) m_pRecordDescriptorTable->
ui64Size, m_file ) != (
size_t ) m_pRecordDescriptorTable->
ui64Size )
306 ec = loadRecordDescriptor();
311 if( getFirstFileBlockByID( FILEBLOCK_DAFF1_DATA_ID, m_pDataFileBlock ) != 1 )
318 fseek( m_file, (
long ) m_pDataFileBlock->
ui64Offset, SEEK_SET );
319 if( fread( m_pDataBlock, 1, (
size_t ) m_pDataFileBlock->
ui64Size, m_file ) != (
size_t ) m_pDataFileBlock->
ui64Size )
326 ec = loadRecordData();
332 if( getFirstFileBlockByID( FILEBLOCK_DAFF1_METADATA_ID, pMetadataFileBlock ) > 1 )
338 if( pMetadataFileBlock ==
nullptr )
342 else if( pMetadataFileBlock->
ui64Size == 0 )
350 fseek( m_file, (
long ) pMetadataFileBlock->
ui64Offset, SEEK_SET );
351 if( fread( pMetadataBuf, 1, (
size_t ) pMetadataFileBlock->
ui64Size, m_file ) != (
size_t ) pMetadataFileBlock->
ui64Size )
358 ec = loadMetadata( (
char* ) pMetadataBuf );
372 m_sFilePath = sFilePath;
373 m_bDAFFObjectValid =
true;
374 m_bDAFFObjectFromFileValid =
true;
379 int DAFFReaderImpl::loadFileHeader()
415 int DAFFReaderImpl::loadFileBlockTable()
421 m_pFileBlockTable[ i ].fixEndianness();
423 #if ( DAFF_DEBUG == 1 ) 425 printf(
"FILE BLOCK[%d] = { ID = 0x%04X, offset = %llu, size = %llu bytes }\n",
426 i, m_pFileBlockTable[i].iID, m_pFileBlockTable[i].ui64Offset, m_pFileBlockTable[i].ui64Size );
433 if( ( m_pFileBlockTable[ i ].ui64Offset < (
sizeof(
DAFFFileHeader ) + iFileBlockTableSize ) ) )
443 int DAFFReaderImpl::loadMainHeader()
511 if( ( m_pMainHeader->
fBetaEnd < 0.0f ) || ( m_pMainHeader->
fBetaEnd > 180.0f ) )
523 int DAFFReaderImpl::loadContentHeader()
557 pfFreqs = (
float* ) ( (
char* ) m_pContentHeader + 8 );
563 m_vfFreqs.resize( m_pContentHeaderMS->
iNumFreqs );
564 for(
int i = 0; i < m_pContentHeaderMS->
iNumFreqs; i++ )
565 m_vfFreqs[ i ] = pfFreqs[ i ];
576 pfFreqs = (
float* ) ( (
char* ) m_pContentHeader + 8 );
582 m_vfFreqs.resize( m_pContentHeaderPS->
iNumFreqs );
583 for(
int i = 0; i < m_pContentHeaderPS->
iNumFreqs; i++ ) m_vfFreqs[ i ] = pfFreqs[ i ];
591 if( m_pContentHeaderMPS->
iNumFreqs <= 0 )
594 pfFreqs = (
float* ) ( (
char* ) m_pContentHeader + 8 );
600 m_vfFreqs.resize( m_pContentHeaderMPS->
iNumFreqs );
601 for(
int i = 0; i < m_pContentHeaderMPS->
iNumFreqs; i++ ) m_vfFreqs[ i ] = pfFreqs[ i ];
619 int DAFFReaderImpl::loadRecordDescriptor()
631 assert( m_iRecordChannelDescSize == 20 );
634 for(
int i = 0; i < m_pMainHeader->
iNumRecords; i++ )
655 for(
int i = 0; i < m_pMainHeader->
iNumRecords; i++ )
672 int DAFFReaderImpl::loadRecordData()
697 int DAFFReaderImpl::loadMetadata(
char* pMetadataBuf )
704 if( getFirstFileBlockByID( FILEBLOCK_DAFF1_METADATA_ID, pMetadataFileBlock ) > 1 )
710 if( pMetadataFileBlock ==
nullptr )
714 else if( pMetadataFileBlock->
ui64Size == 0 )
723 size_t iBytesRead = 0;
724 char* pCurrentBuf = pMetadataBuf;
725 char* pEndOfMetaDataBuf = pCurrentBuf + ( size_t ) pMetadataFileBlock->
ui64Size;
726 while( pCurrentBuf < pEndOfMetaDataBuf )
729 int iError = pMetadataImpl->
load( pCurrentBuf, iBytesRead );
730 if( ( iError != 0 ) || ( iBytesRead == 0 ) )
736 m_vpMetadata.push_back( pMetadataImpl );
739 pCurrentBuf += iBytesRead;
746 void DAFFReaderImpl::fixAngleRanges()
774 if( fAlphaSpan == 360 )
775 m_fAlphaResolution = fAlphaSpan / m_pMainHeader->
iAlphaPoints;
777 m_fAlphaResolution = fAlphaSpan / ( m_pMainHeader->
iAlphaPoints - 1 );
780 m_fAlphaResolution = 0;
783 m_fBetaResolution = fBetaSpan / ( m_pMainHeader->
iBetaPoints - 1 );
785 m_fBetaResolution = 0;
790 if( !m_bDAFFObjectValid )
796 void DAFFReaderImpl::tidyup()
805 m_pFileBlockTable =
NULL;
808 m_pMainHeader =
NULL;
811 m_pContentHeader =
NULL;
814 m_pRecordDescriptorBlock =
NULL;
819 for(
size_t i = 0; i < m_vpMetadata.size(); ++i )
820 delete m_vpMetadata[ i ];
822 m_vpMetadata.clear();
825 m_bDAFFObjectValid =
false;
828 int DAFFReaderImpl::getFirstFileBlockByID(
int iID,
DAFFFileBlockEntry*& pfDest )
const 830 std::vector<DAFFFileBlockEntry*> v;
831 getFileBlocksByID( iID, v );
840 return (
int ) v.size();
843 int DAFFReaderImpl::getFileBlocksByID(
int iID, std::vector<DAFFFileBlockEntry*>& vpfDest )
const 847 if( m_pFileBlockTable[ i ].iID == iID ) vpfDest.push_back( &( m_pFileBlockTable[ i ] ) );
850 return (
int ) vpfDest.size();
855 assert( m_bDAFFObjectValid );
861 assert( m_bDAFFObjectValid );
867 assert( m_bDAFFObjectValid );
873 assert( m_bDAFFObjectValid );
881 assert( m_bDAFFObjectValid );
882 return m_vpMetadata[ 0 ];
887 assert( m_bDAFFObjectValid );
894 assert( m_bDAFFObjectValid );
896 std::stringstream ss;
905 ss <<
"Alpha range: [" <<
909 ss <<
"Beta range: [" <<
915 ss <<
"Orientation: " << o.toString() << std::endl;
920 std::vector<float> vsFrequencies;
935 ss <<
"Frequency support: ";
936 for(
size_t i = 0; i < vsFrequencies.size(); i++ ) {
938 if( i < ( vsFrequencies.size() - 1 ) ) ss <<
", ";
940 ss <<
" Hz" << std::endl;
947 ss <<
"Symmetric: " << ( ( pContentDFT->
isSymmetric() ) ?
"yes" :
"no" ) << std::endl;
948 ss <<
"Samplerate: " << pContentDFT->
getSamplerate() << std::endl;
957 assert( m_bDAFFObjectValid );
962 assert( m_bDAFFObjectValid );
968 assert( m_bDAFFObjectValid );
982 assert( m_bDAFFObjectValid );
983 assert( ( iChannel >= 0 ) && ( iChannel < m_pMainHeader->iNumChannels ) );
986 std::stringstream ss;
987 ss <<
"LABEL_CHANNEL_" << ( iChannel + 1 );
988 return ( ( m_vpMetadata.size() > 0 ) && ( m_vpMetadata[ 0 ]->hasKey( ss.str() ) ) ? m_vpMetadata[ 0 ]->getKeyString( ss.str() ) :
"" );
993 assert( m_bDAFFObjectValid );
998 assert( m_bDAFFObjectValid );
1000 return m_fAlphaResolution;
1004 assert( m_bDAFFObjectValid );
1009 assert( m_bDAFFObjectValid );
1014 assert( m_bDAFFObjectValid );
1022 assert( m_bDAFFObjectValid );
1027 assert( m_bDAFFObjectValid );
1028 return m_fBetaResolution;
1032 assert( m_bDAFFObjectValid );
1037 assert( m_bDAFFObjectValid );
1042 assert( m_bDAFFObjectValid );
1047 assert( m_bDAFFObjectValid );
1048 o = m_orientationDefault;
1052 assert( m_bDAFFObjectValid );
1057 assert( m_bDAFFObjectValid );
1062 assert( m_bDAFFObjectValid );
1067 assert( m_bDAFFObjectValid );
1076 assert( m_bDAFFObjectValid );
1085 assert( m_bDAFFObjectValid );
1110 assert( ( iRecordIndex >= 0 ) && ( iRecordIndex < m_pMainHeader->iNumRecords ) );
1112 if( ( iRecordIndex < 0 ) || ( iRecordIndex >= m_pMainHeader->
iNumRecords ) )
1113 return m_pEmptyMetadata;
1115 int iMetadataIndex = *getRecordMetadataIndexPtr( iRecordIndex );
1117 assert( ( iMetadataIndex >= -1 ) && ( iMetadataIndex < (
int ) m_vpMetadata.size() ) );
1119 if( iMetadataIndex == -1 )
1120 return m_pEmptyMetadata;
1122 return m_vpMetadata[ iMetadataIndex ];
1126 assert( ( iRecordIndex >= 0 ) || ( iRecordIndex < m_pMainHeader->iNumRecords ) );
1130 if( ( iRecordIndex < 0 ) || ( iRecordIndex >= m_pMainHeader->
iNumRecords ) ) {
1136 float fAlpha, fBeta;
1138 bool bSouthPolePresent =
false;
1140 bSouthPolePresent =
true;
1142 if( bSouthPolePresent ) {
1143 if( iRecordIndex == 0 ) {
1148 iAlpha = ( iRecordIndex - 1 ) % m_pMainHeader->
iAlphaPoints;
1149 iBeta = 1 + (
int ) ( ( iRecordIndex - 1 ) / m_pMainHeader->
iAlphaPoints );
1150 fAlpha = m_pMainHeader->
fAlphaStart + ( ( float ) iAlpha * m_fAlphaResolution );
1151 fBeta = ( float ) iBeta * m_fBetaResolution;
1156 iBeta = ( int ) ( iRecordIndex / m_pMainHeader->
iAlphaPoints );
1157 fAlpha = m_pMainHeader->
fAlphaStart + ( ( float ) iAlpha * m_fAlphaResolution );
1158 fBeta = m_pMainHeader->
fBetaStart + ( ( float ) iBeta * m_fBetaResolution );
1194 bOutOfBounds =
false;
1196 int iAlphaIndex, iBetaIndex;
1202 bOutOfBounds =
true;
1203 if( fAlpha == m_pMainHeader->
fAlphaStart && fAlpha == std::fmod( m_pMainHeader->
fAlphaEnd, 360.0f ) )
1204 bOutOfBounds =
false;
1208 if( ( fAlpha >= m_pMainHeader->
fAlphaStart ) && ( fAlpha <= m_pMainHeader->fAlphaEnd ) )
1211 iAlphaIndex = ( int ) roundf( ( fAlpha - m_pMainHeader->
fAlphaStart ) / m_fAlphaResolution );
1222 bOutOfBounds =
true;
1230 bOutOfBounds =
true;
1232 bOutOfBounds =
false;
1239 iBetaIndex = ( int ) roundf( ( fBeta - m_pMainHeader->
fBetaStart ) / m_fBetaResolution );
1245 if( std::abs( m_pMainHeader->
fBetaStart - fBeta ) <= std::abs( m_pMainHeader->
fBetaEnd - fBeta ) )
1248 iBetaIndex = ( int ) m_pMainHeader->
iBetaPoints - 1;
1250 bOutOfBounds =
true;
1257 if( iBetaIndex == 0 )
1263 if( ( iBetaIndex == m_pMainHeader->
iBetaPoints - 1 ) && ( m_pMainHeader->
fBetaEnd == 180.0f ) )
1264 iRecordIndex = 1 + ( iBetaIndex - 1 ) * m_pMainHeader->
iAlphaPoints;
1266 iRecordIndex = 1 + ( iBetaIndex - 1 ) * m_pMainHeader->
iAlphaPoints + iAlphaIndex;
1271 if( ( iBetaIndex == m_pMainHeader->
iBetaPoints - 1 ) && ( m_pMainHeader->
fBetaEnd == 180.0f ) )
1272 iRecordIndex = iBetaIndex * m_pMainHeader->
iAlphaPoints;
1274 iRecordIndex = iBetaIndex * m_pMainHeader->
iAlphaPoints + iAlphaIndex;
1283 float fAlpha = fAngle1;
1284 float fBeta = fAngle2;
1299 float fAlpha1 = 0, fAlpha2 = 0, fAlpha3 = 0, fAlpha4 = 0;
1300 float fBeta1 = 0, fBeta2 = 0, fBeta3 = 0, fBeta4 = 0;
1313 if( fBeta2 > 180.0f ) {
1361 int iEffectiveLength;
1368 for(
int i = 0; i < iOffset; i++ )
1385 int iEffectiveLength;
1402 assert( ( iRecordIndex >= 0 ) && ( iRecordIndex < m_pMainHeader->iNumRecords ) );
1403 assert( ( iChannel >= 0 ) && ( iChannel < m_pMainHeader->iNumChannels ) );
1405 if( ( iRecordIndex < 0 ) || ( iRecordIndex >= m_pMainHeader->
iNumRecords ) ||
1406 ( iChannel < 0 ) || ( iChannel >= m_pMainHeader->
iNumChannels ) )
1418 assert( ( iRecordIndex >= 0 ) && ( iRecordIndex < m_pMainHeader->iNumRecords ) );
1419 assert( ( iChannel >= 0 ) && ( iChannel < m_pMainHeader->iNumChannels ) );
1421 if( ( iRecordIndex < 0 ) || ( iRecordIndex >= m_pMainHeader->
iNumRecords ) ||
1422 ( iChannel < 0 ) || ( iChannel >= m_pMainHeader->
iNumChannels ) )
1425 if( pfDest ==
NULL )
1431 void* pData =
reinterpret_cast< char*
>( m_pDataBlock ) + pDesc->
ui64DataOffset;
1447 memcpy( pfDest, pData, pDesc->
iElementLength *
sizeof(
float ) );
1452 float* pfData = (
float* ) pData;
1454 pfDest[ i ] = pfData[ i ] * fGain;
1464 assert( ( iRecordIndex >= 0 ) && ( iRecordIndex < m_pMainHeader->iNumRecords ) );
1465 assert( ( iChannel >= 0 ) && ( iChannel < m_pMainHeader->iNumChannels ) );
1467 if( ( iRecordIndex < 0 ) || ( iRecordIndex >= m_pMainHeader->
iNumRecords ) ||
1468 ( iChannel < 0 ) || ( iChannel >= m_pMainHeader->
iNumChannels ) )
1476 void* pData =
reinterpret_cast< char*
>( m_pDataBlock ) +pDesc->
ui64DataOffset;
1489 float* pfData = (
float* ) pData;
1491 pfDest[ i ] += pfData[ i ] * fGain;
1520 return m_pContentHeaderMS->
fMax;
1522 return m_pContentHeaderMPS->
fMax;
1524 return m_pContentHeaderDFT->
fMax;
1531 if( !m_bOverallPeakInitialized )
1536 pBuf =
new float[ iSize ];
1537 for(
int i = 0; i < m_pMainHeader->
iNumRecords; i++ )
1538 for(
int j = 0; j < m_pMainHeader->
iNumChannels; j++ ) {
1541 for(
int k = 0; k<iLen - iOffs; k++ )
1542 if( fabs( pBuf[ k ] ) > m_fOverallPeak )
1543 m_fOverallPeak = fabs( pBuf[ k ] );
1546 m_bOverallPeakInitialized =
true;
1548 return m_fOverallPeak;
1552 assert( ( iRecordIndex >= 0 ) && ( iRecordIndex < m_pMainHeader->iNumRecords ) );
1553 assert( ( iChannel >= 0 ) && ( iChannel < m_pMainHeader->iNumChannels ) );
1555 if( ( iRecordIndex < 0 ) || ( iRecordIndex >= m_pMainHeader->
iNumRecords ) ||
1556 ( iChannel < 0 ) || ( iChannel >= m_pMainHeader->
iNumChannels ) )
1566 pfSrc =
reinterpret_cast< float*
>(
reinterpret_cast< char*
>( m_pDataBlock ) +pDesc->
ui64DataOffset );
1567 memcpy( pfData, pfSrc, m_pContentHeaderMS->
iNumFreqs*
sizeof(
float ) );
1570 pfSrc =
reinterpret_cast< float*
>(
reinterpret_cast< char*
>( m_pDataBlock ) +pDesc->
ui64DataOffset );
1572 for(
int i = 0; i <= m_pContentHeaderMPS->
iNumFreqs; i++ )
1573 pfData[ i ] = pfSrc[ 2 * i ];
1584 assert( ( iRecordIndex >= 0 ) && ( iRecordIndex < m_pMainHeader->iNumRecords ) );
1585 assert( ( iChannel >= 0 ) && ( iChannel < m_pMainHeader->iNumChannels ) );
1587 if( ( iRecordIndex < 0 ) || ( iRecordIndex >= m_pMainHeader->
iNumRecords ) ||
1588 ( iChannel < 0 ) || ( iChannel >= m_pMainHeader->
iNumChannels ) )
1592 float* pfSrc =
NULL;
1597 if( ( iFreqIndex < 0 ) || ( iFreqIndex >= m_pContentHeaderMS->
iNumFreqs ) )
1600 pfSrc =
reinterpret_cast< float*
>(
reinterpret_cast< char*
>( m_pDataBlock ) + pDesc->
ui64DataOffset );
1601 fMag = pfSrc[ iFreqIndex ];
1604 if( ( iFreqIndex < 0 ) || ( iFreqIndex >= m_pContentHeaderMPS->
iNumFreqs ) )
1607 pfSrc =
reinterpret_cast< float*
>(
reinterpret_cast< char*
>( m_pDataBlock ) + pDesc->
ui64DataOffset );
1608 fMag = pfSrc[ 2 * iFreqIndex ];
1619 assert( ( iRecordIndex >= 0 ) && ( iRecordIndex < m_pMainHeader->iNumRecords ) );
1620 assert( ( iChannel >= 0 ) && ( iChannel < m_pMainHeader->iNumChannels ) );
1622 if( ( iRecordIndex < 0 ) || ( iRecordIndex >= m_pMainHeader->
iNumRecords ) ||
1623 ( iChannel < 0 ) || ( iChannel >= m_pMainHeader->
iNumChannels ) )
1634 pfSrc =
reinterpret_cast< float*
>(
reinterpret_cast< char*
>( m_pDataBlock ) +pDesc->
ui64DataOffset );
1635 memcpy( pfData, pfSrc, m_pContentHeaderPS->
iNumFreqs *
sizeof(
float ) );
1638 pfSrc =
reinterpret_cast< float*
>(
reinterpret_cast< char*
>( m_pDataBlock ) +pDesc->
ui64DataOffset );
1639 for(
int i = 0; i <= m_pContentHeaderMPS->
iNumFreqs; i++ )
1640 pfData[ i ] = pfSrc[ 2 * i + 1 ];
1650 assert( ( iRecordIndex >= 0 ) && ( iRecordIndex < m_pMainHeader->iNumRecords ) );
1651 assert( ( iChannel >= 0 ) && ( iChannel < m_pMainHeader->iNumChannels ) );
1653 if( ( iRecordIndex < 0 ) || ( iRecordIndex >= m_pMainHeader->
iNumRecords ) ||
1654 ( iChannel < 0 ) || ( iChannel >= m_pMainHeader->
iNumChannels ) )
1662 if( ( iFreqIndex < 0 ) || ( iFreqIndex >= m_pContentHeaderPS->
iNumFreqs ) )
1665 pfSrc =
reinterpret_cast< float*
>(
reinterpret_cast< char*
>( m_pDataBlock ) +pDesc->
ui64DataOffset );
1666 fPhase = pfSrc[ iFreqIndex ];
1669 if( ( iFreqIndex < 0 ) || ( iFreqIndex >= m_pContentHeaderMPS->
iNumFreqs ) )
1672 pfSrc =
reinterpret_cast< float*
>(
reinterpret_cast< char*
>( m_pDataBlock ) +pDesc->
ui64DataOffset );
1673 fPhase = pfSrc[ 2 * iFreqIndex + 1 ];
1682 assert( ( iRecordIndex >= 0 ) && ( iRecordIndex < m_pMainHeader->iNumRecords ) );
1683 assert( ( iChannel >= 0 ) && ( iChannel < m_pMainHeader->iNumChannels ) );
1685 if( ( iRecordIndex < 0 ) || ( iRecordIndex >= m_pMainHeader->
iNumRecords ) ||
1686 ( iChannel < 0 ) || ( iChannel >= m_pMainHeader->
iNumChannels ) )
1692 float* pfSrc =
reinterpret_cast< float*
>(
reinterpret_cast< char*
>( m_pDataBlock ) +pDesc->
ui64DataOffset );
1695 for(
int i = 0; i <= m_pContentHeaderMPS->
iNumFreqs; i++ ) {
1697 pfDest[ 2 * i ] =
DAFF::cabs( pfSrc[ 2 * i ], pfSrc[ 2 * i + 1 ] );
1699 pfDest[ 2 * i + 1 ] =
DAFF::carg( pfSrc[ 2 * i ], pfSrc[ 2 * i + 1 ] );
1706 assert( ( iRecordIndex >= 0 ) && ( iRecordIndex < m_pMainHeader->iNumRecords ) );
1707 assert( ( iChannel >= 0 ) && ( iChannel < m_pMainHeader->iNumChannels ) );
1709 if( ( iRecordIndex < 0 ) || ( iRecordIndex >= m_pMainHeader->
iNumRecords ) ||
1710 ( iChannel < 0 ) || ( iChannel >= m_pMainHeader->
iNumChannels ) )
1716 float* pfSrc =
reinterpret_cast< float*
>(
reinterpret_cast< char*
>( m_pDataBlock ) +pDesc->
ui64DataOffset );
1717 memcpy( pfDest, pfSrc, 2 * m_pContentHeaderMPS->
iNumFreqs*
sizeof(
float ) );
1740 assert( ( iRecordIndex >= 0 ) && ( iRecordIndex < m_pMainHeader->iNumRecords ) );
1741 assert( ( iChannel >= 0 ) && ( iChannel < m_pMainHeader->iNumChannels ) );
1742 assert( ( iDFTCoeff >= 0 ) && ( iDFTCoeff < m_pContentHeaderDFT->iNumDFTCoeffs ) );
1747 float* pfSrc =
reinterpret_cast< float*
>(
reinterpret_cast< char*
>( m_pDataBlock ) +pDesc->
ui64DataOffset );
1749 fReal = pfSrc[ 2 * iDFTCoeff + 0 ];
1750 fImag = pfSrc[ 2 * iDFTCoeff + 1 ];
1756 assert( ( iRecordIndex >= 0 ) && ( iRecordIndex < m_pMainHeader->iNumRecords ) );
1757 assert( ( iChannel >= 0 ) && ( iChannel < m_pMainHeader->iNumChannels ) );
1759 if( ( iRecordIndex < 0 ) || ( iRecordIndex >= m_pMainHeader->
iNumRecords ) ||
1760 ( iChannel < 0 ) || ( iChannel >= m_pMainHeader->
iNumChannels ) )
1766 float* pfSrc =
reinterpret_cast< float*
>(
reinterpret_cast< char*
>( m_pDataBlock ) +pDesc->
ui64DataOffset );
1767 memcpy( pfDest, pfSrc, 2 * m_pContentHeaderDFT->
iNumDFTCoeffs*
sizeof(
float ) );
1772 void* DAFFReaderImpl::getRecordChannelDescPtr(
int iRecord,
int iChannel )
const 1775 uint64_t uiRecordDescriptorOffset = iRecord * ( m_pMainHeader->
iNumChannels * m_iRecordChannelDescSize ) + iChannel * m_iRecordChannelDescSize;
1778 assert( uiRecordDescriptorOffset < m_pRecordDescriptorTable->ui64Size );
1781 void* pPtr = ( (
char* ) m_pRecordDescriptorBlock ) + uiRecordDescriptorOffset;
1785 int* DAFFReaderImpl::getRecordMetadataIndexPtr(
int iRecord )
const 1787 char* p = (
char* ) ( getRecordChannelDescPtr( iRecord, 0 ) );
1788 int* piMetaDataIndex = (
int* ) ( p );
1790 return piMetaDataIndex;
int getNumberOfRecords() const
Returns the overall number of records.
int getPhases(int iRecordIndex, int iChannel, float *pfData) const
Retrieves phase coefficients.
float fOrientPitch
@ Yaw angle of the orientation [°]
float getBetaResolution() const
float getAlphaEnd() const
File has unkown content type (IR, MS, DFT, etc)
void fixEndianness()
@ Roll angle of the orientation [°]
float fPitchAngleDeg
Pitch angle (degrees)
float fBetaStart
@ Number of measurement points in beta range [0°, 180°]
void getDefaultOrientation(DAFFOrientationYPR &o) const
Returns the default orientation as stored in the file.
Reader interface for DAFF files.
int getRecordCoords(int iRecordIndex, int iView, float &fAngle1, float &fAngle2) const
Determines the spherical coordinates of a record (grid point on spherical regular grid) ...
Discrete Fourier spectrum in the frequency-domain.
virtual int getTransformSize() const =0
Returns the size of the transform (number of overall DFT coefficients)
int getQuantization() const
Returns the quantization of the data elements.
void closeFile()
Closes an opened DAFF file.
Invalid alpha angles or range problem.
std::string getChannelLabel(int iChannel) const
Returns the label of a channel.
bool coversFullAlphaRange() const
Indicates whether the data covers the full alpha range [0°, 360°)
int32_t iLeadingZeros
@ Position inside the file where samples/coefficients reside (in bytes)
void fixEndianness()
@ Number of data values (length of element of record channel for a single channel, only)
uint64_t ui64DataOffset
@ Index in metadata table (C-style indexing: beginning with 0)
Invalid index (e.g. record index)
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.
static void NormalizeDirection(int iView, float fAngle1DegIn, float fAngle2DegIn, float &fAngle1DegOut, float &fAngle2DegOut)
Normalize a direction (angular pair)
Common content interface.
Pure data class that describes the points of a quad by their indices and coordinates.
void(* le2se_2byte)(void *src, size_t count)
void(* le2se_3byte)(void *src, size_t count)
Magnitude spectrum defined at discrete frequencies.
int addFilterCoeffs(int iRecordIndex, int iChannel, float *pfDest, float fGain=1.0F) const
Adds filter coefficients for record and channel to a given buffer.
File format version is not supported by this library version.
uint64_t ui64DataOffset
@ Index in metadata table (C-style indexing: beginning with 0)
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.
int32_t iElementLength
@ Offset of actual data within impulse response (leading zeros that are not included in DAFF data) ...
Invalid beta angles or range problem.
int getNumberOfChannels() const
Returns the number of channels.
int32_t iAlphaPoints
@ Index of global metadata
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)
virtual int getFilterLength() const =0
Returns the number of filter coefficients.
virtual double getSamplerate() const =0
Returns the sampling rate [in Hertz].
int openFile(const std::string &)
Opens a DAFF file for reading.
Magnitude-phase spectrum defined at discrete frequencies.
static std::string StrQuantizationType(int iQuantizationType)
Returns a string corresponding to a quantization type.
int getFileFormatVersion() const
Returns the DAFF version of the file format.
const DAFFMetadata * getRecordMetadata(int iRecordIndex) const
Returns the metadata of a record.
void stc_sint16_to_float(float *dest, const short *src, size_t count, int input_stride, int output_stride, float gain)
Convert signed integer 16-Bit -> single precision floating point (32-Bit)
int getAlphaPoints() const
void stc_sint24_to_float(float *dest, const void *src, size_t count, int input_stride, int output_stride, float gain)
Convert signed integer 24-Bit -> single precision floating point (32-Bit)
Impulse response (IR) in the time-domain.
int32_t iElementsPerRecord
@ Overall number of records
int getMaxEffectiveFilterLength() const
Returns the maximum effective filter length over all records.
int iIndex1
First index point.
void transformAnglesO2D(float fAzimuth, float fElevation, float &fAlpha, float &fBeta) const
Transforms object spherical coordinates into data spherical coordinates.
float carg(float Re, float Im)
int getEffectiveFilterCoeffs(int iRecordIndex, int iChannel, float *pfDest, float fGain=1.0F) const
Retrieves effective filter coefficients for record and channel.
Modal error (e.g. close a file that is not opened)
float fAlphaStart
@ Number of measurement points in alpha range [0°, 360°)
int32_t iNumRecords
@ Number of channels
void stc_sint16_to_float_add(float *dest, const short *src, size_t count, int input_stride, int output_stride, float gain)
double getSamplerate() const
Returns the correspondig sampling rate [in Hertz].
float getAlphaStart() const
virtual int getAlphaPoints() const =0
void getNearestNeighbour(int iView, float fAngle1Deg, float fAngle2Deg, int &iRecordIndex) const
Determine the nearest neighbour record and return its index.
int getDFTCoeffs(int iRecordIndex, int iChannel, float *pfDest) const
Retrieves magnitude coefficients.
int deserialize(char *pDAFFDataBuffer)
Deserializes DAFF content from a byte buffer.
static std::string Double2StrNice(double d, int precision, bool showpos, int leadingzeros=0)
Converts a double precision floating point into nice std::string.
int getNumFrequencies() const
Returns the number of support points (frequencies)
float fRollAngleDeg
Roll angle (degrees)
Data reading error of an otherwise valid DAFF file.
float getOverallPeak()
Get overall peak value.
virtual int getNumberOfRecords() const =0
Returns the overall number of records.
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
int32_t iQuantization
@ Identificator of the database content type
Content parameter invalid (sampling rate, num supporting frequencies, etc)
Invalid DAFF file, i.e. wrong signature.
float anglef_mindiff_abs_0_360_DEG(float alpha, float beta)
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.
float fYawAngleDeg
Yaw angle (degrees)
Impulse response content interface.
const std::vector< float > & getFrequencies() const
Retrieves the frequencies [in Hertz] at which values are defined.
void fixEndianness()
@ Position inside the file where samples/coefficients reside
void(* le2se_4byte)(void *src, size_t count)
double getFrequencyBandwidth() const
Returns the frequency resolution [in Hertz].
const DAFFMetadata * getMetadata() const
Returns the metadata.
int iIndex3
Third index point.
int iIndex2
Second index point.
int getMagnitude(int iRecordIndex, int iChannel, int iFreqIndex, float &fMag) const
Retrieves a single magnitude coefficient.
virtual bool isSymmetric() const =0
Returns whether the spectrum is complex-conjugated symmetric.
int getCoefficientsRI(int iRecordIndex, int iChannel, float *pfDest) const
Retrieves coefficients in cartesian form.
float cabs(float Re, float Im)
float getAlphaResolution() const
Discrete Fourier spectrum content interface.
Data uses unrecognized or wrong quantization.
int getNumDFTCoeffs() const
Returns the number of DFT coefficients.
virtual bool coversFullSphere() const =0
Indicates whether the data covers the full sphere.
int iIndex4
Fourth index point.
static std::string StrContentType(int iContentType)
Returns a string corresponding to a content type.
virtual int getBetaPoints() const =0
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) ...
void * malloc_aligned16(size_t bytes)
Phase spectrum defined at discrete frequencies.
int32_t iNumChannels
@ Quantization of samples/coefficients
File has invalid main header parameter (num channels, etc)
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.
virtual double getSamplerate() const =0
Returns the correspondig sampling rate [in Hertz].
static std::string Float2StrNice(float f, int precision, bool showpos, int leadingzeros=0)
Converts a single precision floating point into nice std::string.
void stc_sint24_to_float_add(float *dest, const void *src, size_t count, int input_stride, int output_stride, float gain)
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
virtual int getNumberOfChannels() const =0
Returns the number of channels.
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) ...
bool coversFullSphere() const
Indicates whether the data covers the full sphere.
int32_t iBetaPoints
@ Alpha range boundaries
DAFFReader * getParent() const
Returns the parent reader.
void getOrientation(DAFFOrientationYPR &o) const
Returns the current orientation of the object view.
void free_aligned16(void *ptr)
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.
float fOrientRoll
@ Pitch angle of the orientation [°]
Data-related view referring to data spherical coordinates (DSC)
Record channel descriptor: impulse responses content.
bool coversFullBetaRange() const
Indicates whether the data covers the full beta range [0°, 180°].
Object-related view referring to object spherical coordinates (OSC)
float fOrientYaw
@ Beta range boundaries