private void button1_Click(object sender, System.EventArgs e) { FMOD.RESULT result; result = system.playSound(FMOD.CHANNELINDEX.FREE, sound1, false, ref channel); ERRCHECK(result); }
private void btnTestDict_Click(object sender, EventArgs e) { FMOD.RESULT result; result = system.playSound(FMOD.CHANNELINDEX.FREE, sounds[0], false, ref channel); ERRCHECK(result); }
public void Play(string name, byte[] soundBuf) { FMOD.CREATESOUNDEXINFO sndInfo = new FMOD.CREATESOUNDEXINFO() { length = (uint)soundBuf.Length, }; FMOD.RESULT result = system.createSound(soundBuf, FMOD.MODE.OPENMEMORY, ref sndInfo, out sound); ERRCHECK(result, "system.createSound"); if (result == FMOD.RESULT.OK) { int numSubSounds; result = sound.getNumSubSounds(out numSubSounds); ERRCHECK(result, "sound.getNumSubSounds"); if (numSubSounds > 0) { result = sound.getSubSound(0, out subSound); ERRCHECK(result, "sound.getSubSound"); result = system.playSound(subSound, null, false, out channel); } else { result = system.playSound(sound, null, false, out channel); } ERRCHECK(result, "sound.playSound"); } }
private void play_Click(object sender, System.EventArgs e) { FMOD.RESULT result; result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel); ERRCHECK(result); play.Enabled = false; }
private void frontLeft_Click(object sender, System.EventArgs e) { FMOD.RESULT result; result = system.playSound(FMOD.CHANNELINDEX.FREE, sound1, true, ref channel); ERRCHECK(result); result = channel.setSpeakerMix(1.0f, 0, 0, 0, 0, 0, 0, 0); ERRCHECK(result); result = channel.setPaused(false); ERRCHECK(result); }
public void PlaySound(int soundId) { if (soundId >= 0 && soundId < NUM_SFX && SoundFX[soundId] != null) { FMOD.RESULT r = FMODSystem.playSound(SoundFX[soundId], null, false, out SoundChannel); //UpdateVolume(1.0f); SoundChannel.setMode(FMOD.MODE.LOOP_OFF); SoundChannel.setLoopCount(-1); Console.WriteLine("Playing sound " + soundId + ", got result " + r); m_iCurrentSongID = soundId; } }
public SoundSource(FMOD.System system, FMOD.Sound sound, int posx, int posy) { FMOD.RESULT result; mPos.x = posx; mPos.y = posy; mPos.z = 0; mVel.x = 0; mVel.y = 0; mVel.z = 0; mSystem = system; result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, true, ref mChannel); VirtualVoices.ERRCHECK(result); SetPosition(mPos.x, mPos.y); Random r = new Random(posx); result = mChannel.setFrequency(r.Next(22050, 44100)); VirtualVoices.ERRCHECK(result); result = mChannel.setPaused(false); VirtualVoices.ERRCHECK(result); mBrushBlue = new SolidBrush(Color.Blue); mBrushRed = new SolidBrush(Color.Red); }
// ======================================================================================================================================== #region Start / Stop void StartFMODSound(int sampleRate) { this.StopFMODSound(); FMOD.CREATESOUNDEXINFO exinfo = new FMOD.CREATESOUNDEXINFO(); // exinfo.cbsize = sizeof(FMOD.CREATESOUNDEXINFO); exinfo.numchannels = this.unityOAFRChannels; /* Number of channels in the sound. */ exinfo.defaultfrequency = sampleRate; /* Default playback rate of sound. */ exinfo.decodebuffersize = (uint)this.unityOAFRDataLength; /* Chunk size of stream update in samples. This will be the amount of data passed to the user callback. */ exinfo.length = (uint)(exinfo.defaultfrequency * exinfo.numchannels * this.elementSize); /* Length of PCM data in bytes of whole song (for Sound::getLength) */ exinfo.format = FMOD.SOUND_FORMAT.PCM16; /* Data format of sound. */ exinfo.pcmreadcallback = this.pcmreadcallback; /* User callback for reading. */ exinfo.pcmsetposcallback = this.pcmsetposcallback; /* User callback for seeking. */ result = system.createSound("" , FMOD.MODE.OPENUSER | FMOD.MODE.CREATESTREAM | FMOD.MODE.LOOP_NORMAL , ref exinfo , out sound); AudioStreamSupport.ERRCHECK(result, this.logLevel, this.gameObjectName, null, "system.createSound"); AudioStreamSupport.LOG(LogLevel.DEBUG, this.logLevel, this.gameObjectName, null, "About to play..."); result = system.playSound(sound, null, false, out channel); AudioStreamSupport.ERRCHECK(result, this.logLevel, this.gameObjectName, null, "system.playSound"); }
/// <summary> /// Play a new BGM in the BGM channel. /// </summary> /// <param name="file">The file containing the BGM</param> public void PlayBGM(string file) { //If file doesn exist if (!FlatRedBall.IO.FileManager.FileExists(Global.BGM_FOLDER + file)) { //Log it then get out Global.Logger.AddLine(Global.NOFILE_ERROR + file); return; } //Stop bgm if it exist if (m_BGMChannel != null) { CheckError(m_BGMChannel.stop()); } //Create and play bgm #region BGM Playing CheckError(m_System.createSound(Global.BGM_FOLDER + file, MODE.LOOP_NORMAL | MODE._2D | MODE.HARDWARE, ref m_BGM)); CheckError(m_System.playSound(CHANNELINDEX.REUSE, m_BGM, true, ref m_BGMChannel)); CheckError(m_BGMChannel.setPaused(false)); #endregion //Logging info Global.Logger.AddLine("BGM file " + file + " is loaded and played."); }
private MusicPlayer() { result = FMOD.Factory.System_Create(out FMODSystem); if (result != FMOD.RESULT.OK) { throw new Exception("This crap didn't work!!"); } result = FMODSystem.setDSPBufferSize(1024, 10); result = FMODSystem.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)0); var info = new FMOD.CREATESOUNDEXINFO(); var song = new FMOD.Sound(); ChannelGroup = new FMOD.ChannelGroup(); ChannelGroup.clearHandle(); result = FMODSystem.createStream("rain.ogg", FMOD.MODE.DEFAULT, out song); result = FMODSystem.playSound(song, ChannelGroup, false, out Channel); bool isPlaying = false; Channel.isPlaying(out isPlaying); Channel.setVolume(1); Channel.setMode(FMOD.MODE.LOOP_NORMAL); Channel.setLoopCount(-1); int t = 1; }
private void playButton_Click(object sender, System.EventArgs e) { FMOD.RESULT result; bool isplaying = false; if (channel != null) { channel.isPlaying(ref isplaying); } if (sound != null && !isplaying) { result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel); ERRCHECK(result); playButton.Text = "Stop"; } else { if (channel != null) { channel.stop(); channel = null; } playButton.Text = "Play"; } }
private void button1_Click(object sender, System.EventArgs e) { FMOD.RESULT result; if (!soundcreated) { result = system.createSound( (string)null, (mode | FMOD.MODE.CREATESTREAM), ref createsoundexinfo, ref sound); ERRCHECK(result); soundcreated = true; } system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel); }
private bool PlaySound(FMOD.Sound sound) { try { FMOD.Channel channel = null; FMOD.RESULT result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, true, ref channel); if (result == FMOD.RESULT.OK && channel != null) { channel.setVolume(volume); channel.setPaused(false); } return(FMOD.ERROR.ERRCHECK(result)); } catch { return(false); } }
private void timer_Tick(object sender, System.EventArgs e) { FMOD.RESULT result; FMOD.OPENSTATE openstate = 0; uint percentbuffered = 0; bool starving = false; bool busy = false; if (soundcreated) { result = sound.getOpenState(ref openstate, ref percentbuffered, ref starving, ref busy); ERRCHECK(result); if (openstate == FMOD.OPENSTATE.READY && channel == null) { result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel); ERRCHECK(result); } } if (channel != null) { uint ms = 0; bool playing = false; bool paused = false; for (;;) { FMOD.TAG tag = new FMOD.TAG(); if (sound.getTag(null, -1, ref tag) != FMOD.RESULT.OK) { break; } if (tag.datatype == FMOD.TAGDATATYPE.STRING) { textBox.Text = tag.name + " = " + Marshal.PtrToStringAnsi(tag.data) + " (" + tag.datalen + " bytes)"; } else { break; } } result = channel.getPaused(ref paused); ERRCHECK(result); result = channel.isPlaying(ref playing); ERRCHECK(result); result = channel.getPosition(ref ms, FMOD.TIMEUNIT.MS); ERRCHECK(result); statusBar.Text = "Time " + (ms / 1000 / 60) + ":" + (ms / 1000 % 60) + ":" + (ms / 10 % 100) + (openstate == FMOD.OPENSTATE.BUFFERING ? " Buffering..." : (openstate == FMOD.OPENSTATE.CONNECTING ? " Connecting..." : (paused ? " Paused " : (playing ? " Playing " : " Stopped ")))) + "(" + percentbuffered + "%)" + (starving ? " STARVING" : " "); } if (system != null) { system.update(); } }
public void PlayBGM(string path = null) { string play; if (path == null) { path = BGMPlaylist[BGMId]; } play = "Media/Music/" + path; Result = System.createStream(play, FMOD.MODE.DEFAULT, ref SoundBGM); Result = System.playSound(0, SoundBGM, false, ref ChannelBGM); IsBGMPlaying = true; Volume = _volume; }
private void PlayPause_Click(object sender, EventArgs e) { fsb.getSubSound(0, ref subsound); FMOD.RESULT res = system.playSound(FMOD.CHANNELINDEX.FREE, subsound, false, ref channel); if (res != FMOD.RESULT.OK) { MessageBox.Show("Cannot Play file. Reason: " + res.ToString(), "FMOD Load Error", MessageBoxButtons.OK); } }
public static void LoadSong(int id, bool loop) { PlayingSongID = id; if (CurrentSong != null) { CurrentSong.release(); } FMOD.MODE mode = (loop) ? FMOD.MODE.LOOP_NORMAL : FMOD.MODE.DEFAULT; system.createStream(PlayList[id], mode, out CurrentSong); system.playSound(CurrentSong, ChannelGroup, false, out Channel); }
/// <summary> /// Play a loaded sound on a specified channel. /// </summary> /// <param name="p_sound">A loaded sound.</param> /// <param name="p_channelGroup">The channel group to play on.</param> /// <param name="o_channel">The channel created.</param> /// <returns></returns> public bool PlaySound(FMOD.Sound p_sound, FMOD.ChannelGroup p_channelGroup, out FMOD.Channel o_channel) { FMOD.RESULT r = m_fmodSystem.playSound( p_sound, p_channelGroup, false, out o_channel ); return(r == FMOD.RESULT.OK); }
public SoundSource(FMOD.System fmod, FMOD.Sound sound, string name, bool ambient) : base(name, ambient) { FMOD.RESULT result; result = fmod.playSound(FMOD.CHANNELINDEX.FREE, sound, true, ref channel); SoundManager.CheckResults(result); result = channel.setVolume(0); SoundManager.CheckResults(result); }
public About() { img = Properties.Resources.nfo; img.MakeTransparent(Color.Black); InitializeComponent(); exInfo.cbsize = Marshal.SizeOf(exInfo); exInfo.length = (uint)Properties.Resources.teh.Length; SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.Opaque, true); SetStyle(ControlStyles.OptimizedDoubleBuffer, true); int step = 5; Color color = Color.FromArgb(255, 0, 0); customSpectrum.AddRange(Ext.Interpolate(ColorEnum.Green, ChangeEnum.Higher, color, step)); color = Color.FromArgb(255, 255, 0); customSpectrum.AddRange(Ext.Interpolate(ColorEnum.Red, ChangeEnum.Lower, color, step)); color = Color.FromArgb(0, 255, 0); customSpectrum.AddRange(Ext.Interpolate(ColorEnum.Blue, ChangeEnum.Higher, color, step)); color = Color.FromArgb(0, 255, 255); customSpectrum.AddRange(Ext.Interpolate(ColorEnum.Green, ChangeEnum.Lower, color, step)); color = Color.FromArgb(0, 0, 255); customSpectrum.AddRange(Ext.Interpolate(ColorEnum.Red, ChangeEnum.Higher, color, step)); color = Color.FromArgb(255, 0, 255); customSpectrum.AddRange(Ext.Interpolate(ColorEnum.Blue, ChangeEnum.Lower, color, step)); DoubleBuffered = true; this.Width = img.Width; y = -this.Height; FMOD.Factory.System_Create(ref soundSystem); soundSystem.init(32, FMOD.INITFLAG.NORMAL | FMOD.INITFLAG.WASAPI_EXCLUSIVE, IntPtr.Zero); soundSystem.createSound(Properties.Resources.teh, FMOD.MODE.SOFTWARE | FMOD.MODE._2D | FMOD.MODE.OPENMEMORY | FMOD.MODE.ACCURATETIME | FMOD.MODE.LOOP_NORMAL, ref exInfo, ref sound); soundSystem.playSound(FMOD.CHANNELINDEX.REUSE, sound, false, ref soundChannel); soundChannel.setVolume(.75f); tmr.Interval = 25; tmr.Tick += new EventHandler(tmr_Tick); tmr.Start(); }
public static void StartMusic(int n) { if (SoundChannel != null) { SoundChannel.stop(); } SoundSystem.playSound(FMOD.CHANNELINDEX.FREE, tunes[n], false, ref SoundChannel); SoundChannel.setVolume(0.5f); tuneIndex = n; }
private void Form1_Load(object sender, System.EventArgs e) { uint version = 0; FMOD.RESULT result; /* * Create a System object and initialize. */ 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(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null); ERRCHECK(result); result = system.createSound("../../../../../examples/media/drumloop.wav", FMOD.MODE.SOFTWARE | FMOD.MODE.LOOP_NORMAL, ref sound); ERRCHECK(result); result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel); ERRCHECK(result); /* * Create DSP unit */ cohar[] nameArray = new char[32]; dspname.ToCharArray().CopyTo(nameArray, 0); dspdesc.name = nameArray; dspdesc.channels = 0; dspdesc.read = dspreadcallback; result = system.createDSP(ref dspdesc, ref mydsp); ERRCHECK(result); result = system.addDSP(mydsp, ref dspconnectiontemp); ERRCHECK(result); result = mydsp.setActive(true); ERRCHECK(result); result = mydsp.setBypass(true); ERRCHECK(result); }
public void PlaySound() { bool state = true; while (state) { FMOD.OPENSTATE openstate = 0; uint percentbuffered = 0; bool starving = false; bool busy = false; FMOD.RESULT result = sounds.getOpenState(ref openstate, ref percentbuffered, ref starving, ref busy); ErrorCheck(result); if (openstate == FMOD.OPENSTATE.READY && channels == null) { result = system.playSound(FMOD.CHANNELINDEX.FREE, sounds, false, ref channels); ErrorCheck(result); channels.setVolume(0.0f); state = false; } } }
public FMOD.Channel PlaySound(FMOD.Sound sound, FMOD.ChannelGroup group, bool paused = false) { FMOD.Channel channel; FMOD.RESULT res = soundSystem.playSound(sound, group, paused, out channel); if (res == FMOD.RESULT.OK) { return(channel); } else { throw new Exceptions.LoadFailException(FMOD.Error.String(res)); } }
/// <summary> /// Takes a media info object and plays it on an open channel /// </summary> /// <param name="media"></param> /// <returns></returns> private void PlayStream() { //result FMOD.RESULT result; //play the sound on the channel result = _system.playSound(_sound, null, true, out _channel); CheckError(result); //prepare the equalizer SetupEqualizer(); //create the dsp, although it will not be active at this time result = _system.createDSP(ref _dspDesc, out _dsp); ////deactivate //_dsp.setBypass(true); //add to dsp chain _channel.addDSP(0, _dsp); //unpause when ready to begin playing result = _channel.setPaused(false); CheckError(result); ////activate //_dsp.setBypass(false); //fire PlaybackStatusChanged event OnPlaybackStatusChanged(); //hold the thread hostage while (GetIsPlaying()) { //check to see if playback should stop if (_playbackCts.IsCancellationRequested) { //we requested to stop playback break; } //get the current position InternalPosition = GetPosition(); //update fmod Update(); //sleep for a few miliseconds Thread.Sleep(25); } }
private void comboBoxRecord_SelectedIndexChanged(object sender, System.EventArgs e) { FMOD.CREATESOUNDEXINFO exinfo = new FMOD.CREATESOUNDEXINFO(); FMOD.RESULT result; FMOD.DSP_RESAMPLER resampler = FMOD.DSP_RESAMPLER.MAX; int selected = comboBoxRecord.SelectedIndex; int temp = 0; FMOD.SOUND_FORMAT format = FMOD.SOUND_FORMAT.NONE; result = system.setSoftwareFormat(OUTPUTRATE, FMOD.SOUND_FORMAT.PCM16, 1, 0, 0); ERRCHECK(result); result = system.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null); ERRCHECK(result); result = system.getSoftwareFormat(ref outputfreq, ref format, ref temp, ref temp, ref resampler, ref temp); ERRCHECK(result); /* * Create a sound to record to. */ exinfo.cbsize = Marshal.SizeOf(exinfo); exinfo.numchannels = 1; exinfo.format = FMOD.SOUND_FORMAT.PCM16; exinfo.defaultfrequency = OUTPUTRATE; exinfo.length = (uint)(exinfo.defaultfrequency * 2 * exinfo.numchannels * 5); result = system.createSound((string)null, (FMOD.MODE._2D | FMOD.MODE.SOFTWARE | FMOD.MODE.LOOP_NORMAL | FMOD.MODE.OPENUSER), ref exinfo, ref sound); ERRCHECK(result); comboBoxOutput.Enabled = false; comboBoxPlayback.Enabled = false; comboBoxRecord.Enabled = false; /* * Start recording */ result = system.recordStart(selected, sound, true); ERRCHECK(result); Thread.Sleep(200); /* Give it some time to record something */ result = system.playSound(FMOD.CHANNELINDEX.REUSE, sound, false, ref channel); ERRCHECK(result); /* Dont hear what is being recorded otherwise it will feedback. Spectrum analysis is done before volume scaling in the DSP chain */ result = channel.setVolume(0); ERRCHECK(result); }
private void effects_Load(object sender, System.EventArgs e) { uint version = 0; FMOD.RESULT result; /* * Create a System object and initialize. */ 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(32, FMOD.INITFLAGS.NORMAL, (IntPtr)null); ERRCHECK(result); result = system.createSound("../../../../../examples/media/drumloop.wav", FMOD.MODE.SOFTWARE, ref sound); ERRCHECK(result); result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel); ERRCHECK(result); /* * Create some effects to play with. */ result = system.createDSPByType(FMOD.DSP_TYPE.LOWPASS, ref dsplowpass); ERRCHECK(result); result = system.createDSPByType(FMOD.DSP_TYPE.HIGHPASS, ref dsphighpass); ERRCHECK(result); result = system.createDSPByType(FMOD.DSP_TYPE.ECHO, ref dspecho); ERRCHECK(result); result = system.createDSPByType(FMOD.DSP_TYPE.FLANGE, ref dspflange); ERRCHECK(result); result = system.createDSPByType(FMOD.DSP_TYPE.DISTORTION, ref dspdistortion); ERRCHECK(result); result = system.createDSPByType(FMOD.DSP_TYPE.CHORUS, ref dspchorus); ERRCHECK(result); result = system.createDSPByType(FMOD.DSP_TYPE.PARAMEQ, ref dspparameq); ERRCHECK(result); }
private void playButton_Click(object sender, System.EventArgs e) { FMOD.RESULT result; if (looping) { result = sound.setMode(FMOD.MODE.LOOP_NORMAL); } else { result = sound.setMode(FMOD.MODE.LOOP_OFF); } ERRCHECK(result); result = system.playSound(FMOD.CHANNELINDEX.REUSE, sound, false, ref channel); ERRCHECK(result); }
private bool PlayMusicCallback(FMOD.Sound sound) { FMOD.RESULT result; lock (syncMusicCallback) { bool isPlaying = false; manualMusicEnd = false; if (channel != null) { channel.isPlaying(ref isPlaying); } else { isPlaying = false; } if (isPlaying && channel != null) { manualMusicEnd = true; InfoLog.WriteInfo(DateTime.Now.ToString() + " | Music is playing, Manual music end: " + manualMusicEnd, EPrefix.AudioEngine); channel.setMute(true); channel.stop(); channel = null; } else { InfoLog.WriteInfo(DateTime.Now.ToString() + " | Music is not playing, Manual music end: " + manualMusicEnd, EPrefix.AudioEngine); } result = system.playSound(FMOD.CHANNELINDEX.REUSE, sound, true, ref channel); if (result == FMOD.RESULT.OK && channel != null) { channel.setVolume(volume); channel.setCallback(FMOD.CHANNEL_CALLBACKTYPE.END, endPlayCallback, 0); InfoLog.WriteInfo(DateTime.Now.ToString() + " | Before Play music begin", EPrefix.AudioEngine); channel.setPaused(false); } } InfoLog.WriteInfo(DateTime.Now.ToString() + " | After Play music begin, result: " + result, EPrefix.AudioEngine); return(FMOD.ERROR.ERRCHECK(result)); }
public void PlayInnerSound(SoundType type) { FMOD.RESULT result; FMOD.Sound sound = GetSound(type); if (sound != null) { result = soundsystem.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel); ERRCHECK(result); if (type == SoundType.ST_level1 || type == SoundType.ST_level2) { channel.setVolume(1f); } else { channel.setVolume(0.15f); } } }