Skip to content

Commit

Permalink
improve AudioClip export
Browse files Browse the repository at this point in the history
  • Loading branch information
Perfare committed Jan 21, 2018
1 parent 7e67f35 commit 4d85c7f
Show file tree
Hide file tree
Showing 12 changed files with 356 additions and 260 deletions.
168 changes: 65 additions & 103 deletions Unity Studio/ExportOptions.Designer.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Unity Studio/ExportOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ExportOptions()
upAxis.SelectedIndex = (int)Properties.Settings.Default["upAxis"];
showExpOpt.Checked = (bool)Properties.Settings.Default["showExpOpt"];
converttexture.Checked = (bool)Properties.Settings.Default["convertTexture"];
convertfsb.Checked = (bool)Properties.Settings.Default["convertfsb"];
convertAudio.Checked = (bool)Properties.Settings.Default["convertAudio"];
var str = (string)Properties.Settings.Default["convertType"];
foreach (Control c in panel1.Controls)
{
Expand Down Expand Up @@ -54,7 +54,7 @@ private void fbxOKbutton_Click(object sender, EventArgs e)
Properties.Settings.Default["scaleFactor"] = scaleFactor.Value;
Properties.Settings.Default["upAxis"] = upAxis.SelectedIndex;
Properties.Settings.Default["convertTexture"] = converttexture.Checked;
Properties.Settings.Default["convertfsb"] = convertfsb.Checked;
Properties.Settings.Default["convertAudio"] = convertAudio.Checked;
foreach (Control c in panel1.Controls)
{
if (((RadioButton)c).Checked)
Expand Down
3 changes: 0 additions & 3 deletions Unity Studio/ExportOptions.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,4 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="saveFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
8 changes: 4 additions & 4 deletions Unity Studio/Properties/Settings.Designer.cs

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

2 changes: 1 addition & 1 deletion Unity Studio/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<Setting Name="convertTexture" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="convertfsb" Type="System.Boolean" Scope="User">
<Setting Name="convertAudio" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="convertType" Type="System.String" Scope="User">
Expand Down
204 changes: 153 additions & 51 deletions Unity Studio/Unity Classes/AudioClip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AudioClip
{
public string m_Name;
public int m_Format;
public int m_Type = -1;
public AudioType m_Type;
public bool m_3D;
public bool m_UseHardware;

Expand All @@ -26,13 +26,15 @@ class AudioClip
public bool m_PreloadAudioData;
public bool m_LoadInBackground;
public bool m_Legacy3D;
public int m_CompressionFormat = -1;
public AudioCompressionFormat m_CompressionFormat;

public string m_Source;
public long m_Offset;
public long m_Size;
public byte[] m_AudioData;

public bool version5;

public AudioClip(AssetPreloadData preloadData, bool readSwitch)
{
var sourceFile = preloadData.sourceFile;
Expand All @@ -47,12 +49,12 @@ public AudioClip(AssetPreloadData preloadData, bool readSwitch)
}

m_Name = a_Stream.ReadAlignedString(a_Stream.ReadInt32());

version5 = sourceFile.version[0] >= 5;
if (sourceFile.version[0] < 5)
{

m_Format = a_Stream.ReadInt32(); //channels?
m_Type = a_Stream.ReadInt32();
m_Type = (AudioType)a_Stream.ReadInt32();
m_3D = a_Stream.ReadBoolean();
m_UseHardware = a_Stream.ReadBoolean();
a_Stream.Position += 2; //4 byte alignment
Expand All @@ -69,11 +71,14 @@ public AudioClip(AssetPreloadData preloadData, bool readSwitch)
m_Source = sourceFile.filePath + ".resS";
}
}
else { m_Size = a_Stream.ReadInt32(); }
else
{
m_Size = a_Stream.ReadInt32();
}
}
else
{
m_LoadType = a_Stream.ReadInt32();//Decompress on load, Compressed in memory, Streaming
m_LoadType = a_Stream.ReadInt32(); //Decompress on load, Compressed in memory, Streaming
m_Channels = a_Stream.ReadInt32();
m_Frequency = a_Stream.ReadInt32();
m_BitsPerSample = a_Stream.ReadInt32();
Expand All @@ -92,7 +97,7 @@ public AudioClip(AssetPreloadData preloadData, bool readSwitch)
m_Source = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), m_Source.Replace("archive:/", ""));
m_Offset = a_Stream.ReadInt64();
m_Size = a_Stream.ReadInt64();
m_CompressionFormat = a_Stream.ReadInt32();
m_CompressionFormat = (AudioCompressionFormat)a_Stream.ReadInt32();
}

if (readSwitch)
Expand All @@ -103,7 +108,7 @@ public AudioClip(AssetPreloadData preloadData, bool readSwitch)
m_AudioData = a_Stream.ReadBytes((int)m_Size);
}
else if (File.Exists(m_Source) ||
File.Exists(m_Source = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), Path.GetFileName(m_Source))))
File.Exists(m_Source = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), Path.GetFileName(m_Source))))
{
BinaryReader reader = new BinaryReader(File.OpenRead(m_Source));
reader.BaseStream.Position = m_Offset;
Expand All @@ -127,65 +132,162 @@ public AudioClip(AssetPreloadData preloadData, bool readSwitch)
{
preloadData.InfoText = "Compression format: ";

switch (m_Type)
if (sourceFile.version[0] < 5)
{
case 2:
preloadData.extension = ".aif";
preloadData.InfoText += "AIFF";
break;
case 13:
preloadData.extension = ".mp3";
preloadData.InfoText += "MP3";
break;
case 14:
preloadData.extension = ".ogg";
preloadData.InfoText += "Ogg Vorbis";
break;
case 20:
preloadData.extension = ".wav";
preloadData.InfoText += "WAV";
break;
case 22: //xbox encoding
preloadData.extension = ".wav";
preloadData.InfoText += "Xbox360 WAV";
break;
}
switch (m_Type)
{
case AudioType.ACC:
preloadData.extension = ".m4a";
preloadData.InfoText += "Acc";
break;
case AudioType.AIFF:
preloadData.extension = ".aif";
preloadData.InfoText += "AIFF";
break;
case AudioType.IT:
preloadData.extension = ".it";
preloadData.InfoText += "Impulse tracker";
break;
case AudioType.MOD:
preloadData.extension = ".mod";
preloadData.InfoText += "Protracker / Fasttracker MOD";
break;
case AudioType.MPEG:
preloadData.extension = ".mp3";
preloadData.InfoText += "MP2/MP3 MPEG";
break;
case AudioType.OGGVORBIS:
preloadData.extension = ".ogg";
preloadData.InfoText += "Ogg vorbis";
break;
case AudioType.S3M:
preloadData.extension = ".s3m";
preloadData.InfoText += "ScreamTracker 3";
break;
case AudioType.WAV:
preloadData.extension = ".wav";
preloadData.InfoText += "Microsoft WAV";
break;
case AudioType.XM:
preloadData.extension = ".xm";
preloadData.InfoText += "FastTracker 2 XM";
break;
case AudioType.XMA:
preloadData.extension = ".wav";
preloadData.InfoText += "Xbox360 XMA";
break;
case AudioType.VAG:
preloadData.extension = ".vag";
preloadData.InfoText += "PlayStation Portable ADPCM";
break;
case AudioType.AUDIOQUEUE:
preloadData.extension = ".fsb";
preloadData.InfoText += "iPhone";
break;
}

switch (m_CompressionFormat)
}
else
{
case 0:
preloadData.extension = ".fsb";
preloadData.InfoText += "PCM";
break;
case 1:
preloadData.extension = ".fsb";
preloadData.InfoText += "Vorbis";
break;
case 2:
preloadData.extension = ".fsb";
preloadData.InfoText += "ADPCM";
break;
case 3:
preloadData.extension = ".fsb";
preloadData.InfoText += "MP3";//not sure
break;
case 7:
preloadData.extension = ".m4a";
preloadData.InfoText += "M4a";
break;
switch (m_CompressionFormat)
{
case AudioCompressionFormat.PCM:
preloadData.extension = ".fsb";
preloadData.InfoText += "PCM";
break;
case AudioCompressionFormat.Vorbis:
preloadData.extension = ".fsb";
preloadData.InfoText += "Vorbis";
break;
case AudioCompressionFormat.ADPCM:
preloadData.extension = ".fsb";
preloadData.InfoText += "ADPCM";
break;
case AudioCompressionFormat.MP3:
preloadData.extension = ".fsb";
preloadData.InfoText += "MP3";
break;
case AudioCompressionFormat.VAG:
preloadData.extension = ".vag";
preloadData.InfoText += "PlayStation Portable ADPCM";
break;
case AudioCompressionFormat.HEVAG:
preloadData.extension = ".vag";
preloadData.InfoText += "PSVita ADPCM";
break;
case AudioCompressionFormat.XMA:
preloadData.extension = ".wav";
preloadData.InfoText += "Xbox360 XMA";
break;
case AudioCompressionFormat.AAC:
preloadData.extension = ".m4a";
preloadData.InfoText += "Acc";
break;
case AudioCompressionFormat.GCADPCM:
preloadData.extension = ".fsb";
preloadData.InfoText += "Nintendo 3DS/Wii DSP";
break;
case AudioCompressionFormat.ATRAC9:
preloadData.extension = ".at9";
preloadData.InfoText += "PSVita ATRAC9";
break;
}
}

if (preloadData.extension == null)
{
preloadData.extension = ".AudioClip";
preloadData.InfoText += "Unknown";
}

preloadData.InfoText += "\n3D: " + m_3D;

preloadData.Text = m_Name;
if (m_Source != null)
preloadData.fullSize = preloadData.Size + (int)m_Size;
}
}

public bool IsFMODSupport
{
get
{
if (!version5)
{
switch (m_Type)
{
case AudioType.AIFF:
case AudioType.IT:
case AudioType.MOD:
case AudioType.S3M:
case AudioType.XM:
case AudioType.XMA:
case AudioType.VAG:
case AudioType.AUDIOQUEUE:
return true;
default:
return false;
}
}
else
{
switch (m_CompressionFormat)
{
case AudioCompressionFormat.PCM:
case AudioCompressionFormat.Vorbis:
case AudioCompressionFormat.ADPCM:
case AudioCompressionFormat.MP3:
case AudioCompressionFormat.VAG:
case AudioCompressionFormat.HEVAG:
case AudioCompressionFormat.XMA:
case AudioCompressionFormat.GCADPCM:
case AudioCompressionFormat.ATRAC9:
return true;
default:
return false;
}
}
}
}
}
}
Loading

0 comments on commit 4d85c7f

Please sign in to comment.