//This function is used to add a delay in the detection to playback ratio. //For example, if an obstacle is spawned to the music, it will be spawned immediately //upon the song detecting a beat, when oftentimes we want to line up that obstacle //with the point in the music it plays. So, the obstacle will spawn before the song gets //to the beat detected point. //Use milliseconds to express the amount of delay time you want between playback and detection. public void loadSongToDelay(int milliseconds) { delayedSong = true; songChannel1.setVolume(0); audio2 = new FMOD.Sound(); FMODErrorCheck(system.createStream(songString, FMOD.MODE.SOFTWARE, ref audio2)); songChannel2 = new FMOD.Channel(); FMODErrorCheck(system.playSound(FMOD.CHANNELINDEX.FREE, audio2, true, ref songChannel2)); songChannel2.setChannelGroup(channelMusic); timeToDelay = milliseconds; }
public void Play(float Volume = 1f) { if (!SoundSystem.AudioFound) { return; } RESULT result = _system.System.playSound(CHANNELINDEX.FREE, _sound, false, ref ActiveChannel); if (result != RESULT.OK) { throw new Exception("Play Sound Failed\r\n" + result.ToString()); } ActiveChannel.setVolume(Volume); ActiveChannel.setChannelGroup(_system.ChannelGroupSFX); }
//Loads a song into memory given a sample size and file-path to an audio file. //The most commonly used and accurate Sample Size is 1024. public void LoadSong(int sSize, string audioString) { //Take in Aruguments sampleSize = sSize; songString = audioString; stopW.Start(); areWePlaying = true; specFlux = 0.0f; timeBetween = 0; initialTime = (int)stopW.ElapsedMilliseconds; currentTime = 0; currentSeconds = 0; lastSeconds = 0; currentMillis = 0; currentMinutes = 0; median = 0.0f; smoothMedian = 0.0f; beatThreshold = 0.6f; thresholdSmoother = 0.6f; started = false; lastBeatRegistered = new TimeStamp(); audio = new FMOD.Sound(); songChannel1 = new FMOD.Channel(); channelMusic = new FMOD.ChannelGroup(); previousFFT = new float[sampleSize / 2 + 1]; for (int i = 0; i < sampleSize / 2; i++) { previousFFT[i] = 0; } //Brute force for testing //songString = "Music/drums.wav"; //Create channel and audio FMODErrorCheck(system.createChannelGroup(null, ref channelMusic)); // CREATESOUNDEXINFO ex = new CREATESOUNDEXINFO(); FMODErrorCheck(system.createStream(songString, FMOD.MODE.SOFTWARE, ref audio)); audio.getLength(ref seconds, FMOD.TIMEUNIT.MS); audio.getDefaults(ref sampleRate, ref zeroF, ref zeroF, ref zero); seconds = ((seconds + 500) / 1000); minutes = seconds / 60; fullSeconds = (int)seconds; seconds = seconds - (minutes * 60); FMODErrorCheck(system.playSound(FMOD.CHANNELINDEX.FREE, audio, true, ref songChannel1)); //hzRange = (sampleRate / 2) / static_cast<float>(sampleSize); songChannel1.setChannelGroup(channelMusic); songChannel1.setPaused(true); Console.WriteLine("Song Length: " + minutes + ":" + seconds); Console.WriteLine("Sample Rate: " + sampleRate); //std::cout << "Freq Range: " << hzRange << std::endl; //songChannel1.setVolume(0); }
//Loads a song into memory given a sample size and file-path to an audio file. //The most commonly used and accurate Sample Size is 1024. public void LoadSong(int sSize, string audioString) { //Take in Aruguments sampleSize = sSize; songString = audioString; stopW.Start(); areWePlaying = true; specFlux = 0.0f; timeBetween = 0; initialTime = (int)stopW.ElapsedMilliseconds; currentTime = 0; currentSeconds = 0; lastSeconds = 0; currentMillis = 0; currentMinutes = 0; median = 0.0f; smoothMedian = 0.0f; beatThreshold = 0.6f; thresholdSmoother = 0.6f; started = false; lastBeatRegistered = new TimeStamp(); audio = new FMOD.Sound(); songChannel1 = new FMOD.Channel(); beatWait = false; channelMusic = new FMOD.ChannelGroup(); previousFFT = new float[sampleSize / 2 + 1]; for (int i = 0; i < sampleSize / 2; i++) { previousFFT[i] = 0; } //Brute force for testing //songString = "Music/drums.wav"; //Create channel and audio FMODErrorCheck(system.createChannelGroup(null, ref channelMusic)); // CREATESOUNDEXINFO ex = new CREATESOUNDEXINFO(); FMODErrorCheck(system.createStream(songString, FMOD.MODE.SOFTWARE, ref audio)); audio.getLength(ref seconds, FMOD.TIMEUNIT.MS); audio.getDefaults(ref sampleRate, ref zeroF, ref zeroF, ref zero); seconds = ((seconds + 500) / 1000); minutes = seconds / 60; fullSeconds = (int)seconds; seconds = seconds - (minutes * 60); FMODErrorCheck(system.playSound(FMOD.CHANNELINDEX.FREE, audio, true, ref songChannel1)); //hzRange = (sampleRate / 2) / static_cast<float>(sampleSize); songChannel1.setChannelGroup(channelMusic); songChannel1.setPaused(true); Console.WriteLine("Song Length: " + minutes + ":" + seconds); Console.WriteLine("Sample Rate: " + sampleRate); //std::cout << "Freq Range: " << hzRange << std::endl; //songChannel1.setVolume(0); }