dump_ed: more work on the output

This commit is contained in:
Vince Weaver 2017-06-20 22:39:45 -04:00
parent dd53ec31c7
commit 3abd6ffdfa
2 changed files with 127 additions and 8 deletions

View File

@ -7,30 +7,127 @@
int main(int argc, char **argv) {
int i;
unsigned char triad[3];
char temp[5];
int fd,result;
char *filename;
int instrument1=-1,new_instrument1=0;
int instrument2=-1,new_instrument2=0;
int line=0;
int length=0;
fd=open("HIGHWIND.ED",O_RDONLY);
if (argc>1) {
filename=argv[1];
}
else {
printf("Usage: %s file.ed\n\n",argv[0]);
return 0;
}
fd=open(filename,O_RDONLY);
if (fd<0) {
fprintf(stderr,"Could not open HIGHWIND.ED\n");
fprintf(stderr,"Could not open %s\n",filename);
return -1;
}
printf("\' HEADER:\t\t2\n");
printf("\'\n");
printf("\' TITLE:\t%s\n",filename);
printf("\' AUTHOR:\t%s\n","dump_ed.c");
printf("\' COMMENTS:\tConverted from Electric Duet format\n");
printf("\' LOOP:\t\t0\n");
printf("\' BPM:\t\t120\n");
printf("\' TEMPO:\t3\n");
printf("\' FREQ:\t\t1000000\n");
printf("\' IRQ:\t\t50\n");
printf("\' LYRICS:\t0\n");
printf("\'\n");
printf("\' INSTRUMENT: 0\n");
printf("\' NAME: piano\n");
printf("\' ADSR: 1\n");
printf("\' NOISE: 0\n");
printf("\' ATTACK: 14,15,15\n");
printf("\' DECAY: 14\n");
printf("\' SUSTAIN: 13\n");
printf("\' RELEASE: 10,5\n");
printf("\' ONCE: 0\n");
printf("\' ENDINSTRUMENT\n");
printf("\'\n");
printf("\' ENDHEADER\n");
printf("\'\n");
/* from about.md */
/* First byte 0: Voice */
/* byte1 = voice1 instrument */
/* byte2 = voice2 instrument */
/* Varies, bigger than 8 seem to make no difference */
/* Otherwise, byte0 = duration (20=quarter, 40=half) */
/* byte1 = voice1 note */
/* byte2 = voice2 note */
// assume for us, we have 96/3=32 lines per whole note
// 80/x = 32 whole
// 40/2 = 16 half
// 20/x = 8 quarter
// 10/x = 4 eigth
// 5/x = 2 sixteenth
// 2.5 = 1 thirtysecond
// so times 2 divide by 5
while(1) {
result=read(fd,triad,3);
if (result<3) break;
if ((triad[0]==0) && (triad[1]==0) && (triad[2]==0)) break;
if (triad[0]==0) {
printf("Instrument 1=%d, Instrument 2=%d\n",triad[1],triad[2]);
new_instrument1=triad[1];
new_instrument2=triad[2];
//printf("Instrument 1=%d, Instrument 2=%d\n",triad[1],triad[2]);
}
else {
printf("Duration %d, ",triad[0]);
printf("%s ",ed_to_note(triad[1],temp));
printf("%s ",ed_to_note(triad[2],temp));
// printf("Duration %d, ",triad[0]);
length=(triad[0]*2)/5;
// printf("Duration %d, ",length);
printf("%02X\t%s? ",line,ed_to_note(triad[1],temp));
if (new_instrument1!=instrument1) {
printf("%d",new_instrument1);
}
else {
printf("-");
}
printf("------\t");
printf("%s? ",ed_to_note(triad[2],temp));
if (new_instrument2!=instrument2) {
printf("%d",new_instrument2);
}
else {
printf("-");
}
printf("------");
printf("\n");
}
instrument1=new_instrument1;
instrument2=new_instrument2;
line++;
if (line==32) {
line=0;
printf("\'\n");
}
for(i=0;i<length-1;i++) {
printf("%02X\t------------\t------------\n",line);
line++;
if (line==32) {
line=0;
printf("\'\n");
}
}
}
close(fd);

View File

@ -93,7 +93,7 @@ static char sharps[12]={' ','#',' ',' ','#',' ','#',' ',' ','#',' ','#'};
char *ed_to_note(int freq, char *out) {
int i,j;
int note=0,octave=0;
int note=0,octave=0,notefound=0;;
// printf("Freq=%d\n",freq);
@ -108,10 +108,32 @@ char *ed_to_note(int freq, char *out) {
for(j=0;j<12;j++) {
if (freq==note_mapping[i].freq[j]) {
note=j;
notefound=1;
break;
}
}
if (j==12) {
if ((!notefound) && (freq>28)) {
for(j=0;j<12;j++) {
if ((freq+1)==note_mapping[i].freq[j]) {
note=j;
notefound=1;
break;
}
}
}
if ((!notefound) && (freq>28)) {
for(j=0;j<12;j++) {
if ((freq-1)==note_mapping[i].freq[j]) {
note=j;
notefound=1;
break;
}
}
}
if (!notefound) {
sprintf(out,"%3d",freq);
}
else {