| 2467 | } |
| 2468 | |
| 2469 | void AudioIO::AILAProcess(double maxPeak) { |
| 2470 | const auto proj = mOwningProject.lock(); |
| 2471 | if (proj && mAILAActive) { |
| 2472 | if (mInputMeter && mInputMeter->IsClipping()) { |
| 2473 | mAILAClipped = true; |
| 2474 | wxPrintf("clipped"); |
| 2475 | } |
| 2476 | |
| 2477 | mAILAMax = max(mAILAMax, maxPeak); |
| 2478 | |
| 2479 | if ((mAILATotalAnalysis == 0 || mAILAAnalysisCounter < mAILATotalAnalysis) && mPlaybackSchedule.GetSequenceTime() - mAILALastStartTime >= mAILAAnalysisTime) { |
| 2480 | auto ToLinearIfDB = [](double value, int dbRange) { |
| 2481 | if (dbRange >= 0) |
| 2482 | value = pow(10.0, (-(1.0-value) * dbRange)/20.0); |
| 2483 | return value; |
| 2484 | }; |
| 2485 | |
| 2486 | putchar('\n'); |
| 2487 | mAILAMax = mInputMeter ? ToLinearIfDB(mAILAMax, mInputMeter->GetDBRange()) : 0.0; |
| 2488 | double iv = (double) Px_GetInputVolume(mPortMixer); |
| 2489 | unsigned short changetype = 0; //0 - no change, 1 - increase change, 2 - decrease change |
| 2490 | wxPrintf("mAILAAnalysisCounter:%d\n", mAILAAnalysisCounter); |
| 2491 | wxPrintf("\tmAILAClipped:%d\n", mAILAClipped); |
| 2492 | wxPrintf("\tmAILAMax (linear):%f\n", mAILAMax); |
| 2493 | wxPrintf("\tmAILAGoalPoint:%f\n", mAILAGoalPoint); |
| 2494 | wxPrintf("\tmAILAGoalDelta:%f\n", mAILAGoalDelta); |
| 2495 | wxPrintf("\tiv:%f\n", iv); |
| 2496 | wxPrintf("\tmAILAChangeFactor:%f\n", mAILAChangeFactor); |
| 2497 | if (mAILAClipped || mAILAMax > mAILAGoalPoint + mAILAGoalDelta) { |
| 2498 | wxPrintf("too high:\n"); |
| 2499 | mAILATopLevel = min(mAILATopLevel, iv); |
| 2500 | wxPrintf("\tmAILATopLevel:%f\n", mAILATopLevel); |
| 2501 | //if clipped or too high |
| 2502 | if (iv <= LOWER_BOUND) { |
| 2503 | //we can't improve it more now |
| 2504 | if (mAILATotalAnalysis != 0) { |
| 2505 | mAILAActive = false; |
| 2506 | ProjectStatus::Get( *proj ).Set( |
| 2507 | XO( |
| 2508 | "Automated Recording Level Adjustment stopped. It was not possible to optimize it more. Still too high.") ); |
| 2509 | } |
| 2510 | wxPrintf("\talready min vol:%f\n", iv); |
| 2511 | } |
| 2512 | else { |
| 2513 | float vol = (float) max(LOWER_BOUND, iv+(mAILAGoalPoint-mAILAMax)*mAILAChangeFactor); |
| 2514 | Px_SetInputVolume(mPortMixer, vol); |
| 2515 | auto msg = XO( |
| 2516 | "Automated Recording Level Adjustment decreased the volume to %f.").Format( vol ); |
| 2517 | ProjectStatus::Get( *proj ).Set(msg); |
| 2518 | changetype = 1; |
| 2519 | wxPrintf("\tnew vol:%f\n", vol); |
| 2520 | float check = Px_GetInputVolume(mPortMixer); |
| 2521 | wxPrintf("\tverified %f\n", check); |
| 2522 | } |
| 2523 | } |
| 2524 | else if ( mAILAMax < mAILAGoalPoint - mAILAGoalDelta ) { |
| 2525 | //if too low |
| 2526 | wxPrintf("too low:\n"); |
no test coverage detected