Skip to content

Commit

Permalink
fmod sndi enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
energydrink02 committed Jun 23, 2024
1 parent e4f184c commit eafc31f
Show file tree
Hide file tree
Showing 14 changed files with 351 additions and 379 deletions.
21 changes: 6 additions & 15 deletions IndustrialPark/ArchiveEditor/ArchiveEditorFunctions_Sounds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,14 @@ public byte[] GetSoundData(uint assetID, byte[] previousData)
return file.ToArray();
}

public int GetDefaultSampleRate()
{
foreach (Asset a in assetDictionary.Values)
if (a is AssetSNDI_GCN_V2 SNDI_G2)
if (SNDI_G2.Entry_Sounds != null)
return SNDI_G2.Entry_Sounds.SampleHeader.Frequency;

return 32000;
}

public byte[] CreateSoundFile(AssetType assetType, string fileName, bool ps2Looping = false, bool xboxcompress = true, bool forcemono = false, int samplerate = 0)
public byte[] CreateSoundFile(string fileName, bool ps2Looping = false, bool compress = true, bool forcemono = false, int samplerate = 0)
{
if (platform == Platform.Xbox)
return SoundUtility_XboxADPCM.ConvertSoundToXboxADPCM(fileName, xboxcompress, forcemono, samplerate);
return SoundUtility_XboxADPCM.ConvertSoundToXboxADPCM(fileName, compress, forcemono, samplerate);
if (platform == Platform.PS2)
return SoundUtility_PS2VAG.ConvertSoundToPS2VAG(fileName, ps2Looping, samplerate);
if (platform == Platform.GameCube && game >= Game.Incredibles)
return SoundUtility_FMOD.ConvertSoundToFSB3(fileName, assetType == AssetType.Sound ? GetDefaultSampleRate() : samplerate, assetType == AssetType.Sound ? true : forcemono);
return SoundUtility_FMOD.ConvertSoundToFSB3(fileName, samplerate, forcemono, compress);
if (platform == Platform.GameCube)
return SoundUtility_DSP.ConvertSoundToDSP(fileName, samplerate);

Expand All @@ -156,6 +146,7 @@ public byte[] CreateSoundFile(AssetType assetType, string fileName, bool ps2Loop
public void ImportSounds(bool raw, string[] fileNames, AssetType assetType, bool forceOverwrite, out List<uint> assetIDs)
{
assetIDs = new List<uint>();

ProgressBar progressBar = new ProgressBar("Import Sounds");
progressBar.SetProgressBar(0, fileNames.Count(), 1);
progressBar.Show();
Expand All @@ -176,7 +167,7 @@ public void ImportSounds(bool raw, string[] fileNames, AssetType assetType, bool
continue;
}

byte[] data = raw ? File.ReadAllBytes(fileName) : CreateSoundFile(assetType, fileName);
byte[] data = raw ? File.ReadAllBytes(fileName) : CreateSoundFile(fileName);
if (data == null)
continue;

Expand All @@ -195,7 +186,7 @@ public void ImportSounds(bool raw, string[] fileNames, AssetType assetType, bool
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

UnsavedChanges = true;
Expand Down

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

60 changes: 42 additions & 18 deletions IndustrialPark/ArchiveEditor/InternalEditors/InternalSoundEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ public InternalSoundEditor(AssetSound asset, ArchiveEditorFunctions archive, Act

RefreshPropertyGrid();

if (archive.platform != Platform.Xbox)
xboxCompressCheckBox.Enabled = false;
if (archive.platform == Platform.Xbox || (archive.platform == Platform.GameCube && archive.game >= Game.Incredibles && asset.assetType == AssetType.SoundStream))
compressCheckBox.Enabled = true;
if (archive.platform != Platform.PS2)
checkBoxPS2Looping.Enabled = false;
if (archive.platform == Platform.GameCube && archive.game >= Game.Incredibles && asset.assetType == AssetType.Sound)
forceSampleRateCheckbox.Enabled = false;
if (archive.platform == Platform.Xbox || (archive.platform == Platform.GameCube && archive.game >= Game.Incredibles))
xboxForceMono.Enabled = true;
forceMonoCheckBox.Enabled = true;
}

public void RefreshPropertyGrid()
Expand Down Expand Up @@ -59,6 +57,15 @@ public void RefreshPropertyGrid()
CalculateSoundLength(entry);
return;
}
if (sndi is AssetSNDI_GCN_V2 gcn2)
{
var entry = gcn2.GetEntry(asset.assetID);
soundSizeLabel.Text = ArchiveEditor.ConvertSize(entry.LengthCompressedBytes);
propertyGridSoundData.SelectedObject = entry.Clone();
CalculateSoundLength(entry);
return;

}
}
}
catch (Exception e)
Expand Down Expand Up @@ -91,6 +98,11 @@ private void propertyGridSoundData_PropertyValueChanged(object s, PropertyValueC
gcn1.SetEntry(((SoundInfoGcn1Wrapper)propertyGridSoundData.SelectedObject).Entry, asset.assetType);
archive.UnsavedChanges = true;
}
else if (sndi is AssetSNDI_GCN_V2 gcn2)
{
gcn2.SetEntry((FSB3_SampleHeader)propertyGridSoundData.SelectedObject);
archive.UnsavedChanges = true;
}
}
SoundUtility_vgmstream.ClearSound();
}
Expand Down Expand Up @@ -227,14 +239,16 @@ private void buttonImportSound_Click(object sender, EventArgs e)

if (openFileDialog.ShowDialog() == DialogResult.OK)
{
importSoundStatusLabel.Text = "Import in progress...";
soundLengthLabel.Visible = false;
soundSizeLabel.Visible = false;
Enabled = false;

byte[] data = archive.CreateSoundFile(
asset.assetType,
openFileDialog.FileName,
checkBoxPS2Looping.Checked,
xboxCompressCheckBox.Checked,
xboxForceMono.Checked,
compressCheckBox.Checked,
forceMonoCheckBox.Checked,
(int)samplerateNumeric.Value);

if (data != null)
Expand All @@ -246,16 +260,19 @@ private void buttonImportSound_Click(object sender, EventArgs e)
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

archive.UnsavedChanges = true;
updateListView(asset);
SoundUtility_vgmstream.ClearSound();
}

Enabled = true;
RefreshPropertyGrid();
importSoundStatusLabel.Text = "";
soundLengthLabel.Visible = true;
soundSizeLabel.Visible = true;
}
}

Expand All @@ -279,23 +296,30 @@ private void checkBox1_CheckedChanged(object sender, EventArgs e)
samplerateNumeric.Enabled = forceSampleRateCheckbox.Checked;
}

private string SoundLengthLabelText = "Length: {0:00}:{1:00}";
private void CalculateSoundLength(EntrySoundInfo_XBOX entry)
{
int duration = entry.dataSize / entry.nAvgBytesPerSec;
soundLengthLabel.Text = string.Format(SoundLengthLabelText, duration / 60, duration % 60);
SetSoundLengthLabel((float)entry.dataSize / entry.nAvgBytesPerSec);
}

private void CalculateSoundLength(EntrySoundInfo_PS2 entry)
{
uint duration = ((entry.DataSize / 0x10) * 28) / entry.SampleRate;
soundLengthLabel.Text = string.Format(SoundLengthLabelText, duration / 60, duration % 60);
SetSoundLengthLabel((float)((entry.DataSize / 0x10) * 28) / entry.SampleRate);
}

private void CalculateSoundLength(EntrySoundInfo_GCN_V1 entry)
{
uint duration = entry.num_samples / entry.sample_rate;
soundLengthLabel.Text = string.Format(SoundLengthLabelText, duration / 60, duration % 60);
SetSoundLengthLabel((float)entry.num_samples / entry.sample_rate);
}

private void CalculateSoundLength(FSB3_SampleHeader entry)
{
SetSoundLengthLabel((float)entry.LengthSamples / entry.Frequency);
}

private void SetSoundLengthLabel(float duration)
{
TimeSpan ts = TimeSpan.FromSeconds(duration);
soundLengthLabel.Text = $"Length: {ts:mm\\:ss\\.fff}";
}

}
}
8 changes: 4 additions & 4 deletions IndustrialPark/ArchiveEditor/Other/Sound/SoundUtility_FMOD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class SoundUtility_FMOD
{
private static string ffmpegOutPath => SoundUtility_ffmpeg.ffmpegOutPath;

public static byte[] ConvertSoundToFSB3(string fileName, int frequency, bool forcemono)
public static byte[] ConvertSoundToFSB3(string fileName, int frequency, bool forcemono, bool compress)
{
try
{
Expand Down Expand Up @@ -40,7 +40,7 @@ public static byte[] ConvertSoundToFSB3(string fileName, int frequency, bool for

File.WriteAllText(fsbankTextPath, ffmpegOutPath);

ConvertFSBank(fsbankTextPath, fsbankOutPath);
ConvertFSBank(fsbankTextPath, fsbankOutPath, compress);

var file = File.ReadAllBytes(fsbankOutPath);

Expand Down Expand Up @@ -88,9 +88,9 @@ private static bool InitFSBank()
return true;
}

private static void ConvertFSBank(string inPath, string outPath)
private static void ConvertFSBank(string inPath, string outPath, bool compress)
{
fsbankProcess.StartInfo.Arguments = $"-o \"{outPath}\" \"{inPath}\" -p gc -f gcadpcm -h";
fsbankProcess.StartInfo.Arguments = $"-o \"{outPath}\" \"{inPath}\" -p gc -f {(compress ? "gcadpcm" : "pcm")} -h";
fsbankProcess.Start();
fsbankProcess.WaitForExit();
}
Expand Down
Loading

0 comments on commit eafc31f

Please sign in to comment.