home *** CD-ROM | disk | FTP | other *** search
- //┌───────────────────────────────────────────────────────────────────────┐
- //│ NOHISS: Digital Noise Reduction v1.0 (C) Copyright 1991 Andy Hakim │
- //├───────────────────────────────────────────────────────────────────────┤
- //│ │
- //│ Internet E-Mail: andyh@menudo.uh.edu (starting May 1992) │
- //│ st144@menudo.uh.edu │
- //│ st144@simpsons.cc.uh.edu (NeXT voice mail) │
- //│ cosc12r2@jetson.uh.edu │
- //│ │
- //│ Mail: NOHISS Development │
- //│ P.O. Box 70392 │
- //│ Houston, TX 77270-0392 │
- //│ │
- //│ Phone: (713) 880-3059 │
- //│ │
- //│ BBS: Sands PC Board (713)-961-1604 │
- //│ │
- //│ Compilation Specs: Borland C++ v2.0 (small model) │
- //│ BCC -ms sbcs.lib nohiss.c │
- //├───────────────────────────────────────────────────────────────────────┤
- //│I am making the Nohiss source code available to the public to │
- //│facilitate non-commercial programming for Soundblaster compatible │
- //│cards. Please observe the following conditions: │
- //│ │
- //│* If you borrow extensively from it, "do the right thing" and give │
- //│ credit where it is due. │
- //│ │
- //│* If you want to use it for commercial purposes, contact me. │
- //└───────────────────────────────────────────────────────────────────────┘
-
- #if !defined(__MSDOS__)
- #error OS is not MS-DOS
- #endif
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ INCLUDES │//
- //└───────────────────────────────────────────────────────────────────────┘//
- #include <dir.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <conio.h>
- #include <dos.h>
- #include <bios.h>
- #include <fcntl.h>
- #include <io.h>
- #include <sbc.h>
- #include <sbcvoice.h>
- #include "nohiss.fnt" // New fonts
- #include "vga.fnt" // old fonts
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ DEFINES/ENUMS │//
- //└───────────────────────────────────────────────────────────────────────┘//
- #define DEFAULT_OFFSET 0xAA8A
-
- enum { OFF, ON };
- enum { NO, YES };
- enum { SOU, VOC, S32, SND };
- enum { FALSE, TRUE };
- enum { BIOS, MDA, CGA, EGA, VGA };
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ GLOBAL VARIABLES │//
- //└───────────────────────────────────────────────────────────────────────┘//
- typedef struct
- {
- char nr_factor;
- unsigned minimum;
- unsigned maximum;
- unsigned duration;
- long length;
- char fancy;
- char process;
- char playfile;
- char overwrite;
- unsigned sbport;
- char endpause;
- } DEFAULTS;
- //.........................................................................
- DEFAULTS D = {100, 118, 138, 3600, 200, YES, YES, 3, NO, 0x220, YES};
- DEFAULTS FACTORY = {100, 118, 138, 3600, 200, YES, YES, 3, NO, 0x220, YES};
- //.........................................................................
- long filesize;
- long changes;
- char input_file[64]="",
- output_file[64]="",
- ftype;
- unsigned char chunk[0x8000];
- unsigned char savescreen[7*80*2]={255};
- char buffer[81];
- //.........................................................................
- unsigned
- VIDBASE=0xB800;
-
- char bclr = 7,
- hbclr = 15,
- sbclr = 7,
- ybclr = 14,
- bbclr = 128,
- VCARD = NO,
- SPINYPOS = 3,
- ABORT = NO;
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ PROTOTYPES │//
- //└───────────────────────────────────────────────────────────────────────┘//
- long fsize(char *filename);
- long voc_frequency(char *filename);
-
-
- //┌───────────────────────────────────────────────────────────────────────┐
- //│ QTOOLS.H: detects video card (similar to BC detect_graph) │
- //└───────────────────────────────────────────────────────────────────────┘
- detect_gr_card()
- {
- char card;
- card = CGA; // default card type
- _AX = 0x0F00;
- asm int 0x10;
- if (_AL == 7) return MDA; // checks mono mode
- _AX = 0x1200;
- _BX = 0xFF10;
- asm int 0x10;
- if (_BH != 0xFF) card = EGA; // check for a function that
- _AX = 0x1A00; // only EGA+ can do
- asm int 0x10;
- if (_AL == 0x1A) card = VGA; // check for a function that
- return card; // only VGA+ can do
- }
-
-
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ QTOOLS.H: EGA/VGA blinking attribute changer │
- //└───────────────────────────────────────────────────────────────────────┘//
- qblink (char on_off)
- {
- if (VCARD < EGA) return;
- asm mov ax, 0x1003;
- asm mov bl, on_off;
- asm int 0x10;
- return;
- }
-
-
-
- //┌───────────────────────────────────────────────────────────────────────┐
- //│ QTOOLS.H: Initializes Qvideo system │
- //└───────────────────────────────────────────────────────────────────────┘
- init_video()
- {
- VCARD = detect_gr_card();
- if (VCARD == MDA) VIDBASE=0xB000;
- else VIDBASE=0xB800;
- if (VCARD == MDA || VCARD == CGA)
- {
- bclr = 7;
- hbclr = 15;
- sbclr = 7;
- ybclr = 14;
- bbclr = 128;
- }
- else
- {
- bclr = 128+7;
- hbclr = 128+15;
- sbclr = 128;
- ybclr = 128+14;
- bbclr = 128+1;
- }
- return;
- }
-
-
-
- //┌───────────────────────────────────────────────────────────────────────┐
- //│ QTOOLS.H: Set screen font │
- //└───────────────────────────────────────────────────────────────────────┘
- setfont(char *font, unsigned size)
- {
- if (VCARD < EGA) return;
- _CX=size/16;
- _ES = FP_SEG(font);
- _BP = FP_OFF(font);
- _BH=16;
- _BL=0;
- _DX=128;
- _AX=0x1100;
- asm int 0x10;
- return;
- }
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ │//
- //└───────────────────────────────────────────────────────────────────────┘//
- close_video()
- {
- if (VCARD < EGA) return;
- if (*savescreen != 255)
- movedata (_DS, FP_OFF(savescreen), (unsigned)VIDBASE, 0, (7*80*2));
- setfont(vgafont, sizeof(vgafont));
- _setcursortype (_NORMALCURSOR);
- qblink(1);
- return;
- }
-
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ QTOOLS.H: Quickprint direct screen writing routine │//
- //└───────────────────────────────────────────────────────────────────────┘//
- qprintf (char *txt, char x, char y, unsigned int color)
- {
- unsigned int far *screen;
- //.........................................................................
- x--; y--;
- if (strlen(txt)>80) *(txt+79) = 0;
- color <<= 8;
- screen = MK_FP(VIDBASE, y*160+x*2);
- while (*txt)
- {
- *screen = color + (unsigned char)*txt;
- screen++;
- txt++;
- }
- return;
- }
-
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ SPINNER: 1 = square 2 = circle 3 = bios star 4 = erase │//
- //└───────────────────────────────────────────────────────────────────────┘//
- spinner(char type, char x, char y, char color)
- {
- static char index;
- static clock_t start;
- //.........................................................................
- if (VCARD < EGA) return;
- if ((clock()-start) / CLK_TCK > 0.03)
- {
- start = clock();
- index++;
- }
- else return;
- if (VCARD == MDA || VCARD == CGA) type = 3;
- if (type==1)
- {
- if (index == 1) qprintf ("äÇ", x, y, color); else
- if (index == 2) qprintf ("àü", x, y, color); else
- if (index == 3) qprintf ("åé", x, y, color); else
- if (index == 4) qprintf ("çâ", x, y, color);
- if (index >= 4) index=0;
- }
- else
- if (type==2)
- {
- if (index == 5) qprintf ("£¥", x, y, color); else
- if (index == 10) qprintf ("₧ƒ", x, y, color);
- if (index >= 10) index=0;
- }
- else
- if (type==3)
- {
- if (index == 1) qprintf ("-", x, y, color); else
- if (index == 2) qprintf ("\\", x, y, color); else
- if (index == 3) qprintf ("|", x, y, color); else
- if (index == 4) qprintf ("/", x, y, color);
- if (index >= 4) index=0;
- }
- if (type==4)
- {
- qprintf (" ", x, y, color);
- index = 0;
- }
- return;
- }
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ Displays the background stuff on the screen │//
- //└───────────────────────────────────────────────────────────────────────┘//
- screen_prep()
- {
- char drive[MAXDRIVE];
- char dir[MAXDIR];
- char file[MAXFILE];
- char ext[MAXEXT];
- char i;
- //.........................................................................
- textcolor (7);
- textbackground (0);
- if (VCARD < EGA) return;
-
- qblink (0);
- _setcursortype (_NOCURSOR);
-
- movedata ((unsigned)VIDBASE, 0, _DS, FP_OFF(savescreen), (7*80*2));
-
- setfont(newfont, sizeof(newfont));
-
- qprintf (" áí Digital Noise Reduction v1.0 ", 1, 1, 112);
- qprintf ("êìë ìùÿ¢ÖôæÆÜ èïïè îûÉ¢ ÄÅöôò ", 51, 1, 120);
-
- memset (buffer, 32, 80);
- *(buffer+80)=0;
- for (i=2; i<=6; i++) qprintf (buffer, 1, i, 128);
-
- memset (buffer, 223, 80);
- qprintf (buffer, 1, 7, 7);
- show_keys();
-
- qprintf ("Input file:", 5, 3, 135);
- qprintf ("Output file:", 5, 4, 135);
- qprintf ("Processing:", 39, 3, 135);
- qprintf ("▐", 50, 3, 142);
- qprintf (" ", 51, 3, 224);
-
- strlwr (input_file);
- fnsplit(input_file, drive, dir, file, ext);
- strcpy (buffer, file);
- strcat (buffer, ext);
- qprintf (buffer, 17, 3, 135);
-
- strlwr (output_file);
- fnsplit(output_file, drive, dir, file, ext);
- strcpy (buffer, file);
- strcat (buffer, ext);
- qprintf (buffer, 18, 4, 135);
-
- return;
- }
-
-
- show_header()
- {
- printf ("\nDigital Noise Reduction v1.0 (C) Copyright 1991 Andy Hakim\n");
- printf ("──────────────────────────────────────────────────────────────────────────────\n");
- return;
- }
- //┌───────────────────────────────────────────────────────────────────────┐
- //│ Displays error messege │
- //└───────────────────────────────────────────────────────────────────────┘
- show_error(char errnum, char *info)
- {
- char errmsg[][60] =
- {
- "1: Invalid command line option",
- "2: Input file not found",
- "3: VOC file compressed",
- "4: VOC file corrupt/unsupported format",
- "5: File read error",
- "6: File write error/Disk full?",
- "7: Output file same as input file",
- "8: Option value out of bounds",
- "9: Cannot access program file",
- "10: Soundblaster playback error",
- "11: Soundblaster interrupt error",
- "12: Soundblaster not installed or wrong IO port",
- "13: (User abort)",
- "14: Unauthorized modification of program file"
- };
- //.........................................................................
- fcloseall();
- if (VCARD < EGA) printf ("\n");
- remove (output_file);
- close_video();
- if (errnum == 13) exit(13);
- printf ("Error #");
- if (*info) printf ("%s: %s\n\n", errmsg[--errnum], info);
- else
- printf ("%s\n\n", errmsg[--errnum]);
- printf ("Type NOHISS /? or see NOHISS.DOC for more information\n");
- exit(++errnum);
- return;
- }
-
-
-
- //┌───────────────────────────────────────────────────────────────────────┐
- //│ Converts integer to time │
- //└───────────────────────────────────────────────────────────────────────┘
- int2time(unsigned x, char *txt)
- {
- char tmp[5];
- sprintf (tmp, "%02d:", x / 3600);
- strcpy (txt, tmp);
- sprintf (tmp, "%02d:", (x % 3600) / 60);
- strcat (txt, tmp);
- sprintf (tmp, "%02d", (x % 3600) % 60);
- strcat (txt, tmp);
- return;
- }
-
-
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ SB Disk Play │//
- //└───────────────────────────────────────────────────────────────────────┘//
- sb_disk_play (char *filename)
- {
- ct_io_addx = D.sbport;
- if (sbc_check_card() & 4)
- {
- if (sbc_scan_int())
- {
- if (!ctvd_init(16))
- {
- play_file (filename);
- ctvd_terminate () ;
- }
- else show_error (10, ""); // sb driver
- }
- else show_error (11, ""); // interrupt
- }
- else show_error (12, ""); // no sb present
- if (ABORT) show_error (13, ""); // user pressed ESC
- return;
- }
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ │//
- //└───────────────────────────────────────────────────────────────────────┘//
- play_file (char *filename)
- {
- int handle ;
- if (VCARD >= EGA)
- {
- sprintf (buffer, "%ld Hertz ", voc_frequency(filename));
- qprintf ("Frequency: ", 5, 5, 135);
- qprintf (buffer, 16, 5, 135);
- }
- handle = open(filename, O_RDONLY);
- ctvd_speaker (1);
- if (ctvd_output(handle) == NO_ERROR)
- {
- play_voice_in_bkgnd(handle);
- if (ctvd_drv_error()) show_error (10, "");
- }
- close (handle);
- return;
- }
-
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ │//
- //└───────────────────────────────────────────────────────────────────────┘//
- show_keys()
- {
- qprintf (" ESC ", 0+20, 7, 113);
- qprintf ("exit ", 6+20, 7, 112);
- qprintf (" ENTER ", 11+20, 7, 113);
- qprintf ("skip ", 18+20, 7, 112);
- qprintf (" SPACE ", 23+20, 7, 113);
- qprintf ("pause ", 30+20, 7, 112);
- return;
- }
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ │//
- //└───────────────────────────────────────────────────────────────────────┘//
- play_voice_in_bkgnd (int handle)
- {
- char x,y, pct, ch;
- char time[10];
- clock_t temp, start, end, elapsed = 0;
-
- start = end = clock();
- if (VCARD >= EGA)
- {
- show_bar (0);
- qprintf ("Elapsed:", 42, 5, 135);
- }
- filesize = filelength(handle);
- while (ct_voice_status && (end-start)/CLK_TCK <= D.duration+1)
- {
- spinner (2-(SPINYPOS-3), 2, SPINYPOS, 140);
- end = clock();
- if (((end-start)/CLK_TCK) - ((elapsed)/CLK_TCK) > 1)
- {
- elapsed=end-start;
- pct = (tell(handle) * 100) / filesize;
- int2time ((unsigned)(elapsed/CLK_TCK), time);
- if (VCARD < EGA)
- {
- _setcursortype(_NOCURSOR);
- x = wherex();
- y = wherey();
- printf ("[%d%%]", pct);
- printf (" %s", time);
- gotoxy (x,y);
- _setcursortype(_NORMALCURSOR);
- }
- else {
- show_bar (pct);
- qprintf (time, 51, 5, 135);
- sprintf (time, "[%d%%] ", pct);
- qprintf (time, 61, 5, 135);
- }
- }
- if (kbhit())
- {
- ch = getch();
- if (ch == 13 || ch == 27) break;
- if (ch == 32)
- {
- temp = clock();
- pause();
- start += clock()-temp;
- }
- }
- }
- ctvd_stop();
- if (ch == 27) ABORT = YES;
- if (VCARD < EGA)
- {
- printf ("[%d%%]", (tell(handle) * 100) / filesize);
- int2time ((unsigned)(elapsed/CLK_TCK), time);
- printf (" %s", time);
- printf ("\n");
- }
- return;
- }
-
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ │//
- //└───────────────────────────────────────────────────────────────────────┘//
- pause ()
- {
- ctvd_pause();
- if (VCARD >= EGA)
- {
- qprintf (" SPACE continue ", 20, 7, 112);
- qprintf ("SPACE", 32, 7, 113);
- }
- getch();
- if (VCARD >= EGA) show_keys();
- ctvd_continue();
- return;
- }
-
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ │//
- //└───────────────────────────────────────────────────────────────────────┘//
- show_bar (char percent)
- {
- char graph[30];
- char VGAdetail[]=" óúñ";
- char EGAdetail[]=" ªº¿";
- char solids;
- char *ptr;
-
- if (VCARD==EGA) ptr=EGAdetail; else ptr=VGAdetail;
- percent = percent * 0.84;
- memset (graph, 0, sizeof(graph));
- memset (graph, 32, 28);
- memset (graph, *(ptr+3), percent / 3);
- if ((percent % 3) > 0) memset (graph+(percent/3), *(ptr+percent%3), 1);
- qprintf (graph, 51, 3, 224);
- return;
- }
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ │//
- //└───────────────────────────────────────────────────────────────────────┘//
- fprint_pct(FILE *handle)
- {
- char x,y;
- char pct;
-
- pct = (ftell(handle) * 100) / filesize;
- if (VCARD >= EGA) { show_bar (pct); return; }
- x = wherex();
- y = wherey();
- printf ("[%d%%]", pct);
- gotoxy (x,y);
- return;
- }
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ │//
- //└───────────────────────────────────────────────────────────────────────┘//
- long voc_frequency(char *filename)
- {
- FILE *fin;
- VOCHDR VH;
- long type_size, size;
- char type, frequency;
- long freq;
- //.........................................................................
- freq = 0;
- if ((fin = fopen (filename, "rb")) == NULL) show_error(2, input_file);
- if (fread (&VH, sizeof(VH), 1, fin) == 0) show_error(5, input_file);
- if (fseek (fin, VH.voice_offset, SEEK_SET) != 0) show_error(5, input_file);
- while (!feof(fin))
- {
- if (fread (&type_size, 4, 1, fin) == 0 && !feof(fin)) show_error(5, input_file);
- type = type_size & 0x000000FF;
- size = type_size >> 8;
- if (type == 0) break;
- if (feof(fin)) break;
- if (type == 1)
- {
- fread (&frequency, 1, 1, fin);
- freq = 1000000/(256-(unsigned char)frequency);
- break;
- }
- if (fseek (fin, size, SEEK_CUR) != 0) show_error (5, input_file);
- }
- fclose(fin);
- return freq;
- }
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ │//
- //└───────────────────────────────────────────────────────────────────────┘//
- process_VOC()
- {
- FILE *fin, *fout;
- VOCHDR VH;
- long amount, type_size, size;
- char type, compression, frequency;
- //.........................................................................
- if ((fin = fopen (input_file, "rb")) == NULL) show_error(2, input_file);
- if ((fout = fopen (output_file, "wb")) == NULL) show_error (6, output_file);
- if (fread (&VH, sizeof(VH), 1, fin) == 0) show_error(5, input_file);
- if (fwrite (&VH, sizeof(VH), 1, fout) == 0) show_error(6, output_file);
- if (fseek (fin, VH.voice_offset, SEEK_SET) != 0) show_error(5, input_file);
- if (fseek (fout, VH.voice_offset, SEEK_SET) != 0) show_error(6, output_file);
- while (!feof(fin))
- {
- if (kbhit())
- if (getch() == 27) show_error(13, "");
- if (fread (&type_size, 4, 1, fin) == 0 && !feof(fin)) show_error(5, input_file);
- type = type_size & 0x000000FF;
- size = type_size >> 8;
- if (type == 0) break;
- if (fwrite (&type_size, 4, 1, fout) == 0) show_error(6, input_file);
- if (feof(fin)) break;
- if (type == 1)
- {
- fread (&frequency, 1, 1, fin);
- fwrite (&frequency, 1, 1, fout);
- size--;
- fread (&compression, 1, 1, fin);
- fwrite (&compression, 1, 1, fout);
- size--;
- }
- if (type <= 2 && compression != 0) show_error (3, input_file);
- while (size > 0)
- {
- fprint_pct(fin);
- amount = min (size, sizeof(chunk));
- if (fread (chunk, amount, 1, fin) == 0) show_error(4, input_file);
- if (type <= 2) hiss (chunk, amount);
- if (fwrite (chunk, amount, 1, fout) == 0) show_error(6, input_file);
- size -= amount;
- }
- }
- fputc (0, fout);
- fprint_pct(fin);
- fcloseall();
- if (VCARD < EGA) printf (" \n");
- return;
- }
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ │//
- //└───────────────────────────────────────────────────────────────────────┘//
- process_8()
- {
- FILE *fin, *fout;
- long amount, size, position;
- //.........................................................................
- size = fsize (input_file);
- if ((fin = fopen (input_file, "rb")) == NULL) show_error(5, input_file);
- if ((fout = fopen (output_file, "wb")) == NULL) show_error (6, output_file);
- if (ftype != SOU)
- {
- if (ftype == S32) amount = 32;
- if (ftype == SND) amount = 126;
- fread (&chunk, amount, 1, fin);
- fwrite (&chunk, amount, 1, fout);
- }
- size -= amount;
- while (feof(fin)==0 && size > 0)
- {
- if (kbhit())
- {
- if (getch() == 27) show_error(13, "");
- }
- while (size > 0)
- {
- fprint_pct(fin);
- amount = min (size, sizeof(chunk));
- if (fread (chunk, amount, 1, fin) == 0) show_error(4, input_file);
- hiss (chunk, amount);
- if (fwrite (chunk, amount, 1, fout) == 0) show_error(6, input_file);
- size -= amount;
- }
- }
- fprint_pct(fin);
- fcloseall();
- if (VCARD < EGA) printf (" \n");
- return;
- }
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ HISS REMOVAL │//
- //└───────────────────────────────────────────────────────────────────────┘//
- hiss(unsigned char *chunk, unsigned size)
- {
- unsigned x, t, ok;
- for (x = 0; x <= size;)
- {
- ok = YES;
- for (t = 0; t <= D.length; t++)
- if ((x+t < size) &&
- ((*(chunk+x+t) < D.minimum) || (*(chunk+x+t) > D.maximum))) ok = NO;
- if (ok)
- {
- for (t = 0; t <= D.length; t++)
- if (x+t < size) *(chunk+x+t) = (((*(chunk+x+t)-0x80) * D.nr_factor) / 100)+0x80;
- changes += t;
- }
- x += t;
- sprintf (buffer, "Changes: %ld samples [%d%%]", changes, changes * 100 / filesize);
- if (VCARD >= EGA) qprintf (buffer, 42, 4, 135);
- }
- return;
- }
-
-
- //┌───────────────────────────────────────────────────────────────────────┐
- //│ │
- //└───────────────────────────────────────────────────────────────────────┘
- fsavedefaults(char *filename)
- {
- FILE *test;
- char status;
-
- if ((test = fopen (filename, "rb+")) != NULL)
- {
- printf ("Saving new defaults to %s\n", filename);
- fseek (test, DEFAULT_OFFSET, SEEK_SET);
- fwrite (&D, sizeof(D), 1, test);
- }
- else show_error (9, filename);
- fclose (test);
- return status;
- }
-
-
- //┌───────────────────────────────────────────────────────────────────────┐
- //│ │
- //└───────────────────────────────────────────────────────────────────────┘
- fcheckdefaults(char *filename)
- {
- FILE *test;
- DEFAULTS check;
- char status;
- if ((test = fopen (filename, "rb")) != NULL)
- {
- fseek (test, DEFAULT_OFFSET, SEEK_SET);
- fread (&check, sizeof(check), 1, test);
- }
- else show_error (7, filename);
- if (memcmp (&D, &check, sizeof(D)) != 0) show_error(14, "");
- fclose (test);
- return status;
- }
-
-
- //┌───────────────────────────────────────────────────────────────────────┐
- //│ QTOOLS.H: File exists? │
- //└───────────────────────────────────────────────────────────────────────┘
- fexist(char *filename)
- {
- FILE *test;
- char status;
- status = 0;
- if ((test = fopen (filename, "rb")) == NULL) status = 1;
- fclose (test);
- return status;
- }
-
-
- //┌───────────────────────────────────────────────────────────────────────┐
- //│ │
- //└───────────────────────────────────────────────────────────────────────┘
- long fsize(char *filename)
- {
- FILE *test;
- long size = 0;
- if ((test = fopen (filename, "rb")) != NULL)
- {
- fseek (test, 0, SEEK_END);
- size = ftell(test);
- }
- fclose (test);
- return size;
- }
-
-
- //┌───────────────────────────────────────────────────────────────────────┐
- //│ Returns 1 for 32byte SND, 2 for 126byte SND, and 0 otherwise │
- //└───────────────────────────────────────────────────────────────────────┘
- is_SND(char *filename)
- {
- char drive[MAXDRIVE];
- char dir[MAXDIR];
- char file[MAXFILE];
- char ext[MAXEXT];
- FILE *test;
- char buffer[6];
- char status;
-
- status = 0;
- fnsplit(filename, drive, dir, file, ext);
- if (strcmp (strlwr(ext), "snd")) status = S32;
- if ((test = fopen (filename, "rb")) != NULL)
- {
- fread (&buffer, sizeof(buffer), 1, test);
- if (memcmp (buffer, "SOUND", 5) == 0) status = SND;
- }
- fclose (test);
- return status;
- }
-
-
- //┌───────────────────────────────────────────────────────────────────────┐
- //│ │
- //└───────────────────────────────────────────────────────────────────────┘
- is_VOC(char *filename)
- {
- VOCHDR VH;
- FILE *test;
- char status;
- status = 0;
- if ((test = fopen (filename, "rb")) != NULL)
- {
- fread (&VH, sizeof(VH), 1, test);
- if (memcmp (VH.id, "Creative Voice File", 19) == 0) status = 1;
- }
- fclose (test);
- return status;
- }
-
-
- //┌───────────────────────────────────────────────────────────────────────┐
- //│ │
- //└───────────────────────────────────────────────────────────────────────┘
- fname_inprep (char *filename)
- {
- char status;
- char name[64];
- strupr(filename);
- strcpy (name, filename);
- status = fexist (name);
- if (status)
- {
- strcat (name, ".VOC");
- status = fexist (name);
- }
- if (status)
- {
- strcpy (name, filename);
- strcat (name, ".SOU");
- status = fexist (name);
- };
- if (status)
- {
- strcpy (name, filename);
- strcat (name, ".SND");
- status = fexist (name);
- };
- if (!status)
- {
- strcpy (filename, name);
- filesize = fsize(filename);
- }
- return status;
- }
-
-
- //┌───────────────────────────────────────────────────────────────────────┐
- //│ │
- //└───────────────────────────────────────────────────────────────────────┘
- fname_outprep (char *filename)
- {
- char t;
- strupr(filename);
- if (*filename == 0) strcat (filename, "(NONE)");
- else
- if ((strstr(filename, ".") == NULL) &&
- (strstr(filename, ".VOC") == NULL) &&
- (strstr(filename, ".SND") == NULL) &&
- (strstr(filename, ".SOU") == NULL))
- {
- if (ftype == VOC) strcat (filename, ".VOC");
- if (ftype == SOU) strcat (filename, ".SOU");
- if (ftype == S32) strcat (filename, ".SND");
- if (ftype == SND) strcat (filename, ".SND");
- }
- if (strcmp(filename, input_file)==0) show_error (7, input_file);
- if (fexist (filename)==0 && D.overwrite==NO && D.process==YES)
- {
- printf ("Overwrite %s? (Y or [N]) ", filename);
- t = getche(); printf("\n");
- if (t != 'Y' && t != 'y') exit(4);
- }
- return;
- }
-
-
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ Shows help screen │//
- //└───────────────────────────────────────────────────────────────────────┘//
- show_help()
- {
- char help_text[][81]=
- {
- "Usage:\n NOHISS <inputfile[.ext]> [outputfile[.ext]] [options]\n\n",
- "Options: Defaults\n",
- " /NR=# Noise reduction level %d percent\n",
- " /SIZE=# Minimum duration of hiss %d samples\n",
- " /RANGE=# Hiss spectrum (0 to 254) %d units\n",
- " /MIN=# Hiss lower limit (-127 to +127) %d units\n",
- " /MAX=# Hiss upper limit (-127 to +127) %d units\n",
- " /[NO]FANCY Screen display type %s\n",
- " /[NO]OVER Overwrite output file %s\n",
- " /[NO]PROCESS Noise processor mode %s\n",
- " /[NO]PAUSE Pause after playback %s\n",
- " /[NO]PLAY[I][O] Playback mode (none, in, out) %s\n",
- " /TIME=# Playback timer %d seconds\n",
- " /PORT=# Soundblaster IO port number %x hex\n",
- " /SAVE Save new defaults to NOHISS.EXE\n",
- " /RESET Reset factory defaults in NOHISS.EXE\n\n",
- " Samples may be VOC, SND, SOU or any 8-bit raw data\n"
- };
- show_header();
- printf (help_text[0]);
- printf (help_text[1]);
- printf (help_text[2], D.nr_factor);
- printf (help_text[3], D.length);
- printf (help_text[4], D.maximum-D.minimum);
- printf (help_text[5], D.minimum-128);
- printf (help_text[6], D.maximum-128);
- printf (help_text[7], (D.fancy ? "FANCY" : "NOFANCY"));
- printf (help_text[8], (D.overwrite ? "OVER" : "NOOVER"));
- printf (help_text[9], (D.process ? "PROCESS" : "NOPROCESS"));
- printf (help_text[10], (D.endpause ? "PAUSE" : "NOPAUSE"));
- if (D.playfile == 1) printf (help_text[11], "PLAYI");
- else if (D.playfile == 2) printf (help_text[11], "PLAYO");
- else if (D.playfile == 3) printf (help_text[11], "PLAYIO");
- else printf (help_text[11], "NOPLAY");
- printf (help_text[12], D.duration);
- printf (help_text[13], D.sbport);
- printf (help_text[14]);
- printf (help_text[15]);
- printf (help_text[16]);
- exit(0);
- return;
- }
-
-
- //┌────────────────────────────────────────────────────────────────────────┐
- //│ Parses command line arguements │
- //│ Note: the **argv != NULL method is not stable under COMPACT & > models │
- //│ it is better to have a loop of n=argc │
- //└────────────────────────────────────────────────────────────────────────┘
- parse_args(char argc, char *argv[])
- {
- int value;
- char save = NO;
- char help = NO;
- char *prgname=argv[0];
- fcheckdefaults(prgname);
- if (argc == 1) show_help();
- for (argv++; argc > 1; argc--, argv++)
- {
- strlwr (*argv);
- if (**argv == '-') **argv = '/';
- if (!memcmp("/range=", *argv, 7))
- {
- D.minimum = 128 - (atoi((*argv)+7)/2);
- D.maximum = 128 + (atoi((*argv)+7)/2);
- }
- else if (!memcmp("/nr=", *argv, 4)) D.nr_factor = atol((*argv)+4);
- else if (!memcmp("/size=", *argv, 6)) D.length = atol((*argv)+6);
- else if (!memcmp("/s=", *argv, 3)) D.length = atol((*argv)+3);
- else if (!memcmp("/time=", *argv, 6)) D.duration = atol((*argv)+6);
- else if (!memcmp("/t=", *argv, 3)) D.duration = atol((*argv)+3);
- else if (!memcmp("/port=", *argv, 6)) sscanf((*argv)+6, "%x", &D.sbport);
- else if (!memcmp("/p=", *argv, 3)) sscanf((*argv)+3, "%x", &D.sbport);
- else if (!memcmp("/s", *argv, 2)) save = YES;
- else if (!memcmp("/nopr", *argv, 5)) D.process = 0;
- else if (!memcmp("/pause", *argv, 6)) D.endpause = YES;
- else if (!memcmp("/nopause",*argv, 8)) D.endpause = NO;
- else if (!memcmp("/nofancy",*argv, 8)) D.fancy = NO;
- else if (!memcmp("/fancy", *argv, 6)) D.fancy = YES;
- else if (!memcmp("/noplay", *argv, 7)) D.playfile = 0;
- else if (!memcmp("/playio", *argv, 7)) D.playfile = 3;
- else if (!memcmp("/playoi", *argv, 7)) D.playfile = 3;
- else if (!memcmp("/playi", *argv, 6)) D.playfile = 1;
- else if (!memcmp("/playo", *argv, 6)) D.playfile = 2;
- else if (!memcmp("/min=", *argv, 5)) D.minimum = 128+atoi((*argv)+5);
- else if (!memcmp("/max=", *argv, 5)) D.maximum = 128+atoi((*argv)+5);
- else if (!memcmp("/r", *argv, 2)) {D = FACTORY; save=YES;}
- else if (!memcmp("/noover", *argv, 7)) D.overwrite = NO;
- else if (!memcmp("/o", *argv, 2)) D.overwrite = YES;
- else if (!memcmp("?", *argv, 1)) help = YES;
- else if (!memcmp("/?", *argv, 2)) help = YES;
- else if (!memcmp("/h", *argv, 2)) help = YES;
- else if (**argv != '/')
- {
- if (!*input_file) strcpy (input_file, *argv);
- else if (!*output_file) strcpy (output_file, *argv);
- }
- else show_error(1, *argv);
- }
-
- if ((D.minimum < 1) || (D.minimum > 255) ||
- (D.maximum < 1) || (D.maximum > 255)) show_error (8, "/RANGE from 2 to 254");
- if (D.minimum >= D.maximum) show_error (8, "Minimum must be smaller than maximum");
- if (D.length < 1 || D.length > 32000) show_error (8, "/SIZE from 1 to 32000");
- if (D.nr_factor < 0 || D.nr_factor > 100) show_error (8, "/NR from 0 to 100");
- if (save) fsavedefaults(prgname);
- if (help) show_help();
- if (*input_file==0 && save) exit(2);
- D.nr_factor = 100-D.nr_factor;
- return;
- }
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ │//
- //└───────────────────────────────────────────────────────────────────────┘//
- process()
- {
- if (fname_inprep(input_file)) show_error(2, input_file);
- ftype = is_VOC(input_file);
- if (ftype != VOC) ftype = is_SND(input_file);
- fname_outprep(output_file);
- screen_prep();
- if (D.process)
- {
- if (VCARD < EGA)
- {
- printf ("Processing output file: %s ", output_file);
- }
- else {
- qprintf ("Sample count: ", 5, 5, 135);
- sprintf (buffer, "%ld", fsize (input_file));
- qprintf (buffer, 19, 5, 135);
- }
- if (ftype==VOC) process_VOC(); else process_8();
- sprintf (buffer, "Changes: %ld samples [%d%%]", changes, changes * 100 / filesize);
- if (VCARD < EGA)
- printf ("Reduction changes: %ld samples, affecting %d%% of file\n", changes, changes * 100 / filesize);
- else qprintf (buffer, 42, 4, 135);
- }
- if (ftype == VOC)
- {
- if (D.playfile == 3 || D.playfile == 1)
- {
- if (VCARD < EGA) printf ("Playing input file: %s ", input_file);
- else qprintf (" Playing:", 39, 3, 135);
- sb_disk_play (input_file);
- if (VCARD >= EGA) spinner (4, 2, SPINYPOS, 135);
- }
- if ((D.playfile == 3 || D.playfile == 2) && (!fexist (output_file)))
- {
- SPINYPOS++;
- if (VCARD < EGA) printf ("Playing output file: %s ", output_file);
- sb_disk_play (output_file);
- if (VCARD >= EGA) spinner (4, 2, SPINYPOS, 135);
- }
- }
- if (D.endpause && VCARD >= EGA) pause();
- return;
- }
-
-
- //┌───────────────────────────────────────────────────────────────────────┐//
- //│ MAIN ROUTINE │//
- //└───────────────────────────────────────────────────────────────────────┘//
- main(char argc, char *argv[])
- {
- init_video();
- parse_args (argc, argv);
- if (D.fancy == NO) VCARD = BIOS;
- if (VCARD < EGA) show_header();
- process();
- remove ("(NONE)");
- close_video();
- return 0;
- }
-
-