added parser for Opus identification header
This commit is contained in:
parent
188e930acd
commit
cdfca90c9a
|
@ -0,0 +1,40 @@
|
|||
#include "./opusidentificationheader.h"
|
||||
|
||||
#include "../ogg/oggiterator.h"
|
||||
|
||||
#include "../exceptions.h"
|
||||
|
||||
#include <c++utilities/conversion/binaryconversion.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace ConversionUtilities;
|
||||
|
||||
namespace Media {
|
||||
|
||||
/*!
|
||||
* \class Media::OpusIdentificationHeader
|
||||
* \brief The OpusIdentificationHeader class is an Opus identification header parser.
|
||||
* \sa https://wiki.xiph.org/OggOpus
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Parses the Opus identification header which is read using the specified \a iterator.
|
||||
* \remarks The header is assumed to start at the current position of \a iterator.
|
||||
*/
|
||||
void OpusIdentificationHeader::parseHeader(OggIterator &iterator)
|
||||
{
|
||||
char buff[19 - 8];
|
||||
iterator.read(buff, 8);
|
||||
if(BE::toUInt64(buff) != 0x4F70757348656164u) {
|
||||
throw InvalidDataException(); // not Opus identification header
|
||||
}
|
||||
iterator.read(buff, sizeof(buff));
|
||||
m_version = static_cast<byte>(*(buff));
|
||||
m_channels = static_cast<byte>(*(buff + 1));
|
||||
m_preSkip = LE::toUInt16(buff + 2);
|
||||
m_sampleRate = LE::toUInt32(buff + 4);
|
||||
m_outputGain = LE::toUInt16(buff + 8);
|
||||
m_channelMap = static_cast<byte>(*(buff + 10));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
#ifndef MEDIA_OPUSIDENTIFICATIONHEADER_H
|
||||
#define MEDIA_OPUSIDENTIFICATIONHEADER_H
|
||||
|
||||
#include <c++utilities/application/global.h>
|
||||
#include <c++utilities/conversion/types.h>
|
||||
|
||||
#include <istream>
|
||||
|
||||
namespace Media {
|
||||
|
||||
class OggIterator;
|
||||
|
||||
class LIB_EXPORT OpusIdentificationHeader
|
||||
{
|
||||
public:
|
||||
OpusIdentificationHeader();
|
||||
|
||||
void parseHeader(OggIterator &iterator);
|
||||
|
||||
byte version() const;
|
||||
byte channels() const;
|
||||
uint16 preSkip() const;
|
||||
uint32 sampleRate() const;
|
||||
uint16 outputGain() const;
|
||||
byte channelMap() const;
|
||||
|
||||
private:
|
||||
byte m_version;
|
||||
byte m_channels;
|
||||
uint16 m_preSkip;
|
||||
uint32 m_sampleRate;
|
||||
uint16 m_outputGain;
|
||||
byte m_channelMap;
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Constructs a new vorbis identification header.
|
||||
*/
|
||||
inline OpusIdentificationHeader::OpusIdentificationHeader() :
|
||||
m_version(0),
|
||||
m_channels(0),
|
||||
m_sampleRate(0),
|
||||
m_outputGain(0),
|
||||
m_channelMap(0)
|
||||
{}
|
||||
|
||||
/*!
|
||||
* \brief Returns the version (which should be 1 currently).
|
||||
*/
|
||||
inline byte OpusIdentificationHeader::version() const
|
||||
{
|
||||
return m_version;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the number of channels for the Opus stream.
|
||||
*/
|
||||
inline byte OpusIdentificationHeader::channels() const
|
||||
{
|
||||
return m_channels;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns "pre-skip" value for the Opus stream.
|
||||
*
|
||||
* This is the number of samples (at 48 kHz) to discard from the decoder
|
||||
* output when starting playback, and also the number to subtract from a
|
||||
* page's granule position to calculate its PCM sample position.
|
||||
*/
|
||||
inline uint16 OpusIdentificationHeader::preSkip() const
|
||||
{
|
||||
return m_preSkip;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the INPUT sample rate.
|
||||
* \remarks This is not the sample rate to use for playback of the encoded data.
|
||||
* \sa https://wiki.xiph.org/OggOpus
|
||||
*/
|
||||
inline uint32 OpusIdentificationHeader::sampleRate() const
|
||||
{
|
||||
return m_sampleRate;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the output gain.
|
||||
*
|
||||
* This is a gain to be applied by the decoder. Virtually all players and media frameworks
|
||||
* should apply it by default.
|
||||
*/
|
||||
inline uint16 OpusIdentificationHeader::outputGain() const
|
||||
{
|
||||
return m_outputGain;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the channel mapping family.
|
||||
*
|
||||
* The channel mapping family indicates the order and semantic meaning of the various channels
|
||||
* encoded in each Opus packet.
|
||||
* \sa https://wiki.xiph.org/OggOpus
|
||||
*/
|
||||
inline byte OpusIdentificationHeader::channelMap() const
|
||||
{
|
||||
return m_channelMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // MEDIA_OPUSIDENTIFICATIONHEADER_H
|
Loading…
Reference in New Issue