-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert_xwm_to_wav.ps1
155 lines (127 loc) · 5.01 KB
/
convert_xwm_to_wav.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#
# Pieter De Ridder
# Script to convert Xwm (xMWA) to wav (RIFF) in a loop
# created : 25/02/2020
# updated : 11/01/2021
#
# Usage:
# .\convert_xwm_to_wav.ps1 [-CustomDir <custom_path_directory>]
#
# Global vars
$global:WorkingDir = $($PSScriptRoot)
$global:WorkingDirxWMAEnc = "$($global:WorkingDir)\xWMAEncode"
$global:xWMAEnc = "$($global:WorkingDirxWMAEnc)\xWMAEncode.exe"
#
# Function : Convert-ToWav
# Convert xwm file to wav with xWMAEncode
#
Function Convert-ToWav {
Param(
[string]$XwmFile
)
If (Test-Path -Path $global:xWMAEnc) {
If (Test-Path -Path $XwmFile) {
If ($XwmFile.EndsWith(".xwm")) {
$sOutputPath = Split-Path $XwmFile -Parent
$sOutputFile = (Split-Path $XwmFile -Leaf)
$sOutputFile = $sOutputFile.Substring(0, ($sOutputFile.Length -3)) + "wav"
$sOutput = "$($sOutputPath)\$($sOutputFile)"
If (-not (Test-Path $sOutput)) {
$sProcArgs = "$([char]34)$($XwmFile)$([char]34) $([char]34)$($sOutput)$([char]34)"
#$arrProcArgs = @()
#$arrProcArgs += "$([char]34)$($XwmFile)$([char]34)"
#$arrProcArgs += "$([char]34)$($sOutput)$([char]34)"
Write-Host "Generating $($sOutputFile)..."
#$p = Start-Process -FilePath $global:xWMAEnc -WorkingDirectory $global:WorkingDirxWMAEnc -ArgumentList $arrArgs -NoNewWindow -Wait -PassThru
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = $global:xWMAEnc
$pinfo.WorkingDirectory = $global:WorkingDirxWMAEnc
$pinfo.Arguments = $sProcArgs
$pinfo.CreateNoWindow = $true
$pinfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$p.PriorityClass = [System.Diagnostics.ProcessPriorityClass]::High
$p.WaitForExit()
if ($p.ExitCode -eq 0) {
Write-Warning "xWMAEnc : success"
} else {
Write-Warning "xWMAEnc : failed? [Exitcode $($p.ExitCode)]"
}
} else {
Write-Warning "$([char]34)$($sOutput)$([char]34) already exists."
}
} else {
Write-Warning "$([char]34)$($XwmFile)$([char]34) not a xwm file?"
}
}
} else {
Write-Warning "xWMAEncode missing?!"
}
}
#
# Function : Convert-XwmBulk
# Convert xwm files in bulk to wav
#
Function Convert-XwmBulk {
Param (
[string]$Root
)
Write-Host "Bulk converting xmp files to wav."
Write-Host "Indexing files in $($Root)..."
If (Test-Path $Root) {
$arrXwmFiles = @((Get-ChildItem -Path "$($Root)" -File -Filter *.xwm -Recurse).FullName)
If ($arrXwmFiles.Length -gt 0) {
Write-Host "Starting conversion of files..."
ForEach($XwmFile in $arrXwmFiles) {
Convert-ToWav -XwmFile $XwmFile
}
} else {
Write-Warning "No files found?"
}
} else {
Write-Warning "$($Root) path not found?"
}
}
#
# Function : Main
# Main function
#
#
# convert all xmp files in folder 'in-place' to wav files.
# .xmp files get converted, serial wise a.k.a. synchronious, to .wav.
# the output wav file is placed next to the existing xmp file.
#
Function Main {
Param (
[string[]]$Arguments
)
[string]$MyExtractionFolder = "$($PSScriptRoot)\extracted_sfx" # extraction folder
# logic for cmdline arguments
If ($Arguments) {
for($i = 0; $i -lt $Arguments.Length; $i++) {
#Write-Host "DEBUG : Arg $($i.ToString()) is $($Arguments[$i])"
# default, a PWSH Switch statement on a String is always case insensitive
Switch ($Arguments[$i]) {
"-CustomDir" {
# manually override extraction folder
If (($i +1) -le $Arguments.Length) {
$MyExtractionFolder = $Arguments[$i +1]
}
# remove trailing backslash if needed
If ($MyExtractionFolder.EndsWith('\')) {
$MyExtractionFolder = $MyExtractionFolder.Substring(0, $MyExtractionFolder.Length -1)
}
}
}
}
}
Convert-XwmBulk -Root $MyExtractionFolder
Exit(0)
}
# --- MAIN ---
Main -Arguments $args