indexing description: "[ Implements an echo effect for channels and postmix channel. Note: This effect may boost your CPU. Do not use effects when having a lot of other things (like drawing). ]" date: "$Date$" revision: "$Revision$" class EM_ECHO_EFFECT inherit EM_EFFECT create make feature {NONE} -- Initialization make (a_delay: like delay; a_decay: like decay) is -- Create echo effect with `a_delay' and `a_decay'. do delay := a_delay decay := a_decay create buffer.make (0) ensure delay_set: delay = a_delay decay_set: decay = a_decay end feature -- Access delay: INTEGER -- Delay of echo effect decay: DOUBLE -- Decay of echo effect feature -- Implementation on_effect_function (a_channel: INTEGER; a_stream: POINTER; a_length: INTEGER; a_userdata: POINTER) is -- This feature is called whenever data is ready to apply the effect on. -- -- Use `a_stream' to modify data of an maximum amount of `a_length' bytes. -- Additional user data is given by `a_userdata' on creation of the effect. local i: INTEGER j: INTEGER s: INTEGER d: DOUBLE stream: MANAGED_POINTER do from create stream.share_from_pointer (a_stream, a_length) d := 1 / (1 - decay)^2 s := a_length - delay i := 0 until i >= stream.count or else j >= buffer.count loop if i >= delay then j := i - delay else j := i + s end stream.put_integer_8 ((stream.read_integer_8 (i) - d + buffer.read_integer_8 (j) * decay).rounded.to_integer_8, i) i := i + 1 end create buffer.make_from_pointer (stream.item, stream.count) end on_effect_done (a_channel: INTEGER; a_userdata: POINTER) is -- This feature is called when the effect was unregistered from `a_channel'. -- -- Additional user data is given by `a_userdata' on creation of the effect. do end feature {NONE} -- Internal Variables buffer: MANAGED_POINTER -- Sound buffer invariant buffer_created: buffer /= Void end