DemoGL::Reference::Functions::DEMOGL_SoundSystemStartElement

DEMOGL_SoundSystemStartElement

DEMOGL_SoundSystemStartElement starts a sound element on a new channel. See the remarks section for limitations with starting sound elements more than once.

int
DEMOGL_SoundSystemStartElement(
	const int iElementCodeID,
	const int iElementType, 
	const long lStartPos,
	const bool bLoop,
	const int iVolume,
	const int iPan, 
	const int iFrequency,
	SSoundChannel3DPosition * const p3DPosition, 
	const char *pszChannelScriptID
);
	
Parameters.
iElementCodeID
Specifies the ElementCodeID of the channel which should be removed from the sound system.
iElementType
Specifies of which type the to be loaded sound element is so the sound system can use the correct logic to play the sound. iElementType can be one of the following sound element types:

Sound element type Description
DGL_SS_MP3ELEMENT Sound element stored in the MP3 standard, i.e. MPEG v1.0 and v2.0 layer3.
DGL_SS_MODELEMENT Sound element stored in one of the following formats: MOD, XM, IT, S3M or MTM.
DGL_SS_SAMPLEELEMENT Sound element stored in the standard windows PCM format, or compressed with a custom CODEC. When you use a custom CODEC, this CODEC is required to be installed on the user's computer for the WAV to be decoded. So, you should either distribute the CODEC with your software, or use a CODEC that comes with Windows (eg. Microsoft ADPCM).

lStartPos
Specifies the position where to start the play from. For channels playing DGL_SS_SAMPLEELEMENT sound elements, lStartPos is a position in bytes. For channels playing DGL_SS_MP3ELEMENT sound elements, lStartPos is a position in milliseconds from the start. For channels playing DGL_SS_MODELEMENT sound elements, lStartPos is a value calculated using the macro MAKELONG: MAKELONG(order,row). This will result in a longword with LOWORD=order in the music module and HIWORD=row in that pattern.
bLoop
Specifies if the sound data owned by the element should be restarted when the play of the data is finished (true) or not (false).
iVolume
Specifies the volume of the sound the resulting channel produces. Values have to fall in the range [0, 100], with 0 is total silence and 100 is maximum volume. When -1 is specified the current volume value is left untouched. Will not have any effect when the sound element is loaded with 3D disabled.
iPan
Specifies the panning of the resulting channel in 2D. Values have to fall in the range [-100, 100], with -100 will place the channel totally on the left speaker and 100 will place the channel totally on the right speaker. When -101 is specified the current panning value for this channel is left untouched. Will not have any effect when the sound element is loaded with 3D disabled.
iFrequency
The frequency of the output of the resulting channel. Values have to fall in the range [100, 100000] with 100 the minimum value and 100000 the maximum value. When 0 is specified the original frequency of the resulting channel when it was created is restored. When -1 is specified, the current value for the frequency is left untouched. Will not have any effect when the sound element is loaded with 3D disabled. This value is not recommended for DGL_SS_MP3ELEMENT and DGL_SS_MODELEMENT sound element based channels.
p3DPosition
Pointer to filled SSoundChannel3DPosition structure with the 3D position, orientation and soundspeed to apply to the resulting channel. See note below on listener positions
pszChannelScriptID
Pointer to a zero-terminated string which contains the ChannelScriptID that should be associated with the sound channel where the element will be started on. When DEMOGL_SoundSystemStartElement succeeds, script commands can interact with the started channel, refering to it by using pszChannelScriptID.

Return values.
If the function succeeds, it returns the ChannelCodeID of the channel where the element is started on.
If the function fails, it returns one of the following error codes:

Error code Description
DGL_SS_ERR_CHANNELSTOREFULL Sound element couldn't be started because the channel store is full, there are no more free channels left.
DGL_SS_ERR_CHANNELACTIONFAILED Sound element couldn't be started because the play of the sounddata failed. An errorcode of the lower level sound library is logged on the system console. These errorcodes are defined in DemoGL_Bass.h. Most of these errors are 3D sound related.
DGL_SS_ERR_OPERATIONFAILED Could not start the sound element data, the play and / or the seek into the data to the lStartPos failed.
DGL_SS_ERR_ILLEGALELEMENTID The iElementCodeID value is not found as a loaded sound element.

Remarks.
The play of sound elements will be done by sound channels, thus elements play their data through sound channels. When a sound element is started, it's started on a channel, the element itself is just a container for the sound data. You can refer to the playing sound channel by using the iChannelCodeID you receive when the call to DEMOGL_SoundSystemStartElement succeeds. Elements of type DGL_SS_MP3ELEMENT and DGL_SS_MODELEMENT can be started only once, or better: just one channel can actually play the sound data owned by the element. When you start an element of those types when the element is already playing on another channel, that channel will be stopped and the new channel will continue the play. This is due to a limit in the underlying sound library, however should not be limiting in most circumstances. You can start elements of type DGL_SS_SAMPLEELEMENT on as much channels as you want, all will be playing along.

NOTE: There is just one  listener position in the sound system, because that's the way the underlying sound library works. This way, you have to keep in mind that two or more effects visible at the same time with total different scenes have to use the same global listener position for their 3D enabled sound channels. It will be odd at first, but it's the same way OpenGL works: there is no camera, the frustum is always at (0,0,0) looking at the negative Z, the world is moved/rotated so it looks as if the 'camera' is rotated/moved. Updating the global listener position in more than one effect in one frame is useless: only the last one will have any effect.

Example.

Requirements.
DemoGL v1.3 (build 0112 or higher)

See also.
DEMOGL_SoundSystemSetListener3DPosition, SSoundChannel3DPosition, _SOUNDSYSTEM commands, Definitions and defaults

Last changed on 18-jan-2001

©1999-2001 Solutions Design