Jump to content

Recommended Posts

Posted (edited)

Hi,

To normalize Audio and AudioLaunch via ffmpeg, which comes included in Popper, I AI made a script that can be run on Popper startup.
This script will normalize all MP3 files modified or created on the current day.

To run place file in C:\vPinball\PinUPSystem\Recordings and add run the shortcut.
You can place the shortcut into autostart of Windows or Popper if you like.

Shortcut: 

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "C:\vPinball\PinUPSystem\Recordings\audio_processing.ps1"



 

# Define paths
$audioFolder = "C:\vPinball\PinUPSystem\POPMedia\Visual Pinball X\Audio"
$audiolaunchFolder = "C:\vPinball\PinUPSystem\POPMedia\Visual Pinball X\Audiolaunch"
$targetSubFolder = "normalised"
$ffmpegPath = "C:\vPinball\PinUPSystem\Recordings\ffmpeg.exe"
$today = (Get-Date).Date
Write-Output "********************************************"
Write-Output "********************************************"

# Function to process and normalize files in a given folder
function Normalize-AudioFiles {
    param (
        [string]$sourceFolder
    )

    $targetFolder = Join-Path -Path $sourceFolder -ChildPath $targetSubFolder

    # Create target folder if it doesn't exist
    if (-not (Test-Path -Path $targetFolder)) {
        New-Item -Path $targetFolder -ItemType Directory | Out-Null
    }

    # Find MP3 files created or modified today
    Get-ChildItem -Path $sourceFolder -Filter *.mp3 | Where-Object {
        $_.CreationTime -ge $today -or $_.LastWriteTime -ge $today
    } | ForEach-Object {
        $sourceFile = $_.FullName
        $fileName = $_.Name
        $targetFile = Join-Path -Path $targetFolder -ChildPath $fileName

        # Construct ffmpeg command
        $arguments = "-i `"$sourceFile`" -af loudnorm=I=-23:TP=-2:LRA=7 `"$targetFile`" -y"

        # Execute ffmpeg command
        Write-Output "Processing $sourceFile"
        Start-Process -FilePath $ffmpegPath -ArgumentList $arguments -NoNewWindow -Wait
    }

    Write-Output "Normalization process completed for $sourceFolder."
    Write-Output "###############################"

    # Copy normalized files to the original folder and overwrite existing files
    Get-ChildItem -Path $targetFolder -Filter *.mp3 | ForEach-Object {
        $normalizedFile = $_.FullName
        $destinationFile = Join-Path -Path $sourceFolder -ChildPath $_.Name

        Write-Output "Copying $normalizedFile to $destinationFile"
        Copy-Item -Path $normalizedFile -Destination $destinationFile -Force
    }

    Write-Output "Files copied and overwritten successfully for $sourceFolder."

    # Delete the target folder and its contents
    Write-Output "Deleting $targetFolder"
    Remove-Item -Path $targetFolder -Recurse -Force
    Write-Output "Target folder deleted successfully."
}

# Process files in both folders
Normalize-AudioFiles -sourceFolder $audioFolder
Normalize-AudioFiles -sourceFolder $audiolaunchFolder

 

Edited by Aetron

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...