@@ -7,6 +7,7 @@ Imports SLAM.XmlSerialization
77Imports SLAM.SourceGame
88Imports System.Management
99Imports System.Net.Http
10+ Imports NReco.VideoConverter
1011
1112Public 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
0 commit comments