home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sound Sensations!
/
sound_sensations.iso
/
misc
/
fileid13
/
smus.c
< prev
Wrap
C/C++ Source or Header
|
1991-01-26
|
5KB
|
220 lines
/**************************************************
*
* SMUS.c
*
* IFF-SMUS file manipulation code
*
* Copyright(c), 1990, 1991 Lloyd B. Eldred
* & Fredrick R Homan
**************************************************/
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "fi_IFF.h"
extern UBYTE VERBOSE, TERSE,COMMENT; /* Yuck, global variables... */
void IFF_SMUS(picfile,size)
FILE *picfile;
LONG size;
{
union chunk_ID{
char text_ID[4];
LONG long_ID;} chunk;
LONG ch_size,offset;
if(!TERSE) printf(" SMUS (Simple MUsical Score)\n");
if(TERSE) printf("SMUS ");
offset=0;
while(offset <= size-8){
IFF_ID(picfile,chunk.text_ID);
ch_size = IFF_size(picfile);
offset += (8+ch_size+is_odd(ch_size));
switch(chunk.long_ID){
case ID_SHDR :
IFF_SHDR(picfile,ch_size);
break;
case ID_NAME :
IFF_NAME(picfile,ch_size);
break;
case ID_copyright :
IFF_copyright(picfile,ch_size);
break;
case ID_AUTH :
IFF_AUTH(picfile,ch_size);
break;
case ID_ANNO :
IFF_ANNO(picfile,ch_size);
break;
case ID_INS1 :
IFF_INS1(picfile,ch_size);
break;
case ID_INST :
IFF_INST(picfile,ch_size);
break;
case ID_TRAK :
IFF_TRAK(picfile,ch_size);
break;
case ID_IRev :
IFF_IRev(picfile,ch_size);
break;
case ID_BIAS :
IFF_BIAS(picfile,ch_size);
break;
case ID_SNX1 :
IFF_SNX1(picfile,ch_size);
break;
default:
if(VERBOSE) printf(
" Inappropriate sub chunk for SMUS: %4s\n",chunk.text_ID);
IFF_GotoEnd(picfile,ch_size);
} /* end of switch */
} /* end of while */
IFF_GotoEnd(picfile,size-offset);
if(VERBOSE) printf(" End of SMUS.\n");
}
/************************************************************/
/* Useful chunks for SMUS files */
/************************************************************/
void IFF_SHDR(picfile,size)
FILE *picfile;
LONG size;
{
unsigned char c1,c2,c3,c4;
UWORD tempo;
UBYTE volume, ctTrack;
float tempo2;
if(VERBOSE) printf(" SHDR (sound header) chunk\n");
fi_getc(picfile,&c1);
fi_getc(picfile,&c2);
tempo = (UWORD)c2 + (UWORD)(c1<<8);
tempo2 = tempo/128.0;
fi_getc(picfile,&c3);
volume = ((int)c3 * 100)/127;
fi_getc(picfile,&c4);
ctTrack = c4;
if(!TERSE && !COMMENT){
printf(" Tempo (1/4 notes/min): %g\n",tempo2);
printf(" Volume (percent) : %d\n",volume);
printf(" Tracks : %d\n",ctTrack);
}
if(TERSE) printf(" %g %d %d\n",tempo2,volume,ctTrack);
IFF_GotoEnd(picfile,size-4);
}
void IFF_INS1(picfile,size)
FILE *picfile;
LONG size;
{
char c1,c2,c3,c4;
UBYTE reg,type,data1,data2;
int i;
if(VERBOSE) printf(" INS1 (Instrument) chunk\n");
fi_getc(picfile,&c1);
fi_getc(picfile,&c2);
fi_getc(picfile,&c3);
fi_getc(picfile,&c4);
reg = c1;
type = c2;
data1 = c3;
data2 = c4;
if(VERBOSE) printf(" Instrument Register : %d\n",reg);
if(type == 1)
if(VERBOSE) printf(" If MIDI is available use:"
" MIDI channel %d, preset %d\n",
data1,data2);
if(VERBOSE) printf(" Instrument name : ");
for(i=0;i<size-4;i++){
fi_getc(picfile,&c1);
if(VERBOSE) printf("%c",c1);
}
if(VERBOSE) printf("\n");
if(is_odd(size)) fi_getc(picfile,&c1);
}
void IFF_INST(picfile,size)
FILE *picfile;
LONG size;
{
if(VERBOSE) printf(" INST (Obsolete SMUS Instrument) chunk.\n");
IFF_GotoEnd(picfile,size);
} /* end of IFF_INST */
void IFF_TRAK(picfile,size)
FILE *picfile;
LONG size;
{
if(VERBOSE) printf(" TRAK (SMUS data) chunk.\n");
IFF_GotoEnd(picfile,size);
} /* end of IFF_TRAK */
void IFF_IRev(picfile,size)
FILE *picfile;
LONG size;
{
if(VERBOSE) printf(" IRev (Private Instant Music) chunk.\n");
IFF_GotoEnd(picfile,size);
} /* end of IFF_IRev */
void IFF_BIAS(picfile,size)
FILE *picfile;
LONG size;
{
if(VERBOSE) printf(" BIAS (Private Instant Music) chunk.\n");
IFF_GotoEnd(picfile,size);
} /* end of IFF_BIAS */
void IFF_SNX1(picfile,size)
FILE *picfile;
LONG size;
{
if(VERBOSE) printf(" SNX1 (Sonix proprietary) chunk.\n");
IFF_GotoEnd(picfile,size);
} /* end of IFF_SNX1 */