void OnApplicationQuit() { PlayingMusic.release(); channel.stop(); system.close(); system.release(); channel = null; PlayingMusic = null; system = null; }
protected virtual void Dispose(bool disposing) { if (disposing) { if (m_fadeTimer.Enabled) { m_fadeTimer.Enabled = false; } bool playing = false; if (m_channel != null) { m_channel.isPlaying(ref playing); if (playing) { m_channel.stop(); } m_channel = null; } if (m_sound != null) { m_sound.release(); m_sound = null; } } GC.SuppressFinalize(this); }
public bool LoadTrack(string Path) { if (is_ok) { is_ok = false; if (_channel != null) { _channel.stop(); } if (_sound != null) { _sound.release(); } _fmod.createStream(Path, MODE.LOOP_BIDI | MODE._2D | MODE.ACCURATETIME, out this._sound); _fmod.playSound(_sound, null, false, out _channel); //channel->addDSP(FMOD_CHANNELCONTROL_DSP_TAIL, dsp); _channel.setVolume(this.Volume); this.Name = Path.Split(new char[1] { '\\' }).Reverse().ToArray()[0]; } is_ok = true; return(IsPlaying()); }
private void CleanUpSound(ref FMOD.Sound fmodSound) { this.State = PlayerState.Stop; this.CurrentMediaFile = null; if (this.channelInfo != null && this.channelInfo.Channel != null) { this.channelInfo.File.State = PlayerState.Stop; this.channelInfo.Channel.setCallback(null); this.channelInfo.Channel = null; this.channelInfo.File = null; this.channelInfo = null; } if (fmodSound != null) { var result = fmodSound.release(); result.ERRCHECK(); fmodSound = null; } this.timer.Stop(); this.currentPositionMs = 0; this.OnPropertyChanged("CurrentPositionMs"); this.LengthMs = 0; }
void OnDisable() { //Shut down FMOD.RESULT result; if (sound1 != null) { result = sound1.release(); if (!ERRCHECK(result)) { return; } } if (system != null) { result = system.close(); if (!ERRCHECK(result)) { return; } result = system.release(); if (!ERRCHECK(result)) { return; } Debug.Log("FMOD release! " + result); } }
public virtual void Dispose() { if (!Cloned && sound != null) { sound.release(); sound = null; } disposed = true; }
public void Stop() { if (status != STATUS.STOP) { status = STATUS.STOP; result = channel.stop(); CHECKERR(result, ErrorType.Playback); current.release(); } }
public object[] LoadSoundStats(string fileName) { if (!((fileName != null) && File.Exists(fileName))) { return(null); } Sound sound = null; uint length = 0; this.ERRCHECK(this.m_system.createSound(fileName, MODE.ACCURATETIME | MODE._2D | MODE.HARDWARE | MODE.CREATESTREAM, ref sound)); sound.getLength(ref length, TIMEUNIT.MS); string soundName = this.GetSoundName(sound); sound.release(); return(new object[] { soundName, length }); }
public bool Open(string strFile) { if (channel != null) { channel.stop(); } if (sound != null) { sound.release(); } result = system.createStream(strFile, FMOD.MODE.DEFAULT, out sound); if (result != FMOD.RESULT.OK) { return(false); } return(true); }
public object[] LoadSoundStats(string fileName) { // returns [string name, uint length] if (fileName == null || !File.Exists(fileName)) { return(null); } Sound sound = null; uint length = 0; string name; ERRCHECK(m_system.createSound(fileName, (FMOD.MODE._2D | FMOD.MODE.HARDWARE | FMOD.MODE.CREATESTREAM | MODE.ACCURATETIME), ref sound)); sound.getLength(ref length, TIMEUNIT.MS); name = GetSoundName(sound); sound.release(); return(new object[] { name, length }); }
private void CleanUpSound(ref FMOD.Sound fmodSound) { this.timer.Stop(); this.State = PlayerState.Stop; this.CurrentMediaFile = null; if (this.channelInfo != null) { this.channelInfo.CleanUp(); this.channelInfo = null; this.system.update().ERRCHECK(); } if (fmodSound != null) { fmodSound.release().ERRCHECK(); fmodSound = null; this.system.update().ERRCHECK(); } this.LengthMs = 0; this.CurrentPositionMs = 0; }
static FMOD.RESULT DialogueEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, FMOD.Studio.EventInstance instance, IntPtr parameterPtr) { IntPtr stringPtr; instance.getUserData(out stringPtr); GCHandle stringHandle = GCHandle.FromIntPtr(stringPtr); String key = stringHandle.Target as String; switch (type) { case FMOD.Studio.EVENT_CALLBACK_TYPE.CREATE_PROGRAMMER_SOUND: { FMOD.MODE soundMode = FMOD.MODE.LOOP_NORMAL | FMOD.MODE.CREATECOMPRESSEDSAMPLE | FMOD.MODE.NONBLOCKING; var parameter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)); if (key.Contains(".")) { FMOD.Sound dialogueSound; var soundResult = FMODUnity.RuntimeManager.CoreSystem.createSound(Application.streamingAssetsPath + "/" + key, soundMode, out dialogueSound); if (soundResult == FMOD.RESULT.OK) { parameter.sound = dialogueSound.handle; parameter.subsoundIndex = -1; Marshal.StructureToPtr(parameter, parameterPtr, false); } } else { FMOD.Studio.SOUND_INFO dialogueSoundInfo; var keyResult = FMODUnity.RuntimeManager.StudioSystem.getSoundInfo(key, out dialogueSoundInfo); if (keyResult != FMOD.RESULT.OK) { break; } FMOD.Sound dialogueSound; var soundResult = FMODUnity.RuntimeManager.CoreSystem.createSound(dialogueSoundInfo.name_or_data, soundMode | dialogueSoundInfo.mode, ref dialogueSoundInfo.exinfo, out dialogueSound); if (soundResult == FMOD.RESULT.OK) { parameter.sound = dialogueSound.handle; parameter.subsoundIndex = dialogueSoundInfo.subsoundindex; Marshal.StructureToPtr(parameter, parameterPtr, false); } } } break; case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROY_PROGRAMMER_SOUND: { var parameter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)); var sound = new FMOD.Sound(); sound.handle = parameter.sound; sound.release(); } break; case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROYED: stringHandle.Free(); break; } return(FMOD.RESULT.OK); }
public void Dispose() { _sound.release(); }
//public bool IsValid() //{ // return FmodSound.isValid(); //} public void Dispose() { FmodSound.release().Check(); }
static FMOD.RESULT DumpSoundBank(FMOD.System FModSystem, string FSBFileStr) { bool Flag = false; FMOD.RESULT FModResult; // Set our variable we will keep updating with the FMOD Results Console.WriteLine("File: " + FSBFileStr); FMOD.Sound FModSound = new Sound(); // Initialize a new FMod Sound object with some standard mode flags FModResult = FModSystem.createSound(FSBFileStr, FMOD.MODE.SOFTWARE | FMOD.MODE.CREATESTREAM | FMOD.MODE.ACCURATETIME, ref FModSound); if (FModResult != FMOD.RESULT.OK) { // Again, if something went wrong, print the error. Console.WriteLine("ERR CreateSound: " + FMOD.Error.String(FModResult)); } else { // Otherwise, get the number of sub-sounds within the FSB. int NumSubSounds = 0; FModResult = FModSound.getNumSubSounds(ref NumSubSounds); if (FModResult != FMOD.RESULT.OK) { Console.WriteLine("ERR GetNumSounds: " + FMOD.Error.String(FModResult)); } else { Console.WriteLine(" Sounds: " + NumSubSounds); for (int i = 0; i < NumSubSounds; i++) { // For each sub-sound in the Sound Bank, create a new one and initialize it like we did above FMOD.Sound SubSound = new Sound(); FModResult = FModSystem.createSound(FSBFileStr, FMOD.MODE.SOFTWARE | FMOD.MODE.CREATESTREAM | FMOD.MODE.ACCURATETIME, ref SubSound); if (FModSound.getSubSound(i, ref SubSound) == FMOD.RESULT.OK) { // Get the next sub-sound StringBuilder SubSoundName = new StringBuilder(256); if ((SubSound.getName(SubSoundName, 256) == FMOD.RESULT.OK) && (SubSoundName[0] != 0)) { // Get the sub-sound name and put it in a StringBuilder SubSound.seekData(0); // Seek to the beginning of the sound data string DirName = Path.GetFileName(FSBFileStr).Replace(".fsb", ""); // Set the subdirectory name to the name of the FSB without the extension. if ((!Directory.Exists(TargetDir + @"\" + DirName)) && ExtractFSB) { // Create the subdirectory if it doesn't exist. Console.WriteLine(" Creating Subdirectory: " + DirName); Directory.CreateDirectory(TargetDir + @"\" + DirName); } Console.WriteLine(" " + String.Format("{0:D" + NumSubSounds.ToString().Length + "}", (i + 1)) + "/" + NumSubSounds + ": " + SubSoundName.ToString()); // Print status //if (ExtractFSB && SubSoundName.ToString().ToLower().Contains("female1")) { if (ExtractFSB) { Flag = true; // Piece together a new filename in the format of "TargetDir\FSBName\#_SoundName.wav" and open the file. FileStream SubSoundStream = new FileStream(TargetDir + @"\" + DirName + @"\" + String.Format("{0:D" + NumSubSounds.ToString().Length + "}", (i + 1)) + "_" + SubSoundName.ToString() + ".wav", FileMode.Create, FileAccess.Write); uint Length = WriteHeader(SubSoundStream, SubSound, FSBFileStr); // Manually create the wave header and write it to the file do { byte[] SoundData = new byte[65536]; // Create a max-length buffer for the audio data uint LenToRead; // Specify the length is at most 65,536, or to the end of the data if (Length > SoundData.Length) { LenToRead = 65536; } else { LenToRead = Length; } uint LenRead = LenToRead; IntPtr BufferPtr = Marshal.AllocHGlobal((int)LenToRead); // Allocate the buffer and get its pointer // Read the "LenToRead" bytes into the buffer and update LenRead with the number of bytes read FModResult = SubSound.readData(BufferPtr, LenToRead, ref LenRead); Marshal.Copy(BufferPtr, SoundData, 0, (int)LenRead); // Copy the data out of unmanaged memory into the SoundData byte[] array SubSoundStream.Write(SoundData, 0, (int)LenRead); // Write the sound data to the file Marshal.FreeHGlobal(BufferPtr); Length -= LenRead; // Subtract what we read from the remaining length of data. } while ((Length > 0) && (FModResult == FMOD.RESULT.OK)); // As long as we have no errors and still more data to read long FileSize = SubSoundStream.Position; SubSoundStream.Seek(4, SeekOrigin.Begin); SubSoundStream.Write(BitConverter.GetBytes((long)(FileSize - 8)), 0, 4); SubSoundStream.Close(); } else if (Flag) { Console.ReadLine(); } } } } } FModSound.release(); } return FModResult; }