- replaced FMOD Ex with FMOD Studio API

- audio preview code optimization
- added breakpoints for any FMOD errrs; status messages are now generated instead of crashing the app
- fixed a loop in the FMOD code that caused system overflow
- added platform string to app titlebar
This commit is contained in:
RaduMCosma 2015-11-05 00:13:20 +02:00
parent 2c94852939
commit 93ebc67841
7 changed files with 6335 additions and 195 deletions

View File

@ -16,6 +16,7 @@ namespace Unity_Studio
public int[] version = new int[4] { 0, 0, 0, 0 };
public string[] buildType;
public int platform = 100663296;
public string platformStr = "";
//public EndianType endianType = EndianType.BigEndian;
//public List<AssetPreloadData> preloadTable = new List<AssetPreloadData>();
public Dictionary<long, AssetPreloadData> preloadTable = new Dictionary<long, AssetPreloadData>();
@ -105,21 +106,22 @@ namespace Unity_Studio
a_Stream.endian = EndianType.LittleEndian;
}
/*Platform list:
-2: unitypackage
4: OSX
5: PC
6: Web
7: Web_streamed
9: iOS
10: PS3(big)
11: Xbox360(big)
13: Android
16: Google_NaCl
21: WP8
25: Linux
*/
switch (platform)
{
case -2: platformStr = "Unity Package"; break;
case 4: platformStr = "OSX"; break;
case 5: platformStr = "PC"; break;
case 6: platformStr = "Web"; break;
case 7: platformStr = "Web streamed"; break;
case 9: platformStr = "iOS"; break;
case 10: platformStr = "PS3"; break;
case 11: platformStr = "Xbox 360"; break;
case 13: platformStr = "Android"; break;
case 16: platformStr = "Google NaCl"; break;
case 21: platformStr = "WP8"; break;
case 25: platformStr = "Linux"; break;
}
int baseCount = a_Stream.ReadInt32();
for (int i = 0; i < baseCount; i++)
{

View File

@ -103,9 +103,9 @@ namespace Unity_Studio
{
case 1:
extension = ".fsb";
preloadData.InfoText += "FSB";
preloadData.InfoText += "FSB with substreams";
break;
case 2://FSB5
case 2:
extension = ".fsb";
preloadData.InfoText += "FSB";
break;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,103 @@
/* =================================================================================================== */
/* FMOD Studio - Error string header file. Copyright (c), Firelight Technologies Pty, Ltd. 2004-2015. */
/* */
/* Use this header if you want to store or display a string version / english explanation of */
/* the FMOD error codes. */
/* */
/* =================================================================================================== */
namespace FMOD
{
public class Error
{
public static string String(FMOD.RESULT errcode)
{
switch (errcode)
{
case FMOD.RESULT.OK: return "No errors.";
case FMOD.RESULT.ERR_BADCOMMAND: return "Tried to call a function on a data type that does not allow this type of functionality (ie calling Sound::lock on a streaming sound).";
case FMOD.RESULT.ERR_CHANNEL_ALLOC: return "Error trying to allocate a channel.";
case FMOD.RESULT.ERR_CHANNEL_STOLEN: return "The specified channel has been reused to play another sound.";
case FMOD.RESULT.ERR_DMA: return "DMA Failure. See debug output for more information.";
case FMOD.RESULT.ERR_DSP_CONNECTION: return "DSP connection error. Connection possibly caused a cyclic dependency or connected dsps with incompatible buffer counts.";
case FMOD.RESULT.ERR_DSP_DONTPROCESS: return "DSP return code from a DSP process query callback. Tells mixer not to call the process callback and therefore not consume CPU. Use this to optimize the DSP graph.";
case FMOD.RESULT.ERR_DSP_FORMAT: return "DSP Format error. A DSP unit may have attempted to connect to this network with the wrong format, or a matrix may have been set with the wrong size if the target unit has a specified channel map.";
case FMOD.RESULT.ERR_DSP_INUSE: return "DSP is already in the mixer's DSP network. It must be removed before being reinserted or released.";
case FMOD.RESULT.ERR_DSP_NOTFOUND: return "DSP connection error. Couldn't find the DSP unit specified.";
case FMOD.RESULT.ERR_DSP_RESERVED: return "DSP operation error. Cannot perform operation on this DSP as it is reserved by the system.";
case FMOD.RESULT.ERR_DSP_SILENCE: return "DSP return code from a DSP process query callback. Tells mixer silence would be produced from read, so go idle and not consume CPU. Use this to optimize the DSP graph.";
case FMOD.RESULT.ERR_DSP_TYPE: return "DSP operation cannot be performed on a DSP of this type.";
case FMOD.RESULT.ERR_FILE_BAD: return "Error loading file.";
case FMOD.RESULT.ERR_FILE_COULDNOTSEEK: return "Couldn't perform seek operation. This is a limitation of the medium (ie netstreams) or the file format.";
case FMOD.RESULT.ERR_FILE_DISKEJECTED: return "Media was ejected while reading.";
case FMOD.RESULT.ERR_FILE_EOF: return "End of file unexpectedly reached while trying to read essential data (truncated?).";
case FMOD.RESULT.ERR_FILE_ENDOFDATA: return "End of current chunk reached while trying to read data.";
case FMOD.RESULT.ERR_FILE_NOTFOUND: return "File not found.";
case FMOD.RESULT.ERR_FORMAT: return "Unsupported file or audio format.";
case FMOD.RESULT.ERR_HEADER_MISMATCH: return "There is a version mismatch between the FMOD header and either the FMOD Studio library or the FMOD Low Level library.";
case FMOD.RESULT.ERR_HTTP: return "A HTTP error occurred. This is a catch-all for HTTP errors not listed elsewhere.";
case FMOD.RESULT.ERR_HTTP_ACCESS: return "The specified resource requires authentication or is forbidden.";
case FMOD.RESULT.ERR_HTTP_PROXY_AUTH: return "Proxy authentication is required to access the specified resource.";
case FMOD.RESULT.ERR_HTTP_SERVER_ERROR: return "A HTTP server error occurred.";
case FMOD.RESULT.ERR_HTTP_TIMEOUT: return "The HTTP request timed out.";
case FMOD.RESULT.ERR_INITIALIZATION: return "FMOD was not initialized correctly to support this function.";
case FMOD.RESULT.ERR_INITIALIZED: return "Cannot call this command after System::init.";
case FMOD.RESULT.ERR_INTERNAL: return "An error occurred that wasn't supposed to. Contact support.";
case FMOD.RESULT.ERR_INVALID_FLOAT: return "Value passed in was a NaN, Inf or denormalized float.";
case FMOD.RESULT.ERR_INVALID_HANDLE: return "An invalid object handle was used.";
case FMOD.RESULT.ERR_INVALID_PARAM: return "An invalid parameter was passed to this function.";
case FMOD.RESULT.ERR_INVALID_POSITION: return "An invalid seek position was passed to this function.";
case FMOD.RESULT.ERR_INVALID_SPEAKER: return "An invalid speaker was passed to this function based on the current speaker mode.";
case FMOD.RESULT.ERR_INVALID_SYNCPOINT: return "The syncpoint did not come from this sound handle.";
case FMOD.RESULT.ERR_INVALID_THREAD: return "Tried to call a function on a thread that is not supported.";
case FMOD.RESULT.ERR_INVALID_VECTOR: return "The vectors passed in are not unit length, or perpendicular.";
case FMOD.RESULT.ERR_MAXAUDIBLE: return "Reached maximum audible playback count for this sound's soundgroup.";
case FMOD.RESULT.ERR_MEMORY: return "Not enough memory or resources.";
case FMOD.RESULT.ERR_MEMORY_CANTPOINT: return "Can't use FMOD_OPENMEMORY_POINT on non PCM source data, or non mp3/xma/adpcm data if FMOD_CREATECOMPRESSEDSAMPLE was used.";
case FMOD.RESULT.ERR_NEEDS3D: return "Tried to call a command on a 2d sound when the command was meant for 3d sound.";
case FMOD.RESULT.ERR_NEEDSHARDWARE: return "Tried to use a feature that requires hardware support.";
case FMOD.RESULT.ERR_NET_CONNECT: return "Couldn't connect to the specified host.";
case FMOD.RESULT.ERR_NET_SOCKET_ERROR: return "A socket error occurred. This is a catch-all for socket-related errors not listed elsewhere.";
case FMOD.RESULT.ERR_NET_URL: return "The specified URL couldn't be resolved.";
case FMOD.RESULT.ERR_NET_WOULD_BLOCK: return "Operation on a non-blocking socket could not complete immediately.";
case FMOD.RESULT.ERR_NOTREADY: return "Operation could not be performed because specified sound/DSP connection is not ready.";
case FMOD.RESULT.ERR_OUTPUT_ALLOCATED: return "Error initializing output device, but more specifically, the output device is already in use and cannot be reused.";
case FMOD.RESULT.ERR_OUTPUT_CREATEBUFFER: return "Error creating hardware sound buffer.";
case FMOD.RESULT.ERR_OUTPUT_DRIVERCALL: return "A call to a standard soundcard driver failed, which could possibly mean a bug in the driver or resources were missing or exhausted.";
case FMOD.RESULT.ERR_OUTPUT_FORMAT: return "Soundcard does not support the specified format.";
case FMOD.RESULT.ERR_OUTPUT_INIT: return "Error initializing output device.";
case FMOD.RESULT.ERR_OUTPUT_NODRIVERS: return "The output device has no drivers installed. If pre-init, FMOD_OUTPUT_NOSOUND is selected as the output mode. If post-init, the function just fails.";
case FMOD.RESULT.ERR_PLUGIN: return "An unspecified error has been returned from a plugin.";
case FMOD.RESULT.ERR_PLUGIN_MISSING: return "A requested output, dsp unit type or codec was not available.";
case FMOD.RESULT.ERR_PLUGIN_RESOURCE: return "A resource that the plugin requires cannot be found. (ie the DLS file for MIDI playback)";
case FMOD.RESULT.ERR_PLUGIN_VERSION: return "A plugin was built with an unsupported SDK version.";
case FMOD.RESULT.ERR_RECORD: return "An error occurred trying to initialize the recording device.";
case FMOD.RESULT.ERR_REVERB_CHANNELGROUP: return "Reverb properties cannot be set on this channel because a parent channelgroup owns the reverb connection.";
case FMOD.RESULT.ERR_REVERB_INSTANCE: return "Specified instance in FMOD_REVERB_PROPERTIES couldn't be set. Most likely because it is an invalid instance number or the reverb doesn't exist.";
case FMOD.RESULT.ERR_SUBSOUNDS: return "The error occurred because the sound referenced contains subsounds when it shouldn't have, or it doesn't contain subsounds when it should have. The operation may also not be able to be performed on a parent sound.";
case FMOD.RESULT.ERR_SUBSOUND_ALLOCATED: return "This subsound is already being used by another sound, you cannot have more than one parent to a sound. Null out the other parent's entry first.";
case FMOD.RESULT.ERR_SUBSOUND_CANTMOVE: return "Shared subsounds cannot be replaced or moved from their parent stream, such as when the parent stream is an FSB file.";
case FMOD.RESULT.ERR_TAGNOTFOUND: return "The specified tag could not be found or there are no tags.";
case FMOD.RESULT.ERR_TOOMANYCHANNELS: return "The sound created exceeds the allowable input channel count. This can be increased using the 'maxinputchannels' parameter in System::setSoftwareFormat.";
case FMOD.RESULT.ERR_TRUNCATED: return "The retrieved string is too long to fit in the supplied buffer and has been truncated.";
case FMOD.RESULT.ERR_UNIMPLEMENTED: return "Something in FMOD hasn't been implemented when it should be! contact support!";
case FMOD.RESULT.ERR_UNINITIALIZED: return "This command failed because System::init or System::setDriver was not called.";
case FMOD.RESULT.ERR_UNSUPPORTED: return "A command issued was not supported by this object. Possibly a plugin without certain callbacks specified.";
case FMOD.RESULT.ERR_VERSION: return "The version number of this file format is not supported.";
case FMOD.RESULT.ERR_EVENT_ALREADY_LOADED: return "The specified bank has already been loaded.";
case FMOD.RESULT.ERR_EVENT_LIVEUPDATE_BUSY: return "The live update connection failed due to the game already being connected.";
case FMOD.RESULT.ERR_EVENT_LIVEUPDATE_MISMATCH: return "The live update connection failed due to the game data being out of sync with the tool.";
case FMOD.RESULT.ERR_EVENT_LIVEUPDATE_TIMEOUT: return "The live update connection timed out.";
case FMOD.RESULT.ERR_EVENT_NOTFOUND: return "The requested event, bus or vca could not be found.";
case FMOD.RESULT.ERR_STUDIO_UNINITIALIZED: return "The Studio::System object is not yet initialized.";
case FMOD.RESULT.ERR_STUDIO_NOT_LOADED: return "The specified resource is not loaded, so it can't be unloaded.";
case FMOD.RESULT.ERR_INVALID_STRING: return "An invalid string was passed to this function.";
case FMOD.RESULT.ERR_ALREADY_LOCKED: return "The specified resource is already locked.";
case FMOD.RESULT.ERR_NOT_LOCKED: return "The specified resource is not locked, so it can't be unlocked.";
case FMOD.RESULT.ERR_RECORD_DISCONNECTED: return "The specified recording driver has been disconnected.";
case FMOD.RESULT.ERR_TOOMANYSAMPLES: return "The length provided exceed the allowable limit.";
default: return "Unknown error.";
}
}
}
}

View File

@ -139,6 +139,9 @@
<Compile Include="FBXExport.Designer.cs">
<DependentUpon>FBXExport.cs</DependentUpon>
</Compile>
<Compile Include="FMOD Studio API\fmod.cs" />
<Compile Include="FMOD Studio API\fmod_dsp.cs" />
<Compile Include="FMOD Studio API\fmod_errors.cs" />
<Compile Include="Font.cs" />
<Compile Include="GOHierarchy.cs">
<SubType>Component</SubType>
@ -146,10 +149,6 @@
<Compile Include="Lz4DecoderStream.cs" />
<Compile Include="Material.cs" />
<Compile Include="Mesh.cs" />
<Compile Include="FMOD\fmod.cs" />
<Compile Include="FMOD\fmod_dsp.cs" />
<Compile Include="FMOD\fmod_errors.cs" />
<Compile Include="FMOD\fmod_memoryinfo.cs" />
<Compile Include="GameObject.cs" />
<Compile Include="helpers.cs" />
<Compile Include="PlayerSettings.cs" />
@ -160,15 +159,15 @@
<Compile Include="TextAsset.cs" />
<Compile Include="Texture2D.cs" />
<Compile Include="Transform.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="AssetsFile.cs" />
<Compile Include="UnityStudioForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UnityStudioForm.Designer.cs">
<DependentUpon>UnityStudioForm.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="AssetsFile.cs" />
<EmbeddedResource Include="AboutBox.resx">
<DependentUpon>AboutBox.cs</DependentUpon>
<SubType>Designer</SubType>
@ -176,10 +175,6 @@
<EmbeddedResource Include="FBXExport.resx">
<DependentUpon>FBXExport.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UnityStudioForm.resx">
<DependentUpon>UnityStudioForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
@ -190,6 +185,10 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="UnityStudioForm.resx">
<DependentUpon>UnityStudioForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
@ -222,6 +221,7 @@
<ItemGroup>
<Content Include="unity.ico" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -16,7 +16,9 @@ using System.Web.Script.Serialization;
/*TODO
Load parent nodes even if they are not selected to provide transformations?
For extracting bundles, first check if file exists then decompress*/
For extracting bundles, first check if file exists then decompress
Double-check channelgroup argument in new FMOD Studio API system.playSound method
*/
namespace Unity_Studio
{
@ -39,6 +41,7 @@ namespace Unity_Studio
private FMOD.Sound sound = null;
private FMOD.Channel channel = null;
private FMOD.SoundGroup masterSoundGroup = null;
//private FMOD.ChannelGroup channelGroup = null;
private FMOD.MODE loopMode = FMOD.MODE.LOOP_OFF;
private uint FMODlenms = 0;
private float FMODVolume = 0.8f;
@ -46,7 +49,7 @@ namespace Unity_Studio
private Bitmap imageTexture = null;
//asset list sortign helpers
//asset list sorting helpers
private int firstSortColumn = -1;
private int secondSortColumn = 0;
private bool reverseSort = false;
@ -518,33 +521,27 @@ namespace Unity_Studio
{
FMODpanel.Visible = !FMODpanel.Visible;
FMOD.RESULT result;
if (channel != null)
if (sound != null && channel != null)
{
FMOD.RESULT result;
bool playing = false;
result = channel.isPlaying(ref playing);
result = channel.isPlaying(out playing);
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
if (playing)
if (playing) //stop previous sound
{
result = channel.stop();
ERRCHECK(result);
//channel = null;
timer.Stop();
FMODtimerLabel.Text = "0:00.0 / " + (FMODlenms / 1000 / 60) + ":" + (FMODlenms / 1000 % 60) + "." + (FMODlenms / 10 % 100); ;
FMODstatusLabel.Text = "Stopped";
FMODprogressBar.Value = 0;
FMODpauseButton.Text = "Pause";
//FMODinfoLabel.Text = "";
FMODreset();
}
else if (enablePreview.Checked)
{
result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel);
result = system.playSound(sound, null, false, out channel);
ERRCHECK(result);
timer.Start();
@ -733,7 +730,7 @@ namespace Unity_Studio
{
PlayerSettings plSet = new PlayerSettings(asset);
productName = plSet.productName;
base.Text = "Unity Studio - " + productName + " - " + assetsFile.m_Version;
base.Text = "Unity Studio - " + productName + " - " + assetsFile.m_Version + " - " + assetsFile.platformStr; ;
break;
}
@ -1090,18 +1087,7 @@ namespace Unity_Studio
lastLoadedAsset = null;
StatusStripUpdate("");
FMOD.RESULT result;
if (sound != null)
{
result = sound.release();
ERRCHECK(result);
}
sound = null;
timer.Stop();
FMODtimerLabel.Text = "0:00.0 / 0:00.0";
FMODstatusLabel.Text = "Stopped";
FMODprogressBar.Value = 0;
FMODinfoLabel.Text = "";
FMODreset();
lastSelectedItem = (AssetPreloadData)e.Item;
@ -1179,54 +1165,39 @@ namespace Unity_Studio
{
AudioClip m_AudioClip = new AudioClip(asset, true);
if (m_AudioClip.m_Type == 13 && m_AudioClip.m_Type == 14 && m_AudioClip.m_Type == 20)
//MemoryStream memoryStream = new MemoryStream(m_AudioData, true);
//System.Media.SoundPlayer soundPlayer = new System.Media.SoundPlayer(memoryStream);
//soundPlayer.Play();
FMOD.RESULT result;
FMOD.CREATESOUNDEXINFO exinfo = new FMOD.CREATESOUNDEXINFO();
exinfo.cbsize = Marshal.SizeOf(exinfo);
exinfo.length = (uint)m_AudioClip.m_Size;
result = system.createSound(m_AudioClip.m_AudioData, (FMOD.MODE.OPENMEMORY | loopMode), ref exinfo, out sound);
if (ERRCHECK(result)) { break; }
result = sound.getLength(out FMODlenms, FMOD.TIMEUNIT.MS);
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
//MemoryStream memoryStream = new MemoryStream(m_AudioData, true);
//System.Media.SoundPlayer soundPlayer = new System.Media.SoundPlayer(memoryStream);
//soundPlayer.Play();
//uint version = 0;
FMOD.RESULT result;
FMOD.CREATESOUNDEXINFO exinfo = new FMOD.CREATESOUNDEXINFO();
/*result = FMOD.Factory.System_Create(ref system);
ERRCHECK(result);
result = system.getVersion(ref version);
ERRCHECK(result);
if (version < FMOD.VERSION.number)
{
MessageBox.Show("Error! You are using an old version of FMOD " + version.ToString("X") + ". This program requires " + FMOD.VERSION.number.ToString("X") + ".");
Application.Exit();
}
result = system.init(1, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
ERRCHECK(result);*/
exinfo.cbsize = Marshal.SizeOf(exinfo);
exinfo.length = (uint)m_AudioClip.m_Size;
result = system.createSound(m_AudioClip.m_AudioData, (FMOD.MODE.HARDWARE | FMOD.MODE.OPENMEMORY | loopMode), ref exinfo, ref sound);
ERRCHECK(result);
result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel);
ERRCHECK(result);
result = sound.getLength(ref FMODlenms, FMOD.TIMEUNIT.MS);
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
timer.Start();
FMODstatusLabel.Text = "Playing";
FMODpanel.Visible = true;
result = channel.getFrequency(ref FMODfrequency);
ERRCHECK(result);
FMODinfoLabel.Text = FMODfrequency.ToString() + " Hz";
if (ERRCHECK(result)) { break; }
}
else { StatusStripUpdate("Unsuported audio format"); }
result = system.playSound(sound, null, false, out channel);
if (ERRCHECK(result)) { break; }
timer.Start();
FMODstatusLabel.Text = "Playing";
FMODpanel.Visible = true;
//result = channel.getChannelGroup(out channelGroup);
//if (ERRCHECK(result)) { break; }
result = channel.getFrequency(out FMODfrequency);
ERRCHECK(result);
FMODinfoLabel.Text = FMODfrequency.ToString() + " Hz";
break;
}
#endregion
@ -1337,25 +1308,15 @@ namespace Unity_Studio
private void FMODinit()
{
FMODreset();
FMOD.RESULT result;
timer.Stop();
FMODtimerLabel.Text = "0:00.0 / 0:00.0";
FMODstatusLabel.Text = "Stopped";
FMODprogressBar.Value = 0;
if (sound != null)
{
result = sound.release();
ERRCHECK(result);
sound = null;
}
uint version = 0;
result = FMOD.Factory.System_Create(ref system);
ERRCHECK(result);
result = FMOD.Factory.System_Create(out system);
if (ERRCHECK(result)) { return; }
result = system.getVersion(ref version);
result = system.getVersion(out version);
ERRCHECK(result);
if (version < FMOD.VERSION.number)
{
@ -1364,53 +1325,75 @@ namespace Unity_Studio
}
result = system.init(1, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
ERRCHECK(result);
if (ERRCHECK(result)) { return; }
result = system.getMasterSoundGroup(ref masterSoundGroup);
ERRCHECK(result);
//result = system.getMasterChannelGroup(out channelGroup);
//if (ERRCHECK(result)) { return; }
result = system.getMasterSoundGroup(out masterSoundGroup);
if (ERRCHECK(result)) { return; }
result = masterSoundGroup.setVolume(FMODVolume);
ERRCHECK(result);
if (ERRCHECK(result)) { return; }
}
private void FMODreset()
{
FMOD.RESULT result;
timer.Stop();
FMODprogressBar.Value = 0;
FMODtimerLabel.Text = "0:00.0 / 0:00.0";
FMODstatusLabel.Text = "Stopped";
FMODinfoLabel.Text = "";
if (sound != null)
{
result = sound.release();
if (result != FMOD.RESULT.OK) { StatusStripUpdate("FMOD error! " + result + " - " + FMOD.Error.String(result)); }
sound = null;
}
}
private void FMODplayButton_Click(object sender, EventArgs e)
{
FMOD.RESULT result;
if (channel != null)
if (sound != null && channel != null)
{
timer.Start();
bool playing = false;
result = channel.isPlaying(ref playing);
result = channel.isPlaying(out playing);
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
ERRCHECK(result);
if (ERRCHECK(result)) { return; }
}
if (playing)
{
result = channel.stop();
ERRCHECK(result);
if (ERRCHECK(result)) { return; }
result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel);
ERRCHECK(result);
result = system.playSound(sound, null, false, out channel);
if (ERRCHECK(result)) { return; }
FMODpauseButton.Text = "Pause";
}
else
{
result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel);
ERRCHECK(result);
result = system.playSound(sound, null, false, out channel);
if (ERRCHECK(result)) { return; }
FMODstatusLabel.Text = "Playing";
//FMODinfoLabel.Text = FMODfrequency.ToString();
uint newms = 0;
newms = FMODlenms / 1000 * (uint)FMODprogressBar.Value;
result = channel.setPosition(newms, FMOD.TIMEUNIT.MS);
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
if (FMODprogressBar.Value > 0)
{
ERRCHECK(result);
uint newms = FMODlenms / 1000 * (uint)FMODprogressBar.Value;
result = channel.setPosition(newms, FMOD.TIMEUNIT.MS);
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
if (ERRCHECK(result)) { return; }
}
}
}
}
@ -1420,23 +1403,23 @@ namespace Unity_Studio
{
FMOD.RESULT result;
if (channel != null)
if (sound != null && channel != null)
{
bool playing = false;
bool paused = false;
result = channel.isPlaying(ref playing);
result = channel.isPlaying(out playing);
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
ERRCHECK(result);
if (ERRCHECK(result)) { return; }
}
if (playing)
{
result = channel.getPaused(ref paused);
ERRCHECK(result);
result = channel.getPaused(out paused);
if (ERRCHECK(result)) { return; }
result = channel.setPaused(!paused);
ERRCHECK(result);
if (ERRCHECK(result)) { return; }
//FMODstatusLabel.Text = (!paused ? "Paused" : playing ? "Playing" : "Stopped");
//FMODpauseButton.Text = (!paused ? "Resume" : playing ? "Pause" : "Pause");
@ -1463,23 +1446,23 @@ namespace Unity_Studio
if (channel != null)
{
bool playing = false;
result = channel.isPlaying(ref playing);
result = channel.isPlaying(out playing);
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
ERRCHECK(result);
if (ERRCHECK(result)) { return; }
}
if (playing)
{
result = channel.stop();
ERRCHECK(result);
if (ERRCHECK(result)) { return; }
//channel = null;
//don't FMODreset, it will nullify the sound
timer.Stop();
FMODtimerLabel.Text = "0:00.0 / " + (FMODlenms / 1000 / 60) + ":" + (FMODlenms / 1000 % 60) + "." + (FMODlenms / 10 % 100); ;
FMODstatusLabel.Text = "Stopped";
FMODprogressBar.Value = 0;
FMODtimerLabel.Text = "0:00.0 / 0:00.0";
FMODstatusLabel.Text = "Stopped";
FMODpauseButton.Text = "Pause";
//FMODinfoLabel.Text = "";
}
}
}
@ -1500,29 +1483,29 @@ namespace Unity_Studio
if (sound != null)
{
result = sound.setMode(loopMode);
ERRCHECK(result);
if (ERRCHECK(result)) { return; }
}
if (channel != null)
{
bool playing = false;
result = channel.isPlaying(ref playing);
result = channel.isPlaying(out playing);
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
ERRCHECK(result);
if (ERRCHECK(result)) { return; }
}
bool paused = false;
result = channel.getPaused(ref paused);
result = channel.getPaused(out paused);
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
ERRCHECK(result);
if (ERRCHECK(result)) { return; }
}
if (playing || paused)
{
result = channel.setMode(loopMode);
ERRCHECK(result);
if (ERRCHECK(result)) { return; }
}
/*else
{
@ -1541,39 +1524,14 @@ namespace Unity_Studio
FMODVolume = Convert.ToSingle(FMODvolumeBar.Value) / 10;
result = masterSoundGroup.setVolume(FMODVolume);
ERRCHECK(result);
/*if (channel != null)
{
bool playing = false;
result = channel.isPlaying(ref playing);
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
bool paused = false;
result = channel.getPaused(ref paused);
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
if (playing || paused)
{
result = channel.setVolume(FMODVolume);
ERRCHECK(result);
}
}*/
if (ERRCHECK(result)) { return; }
}
private void FMODprogressBar_Scroll(object sender, EventArgs e)
{
uint newms = 0;
if (channel != null)
{
newms = FMODlenms / 1000 * (uint)FMODprogressBar.Value;
uint newms = FMODlenms / 1000 * (uint)FMODprogressBar.Value;
FMODtimerLabel.Text = (newms / 1000 / 60) + ":" + (newms / 1000 % 60) + "." + (newms / 10 % 100) + "/" + (FMODlenms / 1000 / 60) + ":" + (FMODlenms / 1000 % 60) + "." + (FMODlenms / 10 % 100);
}
}
@ -1585,25 +1543,24 @@ namespace Unity_Studio
private void FMODprogressBar_MouseUp(object sender, MouseEventArgs e)
{
FMOD.RESULT result;
uint newms = 0;
if (channel != null)
{
newms = FMODlenms / 1000 * (uint)FMODprogressBar.Value;
FMOD.RESULT result;
uint newms = FMODlenms / 1000 * (uint)FMODprogressBar.Value;
result = channel.setPosition(newms, FMOD.TIMEUNIT.MS);
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
ERRCHECK(result);
if (ERRCHECK(result)) { return; }
}
bool playing = false;
result = channel.isPlaying(ref playing);
result = channel.isPlaying(out playing);
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
ERRCHECK(result);
if (ERRCHECK(result)) { return; }
}
if (playing) { timer.Start(); }
@ -1619,19 +1576,19 @@ namespace Unity_Studio
if (channel != null)
{
result = channel.getPosition(ref ms, FMOD.TIMEUNIT.MS);
result = channel.getPosition(out ms, FMOD.TIMEUNIT.MS);
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = channel.isPlaying(ref playing);
result = channel.isPlaying(out playing);
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = channel.getPaused(ref paused);
result = channel.getPaused(out paused);
if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
{
ERRCHECK(result);
@ -1649,14 +1606,17 @@ namespace Unity_Studio
}
}
private void ERRCHECK(FMOD.RESULT result)
private bool ERRCHECK(FMOD.RESULT result)
{
if (result != FMOD.RESULT.OK)
{
FMODinit();
MessageBox.Show("FMOD error! " + result + " - " + FMOD.Error.String(result));
//FMODinit();
FMODreset();
StatusStripUpdate("FMOD error! " + result + " - " + FMOD.Error.String(result));
//Environment.Exit(-1);
return true;
}
else { return false; }
}
@ -3051,6 +3011,7 @@ namespace Unity_Studio
enablePreview.Checked = (bool)Properties.Settings.Default["enablePreview"];
openAfterExport.Checked = (bool)Properties.Settings.Default["openAfterExport"];
assetGroupOptions.SelectedIndex = (int)Properties.Settings.Default["assetGroupOption"];
FMODinit();
}
private void resetForm()
@ -3089,7 +3050,8 @@ namespace Unity_Studio
reverseSort = false;
enableFiltering = false;
FMODinit();
//FMODinit();
FMODreset();
}