============================================================================= *** How to use *** Add "echo.c" and "echoblob.h" in your program files. Then include the header "echo.h" in whatever source files you need to access the Echo API, i.e. #include "echo.h" (these files are present in the "c" directory) Then use echo_init to initialize Echo and load the instrument list (see below). After that you can use Echo as needed (e.g. call echo_play_bgm to start playing music, etc.). The file "echoblob.h" is the Z80 binary turned into a C array. If you want to change the blob, just use the included blob2c tool. It's invoked as follows: blob2c «input.bin» «output.h» ============================================================================= *** Initialization *** void echo_init(const void* const* list) Initializes Echo. Loads the instrument list, loads the Z80 engine and gets it running. You need to call this before you can use Echo (usually when the program is just starting). The parameter 'list' is a pointer to an array of pointers, where each entry points to the EIF/EEF/EWF data of each instrument. The list ends with a NULL pointer. For example: const void* const list[] = { instrument1, instrument2, instrument3, NULL }; (if NULL isn't defined for whatever reason just use 0 instead) ============================================================================= *** Background music *** void echo_play_bgm(const void *esf) Starts playback of the specified background music. The parameter 'esf' points to the ESF data for the background music. void echo_stop_bgm() Stops playback of background music. Used both to stop and to pause music. void echo_pause_bgm() Pauses BGM playback (SFXs should be unaffected). void echo_resume_bgm() Resumes BGM playback after it has been paused with echo_pause_bgm. ============================================================================= *** Sound effects *** void echo_play_sfx(const void *esf) Starts playback of the specified sound effect. The parameter 'esf' points to the ESF data for the sound effect. void echo_stop_sfx() Stops playback of sound effects. ============================================================================= *** Direct events *** void echo_play_direct(const void *esf) Injects events to be played as part of the BGM the next tick. The parameter 'esf' points to the ESF data to be injected. The injected events are a small stream on their own. The last event must be $FF (this will return back to the BGM). Do *not* issue $FC, $FD or $FE events, as you'll just break everything instead. The buffer is small, so don't go overboard. There's room for up to 128 bytes (though again, each event is just 2-3 bytes). If there were direct events pending to play, the new events will be appended at the end, so take this into account when it comes to the buffer usage. You can check if there are pending events with Echo_GetStatus (see ECHO_STAT_DIRBUSY) if you're worried about running out of space. The buffer is only checked every tick. ============================================================================= *** Control *** uint16_t echo_get_status() Gets the current status of Echo. Returns an OR of the following flags, as relevant: ECHO_STAT_BGM ....... Background music is playing ECHO_STAT_SFX ....... Sound effect is playing ECHO_STAT_DIRBUSY ... Echo isn't done parsing direct events ECHO_STAT_BUSY ...... Echo is busy (can't take commands) The API will automatically wait if you try to send a command while Echo is busy, so the only reason to check for that is if you don't want to halt the 68000 until Echo is ready to take more commands. void echo_set_volume(uint8_t vol) Sets the global volume. The value 'vol' ranges from 0 (quietest) to 255 (loudest), and every channel is affected immediately. The scale of the volume in this case is *linear*. Note that since PCM doesn't have volume, it gets toggled on/off depending on the volume value (the cut off point is at 25%). void echo_set_volume_ex(const uint8_t *ptr) Sets the global volume for each channel separately. The parameter 'ptr' points to a list of 16 bytes (one for each Echo channel). Values for FM and PSG channels are given in the same way as in events, that is: logarithmic scale, 0..127 for FM, 0..15 for PSG, lower = louder. The last byte (the one belonging to the PCM channel) is used to toggle whether PCM plays, either 0 (disabled) or 1 (enabled). NOTE: the Echo 1.4 docs requested for 13 bytes instead of 16. This has been changed for the sake of expansion. Currently the extra bytes are ignored, but consider adapting your code (just set them to zero). ============================================================================= *** Settings *** void echo_set_pcm_rate(uint8_t rate) Changes the sample rate of PCM. Note this is a global parameter as it affects both BGM and SFX. The value is what one would write in timer A of the YM2612 register. Here are the approximate frequencies for some values (default is 0x04): NTSC PAL | NTSC PAL -----------------------------|--------------------------- 0x01 ... 26632Hz ... 26389Hz | 0x07 ... 6658Hz ... 6597Hz 0x02 ... 17755Hz ... 17593Hz | 0x08 ... 5918Hz ... 5864Hz 0x03 ... 13316Hz ... 13194Hz | 0x09 ... 5326Hz ... 5278Hz 0x04 ... 10653Hz ... 10556Hz | 0x0A ... 4842Hz ... 4798Hz 0x05 .... 8877Hz .... 8796Hz | 0x0B ... 4439Hz ... 4398Hz 0x06 .... 7609Hz .... 7539Hz | 0x0C ... 4097Hz ... 4060Hz The higher the sample rate, the better quality, but also takes up more space and, more importantly, reduces CPU time available for other things (which can hamper Echo's ability to process complex streams). Be careful if you increase the sample rate. ============================================================================= *** Raw access *** void echo_send_command(uint8_t command) Sends an argument-less command to Echo. The parameter 'command' is the command to send, and may be one of the following: ECHO_CMD_STOPBGM ..... Stop background music playback ECHO_CMD_PAUSEBGM .... Pause background music playback ECHO_CMD_RESUMEBGM ... Resume background music playback ECHO_CMD_STOPSFX ..... Stop sound effect playback void echo_send_command_addr(uint8_t command, const void *address) Sends a command to Echo that takes an address as its argument. The parameter 'command' is the command to send, while the parameter 'address' is the address to use as argument. The command may be one of these: ECHO_CMD_PLAYBGM .... Start background music playback ECHO_CMD_PLAYSFX .... Start sound effect playback ECHO_CMD_LOADLIST ... Load instrument list (warning: see below) Do *NOT* use ECHO_CMD_LOADLIST unless you *REALLY* know you're doing, this makes Echo load the instrument list by itself and it expects a different format from the one used by the C API. void echo_send_command_byte(uint8_t command, uint8_t byte) Sends a command to Echo that takes a byte as its argument. The parameter 'command' is the command to send, while the parameter 'byte' is the byte to use as argument. The command may be... just this for now: ECHO_CMD_SETPCMRATE ... Change PCM sample rate =============================================================================