indexing description: "[ Implements a mixer for playing audio files. This is like a base for all audio stuff and should be accessed by {EM_AUDIO_SUBSYSTEM}. This class opens a audio device with output settings. If you don't know what settings are best, use default ones from {EM_AUDIO_CONSTANTS}. ]" date: "$Date$" revision: "$Revision$" class EM_MIXER inherit EM_SHARED_ERROR_HANDLER export {NONE} all end EM_AUDIO_CONSTANTS export {NONE} all {ANY} Em_max_volume end SDL_MIXER_FUNCTIONS_EXTERNAL export {NONE} all end MEMORY rename chunk_size as memory_chunk_size export {NONE} all end create make feature {EM_AUDIO_SUBSYSTEM} -- Initialization make is -- Create new mixer instance. do create internal_channels.make_empty create on_before_close ensure is_closed: not is_open end feature -- Basic mixer operations open_default is -- Open mixer instance with default values. do open (Em_default_frequency, Em_audio_format_s16sys, Em_stereo, Em_default_chunk_size) ensure is_open: is_open end open (a_frequency: INTEGER; a_format: INTEGER; a_channel: INTEGER; a_chunk_size: INTEGER) is -- Open mixer instance with -- `a_frequency' = Output sampling frequency. -- `a_format' = Output sample format. -- `a_channel' = Number of sound channels in output. -- Note: This has nothing to do with mixing channels! -- `a_chunk_size' = Bytes used per output sample. -- -- If unsure, use the following settings for good performance. -- `a_frequency' = Em_default_frequency (22050 Hz). -- `a_format' = Em_audio_format_s16sys. -- `a_channel' = Em_stereo. -- `a_chunk_size' = Em_default_chunk_size (4096 Bytes). require is_closed: not is_open local i: INTEGER do internal_chunk_size := a_chunk_size i := mix_open_audio_external (a_frequency, a_format, a_channel, a_chunk_size) if i = -1 then error_handler.raise_error (error_handler.Em_error_opening_mixer, [a_frequency, a_format, a_channel, a_chunk_size]) end create internal_channels.make_empty ensure is_open: is_open end close is -- Close mixer instance. require is_open: is_open do on_before_close.publish ([]) mix_close_audio_external ensure is_closed: not is_open end feature -- Event on_before_close: EM_EVENT_CHANNEL [TUPLE []] -- Event fired when mixer is going to be closed. feature -- Informations is_open: BOOLEAN is -- Is mixer open? do Result := mix_query_spec_external (Default_pointer, Default_pointer, Default_pointer) > 0 end feature -- Access frequency: INTEGER is -- Mixer output frequency require mixer_open: is_open local dummy_pointer: POINTER frequency_pointer: MANAGED_POINTER i: INTEGER do create frequency_pointer.make (4) i := mix_query_spec_external (frequency_pointer.item, dummy_pointer, dummy_pointer) Result := frequency_pointer.read_integer_32 (0) end format: INTEGER is -- Mixer output format require mixer_open: is_open local dummy_pointer: POINTER format_pointer: MANAGED_POINTER i: INTEGER do create format_pointer.make (4) i := mix_query_spec_external (dummy_pointer, format_pointer.item, dummy_pointer) Result := format_pointer.read_integer_32 (0) end output_channel: INTEGER is -- Mixer output channel require mixer_open: is_open local dummy_pointer: POINTER channel_pointer: MANAGED_POINTER i: INTEGER do create channel_pointer.make (4) i := mix_query_spec_external (dummy_pointer, dummy_pointer, channel_pointer.item) Result := channel_pointer.read_integer_32 (0) end chunk_size: INTEGER is -- Mixer chunk size. require mixer_open: is_open do Result := internal_chunk_size end channels: EM_CHANNELS is -- Mixing channels require open: is_open do Result := internal_channels end feature {NONE} -- Internal variables internal_chunk_size: INTEGER -- Internal chunk size internal_channels: EM_CHANNELS -- Internal channels invariant internal_channels_created: internal_channels /= Void end