aboutsummaryrefslogtreecommitdiff
path: root/doc/api-c.txt
blob: 5bf995f404bbe74c559405da1619985ec975cb61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
=============================================================================

*** 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 **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
   (the latter can be undone with echo_resume_bgm, see below).

void echo_resume_bgm()

   Resumes playback of whatever background music was playing last time before
   echo_stop_bgm was called. Used when you want to unpause music.

=============================================================================

*** 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.

=============================================================================

*** 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_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.

=============================================================================

*** 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 0x05):
   
               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_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

=============================================================================