/// <summary> /// Initializes a new instance of the <see cref="SoundBank"/> class from a soundbank stream. /// </summary> /// <param name="audioEngine">The engine.</param> /// <param name="stream">The soundbank stream stream.</param> /// <unmanaged>HRESULT IXACT3Engine::CreateSoundBank([In] const void* pvBuffer,[In] unsigned int dwSize,[In] unsigned int dwFlags,[In] unsigned int dwAllocAttributes,[Out, Fast] IXACT3SoundBank** ppSoundBank)</unmanaged> public SoundBank(AudioEngine audioEngine, Stream stream) { this.audioEngine = audioEngine; isAudioEngineReadonly = true; soundBankSourceStream = stream as DataStream ?? DataStream.Create(Utilities.ReadStream(stream), true, true); audioEngine.CreateSoundBank(soundBankSourceStream.PositionPointer, (int)(soundBankSourceStream.Length - soundBankSourceStream.Position), 0, 0, this); callback = OnNotificationDelegate; }
/// <summary> /// Registers this instance to notify for a type of notification. /// </summary> /// <param name="notificationType">Type of the notification.</param> public void RegisterNotification(NotificationType notificationType) { if (AudioEngine == null) throw new InvalidOperationException("AudioEngine attached to this instance cannot be null"); var notificationDescription = AudioEngine.VerifyRegister(notificationType, typeof(Wave), callback ?? (callback = OnNotificationDelegate)); notificationDescription.WavePointer = NativePointer; AudioEngine.RegisterNotification(ref notificationDescription); }
/// <summary> /// Verifies a notification registration for a particular type. /// </summary> /// <param name="notificationType">Type of the notification.</param> /// <param name="type">The type.</param> /// <param name="notificationCallback">The notification callback.</param> /// <exception cref="InvalidOperationException">If this registration is invalid</exception> /// <returns></returns> internal static RawNotificationDescription VerifyRegister(NotificationType notificationType, Type type, ManagedNotificationCallback notificationCallback) { if (!AllowedNotifications[notificationType].Contains(type)) throw new InvalidOperationException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Register to notification [{0}] not supported for type [{1}]", notificationType, type)); return new RawNotificationDescription() { Type = notificationType, ContextPointer = Marshal.GetFunctionPointerForDelegate(notificationCallback), Flags = 1, CueIndex = -1, WaveIndex = -1, }; }
/// <summary> /// Unregisters this instance to notify for a type of notification. /// </summary> /// <param name="notificationType">Type of the notification.</param> public void UnregisterNotification(NotificationType notificationType) { var notificationDescription = VerifyRegister(notificationType, typeof(AudioEngine), callback ?? (callback = OnNotificationDelegate)); notificationDescription.SoundBankPointer = NativePointer; UnRegisterNotification(ref notificationDescription); }
/// <summary> /// Unregisters this instance to notify for a type of notification. /// </summary> /// <param name="notificationType">Type of the notification.</param> public void UnregisterNotification(NotificationType notificationType) { if (AudioEngine == null) { throw new InvalidOperationException("AudioEngine attached to this instance cannot be null"); } var notificationDescription = AudioEngine.VerifyRegister(notificationType, typeof(Cue), callback ?? (callback = OnNotificationDelegate)); notificationDescription.CuePointer = NativePointer; AudioEngine.UnRegisterNotification(ref notificationDescription); }