Apparently-To: john.smith@gravis.com


GUS Programmer's Digest     Mon, 7 Feb 94  4:19          Volume 9: Issue   4  

Today's Topics:
                    GUS Programmer's Digest V9 #2
                        Patch Loading ala SDK

Standard Info:
	- Meta-info about the GUS can be found at the end of the Digest.
	- Before you ask a question, please READ THE FAQ.

----------------------------------------------------------------------

Date: Mon, 7 Feb 1994 12:37:20 +1030 (CST)
From: Gavin <SCARMAN@hfrd.dsto.gov.au>
Subject: Re: GUS Programmer's Digest V9 #2

>I want a postscript version of the document, so i did try MS-Word. But
>when I try to load it into Word (We have version 2.0) it chrashes both
>Word and Windows

I think it's truly stuffed, WP4WIN crashes too when you try to load it.

------------------------------

Date: Mon, 7 Feb 1994 17:56:15 +1030 (CST)
From: Gavin <SCARMAN@hfrd.dsto.gov.au>
Subject: Patch Loading ala SDK

OK, to whoever finds the bug in this here code so as to make it play a patch 
gets a postcard from me with a big thankyou. It is compiled with BC3.1 , the 
project file contains this file, config.c, ultra0lb.lib,ultra1lb.lib. It's not 
pretty, and the commented out code was what I've tried but didn't work.
 ----------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <io.h>
#include <dos.h>

#include "patch.h"

#include "forte.h"
#include "gf1proto.h"
#include "extern.h"
#include "ultraerr.h"


PATCHHEADER myPatchHeader;
INSTRUMENTDATA myInstrumentData;
LAYERDATA myLayerData;
PATCHDATA myPatchData;

main()
{
unsigned long wave_loc;
long start_loop,end_loop;
FILE *filePtr1;
int numBytesRead;
ULTRA_CFG config;
void *data_ptr;
int dram_len,done=0,voiceNum;
char voice_mode=0,dma_mode=0,keypress;

printf("Play patch v0.1\n");

/* Get the ULTRASND environment string parameters */
UltraGetCfg(&config);

if (UltraProbe(config.base_port) == NO_ULTRA)
	{
	printf("No card found\n");
	exit(-1);
	}

if (UltraOpen(&config,32) == NO_ULTRA)
	{
	printf("No card found\n");
	exit(-1);
	}

dram_len = UltraSizeDram();

printf("\nFound %dK of Dram\n",dram_len);

printf("Resetting the UltraSound\n");
UltraDisableOutput();
UltraReset(32);
UltraEnableOutput();


printf("Opening patch file %s\n",_argv[1]);

// Read the Patch Header info
//------------------------------------------------------------------
filePtr1=fopen(_argv[1],"rb");
numBytesRead=fread(&myPatchHeader,sizeof(myPatchHeader),1,filePtr1);

printf("\nRead patch-header\nResults:\n",numBytesRead);
printf("Number of waveforms in patch = %u\n",myPatchHeader.wave_forms);
printf("gravis ID = %s\n",myPatchHeader.gravis_id);
printf("data size = %lu\n",myPatchHeader.data_size);

// Read the Instrument Data
//------------------------------------------------------------------
numBytesRead=fread(&myInstrumentData,sizeof(myInstrumentData),1,filePtr1);
printf("Read instrument data\n");

// Read the Layer Data
//------------------------------------------------------------------
numBytesRead=fread(&myLayerData,sizeof(myLayerData),1,filePtr1);
printf("Read layer data\n");

// Read the Patch Data
//------------------------------------------------------------------
numBytesRead=fread(&myPatchData,sizeof(myPatchData),1,filePtr1);
printf("Read Patch data\n");

// file pointer is now pointing to the raw data
//------------------------------------------------------------------
// size of raw data is given from myPatchData.wave_size

data_ptr=malloc(myPatchHeader.data_size);
if (data_ptr==NULL)
		printf("didn't allocate memory properly\n");
printf("memory allocated \n");

if((fread(&data_ptr,myPatchData.wave_size,1,filePtr1))!=1)
printf("Couldn't read wave_size bytes");
else
printf("Read Raw data %lu %x\n",myPatchData.wave_size,myPatchData.modes);

printf("start loop = %lu end loop = %lu\n",
	myPatchData.start_loop,myPatchData.end_loop);

printf("root frequency = %lu\n",myPatchData.root_frequency);

// show mode of patch and set control mode bits
//----------------------------------------------
if (myPatchData.modes & 0x01)
	{
	printf("16 bit data\n");
	dma_mode|=0x40;
	voice_mode|=0x04;
	}
	else
	printf("8 bit data\n");

if (myPatchData.modes & 0x02)
	{
	printf("Unsigned data\n");
	dma_mode|=0x80;
	}
	else
	printf("Signed data\n");

if (myPatchData.modes & 0x04)
	{
	printf("Looping enabled\n");
	voice_mode|=0x08;
	}
	else
	printf("Looping disabled\n");

if (myPatchData.modes & 0x08)
	{
	printf("Bi-directional looping\n");
	voice_mode|=0x10;
	}
	else
	printf("Uni-directional looping\n");

if (myPatchData.modes & 0x10)
	printf("Backward looping enabled\n");
	else
	printf("Backward looping disabled\n");

if (myPatchData.modes & 0x20)
	printf("Sustain enabled\n");
	else
	printf("Sustain disabled\n");
if (myPatchData.modes & 0x40)
	printf("Envelopes enabled\n");
	else
	printf("Envelopes disabled\n");



if ((UltraMemAlloc(myPatchData.wave_size,&wave_loc))==NO_MEMORY)
	printf("No GUS Dram free!");
	else
	printf("Wave_location =%lu",wave_loc);

UltraClearVoices();

//if((UltraAllocVoice(0,&voiceNum))!=ULTRA_OK)
//      printf("problems allocating a voice");
//      else
//      printf("Voice Allocated = %u",voiceNum);

if 
((UltraDownload(data_ptr,dma_mode,wave_loc,myPatchData.wave_size,TRUE))!=ULTRA_O
K)
	printf("download troubles");

printf("UltraDownload\n");

UltraSetLinearVolume(0,256);

voiceNum=0;

UltraSetBalance(voiceNum,7);

UltraSetFrequency(voiceNum,11025);

//UltraSetLoopMode(voiceNum,voice_mode);

while (!done)
{

//UltraVoiceOn(voiceNum,0,myPatchData.start_loop,myPatchData.end_loop,
//              voice_mode,myPatchData.sample_rate);

UltraStartVoice(voiceNum,wave_loc,myPatchData.start_loop+wave_loc,wave_loc+myPat
chData.end_loop,
		voice_mode);

printf("S=%lu - E=%lu\n",start_loop,end_loop);

//delay(100);
}

UltraVoiceOff(1,0);
fclose(filePtr1);

UltraClearVoices();
UltraFreeVoice(1);
printf("close file\n");
UltraClose();
printf("ultraclose\n");
free(data_ptr);
printf("free data_ptr\n");
printf("exit");
exit(0);


}

------------------------------

End of GUS Programmer's Digest V9 #4
************************************

To post to tomorrow's digest:                    <gus-sdk@dsd.es.com>
To (un)subscribe or get help:            <gus-sdk-request@dsd.es.com>
To contact a human (last resort):          <gus-sdk-owner@dsd.es.com>

FTP Sites              Archive                       Directories
---------              -------                       -----------
Main N.American Site:  archive.orst.edu              pub/packages/gravis
                       wuarchive.wustl.edu           systems/ibmpc/ultrasound
Main Asian Site:       nctuccca.edu.tw               PC/ultrasound
European Callers ONLY: theoris.rz.uni-konstanz.de    pub/sound/gus
Submissions:           archive.epas.utoronto.ca      pub/pc/ultrasound/submit
Newly Validated Files: archive.epas.utoronto.ca      pub/pc/ultrasound
Mirrors:               garbo.uwasa.fi                mirror/ultrasound
 
MailServer For Archive Access: Email to <mail-server@nike.rz.uni-konstanz.de>

Hints:
      - Get the FAQ from the FTP sites or the request server.
      - Mail to <gus-sdk-request@dsd.es.com> for info about other GUS
	related mailing lists (general use, musician's, etc.).



