Japanese
SGL User's ManualPROGRAMMER'S TUTORIAL
Back | ■
PROGRAMMER'S TUTORIAL

14. Sound library


This chapter explains the steps and points to note when outputting sound on the Sega Saturn using the sound control library.

14-1. Sound control overview

The Sega Saturn is equipped with the MC68000 as a sound control CPU, allowing it to operate independently of the master CPU.
The master CPU and sound CPU exchange functions through a RAM called a command buffer. Since functions are issued by the sound control library, users can control sounds without being aware of communication between CPUs.
The sound sources that can be used with the Sega Saturn include PCM and CD, and the sound driver controls the PCM sound source.

Figure 14-1 Sound driver system configuration
┏━━━━━━━┓  ┏━━━━━━┓  ┏━━━━━━┓            
┃Sound  ┃  ┃      ┃  ┃      ┃            
┃Library┃←→┃Master┃←→┃Slave ┃            
┠───────┨  ┃ CPU  ┃  ┃ CPU  ┃            
┃       ┃  ┃      ┃  ┃      ┃            
┃       ┃  ┗━━━━━━┛  ┗━━━━━━┛            
┃       ┃      ↑                         
┃       ┃      ↓                         
┃       ┃  ┏━━━━━━━┓                     
┃       ┃  ┃Sound  ┃                     
┃       ┃  ┃Driver ┃  ┏━━━━━━━━┓         
┃       ┃  ┠───────┨  ┃SoundCPU┃         
┗━━━━━━━┛  ┃Command┃←→┃MC68000 ┃         
           ┃Buffer ┃  ┃        ┃         
           ┃       ┃  ┗━━━━━━━━┛         
           ┠───────┨      ↓              
           ┃       ┃  ┏━━━━━━━━━┓        
           ┃Sound  ┃  ┃PCM sound┃→Speaker
           ┃Data   ┃  ┃source   ┃        
           ┃       ┃  ┗━━━━━━━━━┛        
           ┗━━━━━━━┛                     
          Shared RAM                    
                                       

14-2. Sound driver settings

To control sound on your Sega Saturn using a sound driver, follow these steps:

Figure 14-2 Sound control procedure
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Setting the sound driver         ┃
┃ and starting MC68000             ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
                ↓                   
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Sound data set                   ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
                ↓                   
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Control of BGM performance/sound ┃
┃ effects and PCM sound source     ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

Set up the sound driver and start up the MC68000

To use sound, you must first start up the MC68000 for sound control. A driver program that runs on this MC68000 is also required. These can be set by executing the library function “slInitSound()”.

[void slInitSound(void *drv, Uint32 drvsz, void *map, Uint32 mapsz);]
Set the sound driver and initialize the sound CPU (MC68000). “drv” is a sound driver program that runs on the MC68000 and is loaded from address 0 on the MC68000. “drvsz” is the size of this driver program.
Normally,
slInitSound(drv, sizeof(drv), maptbl, sizeof(maptbl));
Use it like this:

This function “slInitSound()” performs the following steps.

  1. Resetting MC68000
  2. MC68000 memory area Clear to 0xB000
  3. Transferring the driver program (size from address 0)
  4. Transfer map data (size from address 0xA000)
  5. Registering memory area for PCM playback
  6. Start of MC68000
  7. Registering map data

set of sound data

If you just execute “slInitSound()” above, the performance data has not been set yet, so let's set it. Performance data is stored in the MC68000's memory area starting from 0xB000 (0x25A0B000 in the program) (this may vary depending on the map data, so please contact your sound designer). Transfer using the following function:

Figure 14-3 Example of setting sound data
┌                                                             ┐
│slDMACopy(sounddat , (void *)0x25a0b000 , sizeof(sounddat)) ;│
│slDMAWait() ;                                                │
└                                                             ┘

Now you're ready to play.

BGM performance

Music (and sound effects) are handled in units called sequences. A sequence is a series of sound combinations (flows) played from beginning to end (this could be a song or a one-shot sound effect), and the Sega Saturn's sound driver allows you to play this sequence from beginning to end. Up to eight instruments can be played at the same time. In SGL, out of these eight sequences, number 0 is allocated for BGM. To play BGM, execute the “slBGMOn()” function.

[Bool slBGMOn(Uint16 Song , Uint8 Prio , Uint8 Volume , Uint8 Rate) ;]
Start BGM playing.

Song: Song (sound effect) number Prio: Priority when using sound source Volume: Volume Rate: Time to reach Volume

Priority "Prio" is called the priority order when using a sound source.Since multiple sequences share a 32-channel sound source to produce sound, it is used when the total number of channels used by each exceeds 32. This is to secure a channel by deleting low-priority sounds.

The volume can be selected from 0 to 127, and the higher the number, the louder the volume. Rate “Rate” is the time it takes to reach the specified volume, and can be specified from 0 to 255. If it is 0, the volume will be set immediately, and if it is 1 to 255, the volume will fade in from 0 to the specified volume.

You can change the tempo and volume of BGM, and stop, pause, and restart the BGM using the following functions.

slBGMTempo(Sint16 Tempo) ; /* Change tempo */
slBGMFade(Uint8 Volume , Uint8 Rate) ; /* Change volume */
slBGMOff(); /* Stop playing */
slBGMPause(); /* Pause the performance */
slBGMCont(); /* Resume playing */
slBGMStat(); /* Check if it is playing */

Sound effect output

Like the BGM above, sound effects are also managed as sequences. To output sound effects, execute the function “slSequenceOn()”.

[Uint8 slSequenceOn(Uint16 Song , Uint8 Prio , Uint8 Volume , Uint8 Pan) ;]
Song: Song (sound effect) number Prio: Priority when using sound sources Volume: Volume Pan: Distribution of left and right volume

The parameters are similar to the BGM function, but the parameter Pan is different. This indicates how the volume is divided between the left and right sides, and can be used to determine which direction the sound is coming from. A value from -128 to +127 can be specified for Pan, with -128 representing the left, 0 representing the front, and +127 representing the right.

Substitution value for parameter Pan:
Left: -128<< 0>> +127 : Right

When watching an explosion in a 3D shooting game, you can increase the sense of reality by setting the Volume and Pan according to the distance and direction.

This function “slSequenceOn()” returns the pronunciation control number at which the specified sound effect is output. This pronunciation control number is used when changing the output sound effect using the following functions.

slSequenceTempo(Uint8 Seqnm , Sint16 Tempo) ; /* Change tempo */

slSequenceFade(Uint8 Seqnm, Uint8 Volume, Uint8 Rate); /* Change volume */

slSequencePan(Uint8 Seqnm, Uint8 Pan); /* Change direction of generation */

slSequenceOff(Uint8 Seqnm) ; /* Stop the sequence */

slSequencePause(Uint8 Seqnm) ; /* Pause the sequence */

slSequenceCont(Uint8 Seqnm) ; /* Resume the paused sequence */

slSequenceStat(Uint8 Seqnm) ; /* Check if the sequence is playing */

Output of sound effects using PCM sound source

If you want to output sampled sound effects such as voices or explosion sounds, you can use a PCM sound source. In addition to the above sequence, up to 4 channels of sound effects can be output simultaneously using the PCM stream. When using a PCM stream, execute the function “slPCMOn()”.

[Sint8 slPCMOn(PCM *pdat , void *data , Uint32 size) ;]
The performance using the PCM sound source will begin.
pdat: PCM type structure data such as playback mode of PCM stream data: Sound source data of PCM stream size: Size of PCM stream data

The PCM type structure data has the following structure and is used to specify the playback parameters of the PCM stream.

Figure 14-4 PCM type structure data


typedef struct{
	Uint8 mode; /* Mode */
	Uint8 channel; /* PCM Channel Number */
	Uint8 level; /* 0 ~ 127 */
	Sint8 pan; /* -128 ‾ +127 */
	Uint16 pitch;
	Uint8 eflevelR; /* Effect level for Right(nomo) 0 ~ 7 */
	Uint8 efselectR; /* Effect select for Right(mono) 0 ~ 15 */
	Uint8 eflevelL; /* Effect level for Left(mono) 0 ~ 7 */
	Uint8 efselectL; /* Effect select for Left(mono) 0 ~ 15 */
	}PCM;

	mode: Specify _Stereo or _Mono, _PCM16Bit or _PCM8Bit channel: PCM playback channel (set by this function)
	level: volume pan: left/right distribution of volume pitch: playback rate (pitch changes)
	eflevelR: Effect level (for right channel)
	efselectR: Effect number (for right channel)
	eflevelL: Effect level (for left channel)
	efselectL: Effect number (for left channel)

Unlike the above sequence, the PCM stream is played back while the master CPU sets the data used by the sound SCSP LSI, which increases the load on the master CPU. Consult with your sound designer and decide whether to output sound in the sequence described above or use a PCM stream. This function “slPCMOn()” returns the management number at which the specified PCM stream is output. In addition to this function, the following functions are used to play sound effects using PCM streams.

slPCMOff(PCM *pdat); /*Stop playing*/
slPCMParmChange(PCM *pdat) ; /*Change parameters*/
slPCMStat(PCM *pdat) ;/*Check whether the specified PCM channel is playing*/

Functions that affect the overall sound output

While the functions above were for individual sound outputs, the following functions affect the entire sound output.

slSndVolume(Uint8 Volume) ; /* Overall volume */
slSoundAllOff(); /* Stop all sound sequences */
slDSPOff(); /* Stop the effect DSP */
slSndMixChange(Uint8 Tbank , Uint8 Mixno) ; /* Switch mixer */
slSndMixParmChange(Uint8 Effect , Uint8 Level , Uint8 Pan) ;
/* Change mixer parameters */

14-3. Memory map

The memory map of the sound CPU is roughly as follows. If a PCM stream is not used, a PCM playback buffer is not required, so it can be used for sequence data.

Figure 14-5 Sound CPU memory map
25A00000┏━━━━━━━━━━━━━━━┓
        ┃               ┃
        ┃ Exception     ┃
        ┃ vectors, etc. ┃
25A00500┣━━━━━━━━━━━━━━━┫
        ┃               ┃
        ┃ Current       ┃
        ┃ map data      ┃
25A00700┣━━━━━━━━━━━━━━━┫
        ┃               ┃
        ┃ Command       ┃
        ┃ buffer        ┃
25A00800┣━━━━━━━━━━━━━━━┫
        ┃               ┃
        ┃ Sound driver  ┃
        ┃               ┃
25A0A000┣━━━━━━━━━━━━━━━┫
        ┃               ┃
        ┃ Map data      ┃
        ┃               ┃
25A0B000┣━━━━━━━━━━━━━━━┫
        ┃               ┃
        ┃ Tones,        ┃
        ┃ sequences     ┃
25A78000┣━━━━━━━━━━━━━━━┫
        ┃               ┃
        ┃ PCM playback  ┃
        ┃ buffer        ┃
25A7FFFF┗━━━━━━━━━━━━━━━┛

14-4. Sample program

Sample program for BGM and sound effect playback test

The following sample program was created for testing the playback of BGM and sound effects. The data file used in this sample has the following structure.

Figure 14-6 Sample program data file

Bank Song Contents ---- ---- ------- 0 0 Song (no loop) 1 Song (with loop) 1 0 Pash (C3) 1 Pash (D3) 2 Pash (E3) 3 Pash (F3) 4 Pash (G3) 5 Pash (A3) 6 Pash (B3) 7 Pash (C4) 2 0 Yeah 3 0 Long violin sound 1 Short violin sound (loop)

Press the X button to play the song specified by bank and song as BGM, and press the A button to play it as a sound effect. Banks and songs are specified using the start key and ten o'clock key. The Y button and B button are used to pause on and off the BGM and sound effects, respectively, and the Z button and C button are used to fade in and out. The sequence number of the sound effect can be specified by pressing the left and right keys at 10 o'clock, and the overall volume can be set by pressing the top and bottom keys at 10 o'clock.

Listing 14-1 sampsnd1: BGM and sound effect playback test

main.c

Flow 14-1 sampsnd1: BGM and sound effect playback test

Sample program for PCM sound source playback test

The following sample program was created for testing PCM sound source playback.
Three types of PCM sound source sample data are available: 16-bit stereo, 8-bit stereo, and 16-bit monaural, and each can be played by inputting the X button, Y button, and Z button.

Listing 14-2 sampsnd2: PCM sound source playback test

main.c

Flow 14-2 sampsnd2: PCM sound source playback test

Appendix Sound library functions introduced in this chapter

In this chapter, we explained the functions in the table below.

Table 14-1 Sound library functions introduced in this chapter
 functional type
 Function name
 Parameter
         function
void slInitSound void *drv,Uint32 drvsz,void *map,Uint32 mapsz Setting the sound driver and initializing the sound control CPU
Bool slBGMOn Uint16 Song, Uint8 Prio, Uint8 Volume, Uint8 Rate Start of BGM performance
Bool slBGMTempo Sint16 Tempo Change BGM playing speed
Bool slBGMFade Uint8 Volume,Uint8 Rate Change BGM performance volume
Bool slBGMOff void Stopping BGM playing
Bool slBGMPause void Pausing BGM play
Bool slBGMCont void Resume playing BGM during pause
Bool slBGMStat void Check if BGM is playing
Uint8 slSequenceOn Uint16 Song, Uint8 Prio, Uint8 Volume, Uint8 Rate Start of the specified sound effect
Bool slSequenceTempo Uint8 Seqnm,Uint16 Tempo Change the speed of the specified sound effect
Bool slSequenceFade Uint8 Seqnm,Uint8 Volume,Uint8 Rate Change the volume of the specified sound effect
Bool slSequencePan Uint8 Seqnm,Uint8 Pan Change the direction of the specified sound effect
Bool slSequenceOff Uint8 Seqnm Stopping the specified sound effect
Bool slSequencePause Uint8 Seqnm Pauses the production of the specified sound effect
Bool slSequenceCont Uint8 Seqnm Resume sound effect while paused
Bool slSequenceStat Uint8 Seqnm Check if the specified sound effect is playing
Sint8 slPCMOn PCM *pdat,void *data,Uint32 size Start of performance using PCM sound source
Bool slPCMOff PCM *pdat Stopping the performance by PCM sound source
Bool slPCMParmChange PCM *pdat Changing parameters for PCM playback
Bool slPCMStat PCM *pdat Checking whether the specified PCM channel is playing
Bool slSndVolume Uint8 Volume whole volume set
Bool slSoundAllOff void Stop playing all sound sequences
Bool slDSPOff void Stopping DSP performance
Bool slSndMixChange Uint8 Tbank,Uint8 Mixno Switching the mixer corresponding to the tone bank
Bool slSndMixParmChange UInt Effect,Uint8 Level,Uint8 Pan Change mixer parameters


Back | ■
SGL User's ManualPROGRAMMER'S TUTORIAL
Copyright SEGA ENTERPRISES, LTD., 1997