/// <summary> /// Initializes a new instance of the <see cref="FMODSong"/> class. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="file">The path to the file from which to stream the song.</param> public FMODSong(UltravioletContext uv, String file) : base(uv) { Contract.RequireNotEmpty(file, nameof(file)); var result = default(FMOD_RESULT); var system = ((FMODUltravioletAudio)uv.GetAudio()).System; // Load song as a sound fixed(FMOD_SOUND **psound = &sound) { var exinfo = new FMOD_CREATESOUNDEXINFO(); exinfo.cbsize = Marshal.SizeOf(exinfo); result = FMOD_System_CreateStream(system, file, FMOD_LOOP_NORMAL | FMOD_2D | FMOD_3D_WORLDRELATIVE | FMOD_3D_INVERSEROLLOFF, &exinfo, psound); if (result != FMOD_OK) { throw new FMODException(result); } } this.duration = GetDuration(sound); this.tags = GetTags(sound, out name, out artist, out album); }
/// <summary> /// Initializes a new instance of the <see cref="FMODSoundEffect"/> class. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="file">The path to the file from which to load the sound effect.</param> public FMODSoundEffect(UltravioletContext uv, String file) : base(uv) { Contract.RequireNotEmpty(file, nameof(file)); var result = default(FMOD_RESULT); var system = ((FMODUltravioletAudio)uv.GetAudio()).System; fixed(FMOD_SOUND **psound = &sound) { var exinfo = new FMOD_CREATESOUNDEXINFO(); exinfo.cbsize = Marshal.SizeOf(exinfo); result = FMOD_System_CreateStream(system, file, FMOD_DEFAULT, &exinfo, psound); if (result != FMOD_OK) { throw new FMODException(result); } } var durationInMilliseconds = 0u; result = FMOD_Sound_GetLength(sound, &durationInMilliseconds, FMOD_TIMEUNIT.FMOD_TIMEUNIT_MS); if (result != FMOD_OK) { throw new FMODException(result); } this.duration = TimeSpan.FromMilliseconds(durationInMilliseconds); }
/// <summary> /// Applies the specified settings. /// </summary> /// <param name="uv">The Ultraviolet context.</param> public void Apply(UltravioletContext uv) { Contract.Require(uv, nameof(uv)); var audio = uv.GetAudio(); audio.AudioMasterVolume = AudioMasterVolume; audio.AudioMuted = AudioMuted; audio.SongsMasterVolume = SongsMasterVolume; audio.SongsMuted = SongsMuted; audio.SoundEffectsMasterVolume = SoundEffectsMasterVolume; audio.SoundEffectsMuted = SoundEffectsMuted; }
/// <summary> /// Creates a set of audio settings from the current application state. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <returns>The audio settings which were retrieved.</returns> public static UltravioletApplicationAudioSettings FromCurrentSettings(UltravioletContext uv) { Contract.Require(uv, nameof(uv)); var audio = uv.GetAudio(); var settings = new UltravioletApplicationAudioSettings(); settings.AudioMasterVolume = audio.AudioMasterVolume; settings.AudioMuted = audio.AudioMuted; settings.SongsMasterVolume = audio.SongsMasterVolume; settings.SongsMuted = audio.SongsMuted; settings.SoundEffectsMasterVolume = audio.SoundEffectsMasterVolume; settings.SoundEffectsMuted = audio.SoundEffectsMuted; return(settings); }
/// <summary> /// Creates a set of audio settings from the current application state. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <returns>The audio settings which were retrieved.</returns> public static UltravioletApplicationAudioSettings FromCurrentSettings(UltravioletContext uv) { Contract.Require(uv, nameof(uv)); var audio = uv.GetAudio(); var settings = new UltravioletApplicationAudioSettings(); settings.AudioMasterVolume = audio.AudioMasterVolume; settings.AudioMuted = audio.AudioMuted; settings.SongsMasterVolume = audio.SongsMasterVolume; settings.SongsMuted = audio.SongsMuted; settings.SoundEffectsMasterVolume = audio.SoundEffectsMasterVolume; settings.SoundEffectsMuted = audio.SoundEffectsMuted; return settings; }