/// <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); }