home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk1.iso
/
altsrc
/
articles
/
11211
< prev
next >
Wrap
Text File
|
1994-09-01
|
7KB
|
269 lines
Path: wupost!gumby!newsxfer.itd.umich.edu!europa.eng.gtefsd.com!howland.reston.ans.net!newsserver.jvnc.net!gateway.rosedale.org!rosedale.org!mvachharajani
From: mvachharajani@rosedale.org (Madhavi Vachharajani)
Newsgroups: alt.sources
Subject: Sound Blaster Code
Date: 1 Sep 1994 16:39:14 GMT
Organization: Educational Testing Service
Lines: 258
Message-ID: <mvachharajani.19.0@rosedale.org>
NNTP-Posting-Host: mxv2521.pclan.rosedale.org
This code plays .VOC files through the Sound Blaster. It requires that your
8 bit DMA is 1 and that your BLASTER environment variable is set.
#include<string.h>
#include<io.h>
#include<fcntl.h>
#include<sys\stat.h>
#include<stdlib.h>
#include<dos.h>
#include<alloc.h>
#include<stdio.h>
#include<conio.h>
#define writedac(x) { while(inportb(PORT + 0xC) & 0x80); outportb(PORT + 0xC, (x)); }
void resetdsp();
void setsamplerate(int);
void initdma(char far *);
void loadsong(char *);
void playback();
void deinit();
void initsb();
void irq(int, char);
void getblaster();
int PORT=0x210, FREQ=22000, IRQ, DMA;
unsigned int FSIZE, FSIZE2=0;
char CLOSEIRQ = 0;
int finished = 0;
int DMACONST[4] = {7, 3, 1, 2};
char far *vocbuf;
static void far interrupt (*OLDSB)(...);
static void far interrupt SBHANDLER(...)
{
enable();
inportb(PORT + 0xE);
if(FSIZE2 != 0)
{
CLOSEIRQ=1;
FSIZE = FSIZE2;
FSIZE2 = 0;
initdma(vocbuf+64000);
playback();
}
else
{
finished = 1;
outportb(0x20,0x20);
}
}
void main()
{
char file[100];
clrscr();
getblaster();
printf("DMA Voc Play Version 1.0\n");
printf("Copyright 1994\n");
printf("By:\n Neil Vachharajani\n");
printf("\nEnter Voc Filename: ");
gets(file);
loadsong(file);
initsb();
initdma(vocbuf);
setsamplerate(FREQ);
playback();
while(!finished);
deinit();
farfree(vocbuf);
}
void resetdsp()
{
int cntr = 0;
int cntr2 = 0;
int found = 0;
while(PORT <= 0x260 && !found)
{
outportb(PORT + 0x6, 1);
delay(3);
outportb(PORT + 0x6, 0);
cntr = 0;
while((inportb(PORT + 0xE) < 128) && cntr < 100)
cntr++;
if(cntr < 10 || (inportb(PORT+0xA) != 0xAA))
{
cntr2++;
if(cntr == 10 || (inportb(PORT + 0xA) != 0xAA))
{
PORT += 0x10;
cntr2 = 0;
}
}
else
found = 1;
}
if(!found)
{
printf("Sound Blaster not found!!");
getch();
exit(0);
}
delay(3);
}
void setsamplerate(int freq)
{
writedac(0xD1);
int byte = 256 - (1000000 / freq);
writedac(0x40);
writedac(byte);
}
void initdma(char far *s)
{
unsigned int segment = FP_SEG(s);
unsigned int offset1 = FP_OFF(s);
long int to;
int t1;
char t2;
to = ((unsigned long)segment << 4) + (unsigned long)offset1;
t1 = int(to & 0xFFFF);
t2 = to >> 16;
disable();
outportb(0xA, 0x5);
outportb(0xC, 0x0);
outportb(0xB, 0x49);
outportb(DMA * 2, t1 & 0x00FF);
delay(1);
outportb(DMA * 2, t1 >> 8);
delay(1);
outportb(0x80 + DMACONST[DMA], t2);
delay(1);
outportb((DMA * 2) + 1, (FSIZE-1) & 0x00FF);
delay(1);
outportb((DMA * 2) + 1, ((FSIZE-1) & 0xFF00) >> 8);
delay(1);
outportb(0xA, 0x1);
delay(1);
enable();
delay(3);
}
void playback()
{
if(CLOSEIRQ)
outportb(0x20, 0x20);
writedac(0x14);
writedac((FSIZE-1) & 0xFF)
writedac((FSIZE-1) >> 8);
}
void loadsong(char *fname)
{
int handle;
if((handle = open(fname, O_BINARY | O_RDWR, S_IREAD | S_IWRITE)) == -1)
{
printf("ERROR: Cannot load song\r\n");
printf("Abnormal Exit from DMA Play");
free(vocbuf);
exit(0);
}
unsigned long size = filelength(handle);
if((vocbuf = (char far *)farmalloc(size+16))==NULL)
{
close(handle);
exit(0);
}
if(size <= 64000)
{
read(handle, vocbuf, 64000);
FSIZE = size;
}
else
{
read(handle, vocbuf, 64000);
read(handle, vocbuf+64000, size - 64000);
FSIZE = 64000;
FSIZE2 = size - 64000;
}
close(handle);
}
void deinit()
{
disable();
setvect(0x8 + IRQ, OLDSB);
// irq(5, 0);
enable();
}
As I said earlier I would post code for playing VOCS.
void initsb()
{
resetdsp();
disable();
OLDSB = getvect(0x8 + IRQ);
setvect(0x8 + IRQ, SBHANDLER);
irq(5, 1);
enable();
}
void irq(int irq, char oo)
{
char orig, edited, temp;
orig = inportb(0x21);
if(oo)
{
temp = ~(1 << irq);
edited = orig & temp;
}
else
{
temp = 1 << temp;
edited = orig | temp;
}
outportb(0x21, edited);
}
void getblaster()
{
char temp[2];
char *blaster = getenv("BLASTER");
if(blaster[0] == NULL)
{
printf("Blaster String not found.");
exit(0);
}
char *ptr = strchr(blaster, 'I');
temp[0] = *(ptr+1);
temp[1] = 0;
IRQ = atoi(temp);
ptr = strchr(blaster, 'D');
temp[0] = *(ptr+1);
temp[1] = 0;
DMA = atoi(temp);
if(DMA > 3)
{
printf("8 Bit DMA's only. \nEdit the Dx Parameter in your Blaster String.");
exit(0);
}
}
/----------------------------------------------------------------------\
| Disclaimer: Opinions expressed are those of the author and do not |
| reflect those of the Educational Testing Service. |
\----------------------------------------------------------------------/