-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathakaiutil_file.c
2494 lines (2262 loc) · 71.2 KB
/
akaiutil_file.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2010,2012,2018,2019 Klaus Michael Indlekofer. All rights reserved.
*
* m.indlekofer@gmx.de
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "akaiutil_io.h"
#include "akaiutil.h"
#include "akaiutil_file.h"
#include "akaiutil_wav.h"
/* AKAI file info */
int
akai_file_info(struct file_s *fp,int verbose)
{
static u_char hdrbuf[AKAI_FL_BLOCKSIZE]; /* XXX enough */
u_int hdrsize;
struct akai_genfilehdr_s *hdrp;
static char nbuf[AKAI_NAME_LEN+1]; /* +1 for '\0' */
int s900flag;
int sampleflag;
int programflag;
u_int i;
if ((fp==NULL)
||(fp->volp==NULL)
||(fp->index>=fp->volp->fimax)){
return -1;
}
if (verbose){
printf("%s\n",fp->name);
printf("fnr: %u\n",fp->index+1);
printf("start: block 0x%04x\n",fp->bstart);
printf("size: %u bytes\n",fp->size);
/* file type */
printf("type: ");
if (fp->type==AKAI_CDSETUP3000_FTYPE){
/* CD3000 CD-ROM setup file */
/* Note: generic file header does not apply for this file type! */
printf("CD3000 CD-ROM setup\n");
return akai_cdsetup3000_info(fp);
}
hdrsize=sizeof(struct akai_genfilehdr_s); /* default */
s900flag=0; /* default */
sampleflag=0; /* default */
programflag=0; /* default */
switch (fp->type){
case AKAI_SAMPLE900_FTYPE: /* S900 sample file */
printf("S900 sample\n");
hdrsize=sizeof(struct akai_sample900_s);
s900flag=1;
sampleflag=1;
break;
case AKAI_SAMPLE1000_FTYPE: /* S1000 sample file */
printf("S1000 sample\n");
hdrsize=sizeof(struct akai_sample1000_s);
sampleflag=1;
break;
case AKAI_SAMPLE3000_FTYPE: /* S3000 sample file */
printf("S3000 sample\n");
hdrsize=sizeof(struct akai_sample3000_s);
sampleflag=1;
break;
case AKAI_CDSAMPLE3000_FTYPE: /* CD3000 CD-ROM sample parameters file */
printf("CD3000 CD-ROM sample parameters\n");
break;
case AKAI_PROGRAM900_FTYPE: /* S900 program file */
printf("S900 program\n");
s900flag=1;
programflag=1;
break;
case AKAI_PROGRAM1000_FTYPE: /* S1000 program file */
printf("S1000 program\n");
programflag=1;
break;
case AKAI_PROGRAM3000_FTYPE: /* S3000 program file */
printf("S3000 program\n");
programflag=1;
break;
case AKAI_DRUM900_FTYPE: /* S900 drum settings file */
printf("S900 drum settings\n");
/*s900flag=1;*/
return 0; /* done */
case AKAI_DRUMFILE_FTYPE: /* S1000 or S3000 drum settings file */
printf("S1000/S3000 drum settings\n");
break;
case AKAI_FXFILE_FTYPE: /* S1100 or S3000 effects file */
printf("S1100/S3000 effects\n");
break;
case AKAI_QLFILE_FTYPE: /* S1100 or S3000 cue-list file */
printf("S1100/S3000 cue-list\n");
break;
case AKAI_TLFILE_FTYPE: /* S1100 or S3000 take-list file */
printf("S1100/S3000 take-list\n");
break;
case AKAI_MULTI3000_FTYPE: /* S3000 multi file */
printf("S3000 multi\n");
break; /* use generic file header */
case AKAI_FIXUP900_FTYPE: /* S900 fixup file */
printf("S900 fixup\n");
/*s900flag=1;*/
return 0; /* done */
case AKAI_MEMIMG900_FTYPE: /* S900 memory image file */
printf("S900 memory image\n");
/*s900flag=1;*/
return 0; /* done */
case AKAI_SYS1000_FTYPE: /* S1000 operating system file */
printf("S1000 operating system\n");
return 0; /* done */
case AKAI_SYS3000_FTYPE: /* S3000 operating system file */
printf("S3000 operating system\n");
return 0; /* done */
case AKAI_OVS900_FTYPE: /* S900 overall settings file */
printf("S900 overall settings\n");
/*s900flag=1;*/
return 0; /* done */
default:
/* unknown or unsupported */
printf("\?\?\?\n");
return 1; /* no error */
}
/* read header */
if (akai_read_file(0,hdrbuf,fp,0,hdrsize)<0){
fprintf(stderr,"cannot read header\n");
return -1;
}
/* name */
if (s900flag){ /* S900 type? */
/* Note: name in S900 sample/program file header starts at byte 0 */
akai2ascii_name(hdrbuf,nbuf,1); /* 1: S900 */
}else{
/* generic file header */
hdrp=(struct akai_genfilehdr_s *)hdrbuf;
akai2ascii_name(hdrp->name,nbuf,0); /* 0: not S900 */
}
printf("ramname: \"%s\"\n",nbuf);
if (sampleflag){
/* sample info */
akai_sample_info(fp,hdrbuf);
}else if (programflag){
/* program info */
return akai_program_info(fp);
}
}else{
printf("%3u %-16s %9u 0x%04x ",fp->index+1,fp->name,fp->size,fp->bstart);
if (fp->volp->type==AKAI_VOL_TYPE_S900){
/* S900 volume */
if (fp->osver!=0){ /* compressed file? */
/* number of un-compressed floppy blocks */
printf(" %5u",fp->osver);
}
}else{
/* S1000/S3000 volume */
/* OS version */
if (((0xff&(fp->osver>>8))<100)&&((0xff&fp->osver)<100)){
printf("%2u.%02u ",0xff&(fp->osver>>8),0xff&fp->osver);
}else{
printf("%5u ",fp->osver);
}
/* tags */
for (i=0;i<AKAI_FILE_TAGNUM;i++){
if ((fp->tag[i]>=1)&&(fp->tag[i]<=AKAI_PARTHEAD_TAGNUM)){
printf("%02u ",fp->tag[i]);
}else if ((fp->tag[i]==AKAI_FILE_TAGFREE)||(fp->tag[i]==AKAI_FILE_TAGS1000)){
printf(" ");
}else{
printf("? ");
}
}
}
printf("\n");
}
return 0;
}
void
akai_sample_info(struct file_s *fp,u_char *hdrp)
{
struct akai_sample3000_s *s3000hdrp;
struct akai_sample900_s *s900hdrp;
u_int samplecount;
u_int samplerate;
u_int i,j,k;
if ((fp==NULL)||(hdrp==NULL)){
return;
}
if (fp->type==AKAI_SAMPLE900_FTYPE){
/* S900 sample */
s900hdrp=(struct akai_sample900_s *)hdrp;
/* number of samples */
/* XXX should be an even number */
samplecount=(s900hdrp->slen[3]<<24)
+(s900hdrp->slen[2]<<16)
+(s900hdrp->slen[1]<<8)
+s900hdrp->slen[0];
printf("scount: 0x%08x (%9u)\n",samplecount,samplecount);
samplerate=(s900hdrp->srate[1]<<8)+s900hdrp->srate[0];
printf("srate: %uHz\n",samplerate);
if (samplerate>0){
printf("sdur: %.3lfms\n",1000.0*((double)samplecount)/((double)samplerate));
}
printf("npitch: %.2lf\n",((double)((s900hdrp->npitch[1]<<8)+s900hdrp->npitch[0]))/16.0);
printf("loud: %+i\n",(((int)(char)s900hdrp->loud[1])<<8)+((int)(u_char)s900hdrp->loud[0]));
printf("dmadesa: 0x%02x%02x\n",
s900hdrp->dmadesa[1],
s900hdrp->dmadesa[0]);
printf("locat: 0x%02x%02x%02x%02x\n",
s900hdrp->locat[3],
s900hdrp->locat[2],
s900hdrp->locat[1],
s900hdrp->locat[0]);
printf("start: 0x%02x%02x%02x%02x\n",
s900hdrp->start[3],
s900hdrp->start[2],
s900hdrp->start[1],
s900hdrp->start[0]);
printf("end: 0x%02x%02x%02x%02x\n",
s900hdrp->end[3],
s900hdrp->end[2],
s900hdrp->end[1],
s900hdrp->end[0]);
printf("llen: 0x%02x%02x%02x%02x\n",
s900hdrp->llen[3],
s900hdrp->llen[2],
s900hdrp->llen[1],
s900hdrp->llen[0]);
printf("pmode: ");
switch (s900hdrp->pmode){
case SAMPLE900_PMODE_ONESHOT:
printf("ONESHOT\n");
break;
case SAMPLE900_PMODE_LOOP:
printf("LOOP\n");
break;
case SAMPLE900_PMODE_ALTLOOP:
printf("ALTLOOP\n");
break;
default:
printf("\?\?\?\n");
break;
}
printf("dir: ");
switch (s900hdrp->dir){
case SAMPLE900_DIR_NORM:
printf("NORM\n");
break;
case SAMPLE900_DIR_REV:
printf("REV\n");
break;
default:
printf("\?\?\?\n");
break;
}
printf("type: ");
switch (s900hdrp->type){
case SAMPLE900_TYPE_NORM:
printf("NORM\n");
break;
case SAMPLE900_TYPE_VELXF:
printf("VELXF\n");
break;
default:
printf("\?\?\?\n");
break;
}
printf("compr: %s\n",
(fp->osver!=0)?"ON":"OFF"); /* S900 compressed/non-compressed sample format */
}else if ((fp->type==AKAI_SAMPLE1000_FTYPE)||(fp->type==AKAI_SAMPLE3000_FTYPE)){
/* S1000/S3000 sample */
s3000hdrp=(struct akai_sample3000_s *)hdrp;
/* Note: S1000 header is contained within S3000 header */
/* number of samples */
samplecount=(s3000hdrp->s1000.slen[3]<<24)
+(s3000hdrp->s1000.slen[2]<<16)
+(s3000hdrp->s1000.slen[1]<<8)
+s3000hdrp->s1000.slen[0];
printf("scount: 0x%08x (%9u)\n",samplecount,samplecount);
samplerate=(s3000hdrp->s1000.srate[1]<<8)+s3000hdrp->s1000.srate[0];
printf("srate: %uHz\n",samplerate);
if (samplerate>0){
printf("sdur: %.3lfms\n",1000.0*((double)samplecount)/((double)samplerate));
}
printf("bandw: ");
switch (s3000hdrp->s1000.bandw){
case SAMPLE1000_BANDW_10KHZ:
printf("10kHz\n");
break;
case SAMPLE1000_BANDW_20KHZ:
printf("20kHz\n");
break;
default:
printf("\?\?\?\n");
break;
}
printf("rkey: %u\n",s3000hdrp->s1000.rkey);
printf("ctune: %+i\n",(int)(char)s3000hdrp->s1000.ctune);
printf("stune: %+i\n",(int)(char)s3000hdrp->s1000.stune);
printf("hltoff: %+i\n",(int)(char)s3000hdrp->s1000.hltoff);
k=(s3000hdrp->s1000.stpaira[1]<<8)+s3000hdrp->s1000.stpaira[0];
if (k!=AKAI_SAMPLE1000_STPAIRA_NONE){
if (fp->type==AKAI_SAMPLE3000_FTYPE){
k*=SAMPLE3000_STPAIRA_MULT;
printf("stpaira: 0x%05x\n",k);
}else{
printf("stpaira: 0x%04x\n",k);
}
}
printf("locat: 0x%02x%02x%02x%02x\n",
s3000hdrp->s1000.locat[3],
s3000hdrp->s1000.locat[2],
s3000hdrp->s1000.locat[1],
s3000hdrp->s1000.locat[0]);
printf("start: 0x%02x%02x%02x%02x\n",
s3000hdrp->s1000.start[3],
s3000hdrp->s1000.start[2],
s3000hdrp->s1000.start[1],
s3000hdrp->s1000.start[0]);
printf("end: 0x%02x%02x%02x%02x\n",
s3000hdrp->s1000.end[3],
s3000hdrp->s1000.end[2],
s3000hdrp->s1000.end[1],
s3000hdrp->s1000.end[0]);
printf("pmode: ");
switch (s3000hdrp->s1000.pmode){
case SAMPLE1000_PMODE_LOOP:
printf("LOOP\n");
break;
case SAMPLE1000_PMODE_LOOPNOTREL:
printf("LOOPNOTREL\n");
break;
case SAMPLE1000_PMODE_NOLOOP:
printf("NOLOOP\n");
break;
case SAMPLE1000_PMODE_TOEND:
printf("TOEND\n");
break;
default:
printf("\?\?\?\n");
break;
}
printf("lnum: %u\n",s3000hdrp->s1000.lnum);
printf("lfirst: %u\n",s3000hdrp->s1000.lfirst+1);
for (i=0;i<AKAI_SAMPLE1000_LOOPNUM;i++){
k=(s3000hdrp->s1000.loop[i].time[1]<<8)+s3000hdrp->s1000.loop[i].time[0];
if (k==SAMPLE1000LOOP_TIME_NOLOOP){
continue; /* next loop */
}
j=(s3000hdrp->s1000.loop[i].at[3]<<24)
+(s3000hdrp->s1000.loop[i].at[2]<<16)
+(s3000hdrp->s1000.loop[i].at[1]<<8)
+s3000hdrp->s1000.loop[i].at[0];
if (j>=samplecount){ /* invalid? */
continue; /* next loop */
}
printf("loop %u:\n",i+1);
printf(" loopat: 0x%08x\n",j);
printf(" length: 0x%02x%02x%02x%02x.0x%02x%02x\n",
s3000hdrp->s1000.loop[i].len[3],
s3000hdrp->s1000.loop[i].len[2],
s3000hdrp->s1000.loop[i].len[1],
s3000hdrp->s1000.loop[i].len[0],
s3000hdrp->s1000.loop[i].flen[1],
s3000hdrp->s1000.loop[i].flen[0]);
if (k==SAMPLE1000LOOP_TIME_HOLD){
printf(" ltime: HOLD\n");
}else{
printf(" ltime: %ums\n",k);
}
}
}
}
int
akai_program_info(struct file_s *fp)
{
static char nbuf[AKAI_NAME_LEN+1]; /* +1 for '\0' */
struct akai_program900_s *s900hdrp;
struct akai_program900kg_s *s900kgp;
struct akai_program3000_s *s3000hdrp;
struct akai_program3000kg_s *s3000kgp;
u_char *buf;
u_int hdrsiz;
u_int kgsiz;
u_int kgnum;
u_int i,j,k;
if ((fp==NULL)||(fp->volp==NULL)||(fp->index>=fp->volp->fimax)){
return -1;
}
if (fp->type==AKAI_PROGRAM900_FTYPE){
hdrsiz=sizeof(struct akai_program900_s);
kgsiz=sizeof(struct akai_program900kg_s);
}else if (fp->type==AKAI_PROGRAM1000_FTYPE){
hdrsiz=sizeof(struct akai_program1000_s);
kgsiz=sizeof(struct akai_program1000kg_s);
}else if (fp->type==AKAI_PROGRAM3000_FTYPE){
hdrsiz=sizeof(struct akai_program3000_s);
kgsiz=sizeof(struct akai_program3000kg_s);
}else{
return -1;
}
/* allocate buffer */
if (fp->size<hdrsiz){
fprintf(stderr,"invalid file size\n");
return -1;
}
if ((buf=malloc(fp->size))==NULL){
fprintf(stderr,"cannot allocate memory\n");
return -1;
}
/* read file */
if (akai_read_file(0,buf,fp,0,fp->size)<0){
fprintf(stderr,"cannot read file\n");
free(buf);
return -1;
}
if (fp->type==AKAI_PROGRAM900_FTYPE){
/* S900 program */
s900hdrp=(struct akai_program900_s *)buf;
printf("kgxf: %s\n",(s900hdrp->kgxf!=0x00)?"ON":"OFF");
kgnum=s900hdrp->kgnum;
printf("kgnum: %u\n",kgnum);
if (fp->size<hdrsiz+kgnum*kgsiz){
fprintf(stderr,"invalid file size\n");
free(buf);
return -1;
}
k=(s900hdrp->kg1a[1]<<8)+s900hdrp->kg1a[0];
if (k!=PROGRAM900_KGA_NONE){
printf("kg1a: 0x%04x\n",k);
}
for (i=0;i<kgnum;i++){
printf("keygroup %u:\n",i+1);
s900kgp=(struct akai_program900kg_s *)(buf+hdrsiz+i*kgsiz);
printf(" midichoff: %u\n",s900kgp->midichoff);
printf(" key lo-hi: %u-%u\n",s900kgp->keylo,s900kgp->keyhi);
printf(" outch: ");
switch (s900kgp->outch1){
case PROGRAM900KG_OUTCH1_LEFT:
printf("LEFT\n");
break;
case PROGRAM900KG_OUTCH1_RIGHT:
printf("RIGHT\n");
break;
case PROGRAM900KG_OUTCH1_ANY:
printf("ANY\n");
break;
default:
printf("%u\n",s900kgp->outch1+1);
break;
}
printf(" pitch: %s\n",((PROGRAM900KG_FLAGS_PCONST&s900kgp->flags)!=0x00)?"CONST":"TRACK");
printf(" oneshot: %s\n",((PROGRAM900KG_FLAGS_ONESHOT&s900kgp->flags)!=0x00)?"ON":"OFF");
printf(" velxf: %s\n",((PROGRAM900KG_FLAGS_VELXF&s900kgp->flags)!=0x00)?"ON":"OFF");
printf(" velxfv50: %u\n",s900kgp->velxfv50);
printf(" velswth: %u",s900kgp->velswth);
if (s900kgp->velswth<=PROGRAM900KG_VELSWTH_NOSOFT){
printf(" (no soft sample)\n");
}else if (s900kgp->velswth>=PROGRAM900KG_VELSWTH_NOLOUD){
printf(" (no loud sample)\n");
}else{
printf("\n");
}
printf(" sample 1 (soft):\n");
printf(" tune: %+.2lf\n",((double)((((int)(char)s900kgp->tune1[1])<<8)+((int)(u_char)s900kgp->tune1[0])))/16.0);
printf(" filter: %u\n",s900kgp->filter1);
printf(" loud: %+i\n",(int)(char)s900kgp->loud1);
akai2ascii_name(s900kgp->sname1,nbuf,1); /* 1: S900 */
printf(" sname: \"%s\"\n",nbuf);
k=(s900kgp->shdra1[1]<<8)+s900kgp->shdra1[0];
if (k!=PROGRAM900KG_SHDRA_NONE){
printf(" shdra: 0x%04x\n",k);
}
printf(" sample 2 (loud):\n");
printf(" tune: %+.2lf\n",((double)((((int)(char)s900kgp->tune2[1])<<8)+((int)(u_char)s900kgp->tune2[0])))/16.0);
printf(" filter: %u\n",s900kgp->filter2);
printf(" loud: %+i\n",(int)(char)s900kgp->loud2);
akai2ascii_name(s900kgp->sname2,nbuf,1); /* 1: S900 */
printf(" sname: \"%s\"\n",nbuf);
k=(s900kgp->shdra2[1]<<8)+s900kgp->shdra2[0];
if (k!=PROGRAM900KG_SHDRA_NONE){
printf(" shdra: 0x%04x\n",k);
}
k=(s900kgp->kgnexta[1]<<8)+s900kgp->kgnexta[0];
if (k!=PROGRAM900_KGA_NONE){
printf(" kgnexta: 0x%04x\n",k);
}
}
}else{
/* S1000/S3000 program */
s3000hdrp=(struct akai_program3000_s *)buf;
/* Note: S1000 header is contained within S3000 header */
printf("midich: ");
if (s3000hdrp->s1000.midich1==PROGRAM1000_MIDICH1_OMNI){
printf("OMNI\n");
}else{
printf("%u\n",s3000hdrp->s1000.midich1+1);
}
printf("key lo-hi: %u-%u\n",s3000hdrp->s1000.keylo,s3000hdrp->s1000.keyhi);
printf("oct: %+i\n",(int)(char)s3000hdrp->s1000.oct);
printf("auxch: ");
if (s3000hdrp->s1000.auxch1==PROGRAM1000_AUXCH1_OFF){
printf("OFF\n");
}else{
printf("%u\n",s3000hdrp->s1000.auxch1+1);
}
printf("kgxf: %s\n",(s3000hdrp->s1000.kgxf!=0x00)?"ON":"OFF");
kgnum=s3000hdrp->s1000.kgnum;
printf("kgnum: %u\n",kgnum);
if (fp->size<hdrsiz+kgnum*kgsiz){
fprintf(stderr,"invalid file size\n");
free(buf);
return -1;
}
k=(s3000hdrp->s1000.kg1a[1]<<8)+s3000hdrp->s1000.kg1a[0];
if (k!=PROGRAM1000_KGA_NONE){
if (fp->type==AKAI_PROGRAM3000_FTYPE){
k*=PROGRAM3000_KGA_MULT;
printf("kg1a: 0x%05x\n",k);
}else{
printf("kg1a: 0x%04x\n",k);
}
}
for (i=0;i<kgnum;i++){
printf("keygroup %u:\n",i+1);
s3000kgp=(struct akai_program3000kg_s *)(buf+hdrsiz+i*kgsiz);
printf(" key lo-hi: %u-%u\n",s3000kgp->s1000.keylo,s3000kgp->s1000.keyhi);
printf(" ctune: %+i\n",(int)(char)s3000kgp->s1000.ctune);
printf(" stune: %+i\n",(int)(char)s3000kgp->s1000.stune);
printf(" filter: %u\n",s3000kgp->s1000.filter);
printf(" velxf: %s\n",(s3000kgp->s1000.velxf!=0x00)?"ON":"OFF");
for (j=0;j<PROGRAM1000KG_VELZONENUM;j++){
printf(" velzone %u:\n",j+1);
akai2ascii_name(s3000kgp->s1000.velzone[j].sname,nbuf,0); /* 0: not S900 */
printf(" vel lo-hi: %u-%u\n",s3000kgp->s1000.velzone[j].vello,s3000kgp->s1000.velzone[j].velhi);
printf(" ctune: %+i\n",(int)(char)s3000kgp->s1000.velzone[j].ctune);
printf(" stune: %+i\n",(int)(char)s3000kgp->s1000.velzone[j].stune);
printf(" loud: %+i\n",(int)(char)s3000kgp->s1000.velzone[j].loud);
printf(" filter: %+i\n",(int)(char)s3000kgp->s1000.velzone[j].filter);
printf(" pan: %+i\n",(int)(char)s3000kgp->s1000.velzone[j].pan);
printf(" auxchoff: %u\n",s3000kgp->s1000.auxchoff[j]);
printf(" pitch: %s\n",(s3000kgp->s1000.pconst[j]!=0x00)?"CONST":"TRACK");
printf(" pmode: ");
switch (s3000kgp->s1000.velzone[j].pmode){
case PROGRAM1000_PMODE_SAMPLE:
printf("SAMPLE\n");
break;
case PROGRAM1000_PMODE_LOOP:
printf("LOOP\n");
break;
case PROGRAM1000_PMODE_LOOPNOTREL:
printf("LOOPNOTREL\n");
break;
case PROGRAM1000_PMODE_NOLOOP:
printf("NOLOOP\n");
break;
case PROGRAM1000_PMODE_TOEND:
printf("TOEND\n");
break;
default:
printf("\?\?\?\n");
break;
}
printf(" sname: \"%s\"\n",nbuf);
k=(s3000kgp->s1000.velzone[j].shdra[1]<<8)+s3000kgp->s1000.velzone[j].shdra[0];
if (k!=PROGRAM1000KG_SHDRA_NONE){
if (fp->type==AKAI_PROGRAM3000_FTYPE){
k*=PROGRAM3000_SHDRA_MULT;
printf(" shdra: 0x%05x\n",k);
}else{
printf(" shdra: 0x%04x\n",k);
}
}
}
k=(s3000kgp->s1000.kgnexta[1]<<8)+s3000kgp->s1000.kgnexta[0];
if (k!=PROGRAM1000_KGA_NONE){
if (fp->type==AKAI_PROGRAM3000_FTYPE){
k*=PROGRAM3000_KGA_MULT;
printf(" kgnexta: 0x%05x\n",k);
}else{
printf(" kgnexta: 0x%04x\n",k);
}
}
}
}
free(buf);
return 0;
}
int
akai_cdsetup3000_info(struct file_s *fp)
{
char nbuf[AKAI_NAME_LEN+1]; /* +1 for '\0' */
u_char *buf;
struct akai_cdsetup3000_s *hp;
struct akai_cdsetup3000_entry_s *ep;
u_int enr;
u_int e,i;
if ((fp==NULL)||(fp->volp==NULL)||(fp->index>=fp->volp->fimax)){
return -1;
}
/* allocate buffer */
if (fp->size<sizeof(struct akai_cdsetup3000_s)){
fprintf(stderr,"invalid file size\n");
return -1;
}
if ((buf=malloc(fp->size))==NULL){
fprintf(stderr,"cannot allocate memory\n");
return -1;
}
/* header */
hp=(struct akai_cdsetup3000_s *)buf;
/* marked file entries */
ep=(struct akai_cdsetup3000_entry_s *)(buf+sizeof(struct akai_cdsetup3000_s));
/* number of entries */
enr=(fp->size-sizeof(struct akai_cdsetup3000_s))/sizeof(struct akai_cdsetup3000_entry_s);
/* read file */
if (akai_read_file(0,buf,fp,0,fp->size)<0){
fprintf(stderr,"cannot read file\n");
free(buf);
return -1;
}
/* name */
akai2ascii_name(hp->name,nbuf,fp->volp->type==AKAI_VOL_TYPE_S900);
printf("ramname: \"%s\"\n\n",nbuf);
/* CD-ROM label */
akai2ascii_name(hp->cdlabel,nbuf,fp->volp->type==AKAI_VOL_TYPE_S900);
printf("CD-ROM label: \"%s\"\n",nbuf);
/* print marked file entries */
printf("\nmarked files (part:vol/file):\n---------------------------------------------\n");
i=0;
for (e=0;e<enr;e++){
if (ep[e].parti!=0xff){ /* used entry? */
printf("%c:%03u/%03u ",
'A'+ep[e].parti,
ep[e].voli+1,
(ep[e].filei[1]<<8)+ep[e].filei[0]+1);
if (i%4==3){
printf("\n");
}
i++;
}
}
if (i%4!=0){
printf("\n");
}
printf("---------------------------------------------\n");
free(buf);
return 0;
}
/* fix RAM name of AKAI file */
int
akai_fixramname(struct file_s *fp)
{
static char nbuf[AKAI_NAME_LEN+1]; /* +1 for '\0' */
static u_char buf[sizeof(struct akai_genfilehdr_s)]; /* XXX enough for all cases */
u_char *np;
int s900flag;
if ((fp==NULL)||(fp->volp==NULL)||(fp->index>=fp->volp->fimax)){
return -1;
}
/* file type */
s900flag=0; /* default */
switch (fp->type){
case AKAI_SAMPLE900_FTYPE: /* S900 sample */
case AKAI_PROGRAM900_FTYPE: /* S900 program */
/* Note: name in S900 sample/program file header starts at byte 0 */
np=buf;
s900flag=1;
break;
case AKAI_SAMPLE1000_FTYPE: /* S1000 sample */
case AKAI_SAMPLE3000_FTYPE: /* S3000 sample */
case AKAI_CDSAMPLE3000_FTYPE: /* CD3000 CD-ROM sample parameters */
case AKAI_PROGRAM1000_FTYPE: /* S1000 program */
case AKAI_PROGRAM3000_FTYPE: /* S3000 program */
case AKAI_DRUMFILE_FTYPE: /* S1000 or S3000 drum file */
case AKAI_FXFILE_FTYPE: /* S1100 or S3000 effects file */
case AKAI_QLFILE_FTYPE: /* S1100 or S3000 cue-list file */
case AKAI_TLFILE_FTYPE: /* S1100 or S3000 take-list file */
case AKAI_MULTI3000_FTYPE: /* S3000 multi file */
{
/* use generic file header */
struct akai_genfilehdr_s *p;
p=(struct akai_genfilehdr_s *)buf;
np=p->name;
}
break;
case AKAI_CDSETUP3000_FTYPE:
{
/* CD3000 CD-ROM setup file */
struct akai_cdsetup3000_s *p;
p=(struct akai_cdsetup3000_s *)buf;
np=p->name;
}
break;
default:
/* unknown or unsupported */
return 1; /* no error */
}
/* read header */
if (akai_read_file(0,buf,fp,0,sizeof(struct akai_genfilehdr_s))<0){
fprintf(stderr,"cannot read header\n");
return -1;
}
/* copy file name to name in RAM */
akai2ascii_name(fp->volp->file[fp->index].name,nbuf,fp->volp->type==AKAI_VOL_TYPE_S900);
ascii2akai_name(nbuf,np,s900flag);
/* write header */
if (akai_write_file(0,buf,fp,0,sizeof(struct akai_genfilehdr_s))<0){
fprintf(stderr,"cannot write header\n");
return -1;
}
return 0;
};
int
akai_s900comprfile_updateuncompr(struct file_s *fp)
{
u_int osver;
if (fp==NULL){
return -1;
}
/* check if compressed file in S900 volume */
if ((fp->volp==NULL)||(fp->volp->type!=AKAI_VOL_TYPE_S900)||(fp->osver==0)){
return -1;
}
/* check if supported file type */
if (fp->type!=AKAI_SAMPLE900_FTYPE){
/* no error, keep osver */
return 0;
}
/* S900 sample file, compressed sample format */
/* non-compressed sample size in bytes */
osver=akai_sample900_getsamplesize(fp);
/* number of un-compressed floppy blocks */
/* Note: without sample header */
osver=(osver+AKAI_FL_BLOCKSIZE-1)/AKAI_FL_BLOCKSIZE; /* round up */
if (osver==0){ /* unsuitable osver? */
osver=1; /* XXX non zero */
}
/* set osver of file */
/* Note: akai_rename_file() will correct osver if necessary */
if (akai_rename_file(fp,NULL,fp->volp,AKAI_CREATE_FILE_NOINDEX,NULL,osver)<0){
return -1;
}
return 0;
}
u_int
akai_sample900_getsamplesize(struct file_s *fp)
{
static struct akai_sample900_s s900hdr;
static u_int samplecount;
static u_int samplecountpart;
static u_int samplesize;
if (fp==NULL){
return 0;
}
if (fp->type!=(u_char)AKAI_SAMPLE900_FTYPE){ /* not S900 sample? */
return 0;
}
/* read header to memory */
if (akai_read_file(0,(u_char *)&s900hdr,fp,0,sizeof(struct akai_sample900_s))<0){
fprintf(stderr,"cannot read sample header\n");
return 0;
}
/* number of samples */
/* XXX should be an even number */
samplecount=(s900hdr.slen[3]<<24)
+(s900hdr.slen[2]<<16)
+(s900hdr.slen[1]<<8)
+s900hdr.slen[0];
/* number of samples per part */
samplecountpart=(samplecount+1)/2; /* round up */
/* size in bytes in S900 non-compressed sample format */
samplesize=3*samplecountpart;
return samplesize;
}
void
akai_sample900noncompr_sample2wav(u_char *sbuf,u_char *wavbuf,u_int samplecountpart)
{
u_int i;
if ((sbuf==NULL)||(wavbuf==NULL)){
return;
}
if (samplecountpart==0){
return;
}
/* convert 12bit S900 non-compressed sample format into 16bit WAV sample format */
for (i=0;i<samplecountpart;i++){ /* first part */
wavbuf[i*2+1]=sbuf[i*2+1];
wavbuf[i*2+0]=0xf0&sbuf[i*2+0];
}
for (i=0;i<samplecountpart;i++){ /* second part */
wavbuf[samplecountpart*2+i*2+1]=sbuf[samplecountpart*2+i];
wavbuf[samplecountpart*2+i*2+0]=0xf0&(sbuf[i*2+0]<<4);
}
}
void
akai_sample900noncompr_wav2sample(u_char *sbuf,u_char *wavbuf,u_int samplecountpart)
{
u_int i;
if ((sbuf==NULL)||(wavbuf==NULL)){
return;
}
if (samplecountpart==0){
return;
}
/* convert 16bit WAV sample format into 12bit S900 non-compressed sample format */
for (i=0;i<samplecountpart;i++){ /* first part */
sbuf[i*2+1]=wavbuf[i*2+1];
sbuf[i*2+0]=0xf0&wavbuf[i*2+0];
}
for (i=0;i<samplecountpart;i++){ /* second part */
sbuf[samplecountpart*2+i]=wavbuf[samplecountpart*2+i*2+1];
sbuf[i*2+0]|=0x0f&(wavbuf[samplecountpart*2+i*2+0]>>4);
}
}
u_int
akai_sample900compr_getbits(u_char *buf,u_int bitpos,u_int bitnum)
{
u_int bytepos;
u_char bmask;
u_int val;
u_int i;
if ((buf==NULL)||(bitnum==0)){
return 0;
}
/* XXX no check if bitnum too large for u_int */
/* XXX no check if bitpos+bitnum too large for buf */
val=0;
for (i=0;i<bitnum;i++,bitpos++){
bytepos=(bitpos>>3); /* /8: 8 bits per byte */
bmask=(1<<(7-(7&bitpos))); /* Note: upper bit first */
val<<=1;
if ((bmask&buf[bytepos])!=0){
val|=1;
}
}
return val;
}
u_int
akai_sample900compr_sample2wav(u_char *sbuf,u_char *wavbuf,u_int sbufsiz,u_int wavbufsiz)
{
u_char upsign;
u_short upabsval;
short curval;
short curinc;
u_int bitremain;
u_int bitpos;
u_int wavpos;
u_char code;
u_int i,j,n;
if ((sbuf==NULL)||(wavbuf==NULL)){
return 0;
}
if ((sbufsiz==0)||(wavbufsiz==0)){
return 0;
}
/* convert S900 compressed sample format into 16bit WAV sample format */
curval=0;
curinc=0;
bitremain=sbufsiz*8; /* 8 bits per byte */
bitpos=0;
wavpos=0;
for (;(bitremain>0)&&(wavpos+1<wavbufsiz);){
/* get code nibble */
if (bitremain<4){
break; /* end */
}
code=(u_char)akai_sample900compr_getbits(sbuf,bitpos,4);
#ifdef SAMPLE900COMPR_DEBUG
printf("%08x: code=%x\n",bitpos,code);
#endif
bitpos+=4;
bitremain-=4;
/* parse code */
if (code<SAMPLE900COMPR_BITNUM_OFF-SAMPLE900COMPR_BITNUM_MAX){
/* number of samples */
if (code==0x0){
j=SAMPLE900COMPR_GROUP_SAMPNUM;
}else{
j=code;
}
/* generate signal */
for (i=0;(i<j)&&(wavpos+1<wavbufsiz);i++){
/* update curval */
curval+=curinc;
/* convert 12bit sample into 16bit WAV sample */
wavbuf[wavpos++]=0xf0&(u_char)(curval<<4);
wavbuf[wavpos++]=0xff&(u_char)(curval>>4);
}
}else{
/* number of bits per increment update word */
n=SAMPLE900COMPR_BITNUM_OFF-code;
/* number of required remaining bits for instruction code */
j=SAMPLE900COMPR_GROUP_SAMPNUM*(1+n); /* Note: 1 sign flag bit and n bits per word */
if (bitremain<j){
break; /* end */
}
/* generate signal */
for (i=0;(i<SAMPLE900COMPR_GROUP_SAMPNUM)&&(wavpos+1<wavbufsiz);i++){
/* get sign flag bit */
upsign=(u_char)akai_sample900compr_getbits(sbuf,bitpos+0+i,1);
/* get value word */
upabsval=(u_short)akai_sample900compr_getbits(sbuf,bitpos+SAMPLE900COMPR_GROUP_SAMPNUM+i*n,n);
#ifdef SAMPLE900COMPR_DEBUG
printf(" %c%u\n",(upsign==0)?'+':'-',upabsval);
#endif
/* update curinc */
if (upsign==0){
/* plus */
curinc+=(short)upabsval;
}else{
/* minus */
curinc-=(short)upabsval;
}
/* update curval */
curval+=curinc;
/* Note: SAMPLE900COMPR_BITMASK&curval contains sample value */
/* convert 12bit sample into 16bit WAV sample */
wavbuf[wavpos++]=0xf0&(u_char)(curval<<4);
wavbuf[wavpos++]=0xff&(u_char)(curval>>4);
}