Eiffel Media API
Overview Cluster Class Classes Index      Previous Next      Top Features

em.audio

Class EM_AUDIO_FACTORY


Direct ancestors

EM_SHARED_SUBSYSTEMS, EM_SHARED_ERROR_HANDLER, EM_AUDIO_CONSTANTS, SDL_MIXER_FUNCTIONS_EXTERNAL, SDL_RWOPS_FUNCTIONS_EXTERNAL

Creation

Features

Invariants

indexing

description

Singleton factory that creates objects of type EM_MUSIC, EM_SOUND
and/or to initialize an audio stream.

Use EM_SHARED_AUDIO_FACTORY to access this singleton.

Whenever possible, use creation from file or from pointer.

Avoid creating sound from memory except you know what you're doing.
Audio format has to be the same as output settings in this case.

Streaming will likely boost your CPU if you're doing a lot of other
stuff the same time.

date

$Date: 2005/10/22 13:22:42 $

revision

$Revision: 1.24 $

class

EM_AUDIO_FACTORY

inherit

EM_SHARED_SUBSYSTEMS

create {EM_SHARED_AUDIO_FACTORY}

make

-- Create new audio factory.

feature -- Access

audio_subsystem: EM_AUDIO_SUBSYSTEM

-- EiffelMedia audio subsystem

-- (From EM_SHARED_SUBSYSTEMS)

ensure
audio_subsystem_not_void: Result /= Void
cdrom_subsystem: EM_CDROM_SUBSYSTEM

-- EiffelMedia CD ROM subsystem

-- (From EM_SHARED_SUBSYSTEMS)

ensure
cdrom_subsystem_not_void: Result /= Void
joystick_subsystem: EM_JOYSTICK_SUBSYSTEM

-- EiffelMedia joystick subsystem

-- (From EM_SHARED_SUBSYSTEMS)

ensure
joystick_subsystem_not_void: Result /= Void
network_subsystem: EM_NETWORK_SUBSYSTEM

-- EiffelMedia network subsystem is

-- (From EM_SHARED_SUBSYSTEMS)

ensure
network_subsystem_not_void: Result /= void
timer_subsystem: EM_TIMER_SUBSYSTEM

-- EiffelMedia timer subsystem

-- (From EM_SHARED_SUBSYSTEMS)

ensure
timer_subsystem_not_void: Result /= Void
video_subsystem: EM_VIDEO_SUBSYSTEM

-- EiffelMedia video subsystem

-- (From EM_SHARED_SUBSYSTEMS)

ensure
video_subsystem_not_void: Result /= Void
last_music: EM_MUSIC

-- Last music created

last_sound: EM_SOUND

-- Last sound created

feature -- Music player

set_player (a_command: STRING)

-- Set internal or external music player. This can be used to support more file formats.
--
-- If a_command is an empty string, the internal player will be used (should be default).
--
-- Set a_command to a complete command as if typed into the command line, but it should
-- expect the filename to be added as last argument.
--
-- Attention: This may not work on your system as sound device has to be opened twice.

require
a_command_not_void: a_command /= Void

feature -- Music creation

create_music_from_file (a_filename: STRING)

-- Load music file from a_filename into last_music.
--
-- This can load WAVE, MOD, MIDI, OGG, MP3 and any file that can be played by a command.

require
a_filename_not_void: a_filename /= Void
ensure
music_created: last_music /= Void
create_music_from_pointer (a_pointer: POINTER)

-- Load music file from a_pointer into last_music.
--
-- This can load WAVE, MOD, MIDI, OGG, MP3.
--
-- Note: Set a filename by yourself for easier finding
-- file in lists and/or other containers.

ensure
music_created: last_music /= Void

feature -- Sound creation

create_raw_sound_from_memory (a_memory_buffer: POINTER; a_length: INTEGER)

-- Load a_memory_buffer as a RAW file into last_sound.
--
-- Attention: a_memory_buffer is a memory buffer containing a
-- RAW file in output format.
--
-- This function does very little checking, so don't
-- use this function, if you don't know what you're
-- doing.
--
-- Note: Set a filename by yourself for easier finding
-- file in lists and/or other containers.

require
length_positiv: a_length >= 0
mixer_open: audio_subsystem.mixer.is_open
ensure
sound_created: last_sound /= Void
create_sound_from_file (a_filename: STRING)

-- Load sound from file a_filename into last_sound.
--
-- This can load WAVE, AIFF, RIFF, OGG, and VOC files.
--
-- Attention: You must have an open mixer before using this function
-- as it must know the output characteristics so it can
-- convert this sample for playback. This conversion is done
-- at load time.

require
a_filename_not_void: a_filename /= Void
mixer_open: audio_subsystem.mixer.is_open
ensure
sound_created: last_sound /= Void
create_sound_from_file_pointer (a_pointer: POINTER)

-- Load sound from file pointer a_pointer into last_sound.
--
-- This can load WAVE, AIFF, RIFF, OGG, and VOC files.
--
-- Attention: You must have an open mixer before using this function
-- as it must know the output characteristics so it can
-- convert this sample for playback. This conversion is done
-- at load time.
--
-- Note: Set a filename by yourself for easier finding
-- file in lists and/or other containers.

require
mixer_open: audio_subsystem.mixer.is_open
ensure
sound_created: last_sound /= Void
create_sound_from_pointer (a_pointer: POINTER)

-- Create sound from a_pointer into last_sound.
--
-- This can load WAVE, AIFF, RIFF, OGG, and VOC files.
--
-- Note: Set a filename by yourself for easier finding
-- file in lists and/or other containers.

require
mixer_open: audio_subsystem.mixer.is_open
ensure
sound_created: last_sound /= Void
create_wav_sound_from_memory (a_memory_buffer: POINTER)

-- Load a_memory_buffer as a WAVE/RIFF file into last_sound.
--
-- Attention: a_memory_buffer is a memory buffer containing a
-- WAVE file in output format.
--
-- This function does very little checking, so don't
-- use this function, if you don't know what you're
-- doing.
--
-- Note: Set a filename by yourself for easier finding
-- file in lists and/or other containers.

require
mixer_open: audio_subsystem.mixer.is_open
ensure
sound_created: last_sound /= Void

feature -- Stream creation

create_stream (a_callback: EM_AUDIO_STREAM; an_argument: POINTER)

-- Create stream hook from a_callback.
--
-- Pass in an_argument if you need some userdata in the callback.
-- This argument will be present as a_userdata in later callbacks.
--
-- Note: Streaming may cause your application to crash if you're doing
-- a lot of CPU intensive work in parallel.

require
callback_not_void: a_callback /= Void
mixer_open: audio_subsystem.mixer.is_open
ensure
no_music_created: last_music = Void
no_sound_created: last_sound = Void

invariant

no_music_and_sound_created_at_the_same_time: not (last_music /= Void and then last_sound /= Void)

-- From ANY
reflexive_equality: standard_is_equal (Current)
reflexive_conformance: conforms_to (Current)

end