home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 10
/
Fresh_Fish_10_2352.bin
/
useful
/
mus
/
play
/
dsound
/
dsound.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-07-18
|
28KB
|
1,051 lines
/**************************************************************************/
/* DSound V1.50 */
/* Copyright 1991-1994 by Dave Schreiber, All Rights Reserved. */
/* */
/* To compile with SAS/C version 6, type: */
/* smake */
/* */
/* Revision history: */
/* V1.50 - Fixed a bug that caused DSound's window to have the wrong */
/* height in some instances. Also extended DSound's Workbench*/
/* support: DSound now recognizes a number of tool types */
/* which give the user the same level of control as when */
/* DSound is used from the Shell. */
/* July 18, 1994 */
/* V1.40 - Fixed a bug that caused slowdowns with floptical drives, */
/* added some Workbench support (a project with "DSound" as */
/* its default tool can now be run by double-clicking on its */
/* icon), and added an ARexx port so now one can quit DSound */
/* via an ARexx command. In addition, DSound is no longer */
/* pure (i.e. can not be made resident), due to conflicts */
/* with MinRexx. */
/* July 2, 1994 */
/* V1.31 - Fixed some bugs that caused some samples (esp. ones */
/* without a CHAN chunk) to not play. */
/* March 6, 1994 */
/* V1.30 - DSound now displays the name of the sound sample being */
/* played, the number of seconds of the sample that have been */
/* played, and the total number of seconds in the sample. */
/* A bug that prevent DSound from being aborted from the */
/* window when a stereo sample is played has also been fixed. */
/* July 17, 1993 */
/* V1.20 - Added the ability to stop DSound by typing CTRL-C, and */
/* added the switch '-w', which keeps the DSound window from */
/* opening. */
/* August 23, 1992 */
/* V1.10 - Added the ability to play a sound sample repeatedly (in a */
/* loop). */
/* July 11, 1992 */
/* V1.00 - Added a new module (Mem.c) which allows a sample to be */
/* loaded entirely into memory, so samples can be played from */
/* floppy disk without first copying to a hard or RAM drive. */
/* DSound also can now play a single channel of a stereo */
/* out of two speakers. The small window, used to let the */
/* user abort a playing sample, as been redone (DSound also */
/* now responds instantly when the user clicks on the Close */
/* gadget). DSound now checks a given 8SVX sample to make */
/* sure that it is actually a valid sample. Finally, DSound */
/* has been made pure (residentiable). */
/* Second release (April 16, 1992) */
/* V0.94a - Can now play a mono sample out of both speakers at the */
/* same time (using the -2 switch). */
/* March 27, 1992 (a little later) */
/* V0.93a - Now handles stereo sound samples. Either the right or */
/* left, or both, stereo channels can be played. Also split */
/* off the code that actually plays the sound sample into a */
/* separate source file (Play.c). */
/* March 27, 1992 */
/* V0.92a - Now gets the length of the sound sample from the head of */
/* the BODY chunk, instead of the VHDR (a workaround to a bug */
/* in the Perfect Sound software that would sometimes store */
/* an incorrect length in the VHDR chunk of a sound sample). */
/* November 4, 1991 */
/* V0.91a - First release (September 11, 1991) */
/**************************************************************************/
#include <exec/types.h>
#include <exec/exec.h>
#include <devices/audio.h>
#include <dos/dos.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <graphics/gfxbase.h>
#include <workbench/startup.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "dsound.h"
#include "arexx.h"
#include "minrexx.h"
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/icon.h>
#include <pragmas/intuition_pragmas.h>
#include <pragmas/graphics_pragmas.h>
#include <pragmas/exec_pragmas.h>
#include <pragmas/dos_pragmas.h>
char filename[256];
#define DEF_BUF_SIZE 0xFFFFFFFF
void InterpretArgs(int argc,char *argv[]);
void InterpretWBArgs(struct WBArg *wbArgs);
BOOL LoopAndNoWindow_WB(void);
void showAboutWindow(void);
BOOL noFilter=FALSE;
UBYTE volume=0;
UWORD speed=0;
ULONG bufSize=DEF_BUF_SIZE;
void filter_on(void);
void filter_off(void);
char *getDoubleDigit(unsigned int value,char *buf);
char *version="$VER: DSound V1.50 (18.7.94)";
char *copyright="Copyright 1991-1994 by Dave Schreiber, All Rights Reserved";
extern struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase=NULL;
extern struct Library *IconBase;
struct Window *window=NULL;
BPTR file=NULL;
channel audioChannel=UNSPECIFIED;
BOOL bothChan=FALSE;
BOOL readAll=FALSE;
BOOL loop=FALSE;
BOOL titleBarName=TRUE;
BOOL titleBarTime=TRUE;
/*The window definition*/
struct NewWindow newWindow = {
0,0,
60,56,
0,1,
CLOSEWINDOW,
SMART_REFRESH|WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE,
NULL,
NULL,
"DSound V1.50",
NULL,
NULL,
5,5,
640,200,
WBENCHSCREEN
};
/*This determines whether or not the window will be opened*/
BOOL openTheWdw=TRUE;
ULONG signalMask=SIGBREAKF_CTRL_C;
struct TextFont *titleBarFont=NULL;
long arexxSigBit=0;
extern struct WBStartup *WBenchMsg;
main(int argc,char *argv[])
{
struct Voice8Header vhdr;
UBYTE foo2[5];
UBYTE foo[5];
ULONG chan;
ULONG sampleLength;
ULONG lock;
ULONG titleLength,nameLength,timeLength,colonLength,finalDelta;
char *chanStr;
filename[0]=NULL;
/*If run from the CLI*/
if(WBenchMsg==NULL)
{
/*Get and interpret the command-line arguments*/
InterpretArgs(argc,argv);
}
else
{
if(WBenchMsg->sm_NumArgs>0)
InterpretWBArgs(&WBenchMsg->sm_ArgList[0]);
if(WBenchMsg->sm_NumArgs>1)
{
CurrentDir(WBenchMsg->sm_ArgList[1].wa_Lock);
InterpretWBArgs(&WBenchMsg->sm_ArgList[1]);
if(loop && openTheWdw==FALSE)
if(!LoopAndNoWindow_WB())
exit(0);
strcpy(filename,WBenchMsg->sm_ArgList[1].wa_Name);
}
else
{
showAboutWindow();
exit(0);
}
}
/*Exit if there was no sound sample specified*/
if(filename[0]==NULL)
{
WriteMsg("Please specify the name of a sound sample\n");
cleanup(75);
}
/*Open the file*/
file=Open(filename,MODE_OLDFILE);
if(file==NULL)
{
WriteMsg("Couldn't open the file\n");
cleanup(100);
}
arexxSigBit=initRexxPort();
/*If the user hasn't told us not to open the window*/
if(openTheWdw)
{
char temp[256];
int yDelta=0;
/*Open libraries*/
GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0L);
if(GfxBase==NULL || IntuitionBase==NULL)
{
WriteMsg("A shared library could not be opened\n");
cleanup(50);
}
/*Get the size of the title bar font in a rather illegal way */
/*Note: programmers at C= should put a GetDefTitleBarFontHeight() */
/*function into Intuition before complaining to me about the following*/
/*code. */
lock=LockIBase(0L);
newWindow.Height=IntuitionBase->ActiveScreen->Font->ta_YSize+3;
UnlockIBase(lock);
window=OpenWindow(&newWindow);
if(window->WScreen->Font->ta_YSize+3!=window->Height)
yDelta=window->WScreen->Font->ta_YSize+3-window->Height;
/* SizeWindow(window,0,window->WScreen->Font->ta_YSize+3-window->Height);*/
if(window==NULL)
cleanup(110);
signalMask|=1<<window->UserPort->mp_SigBit;
titleBarFont=OpenFont(IntuitionBase->ActiveScreen->Font);
if(titleBarFont==NULL)
cleanup(115);
SetFont(window->RPort,titleBarFont);
finalDelta=t