void OnDisable() { this.StopFMODSound(); if (this.pcmReadCallbackBuffer != null) { this.pcmReadCallbackBuffer[0].Clear(); this.pcmReadCallbackBuffer[1].Clear(); this.pcmReadCallbackBuffer[0] = null; this.pcmReadCallbackBuffer[1] = null; this.pcmReadCallbackBuffer.Clear(); this.pcmReadCallbackBuffer = null; } this.pcmreadcallback = null; this.pcmsetposcallback = null; if (system != null) { result = system.close(); // ERRCHECK(result, "system.close", false); result = system.release(); // ERRCHECK(result, "system.release", false); } system = null; }
// ======================================================================================================================================== #region Unity lifecycle void Start() { this.gameObjectName = this.gameObject.name; result = FMOD.Factory.System_Create(out system); AudioStreamSupport.ERRCHECK(result, this.logLevel, this.gameObjectName, null, "FMOD.Factory.System_Create"); result = system.getVersion(out version); AudioStreamSupport.ERRCHECK(result, this.logLevel, this.gameObjectName, null, "system.getVersion"); if (version < FMOD.VERSION.number) { var msg = string.Format("FMOD lib version {0} doesn't match header version {1}", version, FMOD.VERSION.number); throw new System.Exception(msg); } int rate; FMOD.SPEAKERMODE sm; int sc; result = system.getSoftwareFormat(out rate, out sm, out sc); AudioStreamSupport.ERRCHECK(result, this.logLevel, this.gameObjectName, null, "system.getSoftwareFormat"); AudioStreamSupport.LOG(LogLevel.INFO, this.logLevel, this.gameObjectName, null, "FMOD samplerate: {0}, speaker mode: {1}, num. of raw speakers {2}", rate, sm, sc); // TODO: evaluate maxchannels result = system.init(32, FMOD.INITFLAGS.NORMAL, extradriverdata); AudioStreamSupport.ERRCHECK(result, this.logLevel, this.gameObjectName, null, "system.init"); this.SetOutput(this.outputDriverID); /* tags ERR_FILE_COULDNOTSEEK: * http://stackoverflow.com/questions/7154223/streaming-mp3-from-internet-with-fmod * http://www.fmod.org/docs/content/generated/FMOD_System_SetFileSystem.html */ // result = system.setFileSystem(null, null, null, null, null, null, -1); // ERRCHECK(result, "system.setFileSystem"); // Explicitly create the delegate object and assign it to a member so it doesn't get freed // by the garbage collected while it's being used this.pcmreadcallback = new FMOD.SOUND_PCMREADCALLBACK(PCMReadCallback); this.pcmsetposcallback = new FMOD.SOUND_PCMSETPOSCALLBACK(PCMSetPosCallback); this.elementSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(System.Int16)); // decodebuffersize samples worth of bytes will be called in read callback // createSound calls back, too this.pcmReadCallbackBuffer = new List <List <byte> >(); this.pcmReadCallbackBuffer.Add(new List <byte>()); this.pcmReadCallbackBuffer.Add(new List <byte>()); }
public SoundProvider(FMOD.System newsys) { newsys.CheckNull("newsys"); system = newsys; SoundDataBuffer = new CircularBuffer(defaultSize); thisLock = new Object(); pcmReadCallback = new FMOD.SOUND_PCMREADCALLBACK(this.PcmReadCallback); pcmSetPosCallback = new FMOD.SOUND_PCMSETPOSCALLBACK(this.PcmSetPosCallback); Sounds = Sound.CreateSound(this.system); Sounds.SoundInit(pcmReadCallback, pcmSetPosCallback); }
public SoundProvider(FMOD.System newsys, string connectionUrl) // reading chunks from stream { newsys.CheckNull("newsys"); system = newsys; SoundDataBuffer = new CircularBuffer(defaultSize); readLock = new Object(); FMOD.RESULT result = system.setStreamBufferSize(64 * 1024, FMOD.TIMEUNIT.RAWBYTES); Sound.ErrorCheck(result); pcmReadCallbackStream = new FMOD.SOUND_PCMREADCALLBACK(this.PcmReadCallbackStream); pcmSetPosCallback = new FMOD.SOUND_PCMSETPOSCALLBACK(this.PcmSetPosCallback); sound = Sound.CreateStream(this.system, connectionUrl, pcmReadCallbackStream, pcmSetPosCallback); }
public void SoundInit(FMOD.SOUND_PCMREADCALLBACK pcmReadCallback, FMOD.SOUND_PCMSETPOSCALLBACK pcmSetPosCallback) // providing data to stream { SoundDataBuffer = new CircularBuffer(defaultSize); thisLock = new Object(); FMOD.CREATESOUNDEXINFO exInfo = new FMOD.CREATESOUNDEXINFO(); exInfo.cbsize = Marshal.SizeOf(exInfo); exInfo.length = (uint)(SoundDataBuffer.Buffer.Length * sizeof(short)); exInfo.numchannels = channelCount; exInfo.fileoffset = 0; exInfo.format = FMOD.SOUND_FORMAT.PCM16; exInfo.defaultfrequency = frequency; exInfo.pcmreadcallback = pcmReadCallback; exInfo.pcmsetposcallback = pcmSetPosCallback; exInfo.dlsname = null; FMOD.RESULT result = system.createSound((string)null, (FMOD.MODE.CREATESTREAM | FMOD.MODE.OPENUSER | FMOD.MODE.OPENRAW | FMOD.MODE._2D | FMOD.MODE.LOOP_NORMAL), ref exInfo, ref sounds); ErrorCheck(result); }
private void StreamInit(string connectionUrl, FMOD.SOUND_PCMREADCALLBACK pcmReadCallback, FMOD.SOUND_PCMSETPOSCALLBACK pcmSetPosCallback) // loading stream data { thisLock = new Object(); SoundDataBuffer = new CircularBuffer(defaultSize); FMOD.CREATESOUNDEXINFO exInfo = new FMOD.CREATESOUNDEXINFO(); exInfo.cbsize = Marshal.SizeOf(exInfo); // exInfo.length = (uint)(SoundDataBuffer.Buffer.Length * sizeof(short)); exInfo.numchannels = channelCount; exInfo.fileoffset = 0; exInfo.format = FMOD.SOUND_FORMAT.PCM16; exInfo.defaultfrequency = frequency; exInfo.pcmreadcallback = pcmReadCallback; exInfo.pcmsetposcallback = pcmSetPosCallback; exInfo.dlsname = null; FMOD.RESULT result = system.createSound(connectionUrl, (FMOD.MODE.HARDWARE | FMOD.MODE._2D | FMOD.MODE.CREATESTREAM | FMOD.MODE.NONBLOCKING), ref exInfo, ref sounds); ErrorCheck(result); }
public static Sound CreateStream(FMOD.System newsys, string connectionUrl, FMOD.SOUND_PCMREADCALLBACK pcmReadCallback, FMOD.SOUND_PCMSETPOSCALLBACK pcmSetPosCallback) { Sound sound = new Sound(newsys); sound.StreamInit(connectionUrl, pcmReadCallback, pcmSetPosCallback); return(sound); }