xm_lib.c
来自「Genetic Programing of music」· C语言 代码 · 共 743 行 · 第 1/2 页
C
743 行
} /* Go to next line */ fprintf(outFile, "\n"); return; } /* end of fprintXMPatternNoteData *//* * fprintXMPatternInfo - prints one patterns data in xmFile to outFile. * Expects xmFile to be queued to the beginning of pattern info, and * leaves xmFile queued to the beginning of the note data. Channels is * the number of channels in this XM file. If printNoteData is true, * the note information is also printed. */voidfprintXMPatternInfo(FILE *xmFile, FILE *outFile, int channels, int printNoteData){ int headerSize; short int dataSize; long patternStart=0; short int rows; /* find pattern start */ patternStart=ftell(xmFile); /* Get pattern header length */ fread(&headerSize, sizeof(int), 1, xmFile); fprintf(outFile, "\tHeader Size =\t%d\n", headerSize); fseek(xmFile, 1, SEEK_CUR); /* skip packing type */ /* Get number of rows in pattern */ fread(&rows, sizeof(short int), 1, xmFile); fprintf(outFile, "\tRows =\t\t%hd\n", rows); /* Get pattern data size */ fread(&dataSize, sizeof(short int), 1, xmFile); fprintf(outFile, "\tData Size =\t%hd\n\n", dataSize); /* If requested, print pattern note info */ if(printNoteData) { fprintf(outFile, "\tPattern Note Data:\n\n"); fprintXMPatternNoteData(xmFile, outFile, dataSize, (int)rows, channels); } /* Go to end of this pattern */ fseek(xmFile, patternStart+headerSize+dataSize, SEEK_SET); return; } /* end of fprintXMPatternInfo *//* * fprintXMExtendedInstrumentInfo - prints one instruments extended data, * including details and sample information, in xmFile to * outFile. Expects xmFile to be queued to the beginning of extended * info (sample header size in xm.txt). It returns the size of the * sample headers, and queues the file to the beginning of the first * sample for this instrument. */intfprintXMExtendedInstrumentInfo(FILE *xmFile, FILE *outFile) { short int tempShort; char tempChar; int headerSize; long extendedStart=0; /* find extended info start */ extendedStart=ftell(xmFile); /* Get sample header size */ fread(&headerSize, sizeof(int), 1, xmFile); fprintf(outFile, "\tSample Header Size =\t%d\n", headerSize); fseek(xmFile, 192, SEEK_CUR); /* skip notes, panning and volume pts */ /* Get number of volume points */ fread(&tempChar, sizeof(char), 1, xmFile); fprintf(outFile, "\tVolume points =\t\t%hd\n", tempChar); /* Get number of panning points */ fread(&tempChar, sizeof(char), 1, xmFile); fprintf(outFile, "\tPanning points =\t%hd\n\n", tempChar); /* Get volume sustain point */ fread(&tempChar, sizeof(char), 1, xmFile); fprintf(outFile, "\tVolume Sustain Point =\t%hd\n", tempChar); /* Get volume loop start point */ fread(&tempChar, sizeof(char), 1, xmFile); fprintf(outFile, "\tVolume Loop Start =\t%hd\n", tempChar); /* Get volume loop end */ fread(&tempChar, sizeof(char), 1, xmFile); fprintf(outFile, "\tVolume Loop End =\t%hd\n\n", tempChar); /* Get panning sustain point */ fread(&tempChar, sizeof(char), 1, xmFile); fprintf(outFile, "\tPanning Sustain Point =\t%hd\n", tempChar); /* Get panning loop start point */ fread(&tempChar, sizeof(char), 1, xmFile); fprintf(outFile, "\tPanning Loop Start =\t%hd\n", tempChar); /* Get panning loop end */ fread(&tempChar, sizeof(char), 1, xmFile); fprintf(outFile, "\tPanning Loop End =\t%hd\n\n", tempChar); /* Get volume type */ fread(&tempChar, sizeof(char), 1, xmFile); if(tempChar & 0x1) fprintf(outFile, "\tVolume is On\n"); else fprintf(outFile, "\tVolume is Off\n"); if(tempChar & 0x2) fprintf(outFile, "\tVolume Sustains\n"); else fprintf(outFile, "\tVolume Doesn't Sustain\n"); if(tempChar & 0x4) fprintf(outFile, "\tVolume Loops\n\n"); else fprintf(outFile, "\tVolume Doesn't Loop\n\n"); /* Get panning type */ fread(&tempChar, sizeof(char), 1, xmFile); if(tempChar & 0x1) fprintf(outFile, "\tPanning is On\n"); else fprintf(outFile, "\tPanning is Off\n"); if(tempChar & 0x2) fprintf(outFile, "\tPanning Sustains\n"); else fprintf(outFile, "\tPanning Doesn't Sustain\n"); if(tempChar & 0x4) fprintf(outFile, "\tPanning Loops\n\n"); else fprintf(outFile, "\tPanning Doesn't Loop\n\n"); /* Get Vibrato Type */ fread(&tempChar, sizeof(char), 1, xmFile); fprintf(outFile, "\tVibrato Type =\t\t%hd\n", tempChar); /* Get Vibrato Sweep */ fread(&tempChar, sizeof(char), 1, xmFile); fprintf(outFile, "\tVibrato Sweep =\t\t%hd\n", tempChar); /* Get Vibrato Depth */ fread(&tempChar, sizeof(char), 1, xmFile); fprintf(outFile, "\tVibrato Depth =\t\t%hd\n", tempChar); /* Get Vibrato Rate */ fread(&tempChar, sizeof(char), 1, xmFile); fprintf(outFile, "\tVibrato Rate =\t\t%hd\n\n", tempChar); /* Get Volume Fadeout */ fread(&tempShort, sizeof(short int), 1, xmFile); fprintf(outFile, "\tVolume Fadeout =\t%hd\n\n", tempShort); fseek(xmFile, 2, SEEK_CUR); /* reserved section */ return headerSize;} /* end of fprintXMExtendedInstrumentInfo *//* * fprintXMSampleInfo - prints one samples info in xmFile to * outFile. Expects xmFile to be queued to the beginning of sample * info, and queues xmFile to the beginning of the next sample/instrument * when done. headerSize is the size of the sample header, and is * used to skip the file to the next sample header. The returned * value is the length of the sample data. */intfprintXMSampleInfo(FILE *xmFile, FILE *outFile, int headerSize) { char tempChar; int tempInt; int dataSize; long sampleStart=0; char tempString[23]; /* find pattern start */ sampleStart=ftell(xmFile); /* Get sample length */ fread(&dataSize, sizeof(int), 1, xmFile); fprintf(outFile, "\t\tSample Length =\t\t%d\n", dataSize); /* Get sample loop start */ fread(&tempInt, sizeof(int), 1, xmFile); fprintf(outFile, "\t\tSample Loop Start =\t%d\n", tempInt); /* Get sample loop length */ fread(&tempInt, sizeof(int), 1, xmFile); fprintf(outFile, "\t\tSample Loop Length =\t%d\n", tempInt); /* Get sample volume */ fread(&tempChar, sizeof(char), 1, xmFile); fprintf(outFile, "\t\tSample Volume =\t\t%hd\n", tempChar); /* Get sample finetune */ fread(&tempChar, sizeof(char), 1, xmFile); fprintf(outFile, "\t\tSample Finetune Value =\t%hd\n", tempChar); /* Get sample type */ fread(&tempChar, sizeof(char), 1, xmFile); switch(tempChar & 0x3) { case 0: fprintf(outFile, "\t\tSample has No Loop\n"); break; case 1: fprintf(outFile, "\t\tSample has Forward Loop\n"); break; case 2: fprintf(outFile, "\t\tSample has Ping-Pong Loop\n"); break; } if(tempChar & 0x8) fprintf(outFile, "\t\tSample has 16-bit data\n"); else fprintf(outFile, "\t\tSample has 8-bit data\n"); /* Get Sample Panning */ fread(&tempChar, sizeof(char), 1, xmFile); tempInt=(int)tempChar; tempInt+=128; fprintf(outFile, "\t\tSample Panning Value =\t%d\n", tempInt); /* Get Sample Relative Note */ fread(&tempChar, sizeof(char), 1, xmFile); fprintf(outFile, "\t\tSample Relative Note =\t%hd\n", tempChar); fseek(xmFile,1, SEEK_CUR); /* seek passed reserved space */ /* Get sample name */ tempString[22]=0; fread(tempString, sizeof(char), 22, xmFile); fprintf(outFile, "\t\tSample Name =\t\t'%s'\n\n", tempString); /* for debugging *//* fprintf(outFile, "Current offset is %#lx\n\n", ftell(xmFile)); fprintf(outFile, "Expect next sample at: %#lx\n\n", sampleStart+headerSize+dataSize); */ /* seek to beginning of next sample/instrument */ fseek(xmFile,sampleStart+headerSize,SEEK_SET); return dataSize;} /* end of fprintXMSampleInfo *//* * fprintXMInstrumentInfo - prints one instruments data in xmFile to * outFile. Expects xmFile to be queued to the beginning of instrument * info, and queues xmFile to the beginning of the next instrument/end * of file when done. */voidfprintXMInstrumentInfo(FILE *xmFile, FILE *outFile) { short int tempShort; int instrumentSize; int sampHeaderSize; int dataSize=0; long instrumentStart=0; char tempString[23]; int i; /* find instrument start */ instrumentStart=ftell(xmFile); /* Get instrument size */ fread(&instrumentSize, sizeof(int), 1, xmFile); fprintf(outFile, "\tInstrument Size =\t%d\n", instrumentSize); /* Get instrument name */ tempString[22]=0; fread(tempString, sizeof(char), 22, xmFile); fprintf(outFile, "\tInstrument Name =\t'%s'\n", tempString); fseek(xmFile, 1, SEEK_CUR); /* skip instrument type */ /* Get number of samples in instrument */ fread(&tempShort, sizeof(short int), 1, xmFile); fprintf(outFile, "\tNumber of Samples =\t%hd\n\n", tempShort); if(tempShort >0) { sampHeaderSize = fprintXMExtendedInstrumentInfo(xmFile, outFile); /* go to start of samples */ fseek(xmFile,instrumentStart+instrumentSize,SEEK_SET); /* Print out each samples information */ for(i=0;i<tempShort;i++) { fprintf(outFile, "\tSample %d Information:\n", i); dataSize+=fprintXMSampleInfo(xmFile, outFile, sampHeaderSize); } /* seek over sample data */ fseek(xmFile,dataSize,SEEK_CUR); } else { /* seek to beginning of next instrument/end of file */ fseek(xmFile,instrumentStart+instrumentSize,SEEK_SET); } return;} /* end of fprintXMInstrumentInfo */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?