Skip to content

Commit 8acf0a6

Browse files
committed
Added FFMPEG as default coverter, and bug fixes
* FFMPEG is now used by default to convert tracks (You can revert to NAudio in the settings). This should fix numerous issues. * Bug fixes.
1 parent 0129f55 commit 8acf0a6

12 files changed

Lines changed: 768 additions & 40 deletions

SLAM/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
<setting name="StartMinimized" serializeAs="String">
5353
<value>False</value>
5454
</setting>
55+
<setting name="UseFFMPEG" serializeAs="String">
56+
<value>True</value>
57+
</setting>
5558
</SLAM.My.MySettings>
5659
</userSettings>
5760
</configuration>

SLAM/Form1.vb

Lines changed: 71 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Imports SLAM.XmlSerialization
77
Imports SLAM.SourceGame
88
Imports System.Management
99
Imports System.Net.Http
10+
Imports NReco.VideoConverter
1011

1112
Public Class Form1
1213

@@ -152,6 +153,22 @@ Public Class Form1
152153
resampler.Dispose()
153154
End Sub
154155

156+
Private Sub FFMPEG_WaveCreator(File As String, outputFile As String, Game As SourceGame)
157+
Dim convert As New FFMpegConverter()
158+
convert.ExtractFFmpeg()
159+
160+
Dim command As String = String.Format("-i ""{0}"" -f wav -flags bitexact -vn -acodec pcm_s16le -ar {1} -ac {2} ""{3}""", Path.GetFullPath(File), Game.samplerate, Game.channels, Path.GetFullPath(outputFile))
161+
convert.Invoke(command)
162+
End Sub
163+
164+
Private Sub FFMPEG_ConvertAndTrim(inpath As String, outpath As String, samplerate As Integer, channels As Integer, starttrim As Double, length As Double, volume As Double)
165+
Dim convert As New FFMpegConverter()
166+
convert.ExtractFFmpeg()
167+
168+
Dim command As String = String.Format("-i ""{0}"" -f wav -flags bitexact -vn -acodec pcm_s16le -ar {1} -ac {2} -ss {3} -t {4} -af ""volume={5}"" ""{6}""", Path.GetFullPath(inpath), samplerate, channels, starttrim, length, volume, Path.GetFullPath(outpath))
169+
convert.Invoke(command)
170+
End Sub
171+
155172
Private Sub GameSelector_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GameSelector.SelectedIndexChanged
156173
ReloadTracks(GetCurrentGame)
157174
RefreshTrackList()
@@ -160,7 +177,7 @@ Public Class Form1
160177
End Sub
161178

162179
Private Sub ImportButton_Click(sender As Object, e As EventArgs) Handles ImportButton.Click
163-
If File.Exists("NAudio.dll") Then
180+
If (My.Settings.UseFFMPEG = True And File.Exists("NReco.VideoConverter.dll")) Or (My.Settings.UseFFMPEG = False And File.Exists("NAudio.dll")) Then
164181
DisableInterface()
165182
If ImportDialog.ShowDialog() = DialogResult.OK Then
166183
ProgressBar1.Maximum = ImportDialog.FileNames.Count
@@ -171,12 +188,12 @@ Public Class Form1
171188
End If
172189

173190
Else
174-
MessageBox.Show("You are missing NAudio.dll! Cannot import without it!", "Missing File", MessageBoxButtons.OK, MessageBoxIcon.Error)
191+
MessageBox.Show("You are missing NAudio.dll or NReco.VideoConverter.dll! Cannot import without it!", "Missing File", MessageBoxButtons.OK, MessageBoxIcon.Error)
175192
End If
176193
End Sub
177194

178195
Private Sub YTButton_Click(sender As Object, e As EventArgs) Handles YTButton.Click
179-
If File.Exists("NAudio.dll") AndAlso File.Exists("Newtonsoft.Json.dll") AndAlso File.Exists("YoutubeExtractor.dll") Then
196+
If File.Exists("NAudio.dll") AndAlso File.Exists("Newtonsoft.Json.dll") AndAlso File.Exists("NReco.VideoConverter.dll") AndAlso File.Exists("YoutubeExtractor.dll") Then
180197
DisableInterface()
181198
Dim YTImporter As New YTImport
182199
If YTImporter.ShowDialog() = DialogResult.OK Then
@@ -188,7 +205,7 @@ Public Class Form1
188205
End If
189206

190207
Else
191-
MessageBox.Show("You are missing either NAudio.dll, Newtonsoft.Json.dll, or YoutubeExtractor.dll! Cannot import from YouTube without them!", "Missing File(s)", MessageBoxButtons.OK, MessageBoxIcon.Error)
208+
MessageBox.Show("You are missing either NAudio.dll, Newtonsoft.Json.dll, NReco.VideoConverter.dll, or YoutubeExtractor.dll! Cannot import from YouTube without them!", "Missing File(s)", MessageBoxButtons.OK, MessageBoxIcon.Error)
192209
End If
193210
End Sub
194211

@@ -202,7 +219,13 @@ Public Class Form1
202219

203220
Try
204221
Dim OutFile As String = Path.Combine(Game.libraryname, Path.GetFileNameWithoutExtension(File) & ".wav")
205-
WaveCreator(File, OutFile, Game)
222+
223+
If My.Settings.UseFFMPEG Then
224+
FFMPEG_WaveCreator(File, OutFile, Game)
225+
Else
226+
WaveCreator(File, OutFile, Game)
227+
End If
228+
206229

207230
If DeleteSource Then
208231
IO.File.Delete(File)
@@ -415,33 +438,41 @@ Public Class Form1
415438
Dim trackfile As String = Game.libraryname & Track.name & Game.FileExtension
416439
If File.Exists(trackfile) Then
417440

418-
If Track.volume = 100 And Track.startpos = -1 And Track.endpos = -1 Then
441+
If Track.volume = 100 And Track.startpos <= 0 And Track.endpos <= 0 Then
419442
File.Copy(trackfile, voicefile)
420443
Else
421444

422-
Dim WaveFloat As New WaveChannel32(New WaveFileReader(trackfile))
445+
If My.Settings.UseFFMPEG Then
423446

424-
If Not Track.volume = 100 Then
425-
WaveFloat.Volume = (Track.volume / 100) ^ 6
426-
End If
447+
FFMPEG_ConvertAndTrim(trackfile, voicefile, Game.samplerate, Game.channels, Track.startpos / Game.samplerate / 2, (Track.endpos - Track.startpos) / Game.samplerate / 2, (Track.volume / 100) ^ 6) ' /2 because SLAM stores Track.startpos and Track.endpos as # of bytes not sample. With 16-bit audio, there are 2 bytes per sample.
448+
449+
Else
427450

428-
If Not Track.startpos = Track.endpos And Track.endpos > 0 Then
429-
Dim bytes((Track.endpos - Track.startpos) * 4) As Byte
451+
Dim WaveFloat As New WaveChannel32(New WaveFileReader(trackfile))
430452

431-
WaveFloat.Position = Track.startpos * 4
432-
WaveFloat.Read(bytes, 0, (Track.endpos - Track.startpos) * 4)
453+
If Not Track.volume = 100 Then
454+
WaveFloat.Volume = (Track.volume / 100) ^ 6
455+
End If
433456

434-
WaveFloat = New WaveChannel32(New RawSourceWaveStream(New MemoryStream(bytes), WaveFloat.WaveFormat))
435-
End If
457+
If Not Track.startpos = Track.endpos And Track.endpos > 0 Then
458+
Dim bytes((Track.endpos - Track.startpos) * 4) As Byte
436459

437-
WaveFloat.PadWithZeroes = False
438-
Dim outFormat = New WaveFormat(Game.samplerate, Game.bits, Game.channels)
439-
Dim resampler = New MediaFoundationResampler(WaveFloat, outFormat)
440-
resampler.ResamplerQuality = 60
441-
WaveFileWriter.CreateWaveFile(voicefile, resampler)
460+
WaveFloat.Position = Track.startpos * 4
461+
WaveFloat.Read(bytes, 0, (Track.endpos - Track.startpos) * 4)
442462

443-
resampler.Dispose()
444-
WaveFloat.Dispose()
463+
WaveFloat = New WaveChannel32(New RawSourceWaveStream(New MemoryStream(bytes), WaveFloat.WaveFormat))
464+
End If
465+
466+
WaveFloat.PadWithZeroes = False
467+
Dim outFormat = New WaveFormat(Game.samplerate, Game.bits, Game.channels)
468+
Dim resampler = New MediaFoundationResampler(WaveFloat, outFormat)
469+
resampler.ResamplerQuality = 60
470+
WaveFileWriter.CreateWaveFile(voicefile, resampler) 'wav
471+
472+
resampler.Dispose()
473+
WaveFloat.Dispose()
474+
475+
End If
445476

446477
End If
447478

@@ -893,20 +924,26 @@ Public Class Form1
893924
End Sub
894925

895926
Private Sub TrimToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TrimToolStripMenuItem.Click
896-
Dim Game As SourceGame = GetCurrentGame()
897-
Dim TrimDialog As New TrimForm
927+
If File.Exists("NAudio.dll") Then
898928

899-
TrimDialog.WavFile = Path.Combine(Game.libraryname, Game.tracks(TrackList.SelectedIndices(0)).name & Game.FileExtension)
900-
TrimDialog.startpos = Game.tracks(TrackList.SelectedIndices(0)).startpos
901-
TrimDialog.endpos = Game.tracks(TrackList.SelectedIndices(0)).endpos
929+
Dim Game As SourceGame = GetCurrentGame()
930+
Dim TrimDialog As New TrimForm
902931

932+
TrimDialog.WavFile = Path.Combine(Game.libraryname, Game.tracks(TrackList.SelectedIndices(0)).name & Game.FileExtension)
933+
TrimDialog.startpos = Game.tracks(TrackList.SelectedIndices(0)).startpos
934+
TrimDialog.endpos = Game.tracks(TrackList.SelectedIndices(0)).endpos
903935

904-
If TrimDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
905-
Game.tracks(TrackList.SelectedIndices(0)).startpos = TrimDialog.startpos
906-
Game.tracks(TrackList.SelectedIndices(0)).endpos = TrimDialog.endpos
907-
SaveTrackKeys(GetCurrentGame)
908-
ReloadTracks(GetCurrentGame)
909-
RefreshTrackList()
936+
937+
If TrimDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
938+
Game.tracks(TrackList.SelectedIndices(0)).startpos = TrimDialog.startpos
939+
Game.tracks(TrackList.SelectedIndices(0)).endpos = TrimDialog.endpos
940+
SaveTrackKeys(GetCurrentGame)
941+
ReloadTracks(GetCurrentGame)
942+
RefreshTrackList()
943+
End If
944+
945+
Else
946+
MessageBox.Show("You are missing NAudio.dll! Cannot trim without it!", "Missing File", MessageBoxButtons.OK, MessageBoxIcon.Error)
910947
End If
911948
End Sub
912949

SLAM/My Project/Application.Designer.vb

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SLAM/My Project/Application.myapp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
33
<MySubMain>true</MySubMain>
44
<MainForm>Form1</MainForm>
5-
<SingleInstance>false</SingleInstance>
5+
<SingleInstance>true</SingleInstance>
66
<ShutdownMode>0</ShutdownMode>
77
<EnableVisualStyles>true</EnableVisualStyles>
88
<AuthenticationMode>0</AuthenticationMode>

SLAM/My Project/AssemblyInfo.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
3131
' by using the '*' as shown below:
3232
' <Assembly: AssemblyVersion("1.0.*")>
3333

34-
<Assembly: AssemblyVersion("1.5.0.0")>
35-
<Assembly: AssemblyFileVersion("1.5.0.0")>
34+
<Assembly: AssemblyVersion("1.5.1.0")>
35+
<Assembly: AssemblyFileVersion("1.5.1.0")>

SLAM/My Project/Settings.Designer.vb

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SLAM/My Project/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,8 @@
4444
<Setting Name="StartMinimized" Type="System.Boolean" Scope="User">
4545
<Value Profile="(Default)">False</Value>
4646
</Setting>
47+
<Setting Name="UseFFMPEG" Type="System.Boolean" Scope="User">
48+
<Value Profile="(Default)">True</Value>
49+
</Setting>
4750
</Settings>
4851
</SettingsFile>

SLAM/SLAM.vbproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@
7474
<Reference Include="Newtonsoft.Json">
7575
<HintPath>lib\Newtonsoft.Json.dll</HintPath>
7676
</Reference>
77+
<Reference Include="NReco.VideoConverter">
78+
<HintPath>lib\NReco.VideoConverter.dll</HintPath>
79+
</Reference>
7780
<Reference Include="System" />
7881
<Reference Include="System.Data" />
7982
<Reference Include="System.Deployment" />

SLAM/SettingsForm.Designer.vb

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SLAM/SettingsForm.vb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
EnableOverrideBox.Checked = My.Settings.OverrideFolders
1515
MinimizeToSysTrayCheckBox.Checked = My.Settings.MinimizeToSysTray
1616
StartMinimizedCheckBox.Checked = My.Settings.StartMinimized
17+
FFMPEGRadio.Checked = My.Settings.UseFFMPEG
18+
NAudioRadio.Checked = Not My.Settings.UseFFMPEG
1719
End Sub
1820

1921
Private Sub UpdateCheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles UpdateCheckBox.CheckedChanged
@@ -104,4 +106,9 @@
104106
My.Settings.StartMinimized = StartMinimizedCheckBox.Checked
105107
My.Settings.Save()
106108
End Sub
109+
110+
Private Sub FFMPEGRadio_CheckedChanged(sender As Object, e As EventArgs) Handles FFMPEGRadio.CheckedChanged
111+
My.Settings.UseFFMPEG = FFMPEGRadio.Checked
112+
My.Settings.Save()
113+
End Sub
107114
End Class

0 commit comments

Comments
 (0)