Be aware that EMULib is a work in progress. Every now and then I add new modules and extend existing ones. Documentation is incomplete and may not always be up to date. In this situation, the header files are your best friends. Check them out for fresh information on the libraries.
void PlayHandler(int Channel,int Frequency,int Volume)which will be used to play sounds from the four PSG channels. The frequency is given in hertz while the volume may vary in 0..255 range. Channels 0-2 are melodic. Channel 3 should generate white noise around given base frequency. After implementing the
PlayHandler()
in your
program, create the PSG context:
SN76489 PSG;This structure contains all PSG registers and other data describing PSG state. You should then initialize it with
Reset76489(&PSG,&PlayHandler);After that, you can write byte values into PSG chip by issuing
Write76489(&PSG,Value);calls. These writes will be converted into calls to the
PlayHandler()
. There are two possible ways to do it though:
PlayHandler()
immediately as
a value is written into the PSG chip. To do this, call
Sync76489(&PSG,PSG_ASYNC);after resetting the PSG.
PlayHandler()
calls about 50-60 times a second,
in the end of a video frame. To do this, call
Sync76489(&PSG,PSG_SYNC);after resetting the PSG. Now, every time you want to put accumulated changes into effect, call
Sync76489(&PSG,PSG_FLUSH);
<Channel><Frequency><Volume>
triplets.
This library can be used for saving soundtrack from an emulator or
converting various music formats into MIDI format. Your typical program
should create a MIDI file in a following way:
FILE *F; F=fopen(FileName,"wb"); InitMIDI(F,Channels,Ticks);The
Channels
parameter should be set to the maximal number
of sound channels you are going to use. The Ticks
parameter
is in hertz and sets the quantization frequency i.e. the smallest period
of time between notes. After creating a MIDI file, it is time to set sound
types for the channels. This is done by issuing
MIDISetSound(Channel,Type);calls where
Type
may take values
SND_MELODIC - Melodic sound SND_NOISE - White noise SND_PERIODIC - Periodic noiseNow, you are ready to start generating some sound. This is done with
MIDISound(Channel,Frequency,Volume);calls where
Frequency
is given in hertz and
Volume
varies in 0..255 range. This call alone is not enough
though. The MIDI standard also requires timestamps to keep track of time.
Writing a timestamp is done using
MIDITicks(Ticks);call where
Ticks
is a number of ticks passed since the
last call to MIDITicks()
. Remember that a "tick" is a unit
of time declared when you initialize MIDI with an InitMIDI()
call. Additional functions which you may find useful are
MIDISetFreq(Channel,Frequency); MIDISetVolume(Channel,Volume);They are both special cases of a more universal
MIDISound()
function. After you are done with the MIDI file, it can be closed in a
following fashion:
TrashMIDI(); fclose(F);