                **************************************
                ***   Real Time Sound Comparator   ***
                **************************************
                       V5.5 from September 25 2000


                        The brief description
                        ~~~~~~~~~~~~~~~~~~~~~


 Hardware requirements:
      PENTIUM-133, (MMX strongly recommended)
      SOUND BLASTER 16 (DSP version 4.XX)

 Software requirements:
      DOS-5.0 and higher
  or  DOS session WINDOWS 95/98


The program is designed for real time scale concurrence detection of a 
sound signal with previously recorded patterns.

One of the most attractive features of the program is the sound signal 
monitoring (TV, Radio, Video ads clipping, the advertising announcements 
passing reliability, songs ratings, on air copyrights control etc.).

The program is not designed for announcer verification or speech 
identification purposes. The program does not allocate any slow 
parameters (the main tone frequency, formants etc.) from signals, 
typical for voice identification programs. Therefore the program 
does not impose any typical restrictions on sound fragments (speech, 
music and other sounds).

   One of the following devices can be chosen as the signal source:
       -  Audio Compact Disk (CD).
       -  Microphone.
       -  Linear input of a sound card.
The Linear input could be connected to an external device, 
e.g. a radio receiver, TV-set etc.

The MONO signal is always recorded and compared. This signal is 
automatically extracted from the sound card regardless of it the 
input is from STEREO source.

 It is possible to create up to 255 sound patterns (PCM, 6144 Hz, 
3 sec, MONO each one). Up to 12 patterns can simultaneously be 
compared to the signal; this limit is dependent on the performance 
of the computer used.  The computing capacity with PENTIUM-133 
processor is enough for continuous comparison only with one pattern. 
For comparison with several patterns simultaneously it requires a 
processor with MMX support.

The RECORD option of the main menu allows recording/replacing of 
patterns from one of the signal sources: Microphone, CD or Linear 
input of a sound card. The input signal value is adjustable by using 
the "<" and ">" keys.  Pattern files (patt001.wav to patt255.wav) are 
located in the \Patterns subdirectory.

The ERASE option allows erasing of patterns and appropriate 
\Checks\CheckXXX existing subdirectories.

 The PLAY option allows hearing of recorded patterns.

The REMARK option allows the adding of a description to each pattern 
of up to 32 characters in length.  This description could be used to 
identify the song's name or the channel number during sound signal 
monitoring. The description is also written to the patterns and 
listing.lst log file.

The PERFORMANCE option serves to give an indication of the computing 
performance required to compare a given number of patterns.  The test 
shows the real computer performance in needed requires in terms of 
percentage. The lowest acceptable performance is considered to be 
100%.  From the comparative chart it is clear that at least a 
PENTIUM-133 is required for one pattern comparison and AMD K6-2 333 
for twelve patterns.  When the performance value is less than 100% 
the comparison result will be unreliable.  The performance of the 
comparison calculations can be reduced considerably by any active 
application, therefore it is very important to close all applications 
and disable screen savers before the comparison start.

When COMPARE option is activated, the pattern quality is tested. 
If the 'Sorry, but Your Pattern-XXX is not acceptable... ' message 
is displayed, it is necessary to return to the main menu and record 
the pattern again.  Such a message can be the result of a low signal 
level or partial signal absence during recording procedure.

During the signal comparison stage, the screen will show the correlation 
between the input signal and appropriate pattern.  After exceeding a 
preset threshold the coincidence is recorded - time, date and remark 
of the concurrent pattern are written to the listing.lst log file.
 
The signal source, inputs/outputs signal level control and comparison
threshold value are adjustable in COMPARE option.  However the default
comparison threshold value is optimal. Also, the signal source, inputs/
outputs signals levels and comparison threshold can be set in the
command line by using the options:

/sL - set signal source: LINE INPUT (by default)
/sC - set signal source: CD
/sM - set signal source: MICROPHONE

/vXX - set input  signal value          XX=[0..31] by default=22
/oXX - set output signal value          XX=[0..31] by default=22
/tXX - set comparison threshold level   XX=[0..54] by default=32


Also, it is possible to add a recording check. Any matched pattern 
will be saved in the \Checks\CheckXXX subdirectory, for later review.  
The name of such a file consists of the date and time of the coincidence.
For example:
      file          11081423.wav     was created in November 8, 14:23
              month_//    \\__minute
              day_____//\\____hour

Accordingly, the fragment of the signal that caused the match with 
the first pattern (patt001.wav) are recorded in the subdirectory 
\Checks\Check001, matches with the second pattern (patt002.wav) are 
recorded in \Checks\Check002, etc.  The automatic check files record 
mode is activated using the "C" key in the COMPARE mode or using the /c 
option on command line. By default this mode is switched off (to save 
disk space).

When the program is run in a multitasking environment (DOS-session 
under Windows), task switching by <Alt-Tab> keys may cause the graphics 
screen to be corrupted.  To restore the display press the <F5> key.

If screenshot is necessary, press <F6> key. The comparat.bmp file will
be created (about 153 Kb). It is expedient to transferred in GIF format
by the any graphics editor - so it will decrease about up to 10 Kb.

Starting from version v3.6 the Auto-Exit mode was implemented. This mode 
considerably expands the possibilities of the program and allows 
interaction of the Real Time Sound Comparator with other programs.  
When this mode is switched on and a pattern is matched, the program 
will finish with a return code (ERRORLEVEL) set to the pattern number 
which was matched, [1..255].  Exit from the program by the user (e.g. 
by pressing Esc) always has return code 0 (ERRORLEVEL=0). By analysing 
this return code it is possible to take a decision about starting other 
programs.  Two examples below show using this mode in batch files.

1) The advertising blocks of many TV channels are preceded and ended 
with short lead-ins.  It is possible to replace (cut) the advertising 
blocks by fixing these lead-ins. The batch file below demonstrates 
this simple function of clipping the advertising blocks without the 
necessity to start any external programs:

Each of the files, patt001.wav and patt002.wav, contains fragments 
of the initial and final lead-ins respectively.

@echo off
REM ********** CLIPING ADVERTISING PROGRAM **********

if not exist patterns\patt001.wav goto exit
if not exist patterns\patt002.wav goto exit

:initial
REM Search INITIAL lead-ins (patt001.wav)
REM Output volume  NORMAL (/o22) !!!

compd5_5.exe /sC /p1 /i /a /o22
REM key /sC  - signal source CD
REM key /p1  - compare only with patt001.wav
REM key /i   - compare immediately
REM key /a   - auto-exit mode ON
REM key /o22 - output volume 22/31

IF ERRORLEVEL=1 goto final
goto exit
REM if exit by user

:final
REM Search FINAL lead-ins (patt002.wav)
REM Output volume LOW (/v3) !!!

compd5_5.exe /sC /p2 /i /a /o3
REM key /sC  - signal source CD
REM key /p2  - compare only with patt002.wav
REM key /i   - compare immediately
REM key /a   - auto-exit mode ON
REM key /o3  - output volume 3/31

IF ERRORLEVEL=2 goto initial
:exit
REM if exit by user
REM *************** THE END ***************

The number of patterns of initial and final lead-ins may be increased 
up to twelve.

2) The second example (written by Andrey Epifanov) shows the possibility 
of interaction of the RTSComparator with an external Windows program.  
This batch file causes execution of a recorder, controlled by RTSComparator.  
The external program "TotalRecorder" (http://www.highcriteria.com) is used 
here as the recorder. "TotalRecorder" is convenient since it allows the 
setting of a recording time from the command line and also can set the 
names of a recorded file to the time/date (for each new file).


  @echo off
  REM *** THE PROGRAM OF RECORDIND 10 SECONDS SOUND FRAGMENTS
  REM *** WHEN DETECTION OF THE GIVEN PATTERN (patt001.wav)
  REM *** IS OCCURS

  :begin
  cd comparat    
  REM set current subdirectory
  compd5_5.exe /p1 /sC /i /a
  REM key /p1  - compare only with patt001.wav
  REM key /sC  - signal source CD
  REM key /i   - compare immediately
  REM key /a   - auto-exit mode ON

  if errorlevel=1 goto record
  goto exit

  :record
  "C:\Program Files\HighCriteria\TotalRecorder\TotalRecorder.exe" /R /T:10
  REM key /R    form names of files of time/date
  REM key /T:10 set recording time 10 seconds
  REM other parameters sets and located into the "TotalRecorder" program

  choice /T:Y,15
  REM delay for 15 sec (10 sec for record + 5 sec for task swiching)
  goto begin
  :exit
  REM ******************* THE END *********************

This batch file should be started from DOS shell (for example NC), 
opened in a window.

 Auto-exit mode is switched on by the "A" key in COMPARE mode or by using /a
 key on the command line. By default this mode is switched off.




                    VALID COMMAND STRING OPTIONS
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/sL - set signal source: LINE INPUT (by default)
/sC - set signal source: CD
/sM - set signal source: MICROPHONE
/vXX - set input  signal value             XX=[0..31] by default=22
/oXX - set output signal value             XX=[0..31] by default=22
/tXX - set comparison threshold level      XX=[0..54] by default=32
/pX,.,X- numbers of patterns for comparison X=[1.255]
/i     - comparison immediately
/c     - record check files
/a     - switch auto-exit mode on
/g     - no scroll graphics (for save Performance)

  By default options are: /sL /v22 /o22 /t32
  and the first 12 existing patterns are active.



               SEVERAL TIPS ON SELECTION OF PATTERNS
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Sound cards characteristics depend on the temperature inside the 
computer.  So it is best to wait 30-40 minutes after starting the 
computer before performing any comparisons.  Also it is desirable 
to use the same sound card for record and comparing patterns.

2. In the process of recording the pattern try not to allow signal 
clipping.  The quality of comparison does not depend entirely on the 
amplitude of the compared signals, therefore for reassurance it is 
possible to slightly reduce the input level of the signal being
recorded.

3. Try not to allow absence of a signal or pauses, even on parts of 
the pattern being recorded.

4. When the signal fragment for the pattern is chosen it is necessary 
to take into consideration the sampling rate limitation - 6144 Hz: so, 
the maximum signal frequency (recorded and compared) cannot exceed 
3072 Hz. All signal components higher than this level will be evaluated 
like noise and will reduce correct comparison probability. A certain 
filtration is used in the program to minimize the noise component.

5. Do not use MIDI-music as patterns. Also it is not desirable to 
use recordings of various electronic instruments - they have a good 
autocorrelation characteristic and may cause miscellaneous maximas 
of the correlation function and could result in malfunctioning of 
the comparator.

6. It is better not to choose patterns that contain continually repeated 
sound fragments.  In some cases it may cause false matches.

>From this point of view, voice fragment on the music background would 
be ideal pattern selections.



                     RUNNING THE PROGRAM
                     ~~~~~~~~~~~~~~~~~~~
1. If the program is running in a DOS-session under WINDOWS 95/98, ensure 
that EMS memory is disabled:
          PROPERTIES/MEMORY/EMS: None

2. If the program is running in DOS, it is necessary to include these 
strings in the CONFIG.SYS file:
          DEVICE=C:\path\HIMEM.SYS
          DEVICE=C:\path\EMM386.EXE D=48 NOEMS



                        DISADVANTAGES
                        ~~~~~~~~~~~~~

The main disadvantage of this program is the necessity to have sound 
card supporting the "Sound Blaster 16" standard in DOS. 
(DSP version = 4.XX).  Unfortunately many modern sound cards support 
only "Sound Blaster Pro" standard (DSP version = 3.XX) in DOS.  
Some sound cards provide SB16 compatibility after installation of 
special drivers. See documentation on your card.

When you are running RTSC under DOS it is necessary to be sure that 
the sound card was configured by the program as SBCONFIG.EXE or 
similar, which is usually located in AUTOEXEC.BAT. This program is 
usually delivered together with the card. When DOS-session of 
Windows-9X is used this is not necessary.

The program supports the following settings of a sound card:

            I/O: 220h,240h,260h,280h
            IRQ:   2,5,7,10
            DMA8:  0,1,3
            DMA16: 5,6,7 (or use DMA8)

If other values are sets in the properties of your card, then change 
to these values.

I developed and tested this program with sound cards of the Sound
Blaster 16 standard of the Creative corporation (Vibra 16 and Value)
on ISA bus.
Working with others (partially compatible) cards is not guaranteed.
(..however some users wrote me that they use SB32 on ISA bus..)

To check the program's efficiency the following procedure is 
recommended (For Windows 95/98):
      
 a) - Insert an audio-CD in CD-ROM drive.
 b) - Load the CD-player or other "Universal player".
 c) - Select devices - sound compact disk.
 d) - Select play on the CD-Player.
 e) - Load the "Real Time Sound Comparator" program
 f) - Enter the Main menu. 
 g) - Choose the option PERFORMANCE.
 h) - Ensure that the Performance > 100% for at least one pattern mode.
 i) - Choose the window SIGNAL SOURCE.
 j) - Ensure that the signal's volume is acceptable.
 k) - To record a pattern: Select RECORD Pattern-1.
 l) - To play back the recorded pattern: Select PLAY Pattern-1
 m) - Choose the option COMPARE.
 n) - Switch to the CD-player application by using <Alt>+<Tab> keys.
 o) - Reset the song to the beginning.
 p) - Return back to the "Real Time Sound Comparator" program by
      using <Alt> + <Tab> keys.
 q) - By waiting for the pattern to match you can be sure that the 
      comparison is working correctly.
 r) - Lastly, quit the program and check that the correct pattern was 
      matched by examining the listing.lst file.

 -------------------------------------------------------------
 For registration, and receipt of new versions of this program visit:
                   WWW: http://www.aha.ru/~takomat
                          E-Mail: takomat@aha.ru


 ------------ Limitations of v5.5 Trial version: -------------
 There is a maximum of One Hour of Continuous Comparison.


 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !!!    ALL REGISTERED CUSTOMERS WILL BE PROVIDED     !!!
 !!!  BY LATEST VERSIONS FREE OFF CHARGE  BY E-MAIL   !!!
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


---------------------------Thanks---------------------------------
Great thanks to Lev Lerner (Russia) for help with the program's
design. Also I am grateful to Clever Pereira (Brazil) for valuable
advices, care and support.
Many thanks to Dave Wilson (England) for translation to English.




 History:
 ~~~~~~~
 V2.0 from July 4 1998       (http://www.aha.ru/~takomat/compdemo.zip)
      - first commercial version
      - sampling rate 5632 Hz

 V2.1 from September 2 1998  (http://www.aha.ru/~takomat/compd2_1.zip)
      - "wave" format of patterns files
      - new comparison scale
      - increase comparison quality
      - volume & comparison threshold control
      - some small enhancements

 V2.2 from November 10 1998  (http://www.aha.ru/~takomat/compd2_2.zip)
      - sampling rate is increased up to 6144 Hz
      - change the SIGNAL SOURCE option
      - the possibility of record of check files is entered
      - some small enhancements
      - the possibility in trial version to work with the several
        patterns
      - fixed some bugs

 V3.0 from February 1 1999   (http://www.aha.ru/~takomat/compd3_0.zip)
      - 16-bit signals quantization (before it was 8-bit)
      - performance was increased
      - up to four patterns can simultaneously be compared
      - response time - less 45 ms
      - increased comparison quality
      - new graphic interface

 V3.5 from February 23 1999  (http://www.aha.ru/~takomat/compd3_5.zip)
      - performance was increased
      - up to five patterns can be simultaneously compared
      - fixed some bugs

 V3.6 from March 24 1999     (http://www.aha.ru/~takomat/compd3_6.zip)
      - auto-exit mode was entered
      - command string options is now available
      - remarks of patterns are now recorded into the patterns files
      - some small enhancements

 V4.0 from August 2 1999     (http://www.aha.ru/~takomat/compd4_0.zip)
      - up to twelve patterns can be simultaneously compared
      - remark field was increased from 15 up to 19 symbols
      - names (with them paths) of Check-files are now recorded into
        the listing.lst log file
      - some bugs fixed and enhancements.

 V5.0 from May 27 2000       (http://www.aha.ru/~takomat/compd5_0.zip)
      - some bugs fixed
      - database up to 255 patterns supporting
      - mouse support
      - improved interface
      - the possibility of erase of pattern files from main menu
      - remark field was increased from 19 up to 32 symbols
      - russian language support
      - help is added

 V5.5 from September 25 2000 (http://www.aha.ru/~takomat/compd5_5.zip)
      - about ten bugs fixed
      - improve engine (+ 15..35 % of performance)
      - add Output volume control (with command string key)
      - possibility screenshots creation
      - vertical synchronization
      - some other enhancements





                                 Russia, Moscow, September 25, 2000
                                                      Eugene Efimov
