double ReplayGain_get_title_gain(replaygain_ReplayGain *self) { double retval; int i; retval = analyzeResult(self->A, sizeof(self->A)/sizeof(*(self->A)) ); for ( i = 0; i < (int)(sizeof(self->A)/sizeof(*(self->A))); i++ ) { self->B[i] += self->A[i]; self->A[i] = 0; } for ( i = 0; i < MAX_ORDER; i++ ) self->linprebuf[i] = self->lstepbuf[i] = self->loutbuf[i] = self->rinprebuf[i] = self->rstepbuf[i] = self->routbuf[i] = 0.f; self->totsamp = 0; self->lsum = self->rsum = 0.; return retval; }
Float_t GetAlbumGain(GainHandle_t **handle, int count) { Uint32_t B [(size_t)(STEPS_per_dB * MAX_dB)]; memset (B, 0, sizeof(B)); int i = 0; unsigned int j = 0; for(i = 0; i < count; ++i) { for(j = 0; j < sizeof(handle[i]->A)/sizeof(*handle[i]->A); ++j) { B[j] += handle[i]->A[j]; } } return analyzeResult(B, sizeof(B)/sizeof(*B)); }
Float_t GetTitleGain ( void ) { Float_t retval; int i; retval = analyzeResult ( A, sizeof(A)/sizeof(*A) ); for ( i = 0; i < (int)(sizeof(A)/sizeof(*A)); i++ ) { B[i] += A[i]; A[i] = 0; } for ( i = 0; i < MAX_ORDER; i++ ) linprebuf[i] = lstepbuf[i] = loutbuf[i] = rinprebuf[i] = rstepbuf[i] = routbuf[i] = 0.f; totsamp = 0; lsum = rsum = 0.; return retval; }
Float_t GetTitleGain(GainHandle_t *handle) { Float_t retval; int i = 0; retval = analyzeResult (handle->A, sizeof(handle->A)/sizeof(*handle->A)); /*for (i = 0; i < (int)(sizeof(handle->A)/sizeof(*handle->A)); i++ ) { handle->B[i] += handle->A[i]; handle->A[i] = 0; }*/ for (i = 0; i < MAX_ORDER; i++ ) { handle->linprebuf[i] = handle->lstepbuf[i] = handle->loutbuf[i] = 0.f; handle->rinprebuf[i] = handle->rstepbuf[i] = handle->routbuf[i] = 0.f; } handle->totsamp = 0; handle->lsum = handle->rsum = 0.; return retval; }
Float_t GetTitleGain(replaygain_t * rgData) { Float_t retval; unsigned int i; retval = analyzeResult(rgData->A, sizeof(rgData->A) / sizeof(*(rgData->A))); for (i = 0; i < sizeof(rgData->A) / sizeof(*(rgData->A)); i++) { rgData->B[i] += rgData->A[i]; rgData->A[i] = 0; } for (i = 0; i < MAX_ORDER; i++) rgData->linprebuf[i] = rgData->lstepbuf[i] = rgData->loutbuf[i] = rgData->rinprebuf[i] = rgData->rstepbuf[i] = rgData->routbuf[i] = 0.f; rgData->totsamp = 0; rgData->lsum = rgData->rsum = 0.; return retval; }
Float_t GetTitleGain ( void ) { Float_t retval; int i; retval = analyzeResult ( A, sizeof(A)/sizeof(*A) ); for ( i = 0; i < (int)(sizeof(A)/sizeof(*A)); i++ ) { B[i] += A[i]; A[i] = 0; } for ( i = 0; i < MAX_ORDER; i++ ) linprebuf[i] = lstepbuf[i] = loutbuf[i] = rinprebuf[i] = rstepbuf[i] = routbuf[i] = 0.f; totsamp = 0; #ifdef HAVE_SSE2 lrsum = _mm_setzero_pd(); #else lsum = rsum = 0.; #endif return retval; }
Float_t GetAlbumGain(replaygain_t const* rgData) { return analyzeResult(rgData->B, sizeof(rgData->B) / sizeof(*(rgData->B))); }
double ReplayGain_get_album_gain(replaygain_ReplayGain *self) { return analyzeResult(self->B, sizeof(self->B)/sizeof(*(self->B)) ); }
Float_t GetAlbumGain ( void ) { return analyzeResult ( B, sizeof(B)/sizeof(*B) ); }
bool SFB::Audio::ReplayGainAnalyzer::GetAlbumGain(float& albumGain) { return analyzeResult(priv->B, sizeof(priv->B) / sizeof(*(priv->B)), albumGain); }
bool SFB::Audio::ReplayGainAnalyzer::AnalyzeURL(CFURLRef url, CFErrorRef *error) { if(nullptr == url) return false; auto decoder = Decoder::CreateDecoderForURL(url, error); if(!decoder || !decoder->Open(error)) return false; AudioStreamBasicDescription inputFormat = decoder->GetFormat(); // Higher sampling rates aren't natively supported but are handled via resampling int32_t decoderSampleRate = (int32_t)inputFormat.mSampleRate; bool validSampleRate = EvenMultipleSampleRateIsSupported(decoderSampleRate); if(!validSampleRate) { if(error) { SFB::CFString description = CFCopyLocalizedString(CFSTR("The file “%@” does not contain audio at a supported sample rate."), ""); SFB::CFString failureReason = CFCopyLocalizedString(CFSTR("Only sample rates of 8.0 KHz, 11.025 KHz, 12.0 KHz, 16.0 KHz, 22.05 KHz, 24.0 KHz, 32.0 KHz, 44.1 KHz, 48 KHz and multiples are supported."), ""); SFB::CFString recoverySuggestion = CFCopyLocalizedString(CFSTR("The file's extension may not match the file's type."), ""); *error = CreateErrorForURL(ReplayGainAnalyzer::ErrorDomain, ReplayGainAnalyzer::FileFormatNotSupportedError, description, url, failureReason, recoverySuggestion); } return false; } Float64 replayGainSampleRate = GetBestReplayGainSampleRateForSampleRate(decoderSampleRate); if(!(1 == inputFormat.mChannelsPerFrame || 2 == inputFormat.mChannelsPerFrame)) { if(error) { SFB::CFString description = CFCopyLocalizedString(CFSTR("The file “%@” does not contain mono or stereo audio."), ""); SFB::CFString failureReason = CFCopyLocalizedString(CFSTR("Only mono or stereo files supported"), ""); SFB::CFString recoverySuggestion = CFCopyLocalizedString(CFSTR("The file's extension may not match the file's type."), ""); *error = CreateErrorForURL(ReplayGainAnalyzer::ErrorDomain, ReplayGainAnalyzer::FileFormatNotSupportedError, description, url, failureReason, recoverySuggestion); } return false; } AudioStreamBasicDescription outputFormat = { .mFormatID = kAudioFormatLinearPCM, .mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved, .mReserved = 0, .mSampleRate = replayGainSampleRate, .mChannelsPerFrame = inputFormat.mChannelsPerFrame, .mBitsPerChannel = 32, .mBytesPerPacket = 4, .mBytesPerFrame = 4, .mFramesPerPacket = 1 }; if(!SetSampleRate((int32_t)outputFormat.mSampleRate)) { if(error) { SFB::CFString description = CFCopyLocalizedString(CFSTR("The file “%@” does not contain audio at a supported sample rate."), ""); SFB::CFString failureReason = CFCopyLocalizedString(CFSTR("Only sample rates of 8.0 KHz, 11.025 KHz, 12.0 KHz, 16.0 KHz, 22.05 KHz, 24.0 KHz, 32.0 KHz, 44.1 KHz, 48 KHz and multiples are supported."), ""); SFB::CFString recoverySuggestion = CFCopyLocalizedString(CFSTR("The file's extension may not match the file's type."), ""); *error = CreateErrorForURL(ReplayGainAnalyzer::ErrorDomain, ReplayGainAnalyzer::FileFormatNotSupportedError, description, url, failureReason, recoverySuggestion); } return false; } // Converter takes ownership of decoder Converter converter(std::move(decoder), outputFormat); if(!converter.Open(error)) return false; const UInt32 bufferSizeFrames = 512; BufferList outputBuffer(outputFormat, bufferSizeFrames); bool isStereo = (2 == outputFormat.mChannelsPerFrame); for(;;) { UInt32 frameCount = converter.ConvertAudio(outputBuffer, bufferSizeFrames); if(0 == frameCount) break; // Find the peak sample magnitude float lpeak, rpeak; vDSP_maxmgv((const float *)outputBuffer->mBuffers[0].mData, 1, &lpeak, frameCount); if(isStereo) { vDSP_maxmgv((const float *)outputBuffer->mBuffers[1].mData, 1, &rpeak, frameCount); priv->trackPeak = std::max(priv->trackPeak, std::max(lpeak, rpeak)); } else priv->trackPeak = std::max(priv->trackPeak, lpeak); // The replay gain analyzer expects 16-bit sample size passed as floats const float scale = 1u << 15; vDSP_vsmul((const float *)outputBuffer->mBuffers[0].mData, 1, &scale, (float *)outputBuffer->mBuffers[0].mData, 1, frameCount); if(isStereo) { vDSP_vsmul((const float *)outputBuffer->mBuffers[1].mData, 1, &scale, (float *)outputBuffer->mBuffers[1].mData, 1, frameCount); AnalyzeSamples((const float *)outputBuffer->mBuffers[0].mData, (const float *)outputBuffer->mBuffers[1].mData, frameCount, true); } else AnalyzeSamples((const float *)outputBuffer->mBuffers[0].mData, nullptr, frameCount, false); } priv->albumPeak = std::max(priv->albumPeak, priv->trackPeak); return true; } bool SFB::Audio::ReplayGainAnalyzer::GetTrackGain(float& trackGain) { if(!analyzeResult(priv->A, sizeof(priv->A) / sizeof(*(priv->A)), trackGain)) return false; for(uint32_t i = 0; i < sizeof(priv->A) / sizeof(*(priv->A)); ++i) { priv->B[i] += priv->A[i]; priv->A[i] = 0; } priv->Zero(); priv->totsamp = 0; priv->lsum = priv->rsum = 0.; return true; } bool SFB::Audio::ReplayGainAnalyzer::GetTrackPeak(float& trackPeak) { trackPeak = priv->trackPeak; priv->trackPeak = 0.; return true; }