[comp.sources.amiga] v90i277: Macto8SVX 1.0 - Mac Sound to Amiga 8SVX converter, Part01/01

amiga-request@abcfd20.larc.nasa.gov (Amiga Sources/Binaries Moderator) (10/11/90)

Submitted-by: "Tim Friest - Programmer/Analyst"  <AXTBF%ALASKA.BITNET@CORNELLC.cit.cornell.edu>
Posting-number: Volume 90, Issue 277
Archive-name: util/macto8svx-1.0/part01

This is a little program I wrote to convert Mac sound samples to Amiga
IFF 8SVX format...   It uses 2.0 stuff, so you'll need 2.0 to compile it.

#!/bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 1)."
# Contents:  Macto8SVX.c Macto8SVX.doc
# Wrapped by tadguy@abcfd20 on Wed Oct 10 21:06:09 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Macto8SVX.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Macto8SVX.c'\"
else
echo shar: Extracting \"'Macto8SVX.c'\" \(9075 characters\)
sed "s/^X//" >'Macto8SVX.c' <<'END_OF_FILE'
X/*
X * Read a Mac sound file and convert it to an IFF 8SVX sound file
X *
X * by: Tim Friest
X * on: 6-August-1990
X */
X
X#include <exec/types.h>
X#include <clib/exec_protos.h>
X#include <pragma/exec_pragma.h>
X#include <exec/memory.h>
X#include <dos/dos.h>
X#include <dos/rdargs.h>
X#include <clib/dos_protos.h>
X#include <pragma/dos_pragma.h>
X#include <libraries/iffparse.h>
X#include <clib/iffparse_protos.h>
X#include <pragma/iffparse_pragma.h>
X#include <iff/iff.h>
X#include <iff/8SVX.h>
X
Xextern struct library *DOSBase;
X
Xchar *version  = "\0$VER: MacTo8SVX 1.0 (8-Aug-90)";
X#define        CREDITS "MacTo8SVX v1.0 (8-Aug-90) by Tim Friest (PD)\n"
X
X#define        ARG_TEMPLATE    "MacSound/A,IFF8SVX/A,Rate=SampleRate/K/N"
X
X#define OPT_FILENAME   0
X#define        OPT_IFFNAME     1
X#define        OPT_RATE        2
X
X#define        OPT_COUNT       3
Xchar   *cmd_opts[OPT_COUNT];
X
Xstruct RDArgs  *argsptr;
X
Xextern void SignalIFFError(int);
Xextern void main(void);
Xvoid main() {
X       int status;
X       ULONG AllocFlags = 0;
X       struct FileInfoBlock    *fib;
X       BPTR    file, flock;
X       struct library *IFFParseBase;
X       struct IFFHandle *IFFHandle;
X       char *filename, *iffname;
X       int SampleRate;
X       Voice8Header VHDR;
X       UBYTE *SoundData;
X       LONG SoundLen, i;
X
X       if ((IFFParseBase = OpenLibrary("iffparse.library", 0)) == NULL) {
X               Write(Output(), "Unable to open IFFParse Library\n", 32);
X               goto CleanUp;
X       }
X       AllocFlags |= (1<<0);
X
X       if ((argsptr = ReadArgs(ARG_TEMPLATE, (LONG *)cmd_opts, NULL)) == NULL)
X{
X               Write(Output(), "Usage: ", 7);
X               Write(Output(), ARG_TEMPLATE, sizeof(ARG_TEMPLATE));
X               Write(Output(), "\n", 1);
X               Write(Output(), CREDITS, sizeof(CREDITS));
X               goto CleanUp;
X       }
X       AllocFlags |= (1<<10);
X
X       filename = cmd_opts[OPT_FILENAME];
X       iffname = cmd_opts[OPT_IFFNAME];
X       if (cmd_opts[OPT_RATE])
X               SampleRate = *(int *)cmd_opts[OPT_RATE];
X       else
X               SampleRate = 11;
X
X       if ((file = Open(filename, MODE_OLDFILE)) == NULL) {
X               Write(Output(), "Error opening file\n", 19);
X               goto CleanUp;
X       }
X       AllocFlags |= (1<<11);
X
X       if ((flock = Lock(filename, MODE_OLDFILE)) == NULL) {
X               Write(Output(), "Error locking file\n", 19);
X               goto CleanUp;
X       }
X       AllocFlags |= (1<<12);
X
X       if ((fib = (struct FileInfoBlock *)AllocMem(sizeof(struct FileInfoBlock)
X, MEMF_CLEAR)) == NULL) {
X               Write(Output(), "Not enough memory for file info block\n", 28);
X               goto CleanUp;
X       }
X       AllocFlags |= (1<<13);
X
X       if (!Examine(flock, fib)) {
X               Write(Output(), "Examine failed!\n", 16);
X               goto CleanUp;
X       }
X       SoundLen = fib->fib_Size;
X
X       FreeMem((char *)fib, sizeof(struct FileInfoBlock));
X       AllocFlags &= ~(1<<13);
X
X       UnLock(flock);
X       AllocFlags &= ~(1<<12);
X
X       if ((SoundData = AllocMem(SoundLen, MEMF_CLEAR)) == NULL) {
X               Write(Output(), "Not enough memory\n", 18);
X               goto CleanUp;
X       }
X       AllocFlags |= (1<<14);
X
X       if (Read(file, SoundData, SoundLen) < SoundLen) {
X               Write(Output(), "Error reading file\n", 19);
X               goto CleanUp;
X       }
X       Close(file);
X       AllocFlags &= ~(1<<11);
X
X       for (i=0; i < SoundLen; i++)
X               SoundData[i] ^= 0x80;   /* toggle high bit */
X
X       VHDR.oneShotHiSamples = SoundLen;
X       VHDR.repeatHiSamples = 0;
X       VHDR.samplesPerHiCycle = 0;
X       switch (SampleRate) {
X               case 5:
X                       VHDR.samplesPerSec = 5696; /*  5.564 * 1024 */
X                       break;
X               case 7:
X                       VHDR.samplesPerSec = 7596; /*  7.418 * 1024 */
X                       break;
X               case 11:
X                       VHDR.samplesPerSec = 11395; /* 11.128 * 1024 */
X                       break;
X               case 22:
X                       VHDR.samplesPerSec = 22790; /* 22.256 * 1024 */
X                       break;
X               default:
X                       Write(Output(), "Sample rate one of 5, 7, 11 and 22, usi
Xng 11\n", 45);
X                       VHDR.samplesPerSec = 11395;
X       } /* switch */
X       VHDR.ctOctave = 1;
X       VHDR.sCompression = sCmpNone;
X       VHDR.volume = Unity;
X
X       if ((IFFHandle = AllocIFF()) == NULL) {
X               Write(Output(), "Not enough memory to allocate IFF Handle\n", 41
X);
X               goto CleanUp;
X       }
X       AllocFlags |= (1<<1);
X       if ((IFFHandle->iff_Stream = (ULONG)Open(iffname, MODE_NEWFILE)) == NULL
X) {
X               Write(Output(), "Error opening file\n", 19);
X               goto CleanUp;
X       }
X       AllocFlags |= (1<<2);
X       InitIFFasDOS(IFFHandle);
X
X       if ((status = OpenIFF(IFFHandle, IFFF_WRITE)) != 0) {
X                       SignalIFFError(status);
X                       goto CleanUp;
X       }
X       AllocFlags |= (1<<3);
X
X       if ((status = PushChunk(IFFHandle, ID_8SVX, ID_FORM, IFFSIZE_UNKNOWN)) !
X= 0) {
X               SignalIFFError(status);
X               goto CleanUp;
X       }
X
X       if ((status = PushChunk(IFFHandle, ID_8SVX, ID_VHDR, sizeof(Voice8Header
X))) != 0) {
X               SignalIFFError(status);
X               goto CleanUp;
X       }
X       if ((status = WriteChunkBytes(IFFHandle, &VHDR, sizeof(Voice8Header))) <
X= 0) {
X               SignalIFFError(status);
X               goto CleanUp;
X       }
X       if ((status = PopChunk(IFFHandle)) != 0) { /* pop the 8SVX VHDR chunk */
X               SignalIFFError(status);
X               goto CleanUp;
X       }
X
X       if ((status = PushChunk(IFFHandle, ID_8SVX, ID_BODY, SoundLen)) != 0) {
X               SignalIFFError(status);
X               goto CleanUp;
X       }
X       if ((status = WriteChunkBytes(IFFHandle, SoundData, SoundLen)) <= 0) {
X               SignalIFFError(status);
X               goto CleanUp;
X       }
X       if ((status = PopChunk(IFFHandle)) != 0) { /* pop the 8SVX BODY chunk */
X               SignalIFFError(status);
X               goto CleanUp;
X       }
X
X       if ((status = PopChunk(IFFHandle)) != 0) { /* pop the FORM 8SVX chunk */
X               SignalIFFError(status);
X               goto CleanUp;
X       }
X
X
X/*
X * Deallocate and close all resources used
X */
XCleanUp:
X       if (AllocFlags & (1<<14))
X               FreeMem(SoundData, SoundLen);
X       if (AllocFlags & (1<<13))
X               FreeMem((char *)fib, sizeof(struct FileInfoBlock));
X       if (AllocFlags & (1<<12))
X               Close(file);
X       if (AllocFlags & (1<<11))
X               UnLock(flock);
X       if (AllocFlags & (1<<10))
X               FreeArgs(argsptr);
X       if (AllocFlags & (1<<3))
X               CloseIFF(IFFHandle);
X       if (AllocFlags & (1<<2))
X               Close(IFFHandle->iff_Stream);
X       if (AllocFlags & (1<<1))
X               FreeIFF(IFFHandle);
X       if (AllocFlags & (1<<0))
X               CloseLibrary(IFFParseBase);
X}
X
X/*
X * Signal IFF error codes to user
X */
Xvoid SignalIFFError(error)
Xint error;
X{
X       switch (error) {
X               case IFFERR_EOF:
X                       Write(Output(), "IFFError: Reached logical end of file\n
X", 38);
X                       break;
X               case IFFERR_EOC:
X                       Write(Output(), "IFFError: About to leave context\n", 33
X);
X                       break;
X               case IFFERR_NOSCOPE:
X                       Write(Output(), "IFFError: No valid scope for property\n
X", 38);
X                       break;
X               case IFFERR_NOMEM:
X                       Write(Output(), "IFFError: Internal memory alloc failed\
Xn", 39);
X                       break;
X               case IFFERR_READ:
X                       Write(Output(), "IFFError: Stream read error\n", 28);
X                       break;
X               case IFFERR_WRITE:
X                       Write(Output(), "IFFError: Stream write error\n", 29);
X                       break;
X               case IFFERR_SEEK:
X                       Write(Output(), "IFFError: Stream seek error\n", 28);
X                       break;
X               case IFFERR_MANGLED:
X                       Write(Output(), "IFFError: Data in file is corrupt\n",34
X );
X                       break;
X               case IFFERR_SYNTAX:
X                       Write(Output(), "IFFError: IFF syntax error\n", 27);
X                       break;
X               case IFFERR_NOTIFF:
X                       Write(Output(), "IFFError: Not an IFF file\n", 26);
X                       break;
X               case IFFERR_NOHOOK:
X                       Write(Output(), "IFFError: No call-back hook provided\n"
X, 37);
X                       break;
X               case IFF_RETURN2CLIENT:
X                       Write(Output(), "IFFError: Client handler normal return\
Xn", 39);
X                       break;
X               default:
X                       Write(Output(), "IFFError: unknown error encountered\n",
X 36);
X       } /* switch (error) */
X}
X
END_OF_FILE
if test 9075 -ne `wc -c <'Macto8SVX.c'`; then
    echo shar: \"'Macto8SVX.c'\" unpacked with wrong size!
fi
# end of 'Macto8SVX.c'
fi
if test -f 'Macto8SVX.doc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Macto8SVX.doc'\"
else
echo shar: Extracting \"'Macto8SVX.doc'\" \(912 characters\)
sed "s/^X//" >'Macto8SVX.doc' <<'END_OF_FILE'
X
X
X                             Mac_To_8SVX
X                                 by
X                             Tim Friest
X                             8-Aug-1990
X
XMacTo8SVX is a AmigaOS 2.0 program which converts Macintosh digitized sound
Xdata to an Amiga IFF 8SVX sound file.
X
XThe program assumes that the Mac data is simply that (a stream of bytes
Xwithout a header, resource fork, or whatever).  I got the speeds for the
Xsampling rates from the March/April 1990 AmigaMail article by John Orr.
X
XThis program only runs under AmigaOS 2.0 (I couldn't resist the IFFParse
Xlibrary or the new DOS calls...  Thanks to Leo, Stuart, and C=.
X
XThis program is not copyrighted and may be destributed or modified in any
Xway you desire.  If you make modifications, I'd appreciate credit where due.
X
XI can be reached:
X
XUSMail:        Tim Friest                      BIX: TFRIEST
X       211 McCarrey #1
X       Anchorage, AK 99508
END_OF_FILE
if test 912 -ne `wc -c <'Macto8SVX.doc'`; then
    echo shar: \"'Macto8SVX.doc'\" unpacked with wrong size!
fi
# end of 'Macto8SVX.doc'
fi
echo shar: End of archive 1 \(of 1\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have the archive.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
Mail submissions (sources or binaries) to <amiga@uunet.uu.net>.
Mail comments to the moderator at <amiga-request@uunet.uu.net>.
Post requests for sources, and general discussion to comp.sys.amiga.