void Trimmer::CopyConstantSubframe(BitIStream& bis, BitOStream& bos, FLACFrameHeader * fh, FLACMetaStreamInfo * msi) { size_t bitsCount = GetBitsPerSample(fh, msi); uint64_t constant = 0; bis.ReadInteger(&constant, bitsCount); bos.WriteInteger(constant, bitsCount); }
/*--------------------------------------------------------------------------------*/ bool ADMRIFFFile::CreateExtraChunks() { bool success = true; if (adm) { RIFFChunk *chunk; uint64_t chnalen; uint8_t *chna; uint_t i, nchannels = GetChannels(); success = true; for (i = 0; i < nchannels; i++) { ADMAudioTrack *track; // create chna track data if ((track = adm->CreateTrack(i)) != NULL) { track->SetSampleRate(GetSampleRate()); track->SetBitDepth(GetBitsPerSample()); } } if (!admfile.empty()) { // create ADM structure (content and objects from file) if (adm->CreateFromFile(admfile.c_str())) { // can prepare cursors now since all objects have been created PrepareCursors(); } else { BBCERROR("Unable to create ADM structure from '%s'", admfile.c_str()); success = false; } } // get ADM object to create chna chunk if ((chna = adm->GetChna(chnalen)) != NULL) { // and add it to the RIFF file if ((chunk = AddChunk(chna_ID)) != NULL) { success &= chunk->CreateChunkData(chna, chnalen); } else BBCERROR("Failed to add chna chunk"); // don't need the raw data any more delete[] chna; } else BBCERROR("No chna data available"); success &= (AddChunk(axml_ID) != NULL); } return success; }
int AudioFormat_YM::GetPosition() { if (!ymFile_) { return 0; } return (int)((ymFile_->getPos()/1000.0f)*GetChannels()*(GetBitsPerSample()/8)*GetFrequency()); }
void AudioFormat_YM::SetPosition(int position) { if (!ymFile_) { return; } float sampleSize=(float)(GetChannels()*GetFrequency()*(GetBitsPerSample()/8)); float time=position/sampleSize; ymFile_->setMusicTime((int)(time*1000.0f)); }
int COMXAudioCodecOMX::GetData(BYTE** dst, double &dts, double &pts) { if (!m_bGotFrame) return 0; int inLineSize, outLineSize; /* input audio is aligned */ int inputSize = m_dllAvUtil.av_samples_get_buffer_size(&inLineSize, m_pCodecContext->channels, m_pFrame1->nb_samples, m_pCodecContext->sample_fmt, 0); /* output audio will be packed */ int outputSize = m_dllAvUtil.av_samples_get_buffer_size(&outLineSize, m_pCodecContext->channels, m_pFrame1->nb_samples, m_desiredSampleFormat, 1); if (!m_bNoConcatenate && m_iBufferOutputUsed && (int)m_frameSize != outputSize) { CLog::Log(LOGERROR, "COMXAudioCodecOMX::GetData Unexpected change of size (%d->%d)", m_frameSize, outputSize); m_bNoConcatenate = true; } // if this buffer won't fit then flush out what we have int desired_size = AUDIO_DECODE_OUTPUT_BUFFER * (m_pCodecContext->channels * GetBitsPerSample()) >> (rounded_up_channels_shift[m_pCodecContext->channels] + 4); if (m_iBufferOutputUsed && (m_iBufferOutputUsed + outputSize > desired_size || m_bNoConcatenate)) { int ret = m_iBufferOutputUsed; m_iBufferOutputUsed = 0; m_bNoConcatenate = false; dts = m_dts; pts = m_pts; *dst = m_pBufferOutput; return ret; } m_frameSize = outputSize; if (m_iBufferOutputAlloced < m_iBufferOutputUsed + outputSize) { m_pBufferOutput = (BYTE*)m_dllAvUtil.av_realloc(m_pBufferOutput, m_iBufferOutputUsed + outputSize + FF_INPUT_BUFFER_PADDING_SIZE); m_iBufferOutputAlloced = m_iBufferOutputUsed + outputSize; } /* need to convert format */ if(m_pCodecContext->sample_fmt != m_desiredSampleFormat) { if(m_pConvert && (m_pCodecContext->sample_fmt != m_iSampleFormat || m_channels != m_pCodecContext->channels)) { m_dllSwResample.swr_free(&m_pConvert); m_channels = m_pCodecContext->channels; } if(!m_pConvert) { m_iSampleFormat = m_pCodecContext->sample_fmt; m_pConvert = m_dllSwResample.swr_alloc_set_opts(NULL, m_dllAvUtil.av_get_default_channel_layout(m_pCodecContext->channels), m_desiredSampleFormat, m_pCodecContext->sample_rate, m_dllAvUtil.av_get_default_channel_layout(m_pCodecContext->channels), m_pCodecContext->sample_fmt, m_pCodecContext->sample_rate, 0, NULL); if(!m_pConvert || m_dllSwResample.swr_init(m_pConvert) < 0) { CLog::Log(LOGERROR, "COMXAudioCodecOMX::Decode - Unable to initialise convert format %d to %d", m_pCodecContext->sample_fmt, m_desiredSampleFormat); return 0; } } /* use unaligned flag to keep output packed */ uint8_t *out_planes[m_pCodecContext->channels]; if(m_dllAvUtil.av_samples_fill_arrays(out_planes, NULL, m_pBufferOutput + m_iBufferOutputUsed, m_pCodecContext->channels, m_pFrame1->nb_samples, m_desiredSampleFormat, 1) < 0 || m_dllSwResample.swr_convert(m_pConvert, out_planes, m_pFrame1->nb_samples, (const uint8_t **)m_pFrame1->data, m_pFrame1->nb_samples) < 0) { CLog::Log(LOGERROR, "COMXAudioCodecOMX::Decode - Unable to convert format %d to %d", (int)m_pCodecContext->sample_fmt, m_desiredSampleFormat); outputSize = 0; } } else { /* copy to a contiguous buffer */ uint8_t *out_planes[m_pCodecContext->channels]; if (m_dllAvUtil.av_samples_fill_arrays(out_planes, NULL, m_pBufferOutput + m_iBufferOutputUsed, m_pCodecContext->channels, m_pFrame1->nb_samples, m_desiredSampleFormat, 1) < 0 || m_dllAvUtil.av_samples_copy(out_planes, m_pFrame1->data, 0, 0, m_pFrame1->nb_samples, m_pCodecContext->channels, m_desiredSampleFormat) < 0 ) { outputSize = 0; } } m_bGotFrame = false; if (m_bFirstFrame) { CLog::Log(LOGDEBUG, "COMXAudioCodecOMX::GetData size=%d/%d line=%d/%d buf=%p, desired=%d", inputSize, outputSize, inLineSize, outLineSize, m_pBufferOutput, desired_size); m_bFirstFrame = false; } m_iBufferOutputUsed += outputSize; return 0; }
uint16_t Trimmer::GetWarmUpSamplesBitSize(FLACFrameHeader * fh, FLACMetaStreamInfo * msi, FLACSubframeHeader * sfh) { return GetBitsPerSample(fh, msi) * GetPredictorOrder(sfh); }
uint16_t Trimmer::GetUnencSubblockBitSize(FLACFrameHeader * fh, FLACMetaStreamInfo * msi) { return GetBlockSize(fh, msi) * GetBitsPerSample(fh, msi); }
void Trimmer::CopyRiceResidual(BitIStream& bis, BitOStream& bos, FLACFrameHeader * fh, FLACMetaStreamInfo * msi, FLACSubframeHeader * sfh) { uint8_t partitionOrder = 0; bis.ReadInteger(&partitionOrder, 4); bos.WriteInteger(partitionOrder, 4); size_t partitionsCount = pow(2, partitionOrder); for (size_t partitionN = 0; partitionN < partitionsCount; partitionN++) { uint8_t riceParameter = 0; bis.ReadInteger(&riceParameter, 4); bos.WriteInteger(riceParameter, 4); bool isUnencoded = false; uint8_t unencBitsPerSample = 0; if (riceParameter == 0b1111) { isUnencoded = true; bis.ReadInteger(&unencBitsPerSample, 5); bos.WriteInteger(unencBitsPerSample, 5); } size_t samplesCount = 0; if (partitionOrder == 0) { samplesCount = GetBlockSize(fh, msi) - GetPredictorOrder(sfh); } else if (partitionN != 0) // this is not first partition of subframe ? { samplesCount = GetBlockSize(fh, msi) / pow(2, partitionOrder); } else { samplesCount = GetBlockSize(fh, msi) / pow(2, partitionOrder) - GetPredictorOrder(sfh); } size_t residualBitSize = 0; if (isUnencoded) { residualBitSize = samplesCount * unencBitsPerSample; } else { residualBitSize = samplesCount * GetBitsPerSample(fh, msi); } /* uint32_t unary = 0; bis.ReadUnary(&unary); bos.WriteUnary(unary); cout << unary << endl;*/ for (size_t i = 0; i < samplesCount; i++) { uint8_t sign = 0; bis.ReadInteger(&sign, 1); bos.WriteInteger(sign, 1); uint32_t unary = 0; bis.ReadUnary(&unary); bos.WriteUnary(unary); uint32_t resudial = 0; if (riceParameter != 0) { bis.ReadInteger(&resudial, riceParameter); bos.WriteInteger(resudial, riceParameter); } } // CopyBits(bis, bos, residualBitSize); } }