diff options
| author | Pierre-Anthony Lemieux <pal@palemieux.com> | 2020-03-10 20:47:33 -0700 |
|---|---|---|
| committer | Pierre-Anthony Lemieux <pal@palemieux.com> | 2020-03-10 20:47:33 -0700 |
| commit | c93f726df76687de551b8b9258305975d56ff102 (patch) | |
| tree | ec52fdffd17911a4e74aa3c81a9dc77eed84ab96 /src/FSKSyncChannel_Generator.cpp | |
| parent | 7b70b206a3bd767aad3a9a3c789cff9d0e9c38f2 (diff) | |
Replaced ATMOS with IAB terminologyissues/0015-replace-ATMOS-w-IAB
Diffstat (limited to 'src/FSKSyncChannel_Generator.cpp')
| -rw-r--r-- | src/FSKSyncChannel_Generator.cpp | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/src/FSKSyncChannel_Generator.cpp b/src/FSKSyncChannel_Generator.cpp new file mode 100644 index 0000000..5a59b81 --- /dev/null +++ b/src/FSKSyncChannel_Generator.cpp @@ -0,0 +1,149 @@ +/* +Copyright (c) 2013-2013, John Hurst +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/*! \file FSKSyncChannel_Generator.cpp + \version $Id$ + \brief SMPTE ST 430-12 sync channel generator implementation +*/ + +#include <FSKSyncChannel_Generator.h> + +#include <AS_DCP.h> + +using namespace ASDCP; + +// +ASDCP::PCM::FSKSyncChannelGenerator::FSKSyncChannelGenerator(ui16_t bitsPerSample, ui32_t sampleRate, + const ASDCP::Rational& editRate, const byte_t* uuid) + : m_syncEncoder(), + m_audioTrackUUID(), + m_ADesc(), + m_syncSignalBuffer(NULL), + m_numSamplesPerFrame(0), + m_currentFrameNumber(0), + m_numBytesPerFrame(0), + m_isSyncEncoderInitialized(false) +{ + + m_ADesc.EditRate = editRate; + m_ADesc.ChannelCount = 1; + m_ADesc.QuantizationBits = bitsPerSample; + m_ADesc.AudioSamplingRate = Rational(sampleRate, 1); + m_ADesc.BlockAlign = ((bitsPerSample + 7) / 8); + m_ADesc.AvgBps = (sampleRate * m_ADesc.BlockAlign); + + memcpy(&m_audioTrackUUID.abyUUIDBytes[0], uuid, UUIDlen); + m_numSamplesPerFrame = (editRate.Denominator * sampleRate) / editRate.Numerator; + m_numBytesPerFrame = m_numSamplesPerFrame * m_ADesc.BlockAlign; + + if (bitsPerSample == 24) + { + ui32_t frameRate = editRate.Numerator/editRate.Denominator; // intentionally allowing for imprecise cast to int + m_isSyncEncoderInitialized = (SyncEncoderInit(&m_syncEncoder, sampleRate, frameRate, &m_audioTrackUUID) == SYNC_ENCODER_ERROR_NONE); + m_syncSignalBuffer = new float[m_numSamplesPerFrame]; + } + else + { + m_isSyncEncoderInitialized = false; + } +} + +ASDCP::PCM::FSKSyncChannelGenerator::~FSKSyncChannelGenerator() +{ + delete [] m_syncSignalBuffer; +} + +ASDCP::Result_t +ASDCP::PCM::FSKSyncChannelGenerator::ReadFrame(FrameBuffer& OutFB) +{ + if (OutFB.Capacity() < m_numBytesPerFrame) + { + return RESULT_SMALLBUF; + } + + /** + * Update frame number and size. + */ + OutFB.FrameNumber(m_currentFrameNumber); + OutFB.Size(m_numBytesPerFrame); + + /** + * Get pointer to frame essence. + */ + byte_t* frameEssence = OutFB.Data(); + + if (m_isSyncEncoderInitialized) + { + /** + * Generate sync signal frame. + */ + int ret = EncodeSync(&m_syncEncoder, m_numSamplesPerFrame, m_syncSignalBuffer, m_currentFrameNumber); + if (ret == SYNC_ENCODER_ERROR_NONE) + { + for (unsigned int i = 0; i < m_numSamplesPerFrame; ++i) + { + /** + * Convert each encoded float sample to a signed 24 bit integer and + * copy into the essence buffer. + */ + i32_t sample = convertSampleFloatToInt24(m_syncSignalBuffer[i]); + memcpy(frameEssence, ((byte_t*)(&sample))+1, NUM_BYTES_PER_INT24); + frameEssence += NUM_BYTES_PER_INT24; + } + } + else + { + /** + * Encoding error, zero out the frame. + */ + memset(frameEssence, 0, m_numBytesPerFrame); + } + } + else + { + /** + * Sync encoder not initialize, zero out the frame. + */ + memset(frameEssence, 0, m_numBytesPerFrame); + } + ++m_currentFrameNumber; + return RESULT_OK; +} + +ASDCP::Result_t +ASDCP::PCM::FSKSyncChannelGenerator::Reset() +{ + m_currentFrameNumber = 0; + return RESULT_OK; +} + +Result_t +ASDCP::PCM::FSKSyncChannelGenerator::FillAudioDescriptor(AudioDescriptor& ADesc) const +{ + ADesc = m_ADesc; + return RESULT_OK; +} + |
