// Use this for initialization void Start () { lowLevelSystem = RuntimeManager.LowlevelSystem; channel = new FMOD.Channel(); lowLevelSystem.getMasterChannelGroup(out channelGroup); soundInfo = new FMOD.CREATESOUNDEXINFO(); soundInfo.cbsize = Marshal.SizeOf(soundInfo); soundInfo.decodebuffersize = (uint)sampleRate / 10; soundInfo.length = (uint)(sampleRate * numberOfChannels * sizeof(short)); soundInfo.numchannels = numberOfChannels; soundInfo.defaultfrequency = sampleRate; soundInfo.format = FMOD.SOUND_FORMAT.PCM16; soundInfo.pcmreadcallback = PCMReadCallback; soundInfo.pcmsetposcallback = PCMSetPositionCallback; lowLevelSystem.setStreamBufferSize(65536, FMOD.TIMEUNIT.RAWBYTES); lowLevelSystem.createStream("SoundGeneratorStream", FMOD.MODE.OPENUSER, ref soundInfo, out generatedSound); generatedSound.setMode(FMOD.MODE.OPENUSER | FMOD.MODE._3D | FMOD.MODE._3D_LINEARSQUAREROLLOFF); lowLevelSystem.playSound(generatedSound, channelGroup, true, out channel); channel.setLoopCount(-1); channel.setMode(FMOD.MODE.LOOP_NORMAL); channel.setPosition(0, FMOD.TIMEUNIT.MS); channel.set3DMinMaxDistance(minDistance, maxDistance); Update(); channel.setPaused(false); }
private IEnumerator WaitForStreamBuffer() { do { yield return(null); } while (state == FMOD.OPENSTATE.CONNECTING || state == FMOD.OPENSTATE.BUFFERING); if (state == FMOD.OPENSTATE.READY) { Debug.Log("Internet stream loaded"); radioStream.setMode(FMOD.MODE.OPENUSER | FMOD.MODE._3D | FMOD.MODE._3D_LINEARROLLOFF); lowLevelSystem.playSound(radioStream, channelGroup, true, out channel); FMOD.ATTRIBUTES_3D attributes = FMODUnity.RuntimeUtils.To3DAttributes(gameObject); FMOD.VECTOR alt_pan_pos = Vector3.zero.ToFMODVector(); channel.set3DMinMaxDistance(minDistance, maxDistance); channel.setLoopCount(-1); channel.setMode(FMOD.MODE.LOOP_NORMAL); channel.set3DAttributes(ref attributes.position, ref attributes.velocity, ref alt_pan_pos); channel.setPaused(false); channel.setVolume(volume); isReadyAndPlaying = true; } else if (state == FMOD.OPENSTATE.ERROR) { Debug.Log("Error while loading online , check the address or connection"); } }
public void PlaySong(String name) { if (!sCurrentTrack.Equals(name)) { Stop(); try { if (dMusicDict[name] != null) { FMOD.RESULT r = FMODSystem.playSound(dMusicDict[name], null, false, out MusicChannel); UpdateVolume(1.0f); MusicChannel.setMode(FMOD.MODE.LOOP_NORMAL); MusicChannel.setLoopCount(-1); sCurrentTrack = name; } else { CConsole.Instance.Print("song " + name + " was null"); } } catch (KeyNotFoundException e) { CConsole.Instance.Print("Track " + name + " wasn't found in dMusicDict, " + e.Message); } } }
public void Play(int songId) { Console.WriteLine("Play(" + songId + ")"); if (_current_song_id != songId) { Stop(); if (songId >= 0 && songId < NUM_SONGS && Songs[songId] != null) { FMODSystem.playSound(Songs[songId], null, false, out Channel); //UpdateVolume(); Channel.setMode(FMOD.MODE.LOOP_NORMAL); Channel.setLoopCount(-1); _current_song_id = songId; } } }
// Use this for initialization void Start() { channel = new FMOD.Channel(); lowLevelSystem = FMODUnity.RuntimeManager.LowlevelSystem; FMODUnity.RuntimeManager.LowlevelSystem.getMasterChannelGroup(out channelGroup); lowLevelSystem.createSound("Assets\\Sounds\\guitar.mp3", FMOD.MODE.DEFAULT, out guitarSong); string songName = ""; guitarSong.getName(out songName, 20); Debug.Log("Playing song: " + songName, gameObject); guitarSong.setMode(FMOD.MODE.OPENUSER | FMOD.MODE._3D | FMOD.MODE._3D_LINEARSQUAREROLLOFF); lowLevelSystem.playSound(guitarSong, channelGroup, true, out channel); channel.set3DMinMaxDistance(minDistance, maxDistance); channel.setLoopCount(-1); channel.setMode(FMOD.MODE.LOOP_NORMAL); FMOD.ATTRIBUTES_3D attributes = FMODUnity.RuntimeUtils.To3DAttributes(gameObject); FMOD.VECTOR alt_pan_pos = Vector3.zero.ToFMODVector(); channel.set3DAttributes(ref attributes.position, ref attributes.velocity, ref alt_pan_pos); channel.setPaused(false); }
// Use this for initialization void Start() { frequency = 800; amplitude = 1.0f; sampleGenerator = GenerateSineSample; sampleGenerator2 = GenerateTriangleSample; //referencja do komponentow FMOD - wysokiego poziomu (studio) i niskiego studioSystem = FMODUnity.RuntimeManager.StudioSystem; lowlevelSystem = FMODUnity.RuntimeManager.LowlevelSystem; //odniesienie do glownego kanalu - do niego bedziemy przesylac nasz dzwiek channel = new Channel(); channel1forInstrument = new Channel(); channel2forInstrument = new Channel(); channel3forSoundFile = new Channel(); FMODUnity.RuntimeManager.LowlevelSystem.getMasterChannelGroup(out channelGroup); FMODUnity.RuntimeManager.LowlevelSystem.getMasterChannelGroup(out channelGroupforInstrument); FMODUnity.RuntimeManager.LowlevelSystem.getMasterChannelGroup(out channelGroupforInstrument2); FMODUnity.RuntimeManager.LowlevelSystem.getMasterChannelGroup(out channelGroupforSoundFile); //inicjalizacja FFT (w FMODzie jako komponent DSP) i linerenderera do wyswietlania equalizera FMODUnity.RuntimeManager.LowlevelSystem.createDSPByType(FMOD.DSP_TYPE.FFT, out fft); fft.setParameterInt((int)FMOD.DSP_FFT.WINDOWTYPE, (int)FMOD.DSP_FFT_WINDOW.HANNING); fft.setParameterInt((int)FMOD.DSP_FFT.WINDOWSIZE, windowSize * 2); lineRendererFFT = gameObject.AddComponent <LineRenderer>(); lineRendererFFT.positionCount = windowSize; lineRendererFFT.startWidth = 0.1f; lineRendererFFT.endWidth = 0.1f; channelGroup.addDSP(FMOD.CHANNELCONTROL_DSP_INDEX.HEAD, fft); //channelGroupforInstrument.addDSP(FMOD.CHANNELCONTROL_DSP_INDEX.HEAD, fft); //channelGroupforInstrument2.addDSP(FMOD.CHANNELCONTROL_DSP_INDEX.HEAD, fft); channelGroupforSoundFile.addDSP(FMOD.CHANNELCONTROL_DSP_INDEX.HEAD, fft); lineRendererSamples = lineRendererHolder.AddComponent <LineRenderer>(); lineRendererSamples.positionCount = sampleRate / 100; lineRendererSamples.startWidth = 0.1f; lineRendererSamples.endWidth = 0.1f; //lowPassFilterGraphMarker = GameObject.CreatePrimitive(PrimitiveType.Cube); //lowPassFilterGraphMarker.transform.position = new Vector3(0, lineRendererSamples.transform.position.y, 0.0f); //lowPassFilterGraphMarker.transform.localScale = new Vector3(0.5f, 5.0f, 0.5f); //lowPassFilterGraphMarker.SetActive(false); //lowPassFilterGraphMarker.GetComponent<Renderer>().material.color = Color.red; //Debug - sprawdzamy czy dobrze udalo nam sie zlapac kanal dzwiekowy (nie mamy jeszcze //obslugi bledow FMOD_OK) uint version; lowlevelSystem.getVersion(out version); bool channelIsPlaying; channel.isPlaying(out channelIsPlaying); UnityEngine.Debug.Log(channelIsPlaying); uint bl; int numbuf; lowlevelSystem.getDSPBufferSize(out bl, out numbuf); UnityEngine.Debug.Log("DSP buffer size is: " + bl + ", " + numbuf); //Wczytujemy i odtwarzamy testowy plik do obiektu 'sound' //Przypisujemy nasz kanal do tej samej grupy co glowny kanal dzwieku FMOD.Sound sound; string nametest = ""; lowlevelSystem.createSound("Assets\\Sounds\\test2.mp3", FMOD.MODE.DEFAULT, out sound); sound.getName(out nametest, 20); UnityEngine.Debug.Log(nametest); InitSampleGeneration(); //debug // (sampleCreated) //{ lowlevelSystem.playSound(generatedSound, channelGroup, true, out channel); channel.setLoopCount(-1); channel.setMode(MODE.LOOP_NORMAL); channel.setPosition(0, TIMEUNIT.MS); channel.setPaused(true); //} //else //{ lowlevelSystem.playSound(sound, channelGroupforSoundFile, true, out channel3forSoundFile); channel3forSoundFile.setLoopCount(-1); channel3forSoundFile.setMode(MODE.LOOP_NORMAL); channel3forSoundFile.setPosition(0, TIMEUNIT.MS); channel3forSoundFile.setPaused(false); //} //lowPassFilterGraphMarker.SetActive(false); InitFilters(); filterApplier.InitFilterApplier(); instrument.InitFilterApplier(); }