1
/*================================================================
2
* print the sbk/sf2 information
4
* Copyright (C) 1996,1997 Takashi Iwai
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
*================================================================*/
29
static char *getname(char *p);
30
static void print_sbk(SFInfo *sf, FILE *fout);
33
int main(int argc, char **argv)
38
fprintf(stderr, "usage: sf2text SoundFontFile [textfile]\n");
42
if ((fp = fopen(argv[1], "r")) == NULL) {
43
fprintf(stderr, "can't open SoundFont file %s\n", argv[1]);
47
load_sbk(fp, &sfinfo);
51
if (argc >= 3 && (fp = fopen(argv[2], "w")) == NULL) {
52
fprintf(stderr, "can't open text file %s\n", argv[2]);
55
print_sbk(&sfinfo, fp);
61
static char *getname(p)
71
static void print_sbk(SFInfo *sf, FILE *fout)
79
fprintf(fout, "** SoundFont: %d %d\n", sf->version, sf->minorversion);
80
fprintf(fout, "** SampleData: %d %d\n", (int)sf->samplepos, (int)sf->samplesize);
82
fprintf(fout, "\n** Presets: %d\n", sf->nrpresets-1);
83
for (i = 0, ip = sf->presethdr; i < sf->nrpresets-1; ip++, i++) {
85
fprintf(fout, "[%s] preset=%d bank=%d layer=%d\n",
86
getname(ip->name), ip->preset, ip->bank,
87
ip[1].bagNdx - ip->bagNdx);
88
for (b = ip->bagNdx; b < ip[1].bagNdx; b++) {
90
fprintf(fout, " BAG %d\n", sf->presetbag[b+1] - sf->presetbag[b]);
91
for (g = sf->presetbag[b]; g < sf->presetbag[b+1]; g++) {
92
sbk_to_text(buf, sf->presetgen[g].oper,
93
sf->presetgen[g].amount, sf);
94
fprintf(fout, " %s\n", buf);
99
fprintf(fout, "\n** Instruments: %d\n", sf->nrinsts-1);
100
for (i = 0, tp = sf->insthdr; i < sf->nrinsts-1; tp++, i++) {
102
fprintf(fout, "[%s] layer=%d\n", getname(tp->name), tp[1].bagNdx - tp->bagNdx);
103
for (b = tp->bagNdx; b < tp[1].bagNdx; b++) {
105
fprintf(fout, " BAG %d\n", sf->instbag[b+1] - sf->instbag[b]);
106
for (g = sf->instbag[b]; g < sf->instbag[b+1]; g++) {
107
sbk_to_text(buf, sf->instgen[g].oper,
108
sf->instgen[g].amount, sf);
109
fprintf(fout, " %s\n", buf);
114
if (sf->version == 1)
115
ninfos = sf->nrinfos;
117
ninfos = sf->nrinfos - 1;
118
fprintf(fout, "\n** SampleInfo: %d\n", ninfos);
119
for (i = 0, hp = sf->sampleinfo; i < ninfos; hp++, i++) {
120
fprintf(fout, "[%s] start=%lx end=%lx startloop=%lx endloop=%lx\n",
121
sf->samplenames[i].name, hp->startsample, hp->endsample,
122
hp->startloop, hp->endloop);
123
if (sf->version > 1) {
124
fprintf(fout, " rate=%d, pitch=%d:%d, link=%d, type=%x\n",