Skip to content

Commit

Permalink
Added FFMPEG as default coverter, and bug fixes
Browse files Browse the repository at this point in the history
* FFMPEG is now used by default to convert tracks (You can revert to
NAudio in the settings). This should fix numerous issues.
* Bug fixes.
  • Loading branch information
SilentSys committed Jul 1, 2017
1 parent 0129f55 commit 8acf0a6
Show file tree
Hide file tree
Showing 12 changed files with 768 additions and 40 deletions.
3 changes: 3 additions & 0 deletions SLAM/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<setting name="StartMinimized" serializeAs="String">
<value>False</value>
</setting>
<setting name="UseFFMPEG" serializeAs="String">
<value>True</value>
</setting>
</SLAM.My.MySettings>
</userSettings>
</configuration>
105 changes: 71 additions & 34 deletions SLAM/Form1.vb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Imports SLAM.XmlSerialization
Imports SLAM.SourceGame
Imports System.Management
Imports System.Net.Http
Imports NReco.VideoConverter

Public Class Form1

Expand Down Expand Up @@ -152,6 +153,22 @@ Public Class Form1
resampler.Dispose()
End Sub

Private Sub FFMPEG_WaveCreator(File As String, outputFile As String, Game As SourceGame)
Dim convert As New FFMpegConverter()
convert.ExtractFFmpeg()

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))
convert.Invoke(command)
End Sub

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)
Dim convert As New FFMpegConverter()
convert.ExtractFFmpeg()

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))
convert.Invoke(command)
End Sub

Private Sub GameSelector_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GameSelector.SelectedIndexChanged
ReloadTracks(GetCurrentGame)
RefreshTrackList()
Expand All @@ -160,7 +177,7 @@ Public Class Form1
End Sub

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

Else
MessageBox.Show("You are missing NAudio.dll! Cannot import without it!", "Missing File", MessageBoxButtons.OK, MessageBoxIcon.Error)
MessageBox.Show("You are missing NAudio.dll or NReco.VideoConverter.dll! Cannot import without it!", "Missing File", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub

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

Else
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)
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)
End If
End Sub

Expand All @@ -202,7 +219,13 @@ Public Class Form1

Try
Dim OutFile As String = Path.Combine(Game.libraryname, Path.GetFileNameWithoutExtension(File) & ".wav")
WaveCreator(File, OutFile, Game)

If My.Settings.UseFFMPEG Then
FFMPEG_WaveCreator(File, OutFile, Game)
Else
WaveCreator(File, OutFile, Game)
End If


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

If Track.volume = 100 And Track.startpos = -1 And Track.endpos = -1 Then
If Track.volume = 100 And Track.startpos <= 0 And Track.endpos <= 0 Then
File.Copy(trackfile, voicefile)
Else

Dim WaveFloat As New WaveChannel32(New WaveFileReader(trackfile))
If My.Settings.UseFFMPEG Then

If Not Track.volume = 100 Then
WaveFloat.Volume = (Track.volume / 100) ^ 6
End If
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.

Else

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

WaveFloat.Position = Track.startpos * 4
WaveFloat.Read(bytes, 0, (Track.endpos - Track.startpos) * 4)
If Not Track.volume = 100 Then
WaveFloat.Volume = (Track.volume / 100) ^ 6
End If

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

WaveFloat.PadWithZeroes = False
Dim outFormat = New WaveFormat(Game.samplerate, Game.bits, Game.channels)
Dim resampler = New MediaFoundationResampler(WaveFloat, outFormat)
resampler.ResamplerQuality = 60
WaveFileWriter.CreateWaveFile(voicefile, resampler)
WaveFloat.Position = Track.startpos * 4
WaveFloat.Read(bytes, 0, (Track.endpos - Track.startpos) * 4)

resampler.Dispose()
WaveFloat.Dispose()
WaveFloat = New WaveChannel32(New RawSourceWaveStream(New MemoryStream(bytes), WaveFloat.WaveFormat))
End If

WaveFloat.PadWithZeroes = False
Dim outFormat = New WaveFormat(Game.samplerate, Game.bits, Game.channels)
Dim resampler = New MediaFoundationResampler(WaveFloat, outFormat)
resampler.ResamplerQuality = 60
WaveFileWriter.CreateWaveFile(voicefile, resampler) 'wav

resampler.Dispose()
WaveFloat.Dispose()

End If

End If

Expand Down Expand Up @@ -893,20 +924,26 @@ Public Class Form1
End Sub

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

TrimDialog.WavFile = Path.Combine(Game.libraryname, Game.tracks(TrackList.SelectedIndices(0)).name & Game.FileExtension)
TrimDialog.startpos = Game.tracks(TrackList.SelectedIndices(0)).startpos
TrimDialog.endpos = Game.tracks(TrackList.SelectedIndices(0)).endpos
Dim Game As SourceGame = GetCurrentGame()
Dim TrimDialog As New TrimForm

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

If TrimDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
Game.tracks(TrackList.SelectedIndices(0)).startpos = TrimDialog.startpos
Game.tracks(TrackList.SelectedIndices(0)).endpos = TrimDialog.endpos
SaveTrackKeys(GetCurrentGame)
ReloadTracks(GetCurrentGame)
RefreshTrackList()

If TrimDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
Game.tracks(TrackList.SelectedIndices(0)).startpos = TrimDialog.startpos
Game.tracks(TrackList.SelectedIndices(0)).endpos = TrimDialog.endpos
SaveTrackKeys(GetCurrentGame)
ReloadTracks(GetCurrentGame)
RefreshTrackList()
End If

Else
MessageBox.Show("You are missing NAudio.dll! Cannot trim without it!", "Missing File", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub

Expand Down
2 changes: 1 addition & 1 deletion SLAM/My Project/Application.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion SLAM/My Project/Application.myapp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MySubMain>true</MySubMain>
<MainForm>Form1</MainForm>
<SingleInstance>false</SingleInstance>
<SingleInstance>true</SingleInstance>
<ShutdownMode>0</ShutdownMode>
<EnableVisualStyles>true</EnableVisualStyles>
<AuthenticationMode>0</AuthenticationMode>
Expand Down
4 changes: 2 additions & 2 deletions SLAM/My Project/AssemblyInfo.vb
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")>

<Assembly: AssemblyVersion("1.5.0.0")>
<Assembly: AssemblyFileVersion("1.5.0.0")>
<Assembly: AssemblyVersion("1.5.1.0")>
<Assembly: AssemblyFileVersion("1.5.1.0")>
16 changes: 14 additions & 2 deletions SLAM/My Project/Settings.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions SLAM/My Project/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@
<Setting Name="StartMinimized" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="UseFFMPEG" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
3 changes: 3 additions & 0 deletions SLAM/SLAM.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
<Reference Include="Newtonsoft.Json">
<HintPath>lib\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NReco.VideoConverter">
<HintPath>lib\NReco.VideoConverter.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
Expand Down
29 changes: 29 additions & 0 deletions SLAM/SettingsForm.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions SLAM/SettingsForm.vb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
EnableOverrideBox.Checked = My.Settings.OverrideFolders
MinimizeToSysTrayCheckBox.Checked = My.Settings.MinimizeToSysTray
StartMinimizedCheckBox.Checked = My.Settings.StartMinimized
FFMPEGRadio.Checked = My.Settings.UseFFMPEG
NAudioRadio.Checked = Not My.Settings.UseFFMPEG
End Sub

Private Sub UpdateCheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles UpdateCheckBox.CheckedChanged
Expand Down Expand Up @@ -104,4 +106,9 @@
My.Settings.StartMinimized = StartMinimizedCheckBox.Checked
My.Settings.Save()
End Sub

Private Sub FFMPEGRadio_CheckedChanged(sender As Object, e As EventArgs) Handles FFMPEGRadio.CheckedChanged
My.Settings.UseFFMPEG = FFMPEGRadio.Checked
My.Settings.Save()
End Sub
End Class
Loading

0 comments on commit 8acf0a6

Please sign in to comment.