/* voiceiff - construct Karl's IFF VOCE FORM files */

#include <stdio.h>
#include <fcntl.h>
#include <exec/lists.h>
#include <hackercorp/iff.h>
#include <hackercorp/8svx.h>
#include <hackercorp/sample.h>
#include <hackercorp/voicebank.h>

short buffer[512];

main(argc,argv)
int argc;
char *argv[];
{
	int voicefd;
	UBYTE *outp;
	int i;
	struct VDAT_struct vdat;
	char s[100];
	unsigned int first_note, last_note, reference_note, low_velocity, high_velocity;
	char samplename[50];

	if (argc != 2)
	{
		fprintf(stderr,"usage: voiceiff <filename.input outIFFfile\n");
		exit(1);
	}

	/* get that IFF file open, we have to cleanup from now on */
	if ((voicefd = CreateIFF(argv[1],ID_FORM,ID_VOCE)) == -1)
		panic("unable to create IFF VOCE file\n");

	if (!WriteTextChunk(voicefd,ID_NAME,argv[1]))
		panic("unable to write NAME chunk");

	if (!WriteTextChunk(voicefd,ID_Copyright,"Copyright (C) 1989 Hackercorp.  All Rights Reserved."))
		panic("unable to write Copyright chunk");

	if (!WriteTextChunk(voicefd,ID_ANNO,"Contact Karl Lehenbauer 3918 Panorama, Missouri City, TX  USA for more info"));

	while (gets(s))
	{
		sscanf(s,"%d %d %d %d %d %s",&first_note,&last_note,&reference_note,&low_velocity,&high_velocity,&samplename[0]);

		printf("'%s' first %d, last %d, reference %d, lo vel %d, hi vel %d\n",samplename,first_note,last_note,reference_note,low_velocity,high_velocity);

		vdat.first_note = first_note;
		vdat.last_note = last_note;
		vdat.reference_note = reference_note;
		vdat.low_velocity = low_velocity;
		vdat.high_velocity = high_velocity;
		strcpy(&vdat.samplename[0],samplename);

		if (!WriteChunk(voicefd,ID_VDAT,&vdat,sizeof(vdat)))
			panic("unable to write VHDR chunk");
	}

	done:
	Rewrite_IFF_header(voicefd);
	exit(0);
}

