home *** CD-ROM | disk | FTP | other *** search
- /*
-
- lp.c PAR Aug 87 Sophus Software
-
- A long sample player and recorder.
- Facilities from recording , playing , saving and loading samples using
- the FAST memory on an expanded Amiga.
-
- Avoids Intuition etc to make the example easier to read and smaller
- at run-time.
-
- */
-
- #include "lattice/stdio.h"
- #include "exec/types.h"
- #include "s5.h"
-
- struct Frag *Left,*Right;
- int LeftSize,RightSize;
- APTR S5Base; /* any pointer would do */
-
- main()
- {
- int ok;
- char c,newline;
-
- printf("lp : Record/play long samples \n");
- printf("Note: files are loaded/saved in SOP3 format. i.e. no format\n");
- printf("Enter option letter followed by RETURN\n\n");
-
- if((S5Base=(APTR)OpenLibrary(S5NAME,0))==0)
- TidyUp("Failed to open S5.library");
-
- LeftSize = 10;
- RightSize = 10;
- Left = (struct Frag *)S5AllocateFrag(LeftSize,1); /* allocate atrivial buffer in FAST memory */
- if(Left==0)
- TidyUp("Not enough memory for LEFT frag");
-
- Right = (struct Frag *)S5AllocateFrag(RightSize,1); /* Same. Not actually used */
- if(Right==0)
- TidyUp("Not enough memory for RIGHT frag");
-
- ok = TRUE;
- while(ok)
- {
- printf(" Options : \n\n");
- printf(" B ... set buffer size. (now %ld)\n",LeftSize);
- printf(" R ... record.\n");
- printf(" P ... play.\n");
- printf(" S ... save to file.\n");
- printf(" L ... load from file.\n");
- printf(" Q ... quit.\n");
- printf("\n\n ? ");
-
- scanf("%c%c",&c,&newline);
- printf("\n\n");
- switch(toupper(c))
- {
- case 'B':
- NewSize();
- break;
- case 'R':
- Disable();
- S5FastMemRecord(Left);
- Enable();
- break;
- case 'P':
- S5FastMemPlay(Left);
- break;
- case 'S':
- SaveFile();
- break;
- case 'L':
- LoadFile();
- break;
- case 'Q':
- ok = FALSE;
- break;
- default:
- printf("Unrecognised option\n");
- }
-
- }
-
- CloseLibrary(S5Base);
- printf("lp finished\n");
- }
-
-
- TidyUp(mess)
- char *mess;
- {
- printf("lp exiting : %s\n",mess);
- if(Left) S5DeallocateFrag(Left);
- if(Right) S5DeallocateFrag(Right);
- if(S5Base) CloseLibrary(S5Base);
- exit(-1);
- }
-
-
- NewSize()
- {
- char nl;
- int size;
- S5DeallocateFrag(Left);
- Left = 0;
- LeftSize = 0;
- do {
- printf("New size ? ");
- scanf("%d%c",&size,&nl);
- Left = (struct Frag *)S5AllocateFrag(size,1);
- if(Left) printf("OK\n");
- else printf("Failed to allocate. Try again.\n");
- } while(Left==0);
- LeftSize = size;
- }
-
- #define EOLN '\n'
- #define FNL 32
- char filename[FNL];
-
-
- GetFileName()
- {
- char *p,c;
- int count;
- /* NB this assumes that getchar() doesnt get any characters until \n is
- pressed - as usual. This permits simple line editing
- */
- count = 0;
- p = filename;
- do {
- c = getchar();
- if(c!=EOLN)
- if(count < (FNL-1))
- {
- *p++ = c;
- count++;
- }
- } while(c!=EOLN);
- *p++ = 0;
- return( count>0 );
- }
-
-
- LoadFile()
- {
- int Success;
- printf("Loader. NB buffer will not be reallocated\n");
- printf("Load from which file ? ");
- if(GetFileName()==0) return(0);
- Success = S5LoadSOP3(Left,filename,1);
- ECode(Success);
- return(Success==E_OK);
- }
-
- SaveFile()
- {
- int Success;
- printf("Save to which file ? ");
- if(GetFileName()==0) return(0);
- Success = S5SaveSOP3(Left,filename,0);
- ECode(Success);
- return(Success=E_OK);
- }
-
-
- ECode(v)
- int v;
- {
- switch(v)
- {
- case E_OK: printf("No error.\n"); break;
- case E_OPEN: printf("Failed to open file.\n"); break;
- case E_CLOSE: printf("Failed to close file.\n"); break;
- case E_READ: printf("Read Error. / End of file.\n"); break;
- case E_WRITE: printf("Write Error. / Disk full.\n"); break;
- case E_FORMAT: printf("File is of an inappropriate format.\n"); break;
- case E_MEM: printf("Insufficient memory.\n"); break;
- case E_DEV: printf("Device Open error.\n"); break;
- case E_PORT: printf("Unable to create port.\n"); break;
- case E_OKNULL: printf("Operation was null. Inappropriate conditions.\n");
- default: printf("Unspecified error.\n");
- }
- }
-
-