Some sophisticated applications required the control of Spectrum Lab by other programs, and vice versa (Spectrum Lab controlling other programs). This chapter describes the two possibilities: using the tiny HTTP server which is integrated in SpecLab, and a system using windows messages. The latter may be a bit simpler if both programs run on the same machine.
For remotely controlled operation of Spectrum Lab, you can use the integrated HTTP server. This has the following advantages:
http://127.0.0.1:80 or http://localhost/
(127.0.0.1 is a dummy IP address of the local machine, and 80 is the default port number for HTTP = hypertext transport protocol )
To configure the built-in HTTP server, select "Options"..."Configure and supervise HTTP Server" in SL's main menu.
|Network name of this machine : ( shows the PC's name, as
seen in the LAN (local area network) )
Local IP Address (of this PC) : ( also just a display for convenience, can be used as browser address )
HTTP Server Port (default=80) : (enter the IP port number under which the server shall be accessed in the LAN)
Root directory for HTTP Server :
[ ] enable HTTP server
(must be checked to activate the server)
[ ] allow _iproc.html and
_ifunc.html (check this if you allow others to remotely control contrast,
[ ] allow remote control
("exec") (allows remotely calling the interpreter's
"exec" command )
Max number of simultaneous connections, Update images only when older than
X seconds, Bandwidth limit...:
Note: If -besides the HTTP server- you also use the
take care not to use the same IP port number for these functions. Both servers
use the IP address of the machine on which they run, so you must use a different
port number for the HTTP server and the audio server. BTW, the default port
number for an HTTP server is 80.
For this task, a simple communication protocol which uses WM_COPYDATA messages was implemented. Detailed information about the protocol (for fellow programmers) can be found on the author's website, search for the file yhf_comm_info.htm, titled
Communication between windows programs using WM_COPYDATA messages
(If the link fails due to server problems, copy the title into your favourite search engine - you may find the file on my "backup" site too)
I didn't include it in the Spectrum Lab documentation because it is used in other projects too (and there shall not be outdated copies of that document all over the place.. ;-) . So follow the above link for the latest up-to-date description of DL4YHF's "YHF_COMM" protocol if you are considering to...
No idea what such an application could be ? You can send any interpreter command which is mentioned in the SL manual in a WM_COPYDATA message, so you could..
The other way around, you can also
All this is possible ... but, due to the unavoidable time lag in the windows message processing system, this message system is not suitable for "tough" real-time operation. Expect a delay of some milliseconds until the command you sent to SL has been executed, and your program receives the result message.
All you have to know -in addition to the general message protocol- are the MODULE-ID's and COMMAND-ID's which are used to invoke the interpreter commands and -functions through WM_COPYDATA messages. The next chapter gives an overview of these values.
To send a windows message to Spectrum Lab, you must know its windows handle.
This can be found with a WinAPI function called "FindWindow". For convenience,
don't search for the window's title (which may change depending on the version),
use the window's class name (lpClassName, which is the first parameter for
"FindWindow"). The class name of Spectrum Lab's main window is
TSpectrumLab. But this is not the only possibility:
To support communication between two instances of SpecLab running on the same PC, the program now uses the following additional names (for programmers: SL creates an extra invisible window for this purpose, which has a unique class name) :
The old class name "TSpectrumLab" (for the main window) remains for backward compatibility.
Module- and Command Identifiers in Spectrum Lab
|Module Identifiers for DL4YHF's inter-application message handler|
|CL||Command Line Interpreter|
The third and fourth character in the message's dwData parameter contain the "command". They are specific to the "module ID". Here are the most important "command IDs" for the Command Line Interpreter built inside DL4YHF's Spectrum Lab:
|Command Identifiers for the command line interpreter in DL4YHF's Spectrum Lab|
|CF||Calculate Function (with result returned in response message)|
|EC||Execute Command (no result, will not send a response message)|
A practical example: To stop the spectrum analyser, send the following message..
// Set module ID "CL" + command ID "EC" :
cds.dwData = ('C')+((DWORD)'L'>>8)+((DWORD)'E'>>16)+((DWORD)'C'>>24);
cds.lpData = "spectrum.pause=1"; // command sent to SpecLab's interpreter
cds.cbData = strlen((char*)cds.lpData); // count of bytes in data block
How to send audio streams per WM_COPYDATA is explained in the next chapter.
See also: Spectrum Lab's main index, Spectrum Lab's interpreter commands / send(), interpreter functions (in separate documents).
Note: If possible, do not use this feature, because it is not available under non-windows operating systems; and both sender and receiver must be running on the same PC. Better use one of the UDP or TCP/IP-based methods mentioned here : They allow sending audio over a local network, and even work between PCs running different operating systems (like Windows and Linux).
The first use for this principle was the "winamp-to-SpecLab" plugin; the WM_COPYDATA method was chosen for simplicity.
As explained in the previous chapter, the four bytes (here: four characters) in the dwData parameter of the WM_COPYDATA message must contain the "module identifier" (here: "AU" for audio data), followed by the "command identifier" (here: "SD" = stream data).
Below is the sourcecode of a C function which sends a block of audio samples
through a WM_COPYDATA message (actually taken from audiomsg.c). The
T_AudioMsgBuffer structure contains the audio block, and some information
about the audio stream (like the number of channels, the sampling rate, etc).
It is defined in the file audiomsg.h which is available in the archive
The same data structures are used when sending audio streams via UDP or TCP/IP. An introduction to the sound utilities is here.
Details, header files, and "C" sourcecodes of a simple test application which uses WM_COPYDATA to send a test signal to Spectrum Lab are included in the zipped archive.
See also: Spectrum Lab's main index, Spectrum Lab's interpreter commands, interpreter functions (in separate documents).