#include "sgl.h"
Uint8 * sddrvaddr;
Uint32 drvsize;
Uint8 * map;
Uint32 mapsize;
void slInitSound (sddrv, drvsize, map, mapsize);
Uint8 * sddrvaddr --Sound driver address Uint32 drvsize --Sound driver size Uint8 * map --Sound area map address Uint32 mapsize --Sound area map size
void --Nothing is returned.
Set the sound driver and initialize the sound control CPU (MC68000).
The sound driver is compatible with version 2.00 or later, so
It cannot be executed with earlier sound drivers.
extern Uint8 * sddrvs;
extern Uint32 sddrvsize;
Uint8 map [256];
Uint32 mapsz = 256;
slInitSound (sddrvs, sddrvszize, map, mzpsz);
Be sure to execute it before executing all sound functions.
The slInitSystem function does not perform any sound initialization.
#include "sgl.h"
void * addr;
void slWaitSound (addr);
void * addr --The address you want to monitor.
void --Nothing is returned.
Wait until the data at the specified address becomes 0.
Indicates that the sound driver has executed the function.
slWaitSound ( slSndMapChange (2));
slSndMapChange | slSoundRequest |
#include "sgl.h"
Uint8 Lvol;
Uint8 Rvol;
Uint8 Lpan;
Uint8 RPan;
Bool slCDDAOn (Lvol, Rvol, Lpan, Rpan);
Uint8 Lvol --Left volume
Uint8 Rvol --Right volume Uint8 Lpan --Left pan Uint8 RPan --Right pan
Bool- A flag that indicates whether the command was issued correctly.
Specify the volume and direction when using CDDA.
Volume is 0 (Off) to 127 (lower 4 bits are invalid), pan is (left -127 to 0 to +127 right)
(However, the lower 3 bits are invalid).
Returns TRUE on success and FALSE on failure.
slCDDAOn (127, 127, 0, 0);
slCDDAOff | slSndFlush |
#include "sgl.h"
Bool slCDDAOff (void);
void --Do not give anything.
Bool- A flag that indicates whether the command was issued correctly.
CDDA playback will stop.
Returns TRUE on success and FALSE on failure.
slCDDAOff ();
slCDDAOn | slSndFlush |
#include "sgl.h"
PCM * pcm;
void * data;
Uint32 size;
Sint8 slPCMOn (pcm, data, size);
PCM * pcm --PCM data management structure void * data --PCM data entity Uint32 size --PCM data size
Sint8 --PCM channel number or error code.
Plays music (sound effects) using a PCM sound source.
data is a PCM data table for playback. In the case of stereo, set the right channel and left channel separately for the first half and the second half as shown in the figure below. In normal PCM data, L channel and R channel alternate, and they are not separated as shown in the figure below.
+ --------------- +
| |
| R data |
| (frame * datasize byte)
+ --------------- +
| |
| L data |
| |
+ --------------- +
PCM type data is a structure in the following format.
typedef struct {
Uint8 mode; / * Playback mode * /
Uint8 channel; / * Playback channel * /
Uint8 level; / * Playback level * /
Sint8 pan; / * Playback pan * /
Uint16 pitch; / * Playback pitch * /
Uint8 eflevelR; / * Effect level (for right and monaural) * /
Uint8 efselectR; / * Effect number (for right and monaural) * /
Uint8 eflevelL; / * Effect level (for left) * /
Uint8 efselectL; / * Effect number (for left) * /
} PCM;
Set the playback mode as follows.
< _Stereo or _Mono > and < _PCM16Bit is _PCM8Bit
The playback channel is set by the slPCMOn function (normally the return value at the end).
Playback level is 0 to 127 (lower 4 bits are invalid),
Set the playback pan to (left -127 to 0 to +127 right) (lower 8 bits are invalid).
The playback pitch is 16 bits and specifies the rate for 44.1kHz.
Specify an effect level of 0 to 7 and an effect number of 0 to 15.
The return value of the function is 0 to 7 for normal termination, -1 for insufficient command buffer,
Returns -2 if the PCM channel is not free and -3 if there is not enough buffer for the PCM.
The PCM playback started by this function will stop when the data ends.
slPCMOn (pcm, dat, datsize);
When transferring PCM playback data to sound RAM. SCU-DMA level 2 is normally used and is forwarded during V-Blank In. However, WorkRAM Low is out of the control of the SCU, so in that case, transfer using CPU-DMA. Therefore, if the playback data is in the WorkRAM-L area, there are the following restrictions.
-Reproduced data is treated as if it is arranged from even-numbered addresses.
(Use with the lower 1 bit of the address set to 0)
Therefore, be sure to place the playback data at even-numbered addresses.
-If the playback data is stereo and 8-bit, it is assumed that the data on the left channel is also arranged from even-numbered addresses.
This means that when playing stereo data, the number of samples must be an even number.
-If the playback data is 8192 frames or more, noise may occur when wrapping the buffer.
Therefore, define the data by duplicating 1 byte for every 8192 frames.
However, it starts at the 1536 (600H) frame offset.
Therefore, the first data to be duplicated is 6656 (1A00H).
The structure of the PCM structure is different between SGL Ver. 3.20 or later and SGL before that.
If the PCM data was created for an older version of SGL, you need to add the last member of the PCM structure. Please be careful.
slPCMOff | slPCMParmChange | slPCMStat | slSndPCMNum |
slSndFlush | DMASt_CPU0 | DMASt_SCU0 |
#include "sgl.h"
PCM * pcm;
Bool slPCMOff (pcm);
PCM * pcm-A management structure for the PCM data that is currently ringing.
Bool- A flag that indicates whether the command was issued correctly.
Stops PCM playback on the specified channel.
Returns TRUE on success and FALSE on failure.
slPCMOff (pcm);
slPCMOn | slPCMParmChange | slPCMStat | slSndPCMNum |
slSndFlush |
#include "sgl.h"
PCM * pcm;
Bool slPCMParmChange (pcm);
PCM * pcm-The management structure for the PCM data you want to change.
Bool- A flag that indicates whether the command was issued correctly.
Change each parameter for PCM playback.
Returns TRUE on success and FALSE on failure.
extern PCM pcm;
pcm.pitch + = 100;
slPCMParmChange (pcm);
slPCMOn | slPCMOff | slPCMStat | slSndPCMNum |
slSndFlush |
#include "sgl.h"
PCM * pcm;
Bool slPCMStat (pcm);
PCM * pcm-A management structure for the PCM data you want to investigate.
Bool- A flag that indicates whether the command was issued correctly.
Checks if the PCM for the specified channel is playing and returns a flag.
TRUE is returned if it is playing, and FALSE is returned if it is finished.
if ( slPCMStat (pcm) == TRUE ) {
/ * Playing * /
} else {
/ * End of playback * /
}
slPCMOn | slPCMOff | slPCMParmChange | slSndPCMNum |
slSndFlush |
#include "sgl.h"
Uint8 mode;
Sint8 slSndPCMNum (mode);
Uint8 mode-Mode (stereo or monaural) (see below)
Sint8 --The number of the free PCM channel.
Returns a free PCM channel number.
If there is no space, -1 is returned, and if it ends normally, 0 to 7 is returned.
Specify _Stereo or _Mono for mode.
PCM can play up to 8 sounds, but for stereo playback,
Please note that you will need two notes, so even if you only have four notes, you may have eight notes.
if ( slSndPCMNum ( _Stereo )! = -1) {
slPCMOn (...)
}
slPCMOn | slPCMOff | slPCMParmChange | slPCMStat |
DMASt_CPU0 | DMASt_SCU0 |
#include "sgl.h"
Uint8 effect;
Bool slSndEffect (effect);
Uint8 efct-Effect number.
Bool- A flag that indicates whether the command was issued correctly.
Switches the sound effect by DSP.
Returns TRUE on success and FALSE on failure.
Assuming that the mixer that outputs no effect is 0 and the original mixer is 1,
slSndMixParmChange (0, 127, 0);
slSndEffect (1);
for (i = 0; i <60; ++ i) slSynch ();
slSndMixParmChange (1, 127, 0);
This is an example of how to suppress the generation of noise when changing effects.
When changing effects, considerable noise may occur depending on the type of effect.
As a way to suppress this, first make a mixer that does not output any effect in advance, and before changing the effect,
Use the slSndMixParmChange function to switch to that effect.
After that, execute slSndEffect , switch the effect, and then wait for about 1 second until the sound stabilizes. Then again
Use the slSndMixParmChange function to revert to the original mixer.
However, there may be a slight noise when first switching to a mixer that does not output effects. In that case, the slSndVolume function can be used to deceive by lowering the total volume, but in this case, all sound sources will be affected, so be careful.
slSndMixParmChange | slSndVolume | slSndFlush |
#include "sgl.h"
Uint8 mix;
Uint8 vol;
Sint8 pan;
Bool slSndMixParmChange (mix, vol, pan);
Uint8 mix --Mixer number Uint8 vol --Volume Sint8 pan --Pan
Bool- A flag that indicates whether the command was issued correctly.
Change the parameters of the mixer.
vol is 0 to 127 (lower 4 bits are invalid), pan is (left -128 to 0 to +127 right)
(Lower 3 bits are invalid) is set.
Returns TRUE on success and FALSE on failure.
slSndMixParmChange (1, 127, 0);
slSndFlush |
#include "sgl.h"
const char * form;
/ * arg1, arg2, ... * /
Sint8 slSoundRequest (form [], ...);
const char * form --Format of the following arguments arg1, arg2, ... --Parameters
Sint8 --Function execution status (status)
Set the data to be passed directly to the sound driver.
The form represents the individual size of the data that follows it as string data.
However, the first data is the function code and is not included in the character string.
The return value is -2, if there are invalid characters in the form string.
Returns -1 if you try to set word data from an odd address.
Returns 0 if successful.
Uint16 Lev;
Uint8 * data;
Uint16 StreamBuf;
Uint16 StreamSize;
Uint16 Pitch;
StreamBuf = ( Uint16 ) (data >> 4);
Lev = 7; / * Set Volume to max * /
slSoundRequest ("bbwwwbb", SND_PCM_START , _Stereo | _PCM16Bit , Lev << 5 | 0,
StreamBuf, StreamSize, Pitch, 0, 0);
In this case, SND_PCM_START is the function code and is not included in the string.
_Stereo | _PCM16Bit , Lev << 5 | 0 is byte data, respectively
StreamBuf >> 4, StreamSize, Pitch are passed to the sound driver as word data respectively.
slSndFlush |
#include "sgl.h"
Bool slDSPOff (void);
void --Do not give anything.
Bool- A flag that indicates whether the command was issued correctly.
Initializes (stops) the DSP.
If it succeeds, the address of the command buffer in which the parameter is set is returned, and if it fails, FALSE is returned as the return value.
slDSPOff ();
slSndFlush | SoundRdCount |
#include "sgl.h"
Uint8 vol;
Bool slSndVolume (vol);
Uint8 vol --The volume of the entire sound.
Bool- A flag that indicates whether the command was issued correctly.
Sets the volume of the entire sound output.
vol specifies 0 to 127 (however, the lower 4 bits are invalid).
If it is 0, no sound is output.
If the volume change is successful, TRUE is returned, and if it is unsuccessful, FALSE is returned as the return value.
slSndVolume (10 << 3);
#include "sgl.h"
Bool slSoundAllOff (void);
void --Do not give anything.
Bool-A flag that indicates whether the command was issued correctly.
Stops all sound sequences.
Returns TRUE on success and FALSE on failure.
slSoundAllOff ();
Executing this function cancels any unprocessed sound processing in the sound command buffer.
Also, execution is immediate without waiting for slSynch.
slSoundAllPause | slSoundAllCont | slSndFlush | SoundRdCount |
#include "sgl.h"
void slSoundAllPause (void);
void --Do not give anything.
void --Nothing is returned.
Pauses the entire sequence (including background music) being played. (However, the PCM stream does not stop)
slSoundAllPause ();
slSoundAllCont | slSoundAllOff | slSndFlush | SoundRdCount |
#include "sgl.h"
void slSoundAllCont (void);
void --Do not give anything.
void --Nothing is returned.
Resume all paused sequences (including background music).
slSoundAllCont ();
slSoundAllPause | slSoundAllOff | slSndFlush | SoundRdCount |
#include "sgl.h"
void slSndFlush (void);
void --Do not give anything.
void --Nothing is returned.
Outputs the control commands remaining in the sound control buffer to the sound driver.
Sound control commands are usually set in a system-provided buffer and output to the sound driver when the buffer is full or the slSynch () function is executed.
However, in the following functions, the buffer is output immediately.
slSndMapChange ()
slDSPOff ()
slPCMOff ()
slSoundRequest ()
slSoundAllPause ()
slSoundAllCont ()
Also, if you execute the following function, the command in the buffer will be discarded.
slSoundAllOff ()
slSndFlush ();