void DecoderOptionsDialog::OnDone( wxCommandEvent& event )
{
    wxFileConfig *pConf = GetOCPNConfigObject();

    pConf->SetPath ( _T ( "/Settings/WeatherFax/Audio" ) );

    bool spin_options_changed =
        m_sBitsPerPixel->GetValue() != pConf->Read ( _T ( "BitsPerPixel" ), 8L ) ||
        m_sCarrier->GetValue() != pConf->Read ( _T ( "Carrier" ), 1900L ) ||
        m_sDeviation->GetValue() != pConf->Read ( _T ( "Deviation" ), 400L ) ||
        m_sMinusSaturationThreshold->GetValue() != pConf->Read ( _T ( "MinusSaturationThreshold" ), 15L );

    pConf->Write ( _T ( "ImageWidth" ), m_sImageWidth->GetValue());
    pConf->Write ( _T ( "BitsPerPixel" ), m_sBitsPerPixel->GetValue());
    pConf->Write ( _T ( "Carrier" ), m_sCarrier->GetValue());
    pConf->Write ( _T ( "Deviation" ), m_sDeviation->GetValue());
    pConf->Write ( _T ( "MinusSaturationThreshold" ), m_sMinusSaturationThreshold->GetValue());
    pConf->Write ( _T ( "Filter" ), m_cFilter->GetSelection());
    pConf->Write ( _T ( "SkipHeaderDetection" ), m_cbSkip->GetValue());
    pConf->Write ( _T ( "IncludeHeadersInImage" ), m_cbInclude->GetValue());

    FaxDecoder &decoder = m_wizard.m_decoder;
    bool capture = decoder.m_CaptureSettings.type == FaxDecoderCaptureSettings::AUDIO ||
        decoder.m_CaptureSettings.type == FaxDecoderCaptureSettings::RTLSDR;

//    Hide();
    EndModal(wxID_OK);

    if(origwidth != m_sImageWidth->GetValue() ||
       (!capture && spin_options_changed)) {
        origwidth = m_sImageWidth->GetValue();
        ResetDecoder();
    }
}
void ConstantLengthHighPulseProtocolBase::Decode(short state, unsigned int duration)
{
    if (state==LOW)
    {
		unsigned int pulsecycleduration = duration + _highpulseduration ;
		if (WithinExpectedDeviation( pulsecycleduration , _shortperiods * _timeperiodduration ,  _timeperiodduration / 8) )
		{
			// Are there more bits in the buffer than is expected for this protocol?
			if (decoder_bitpos == GetBitstreamLength()) 
			{ 
				ShiftFirstBitOut(decoder_bitbuffer , decoder_bitbufferlength, decoder_bitpos);
			}
			AddBit( decoder_bitbuffer , decoder_bitbufferlength, decoder_bitpos , false);				

		} else if (WithinExpectedDeviation( pulsecycleduration , _longperiods * _timeperiodduration ,  _timeperiodduration / 8) )
		{
			// Are there more bits in the buffer than is expected for this protocol?
			if (decoder_bitpos == GetBitstreamLength()) 
			{ 
				ShiftFirstBitOut(decoder_bitbuffer , decoder_bitbufferlength, decoder_bitpos);
			}
			AddBit( decoder_bitbuffer , decoder_bitbufferlength, decoder_bitpos , true);			
		} else 
		{
			DecodeBitstream(_highpulseduration, duration);
			ResetDecoder();
		}
    } else if (state==HIGH)
	{
		_highpulseduration = duration;
	}
}
void DecoderOptionsDialog::ConfigureResetDecoder()
{
    FaxDecoder &decoder = m_wizard.m_decoder;
    if(decoder.m_CaptureSettings.type == FaxDecoderCaptureSettings::FILE)
        ResetDecoder();
    else
        ConfigureDecoder(false);
}
示例#4
0
bool CMpegAudioDecoder::Reset()
{
	if (!ResetDecoder())
		return false;

	ClearAudioInfo();
	m_bDecodeError = false;

	return true;
}
示例#5
0
bool CAacDecoder::Reset()
{
	if (!ResetDecoder())
		return false;

	m_AdtsParser.Reset();
	ClearAudioInfo();
	m_bDecodeError = false;

	return true;
}
示例#6
0
DECODING_STATE CWelsDecoder::DecodeFrame2 (const unsigned char* kpSrc,
    const int kiSrcLen,
    unsigned char** ppDst,
    SBufferInfo* pDstInfo) {
  if (CheckBsBuffer (m_pDecContext, kiSrcLen)) {
    return dsOutOfMemory;
  }
  if (kiSrcLen > 0 && kpSrc != NULL) {
#ifdef OUTPUT_BIT_STREAM
    if (m_pFBS) {
      WelsFwrite (kpSrc, sizeof (unsigned char), kiSrcLen, m_pFBS);
      WelsFflush (m_pFBS);
    }
    if (m_pFBSSize) {
      WelsFwrite (&kiSrcLen, sizeof (int), 1, m_pFBSSize);
      WelsFflush (m_pFBSSize);
    }
#endif//OUTPUT_BIT_STREAM
    m_pDecContext->bEndOfStreamFlag = false;
  } else {
    //For application MODE, the error detection should be added for safe.
    //But for CONSOLE MODE, when decoding LAST AU, kiSrcLen==0 && kpSrc==NULL.
    m_pDecContext->bEndOfStreamFlag = true;
    m_pDecContext->bInstantDecFlag = true;
  }

  int64_t iStart, iEnd;
  iStart = WelsTime();
  ppDst[0] = ppDst[1] = ppDst[2] = NULL;
  m_pDecContext->iErrorCode             = dsErrorFree; //initialize at the starting of AU decoding.
  m_pDecContext->iFeedbackVclNalInAu = FEEDBACK_UNKNOWN_NAL; //initialize
  unsigned long long uiInBsTimeStamp = pDstInfo->uiInBsTimeStamp;
  memset (pDstInfo, 0, sizeof (SBufferInfo));
  pDstInfo->uiInBsTimeStamp = uiInBsTimeStamp;
#ifdef LONG_TERM_REF
  m_pDecContext->bReferenceLostAtT0Flag       = false; //initialize for LTR
  m_pDecContext->bCurAuContainLtrMarkSeFlag = false;
  m_pDecContext->iFrameNumOfAuMarkedLtr      = 0;
  m_pDecContext->iFrameNum                       = -1; //initialize
#endif

  m_pDecContext->iFeedbackTidInAu             = -1; //initialize
  if (pDstInfo) {
    pDstInfo->uiOutYuvTimeStamp = 0;
    m_pDecContext->uiTimeStamp = pDstInfo->uiInBsTimeStamp;
  } else {
    m_pDecContext->uiTimeStamp = 0;
  }
  WelsDecodeBs (m_pDecContext, kpSrc, kiSrcLen, ppDst,
                pDstInfo, NULL); //iErrorCode has been modified in this function
  m_pDecContext->bInstantDecFlag = false; //reset no-delay flag
  if (m_pDecContext->iErrorCode) {
    EWelsNalUnitType eNalType =
      NAL_UNIT_UNSPEC_0; //for NBR, IDR frames are expected to decode as followed if error decoding an IDR currently

    eNalType = m_pDecContext->sCurNalHead.eNalUnitType;

    if (m_pDecContext->iErrorCode & dsOutOfMemory) {
      ResetDecoder();
    }
    //for AVC bitstream (excluding AVC with temporal scalability, including TP), as long as error occur, SHOULD notify upper layer key frame loss.
    if ((IS_PARAM_SETS_NALS (eNalType) || NAL_UNIT_CODED_SLICE_IDR == eNalType) ||
        (VIDEO_BITSTREAM_AVC == m_pDecContext->eVideoType)) {
      if (m_pDecContext->eErrorConMethod == ERROR_CON_DISABLE) {
#ifdef LONG_TERM_REF
        m_pDecContext->bParamSetsLostFlag = true;
#else
        m_pDecContext->bReferenceLostAtT0Flag = true;
#endif
      }
    }

    if (m_pDecContext->bPrintFrameErrorTraceFlag) {
      WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "decode failed, failure type:%d \n",
               m_pDecContext->iErrorCode);
      m_pDecContext->bPrintFrameErrorTraceFlag = false;
    } else {
      m_pDecContext->iIgnoredErrorInfoPacketCount ++;
      if (m_pDecContext->iIgnoredErrorInfoPacketCount == INT_MAX) {
        WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING, "continuous error reached INT_MAX! Restart as 0.");
        m_pDecContext->iIgnoredErrorInfoPacketCount = 0;
      }
    }
    if ((m_pDecContext->eErrorConMethod != ERROR_CON_DISABLE) && (pDstInfo->iBufferStatus == 1)) {
      //TODO after dec status updated
      m_pDecContext->iErrorCode |= dsDataErrorConcealed;

      //
      if ((m_pDecContext->sDecoderStatistics.uiWidth != (unsigned int) pDstInfo->UsrData.sSystemBuffer.iWidth)
          || (m_pDecContext->sDecoderStatistics.uiHeight != (unsigned int) pDstInfo->UsrData.sSystemBuffer.iHeight)) {
        m_pDecContext->sDecoderStatistics.uiResolutionChangeTimes++;
        m_pDecContext->sDecoderStatistics.uiWidth = pDstInfo->UsrData.sSystemBuffer.iWidth;
        m_pDecContext->sDecoderStatistics.uiHeight = pDstInfo->UsrData.sSystemBuffer.iHeight;

      }
      m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;
      if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount == 0) { //exceed max value of uint32_t
        ResetDecStatNums (&m_pDecContext->sDecoderStatistics);
        m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;
      }
      int32_t iMbConcealedNum = m_pDecContext->iMbEcedNum + m_pDecContext->iMbEcedPropNum;
      m_pDecContext->sDecoderStatistics.uiAvgEcRatio = m_pDecContext->iMbNum == 0 ?
          (m_pDecContext->sDecoderStatistics.uiAvgEcRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) : ((
                m_pDecContext->sDecoderStatistics.uiAvgEcRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) + ((
                      iMbConcealedNum * 100) / m_pDecContext->iMbNum));
      m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio = m_pDecContext->iMbNum == 0 ?
          (m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) : ((
                m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) + ((
                      m_pDecContext->iMbEcedPropNum * 100) / m_pDecContext->iMbNum));
      m_pDecContext->sDecoderStatistics.uiEcFrameNum += (iMbConcealedNum == 0 ? 0 : 1);
      m_pDecContext->sDecoderStatistics.uiAvgEcRatio = m_pDecContext->sDecoderStatistics.uiEcFrameNum == 0 ? 0 :
          m_pDecContext->sDecoderStatistics.uiAvgEcRatio / m_pDecContext->sDecoderStatistics.uiEcFrameNum;
      m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio = m_pDecContext->sDecoderStatistics.uiEcFrameNum == 0 ? 0 :
          m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio / m_pDecContext->sDecoderStatistics.uiEcFrameNum;
    }
    iEnd = WelsTime();
    m_pDecContext->dDecTime += (iEnd - iStart) / 1e3;
    return (DECODING_STATE) m_pDecContext->iErrorCode;
  }
  // else Error free, the current codec works well

  if (pDstInfo->iBufferStatus == 1) {

    m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;
    if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount == 0) { //exceed max value of uint32_t
      ResetDecStatNums (&m_pDecContext->sDecoderStatistics);
      m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;
    }

    if ((m_pDecContext->sDecoderStatistics.uiWidth != (unsigned int) pDstInfo->UsrData.sSystemBuffer.iWidth)
        || (m_pDecContext->sDecoderStatistics.uiHeight != (unsigned int) pDstInfo->UsrData.sSystemBuffer.iHeight)) {
      m_pDecContext->sDecoderStatistics.uiResolutionChangeTimes++;
      m_pDecContext->sDecoderStatistics.uiWidth = pDstInfo->UsrData.sSystemBuffer.iWidth;
      m_pDecContext->sDecoderStatistics.uiHeight = pDstInfo->UsrData.sSystemBuffer.iHeight;
    }
  }
  iEnd = WelsTime();
  m_pDecContext->dDecTime += (iEnd - iStart) / 1e3;
  return dsErrorFree;
}
示例#7
0
bool CMpegAudioDecoder::DecodeFrame(const BYTE *pData, DWORD *pDataSize, DecodeFrameInfo *pInfo)
{
	if (!m_bInitialized) {
		return false;
	}

	if (m_MadStream.buffer == nullptr || m_MadStream.error == MAD_ERROR_BUFLEN) {
		size_t ReadSize, Remain;

		if (m_MadStream.next_frame != nullptr) {
			Remain = m_MadStream.bufend - m_MadStream.next_frame;
			::MoveMemory(m_InputBuffer, m_MadStream.next_frame, Remain);
			ReadSize = INPUT_BUFFER_SIZE - Remain;
		} else {
			ReadSize = INPUT_BUFFER_SIZE;
			Remain = 0;
		}

		if (ReadSize > *pDataSize)
			ReadSize = *pDataSize;
		*pDataSize = (DWORD)ReadSize;

		::CopyMemory(&m_InputBuffer[Remain], pData, ReadSize);

		mad_stream_buffer(&m_MadStream, m_InputBuffer, (unsigned long)(ReadSize + Remain));
		m_MadStream.error = MAD_ERROR_NONE;
	} else {
		*pDataSize = 0;
	}

	if (mad_frame_decode(&m_MadFrame, &m_MadStream)) {
		pInfo->Samples = 0;

		if (m_MadStream.error == MAD_ERROR_BUFLEN)
			return true;
		if (MAD_RECOVERABLE(m_MadStream.error))
			return true;
#ifdef _DEBUG
		::OutputDebugStringA("libmad error : ");
		::OutputDebugStringA(mad_stream_errorstr(&m_MadStream));
		::OutputDebugStringA("\n");
#endif
		ResetDecoder();
		return false;
	}

	mad_synth_frame(&m_MadSynth, &m_MadFrame);

	const BYTE Channels = MAD_NCHANNELS(&m_MadFrame.header);
	short *p = m_PcmBuffer;

	if (Channels == 1) {
		for (int i = 0; i < m_MadSynth.pcm.length; i++) {
			*p++ = FixedToInt16(m_MadSynth.pcm.samples[0][i]);
		}
	} else {
		for (int i = 0; i < m_MadSynth.pcm.length; i++) {
			*p++ = FixedToInt16(m_MadSynth.pcm.samples[0][i]);
			*p++ = FixedToInt16(m_MadSynth.pcm.samples[1][i]);
		}
	}

	m_AudioInfo.Frequency = m_MadSynth.pcm.samplerate;
	m_AudioInfo.Channels = Channels;
	m_AudioInfo.OrigChannels = Channels;
	m_AudioInfo.bDualMono = false;

	pInfo->pData = (const BYTE*)m_PcmBuffer;
	pInfo->Samples = m_MadSynth.pcm.length;
	pInfo->Info = m_AudioInfo;
	pInfo->bDiscontinuity = m_bDecodeError;

	return true;
}
示例#8
0
bool CAacDecoder::DecodeFrame(const CAdtsFrame *pFrame, DecodeFrameInfo *pInfo)
{
	if (m_hDecoder == NULL) {
		return false;
	}

	// 初回フレーム解析
	if (m_bInitRequest || pFrame->GetChannelConfig() != m_LastChannelConfig) {
		if (!m_bInitRequest) {
			// チャンネル設定が変化した、デコーダリセット
			if (!ResetDecoder())
				return false;
		}

		unsigned long SampleRate;
		unsigned char Channels;
		if (::NeAACDecInit(m_hDecoder,
				const_cast<BYTE*>(pFrame->GetData()), pFrame->GetSize(),
				&SampleRate, &Channels) < 0) {
			return false;
		}

		m_bInitRequest = false;
		m_LastChannelConfig = pFrame->GetChannelConfig();
	}

	// デコード
	NeAACDecFrameInfo FrameInfo;
	//::ZeroMemory(&FrameInfo, sizeof(FrameInfo));

	BYTE *pPcmBuffer = pointer_cast<BYTE*>(
		::NeAACDecDecode(m_hDecoder, &FrameInfo,
						 const_cast<BYTE*>(pFrame->GetData()), pFrame->GetSize()));

	bool bOK = false;

	if (FrameInfo.error == 0) {
		m_AudioInfo.Frequency = FrameInfo.samplerate;
		m_AudioInfo.Channels = FrameInfo.channels;
		// FAADではモノラルが2chにデコードされる
		if (FrameInfo.channels == 2 && m_LastChannelConfig == 1)
			m_AudioInfo.OrigChannels = 1;
		else
			m_AudioInfo.OrigChannels = FrameInfo.channels;
		m_AudioInfo.bDualMono = FrameInfo.channels == 2 && m_LastChannelConfig == 0;
		if (FrameInfo.samples > 0) {
			pInfo->pData = pPcmBuffer;
			pInfo->Samples = FrameInfo.samples / FrameInfo.channels;
			pInfo->Info = m_AudioInfo;
			pInfo->bDiscontinuity = m_bDecodeError;
			bOK = true;
		}
	} else {
		// エラー発生
#ifdef _DEBUG
		::OutputDebugString(TEXT("CAacDecoder::Decode error - "));
		::OutputDebugStringA(NeAACDecGetErrorMessage(FrameInfo.error));
		::OutputDebugString(TEXT("\n"));
#endif
		// リセットする
		ResetDecoder();
	}

	return bOK;
}