/* * Quartett to mod converter * 03.02.2000 by Settel */ // Includes /*fold00*/ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <sys/stat.h> #include <string.h> #include <math.h> #include "pattern.h" #include "voice.h" #include "common.h" #include "mod.h" // Defines /*fold00*/ #define BASEFREQ 0x879c #define SAMPLESTRETCH 0.95 #define SPEED 0x80 #define PITCH_TOO_LOW 0x10000 #define PITCH_TOO_HIGH 0x20000 #define VOICE_MAP_LOWER 0x100 #define VOICE_MAP_HIGHER 0x200 // Globals /*fold00*/ char *pattern_buf=NULL; char *voices_buf=NULL; int pattern_buf_len=0; int voices_buf_len=0; struct channel chan[4]; int min_step_width=1<<16; int num_steps=0; int mod_patterns_num=0; char *mod_patterns_buf=NULL; struct sample samples[20]; int voice_map[31|VOICE_MAP_HIGHER|VOICE_MAP_LOWER]; int voice_rev_map[31]; int mod_pitch_tab[36]; // init_mod_pitch_tab /*fold00*/ void init_mod_pitch_tab(){ #if 1 int i; for(i=0;i<36;i++) mod_pitch_tab[i]=freqtab[i]; #else int i; double c=exp(log(2)/12.0); char buf[4096]; int fd; fd=open("freq.mod",O_RDONLY); if(fd<0){ perror("open()"); exit(1); } read(fd,buf,sizeof(buf)); close(fd); for(i=0;i<36;i++) mod_pitch_tab[i]=(int)((856.0/pow(c,i))+0.5); for(i=0;i<36;i++){ fd=X32(*((unsigned long *)(buf+i*16+1084))); fd>>=16; fd&=0x7FFF; printf("%2i: %3i <-> %3i (%3i)\n",i,mod_pitch_tab[i],fd,mod_pitch_tab[i]-fd); } #endif } // read_4v /*fold00*/ void read_4v(char *name){ int fd; struct stat stat_buf; int len; if(stat(name,&stat_buf)){ perror("stat()"); exit(1); } pattern_buf_len=stat_buf.st_size; pattern_buf=(char *)malloc(pattern_buf_len); if(!pattern_buf){ pattern_buf_len=0; perror("malloc()"); exit(1); } fd=open(name,O_RDONLY); if(fd<0){ perror("open()"); exit(1); } len=read(fd,pattern_buf,pattern_buf_len); if(len<0){ perror("read()"); exit(1); }else if(len!=pattern_buf_len){ fprintf(stderr,"read incomplete\n"); exit(1); } close(fd); } // read_set /*fold00*/ void read_set(char *name){ int fd; struct stat stat_buf; int len; if(stat(name,&stat_buf)){ perror("stat()"); exit(1); } voices_buf_len=stat_buf.st_size; voices_buf=(char *)malloc(voices_buf_len+32768); if(!voices_buf){ voices_buf_len=0; perror("malloc()"); exit(1); } fd=open(name,O_RDONLY); if(fd<0){ perror("open()"); exit(1); } len=read(fd,voices_buf,voices_buf_len); if(len<0){ perror("read()"); exit(1); }else if(len!=voices_buf_len){ fprintf(stderr,"read incomplete\n"); exit(1); } close(fd); } // dump_channel /*fold00*/ void dump_channel(int i){ struct note *note; for(note=chan[i].start;note<chan[i].end;note++){ printf(" %3i: %c %5i %08lx %08lx\n",note-chan[i].start, note->cmd,note->delay, note->val1,note->val2); } } // preprocess_4v /*fold00*/ void preprocess_4v(){ int i; struct note *note; note=(struct note*)(pattern_buf+16); for(i=0;i<4;i++){ printf("process channel %i: ",i); chan[i].start=note; while(1){ note->cmd=X16(note->cmd); note->delay=X16(note->delay); note->val1=X32(note->val1); note->val2=X32(note->val2); switch(note->cmd){ case NOTE_LOOPSTART: case NOTE_LOOPEND: case NOTE_VOICE: note->delay=0; break; } if(note->cmd==NOTE_END) break; note++; } chan[i].end=note; note++; printf("length %i\n",chan[i].end-chan[i].start); } }
/* * Quartett to mod converter * 03.02.2000 by Settel */ // Includes /*fold00*/ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <sys/stat.h> #include <string.h> #include <math.h> #include "pattern.h" #include "voice.h" #include "common.h" #include "mod.h" // Defines /*fold00*/ #define BASEFREQ 0x879c #define SAMPLESTRETCH 0.95 #define SPEED 0x80 #define PITCH_TOO_LOW 0x10000 #define PITCH_TOO_HIGH 0x20000 #define VOICE_MAP_LOWER 0x100 #define VOICE_MAP_HIGHER 0x200 // Globals /*fold00*/ char *pattern_buf=NULL; char *voices_buf=NULL; int pattern_buf_len=0; int voices_buf_len=0; struct channel chan[4]; int min_step_width=1<<16; int num_steps=0; int mod_patterns_num=0; char *mod_patterns_buf=NULL; struct sample samples[20]; int voice_map[31|VOICE_MAP_HIGHER|VOICE_MAP_LOWER]; int voice_rev_map[31]; int mod_pitch_tab[36]; // init_mod_pitch_tab /*fold00*/ void init_mod_pitch_tab(){ #if 1 int i; for(i=0;i<36;i++) mod_pitch_tab[i]=freqtab[i]; #else int i; double c=exp(log(2)/12.0); char buf[4096]; int fd; fd=open("freq.mod",O_RDONLY); if(fd<0){ perror("open()"); exit(1); } read(fd,buf,sizeof(buf)); close(fd); for(i=0;i<36;i++) mod_pitch_tab[i]=(int)((856.0/pow(c,i))+0.5); for(i=0;i<36;i++){ fd=X32(*((unsigned long *)(buf+i*16+1084))); fd>>=16; fd&=0x7FFF; printf("%2i: %3i <-> %3i (%3i)\n",i,mod_pitch_tab[i],fd,mod_pitch_tab[i]-fd); } #endif } // read_4v /*fold00*/ void read_4v(char *name){ int fd; struct stat stat_buf; int len; if(stat(name,&stat_buf)){ perror("stat()"); exit(1); } pattern_buf_len=stat_buf.st_size; pattern_buf=(char *)malloc(pattern_buf_len); if(!pattern_buf){ pattern_buf_len=0; perror("malloc()"); exit(1); } fd=open(name,O_RDONLY); if(fd<0){ perror("open()"); exit(1); } len=read(fd,pattern_buf,pattern_buf_len); if(len<0){ perror("read()"); exit(1); }else if(len!=pattern_buf_len){ fprintf(stderr,"read incomplete\n"); exit(1); } close(fd); } // read_set /*fold00*/ void read_set(char *name){ int fd; struct stat stat_buf; int len; if(stat(name,&stat_buf)){ perror("stat()"); exit(1); } voices_buf_len=stat_buf.st_size; voices_buf=(char *)malloc(voices_buf_len+32768); if(!voices_buf){ voices_buf_len=0; perror("malloc()"); exit(1); } fd=open(name,O_RDONLY); if(fd<0){ perror("open()"); exit(1); } len=read(fd,voices_buf,voices_buf_len); if(len<0){ perror("read()"); exit(1); }else if(len!=voices_buf_len){ fprintf(stderr,"read incomplete\n"); exit(1); } close(fd); } // dump_channel /*fold00*/ void dump_channel(int i){ struct note *note; for(note=chan[i].start;note<chan[i].end;note++){ printf(" %3i: %c %5i %08lx %08lx\n",note-chan[i].start, note->cmd,note->delay, note->val1,note->val2); } } // preprocess_4v /*fold00*/ void preprocess_4v(){ int i; struct note *note; note=(struct note*)(pattern_buf+16); for(i=0;i<4;i++){ printf("process channel %i: ",i); chan[i].start=note; while(1){ note->cmd=X16(note->cmd); note->delay=X16(note->delay); note->val1=X32(note->val1); note->val2=X32(note->val2); switch(note->cmd){ case NOTE_LOOPSTART: case NOTE_LOOPEND: case NOTE_VOICE: note->delay=0; break; } if(note->cmd==NOTE_END) break; note++; } chan[i].end=note; note++; printf("length %i\n",chan[i].end-chan[i].start); } } // preprocess_set /*fold00*/ void preprocess_set(){ int i,j; struct setheader *setheader=(struct setheader *)voices_buf; unsigned long *offset; memset(voice_map,-1,sizeof(voice_map)); memset(voice_rev_map,-1,sizeof(voice_rev_map)); memset(samples,0,sizeof(samples)); for(i=0;i<20;i++){ strncpy(samples[i].name,setheader->name[i],6); offset=(unsigned long *)setheader->offset; offset+=i; samples[i].descr=(struct sam_descr *)(voices_buf+X32(*offset)); if(X32(*offset)==0 || ((char *)samples[i].descr)+8>voices_buf+voices_buf_len){ samples[i].descr=NULL; samples[i].start=NULL; samples[i].len=0; samples[i].repstart=0; samples[i].replen=0; voice_map[i]=-1; }else{ voice_map[i]=i; voice_rev_map[i]=i; samples[i].start=voices_buf+X32(*offset)+8; samples[i].len=X16(samples[i].descr->len)&0x7FFF; samples[i].repstart=(X16(samples[i].descr->len)&0x7FFF)- (X16(samples[i].descr->replen)&0x7FFF); samples[i].replen=X16(samples[i].descr->replen)&0x7FFF; for(j=0;j<i;j++){ if(samples[j].descr==samples[i].descr){ samples[i].descr=NULL; samples[i].start=NULL; samples[i].len=0; samples[i].repstart=0; samples[i].replen=0; voice_map[i]=j; voice_rev_map[i]=-1; break; } } } printf("sam %2i: mapped to %2i,",i,voice_map[i]); if(voice_map[i]>=0){ printf(" \"%6s\", %6i\n",samples[voice_map[i]].name,samples[voice_map[i]].len); }else{ printf("\n"); } } }
* Translate current exceptions into `first' exception. The * bits go the wrong way for ffs() (0x10 is most important, etc). * There are only 5, so do it the obvious way. */ #define X1(x) x #define X2(x) x,x #define X4(x) x,x,x,x #define X8(x) X4(x),X4(x) #define X16(x) X8(x),X8(x) static char cx_to_trapx[] = { X1(FSR_NX), X2(FSR_DZ), X4(FSR_UF), X8(FSR_OF), X16(FSR_NV) }; static u_char fpu_codes[] = { X1(FPE_FLTINEX_TRAP), X2(FPE_FLTDIV_TRAP), X4(FPE_FLTUND_TRAP), X8(FPE_FLTOVF_TRAP), X16(FPE_FLTOPERR_TRAP) }; static int fpu_types[] = { X1(FPE_FLTRES), X2(FPE_FLTDIV), X4(FPE_FLTUND), X8(FPE_FLTOVF), X16(FPE_FLTINV)
{ return sq_dequote_to_argv_internal(arg, NULL, NULL, NULL, array); } /* 1 means: quote as octal * 0 means: quote as octal if (quote_path_fully) * -1 means: never quote * c: quote as "\\c" */ #define X8(x) x, x, x, x, x, x, x, x #define X16(x) X8(x), X8(x) static signed char const sq_lookup[256] = { /* 0 1 2 3 4 5 6 7 */ /* 0x00 */ 1, 1, 1, 1, 1, 1, 1, 'a', /* 0x08 */ 'b', 't', 'n', 'v', 'f', 'r', 1, 1, /* 0x10 */ X16(1), /* 0x20 */ -1, -1, '"', -1, -1, -1, -1, -1, /* 0x28 */ X16(-1), X16(-1), X16(-1), /* 0x58 */ -1, -1, -1, -1,'\\', -1, -1, -1, /* 0x60 */ X16(-1), X8(-1), /* 0x78 */ -1, -1, -1, -1, -1, -1, -1, 1, /* 0x80 */ /* set to 0 */ }; static inline int sq_must_quote(char c) { return sq_lookup[(unsigned char)c] + quote_path_fully > 0; } /* returns the longest prefix not needing a quote up to maxlen if positive. This stops at the first \0 because it's marked as a character needing an