Hi Christoph,

Just a few questions about how FreeSCI stores MIDI data.

I've been trying to work out what the bytes are before song position 33. I
thought they might be the MTrk or MThd headers but they aren't.

Secondly, I've written a little procedure to dump out a song's data but I'm not
sure if it's correct. Attached is an example. You'll notice that some of the
midi commands aren't in the 0x80 to 0xFF range, so what are they?

I think that's all for now. Thanks!

Alex.


----- Original Message ----- 
Wrom: LHPQQWOYIYZUNNYCGPKYLEJGDGVCJVTLBXFGGMEPYOQKEDOT
To: "Alexander R Angas" <[EMAIL PROTECTED]>
Sent: Friday, October 12, 2001 7:04 PM
Subject: Re: [freesci-develop] Re: Problems incrementing sound position


> Hi Alex,
> 
> 
> Sorry that this took so long, it's been a busy week for me (and will, in
> all likelihood, remain one).
> 
> Just in case you're interested, here's a site containing all the MIDI and
> SMF (Standard Midi File) gore:
> http://www.borg.com/~jglatt/tech/miditech.htm
> 
> I've cut out part of the relevant piece of code and am going to comment on
> it:
> 
> 
> /* if this song has data, process it */
> if (playing_song->data)
> {
> int midi_cmd;
> 
> /* retrieve MIDI command */
> midi_cmd = playing_song->data[playing_song->pos];
> 
> /* TODO: fix comment - i have no idea what this does */
> if (midi_cmd & 0x80)
> {
> ++(playing_song->pos);
> }
> //- This handles the 'running status mode' defined in the MIDI specs,
> //- and it handles it incorrectly (see soundserver.c for correct
> //- handling).
> //- In short, if a MIDI command does not start with the MSB set, then
> //- the previous command is repeated with the new parameters.
> //- However, _before_ reading the command, the delta time must be read.
> 
> 
> /* handle length escape sequence (see SCI sound specs) - this
> * basically means playing no sound for an amount of time */
> 
> //- Not just like that. Each MIDI command (see specs) starts with a delay
> //- performed before the command is executed. The delay is at least one
> //- byte (and may be zero), but more than one byte is possible. SCI
> //- violates the MIDI spec here by using the magic number 0xf0 to mark
> //- "Wait 240 ticks plus whatever follows", in a recursive definition
> //- (e.g. f0 f0 03 would mean 'wait 483 ticks).
> 
> if (midi_cmd == SCI_MIDI_TIME_EXPANSION_PREFIX)
> {
> /* must wait 240 ticks for each SCI_MIDI_TIME_EXPANSION_PREFIX */
> int expansions = 0;
> 
> while ((playing_song->data[(playing_song->pos)++]) ==
> SCI_MIDI_TIME_EXPANSION_PREFIX )
> expansions++;
> 
> /* set timer in milliseconds */
> if (timeSetEvent(ticks_to_milliseconds(expansions * 240), 1,
> do_sound, SCI_MIDI_TIME_TIMER, TIME_ONESHOT) == 0)
> fprintf(stderr, "SCI_MIDI_TIME_TIMER creation failed\n");
> 
> waiting_midi_time = 1;
> return;
> 
> //- This is the problem.
> 
> Let's first summarize some relevant facts.
> Each atomic SCI MIDI op looks like this:
> 
> rt times   t   (*)  parameters, n = f(op)
> _________      ____ _____________
> f0 f0 ... <xx> <op> <p0> ... <pn>
> 
> (*): The operation is optional (-> running status mode).
> 
> The total delta time (number of ticks to wait BEFORE this operation is
> executed) is (rt*240 + t).
> After this amount of time, <op> is evaluated. If <op> is not present, the
> operation from the last command is executed (running status mode).
> An operation can be identified by the fact that it has its MSB set.
> The number of parameters, n, is a function of <op> and generally between 0
> and 2, inclusive.
> 
> Therefore, when processing a MIDI command, the correct action to take is
> the following:
> 
> delta : INTEGER;
> cmd, old_cmd : INTEGER;
> i : INTEGER;
> op, channel : INTEGER;
> parameters : ARRAY[0..2] OF INTEGER;
> parameters_nr, parameters_needed : INTEGER;
> 
> old_cmd = 0;
> WHILE <song not finished> DO
> delta := read_delta_time();
> 
> wait_ticks(delta);
> 
> parameters_nr = 0;
> cmd := get_next_MIDI_byte();
> 
> IF (cmd & $80) = 0 THEN  (* running status mode! *)
> parameters[0] := cmd;
> parameters_nr := 1;
> cmd := old_cmd;
> ELSE
> old_cmd = cmd;
> FI
> 
> op := cmd & $f0;
> channel := cmd & $0f;
> 
> parameters_needed := f(op);  (* Usually implemented as a LUT *)
> parameters_needed := parameters_needed - parameters_nr;
> 
> FOR i := 0 TO parameters_needed -1 DO
> parameters[parameters_nr] := get_next_MIDI_byte();
> parameters_nr := parameters_nr +1;
> OD
> 
> play_midi(op, channel, parameters);
> OD 
> 
> 
> The problem when creating an event-based implementation is to separate the
> first and second block of this loop while maintaining correct semantics.
> 
> 
> Your code looks roughly like this ATM:
> 
> start:
> if (<data is valid>) {
> if (<we have a time expansion prefix>) {
> sleep(<a while>);
> goto start;
> } else if (<end of track>) {
> <finish song>
> } else {
> <play note>
> }
> }
> 
> ...which is quite different from what we need (and also from the code in
> soundserver.c).
> 
> I hope this helps. If you have further questions or would like a
> suggestion on how to implement this, please don't hesistate to contact me
> again- I promise I won't take as long this time!
> 
> llap,
>  Christoph
> 
>


-- Attached file included as plaintext by Listar --
-- File: songdump.txt

Song data for 26f2:
Pos     Time    Command Msg     Chan    Param1  Param2
   0    (unknown data:  000 / 0x00)
   1    (unknown data:  000 / 0x00)
   2    (unknown data:  048 / 0x30)
   3    (unknown data:  001 / 0x01)
   4    (unknown data:  007 / 0x07)
   5    (unknown data:  003 / 0x03)
   6    (unknown data:  015 / 0x0F)
   7    (unknown data:  001 / 0x01)
   8    (unknown data:  015 / 0x0F)
   9    (unknown data:  001 / 0x01)
  10    (unknown data:  015 / 0x0F)
  11    (unknown data:  000 / 0x00)
  12    (unknown data:  000 / 0x00)
  13    (unknown data:  000 / 0x00)
  14    (unknown data:  000 / 0x00)
  15    (unknown data:  000 / 0x00)
  16    (unknown data:  000 / 0x00)
  17    (unknown data:  000 / 0x00)
  18      0     0x80    8        0        9       0
  22    (unknown data:  016 / 0x10)
  23    (unknown data:  000 / 0x00)
  24    (unknown data:  016 / 0x10)
  25    (unknown data:  001 / 0x01)
  26    (unknown data:  006 / 0x06)
  27    (unknown data:  001 / 0x01)
  28    (unknown data:  006 / 0x06)
  29    (unknown data:  000 / 0x00)
  30    (unknown data:  000 / 0x00)
  31    (unknown data:  000 / 0x00)
  32    (unknown data:  000 / 0x00)
  33      0     0xC1    C        1       39
  36      0     0xE1    E        1      0x0040
  40      0     0xC4    C        4        7
  43      0     0xE4    E        4      0x0040
  47      0     0xC2    C        2       51
  50      0     0xE2    E        2      0x0040
  54      0     0xC3    C        3       26
  57      0     0xE3    E        3      0x0040
  61      0     0xC9    C        9        0
  64      0     0xE9    E        9      0x0040
  68      0     0xCB    C       11        0
  71      0     0xEB    E       11      0x0040
  75      0     0xBB    B       11        7      90
  79      0     0xC0    C        0        0
  82      0     0xE0    E        0      0x0040
  86      0     0xB0    B        0        7     120
  90      0     0xCA    C       10        0
  93      0     0xEA    E       10      0x0040
  97      0     0xBA    B       10        7     110
 101      0     0xCC    C       12        0
 104      0     0xCD    C       13        1
 107      0     0xB1    B        1        7     120
 111    (unknown data:  000 / 0x00)
 112    (unknown data:  070 / 0x46)
 113    (unknown data:  120 / 0x78)
 114      0     0xBB    B       11       70     120
 118      0     0xB4    B        4        7     108
 122    (unknown data:  000 / 0x00)
 123    (unknown data:  070 / 0x46)
 124    (unknown data:  108 / 0x6C)
 125      0     0xBA    B       10       70     108
 129      0     0xC2    C        2       51
 132      0     0xB3    B        3        7     106
 136      0     0xB2    B        2        7     122
 140      0     0xB3    B        3       10      90
 144      0     0xC3    C        3       26
 147      0     0xB2    B        2       10      49
 151      0     0xC4    C        4        7
 154      0     0xB4    B        4       10      20
 158      0     0xBA    B       10       10      20
 162      0     0xB1    B        1       10      63
 166      0     0xC1    C        1       39
 169      0     0xBB    B       11       10      63
 173      0     0xB9    B        9        7     115
 177      0     0xB2    B        2        7       0
 181    (unknown data:  000 / 0x00)
 182    (unknown data:  007 / 0x07)
 183    (unknown data:  122 / 0x7A)
 184     16     0xCF    C       15      127
 187      0     0x92    9        2       69      80
 191      0     0x93    9        3       69      70
 195      0     0x90    9        0       69     115
 199      6     0x92    9        2       69       0
 203    (unknown data:  001 / 0x01)
 204    (unknown data:  072 / 0x48)
 205    (unknown data:  066 / 0x42)
 206      0     0x93    9        3       72      68
 210      0     0x90    9        0       72     115
 214      1     0x93    9        3       69       0
 218      0     0x90    9        0       69       0
 222     11     0x92    9        2       72       0
 226      1     0x93    9        3       72       0
 230      0     0x90    9        0       72       0
 234      1     0x93    9        3       74      62
 238      0     0x90    9        0       74     115
 242      1     0x92    9        2       74      58
 246      6     0x99    9        9       36      86
 250      0     0x9C    9       12       36      86
 254      0     0x92    9        2       74       0
 258      0     0x93    9        3       75      58
 262      0     0x90    9        0       75     115
 266      1     0x91    9        1       38      74
 270      0     0x9B    9       11       50     115
 274      0     0x92    9        2       50      64
 278    (unknown data:  000 / 0x00)
 279    (unknown data:  075 / 0x4B)
 280    (unknown data:  064 / 0x40)
 281      0     0x99    9        9       46      80
 285      1     0x93    9        3       74       0
 289      0     0x90    9        0       74       0
 293      9     0x99    9        9       36       0
 297      0     0x9C    9       12       36       0
 301      5     0x92    9        2       75       0
 305    (unknown data:  000 / 0x00)
 306    (unknown data:  076 / 0x4C)
 307    (unknown data:  052 / 0x34)
 308      0     0x93    9        3       76      47
 312    (unknown data:  000 / 0x00)
 313    (unknown data:  075 / 0x4B)
 314    (unknown data:  000 / 0x00)
 315      0     0x90    9        0       76     115
 319    (unknown data:  000 / 0x00)
 320    (unknown data:  075 / 0x4B)
 321    (unknown data:  000 / 0x00)
 322      6     0x92    9        2       76       0
 326      0     0x93    9        3       76       0
 330      0     0x99    9        9       46       0
 334      0     0x90    9        0       76       0
 338      0     0x99    9        9       42      92
 342      0     0x92    9        2       50       0
 346      1     0x93    9        3       72      56
 350      0     0x90    9        0       72     115
 354      0     0x92    9        2       60      35
 358    (unknown data:  000 / 0x00)
 359    (unknown data:  072 / 0x48)
 360    (unknown data:  066 / 0x42)
 361    (unknown data:  000 / 0x00)
 362    (unknown data:  069 / 0x45)
 363    (unknown data:  062 / 0x3E)
 364      0     0x99    9        9       38     115
 368      0     0x9D    9       13       38     115
 372      0     0x92    9        2       66      44
 376      3     0x91    9        1       38       0
 380      0     0x9B    9       11       50       0
 384      2     0x99    9        9       42       0
 388    (unknown data:  003 / 0x03)
 389    (unknown data:  038 / 0x26)
 390    (unknown data:  000 / 0x00)
 391      0     0x9D    9       13       38       0
 395      2     0x92    9        2       60       0
 399    (unknown data:  001 / 0x01)
 400    (unknown data:  069 / 0x45)
 401    (unknown data:  000 / 0x00)
 402    (unknown data:  001 / 0x01)
 403    (unknown data:  066 / 0x42)
 404    (unknown data:  000 / 0x00)
 405    (unknown data:  001 / 0x01)
 406    (unknown data:  072 / 0x48)
 407    (unknown data:  000 / 0x00)
 408      1     0x93    9        3       72       0
 412      0     0x90    9        0       72       0
 416      0     0x91    9        1       38      78
 420      0     0x9B    9       11       50     115
 424      1     0x93    9        3       69      64
 428      0     0x90    9        0       69     115
 432      0     0x92    9        2       69      74
 436      0     0x99    9        9       46      70
 440    (unknown data:  001 / 0x01)
 441    (unknown data:  036 / 0x24)
 442    (unknown data:  029 / 0x1D)
 443      0     0x9C    9       12       36      29
 447      0     0x99    9        9       36       0
 451      0     0x9C    9       12       36       0
 455      2     0x99    9        9       46       0
 459      2     0x91    9        1       38       0
 463      0     0x92    9        2       69       0
 467      0     0x9B    9       11       50       0
 471      1     0x93    9        3       69       0
 475      0     0x90    9        0       69       0
 479      1     0x99    9        9       36      64
 483      0     0x9C    9       12       36      64
 487      0     0x92    9        2       43      78
 491    (unknown data:  000 / 0x00)
 492    (unknown data:  072 / 0x48)
 493    (unknown data:  064 / 0x40)
 494      0     0x93    9        3       72      62
 498      0     0x99    9        9       46      70
 502      0     0x90    9        0       72     115
 506      1     0x91    9        1       31      80
 510      0     0x9B    9       11       43     115
 514      4     0x99    9        9       36       0
 518      0     0x9C    9       12       36       0
 522      2     0x99    9        9       46       0
 526      4     0x91    9        1       31       0
 530      0     0x9B    9       11       43       0
 534      2     0x93    9        3       72       0
 538      0     0x90    9        0       72       0
 542      0     0x92    9        2       72       0
 546    (unknown data:  001 / 0x01)
 547    (unknown data:  043 / 0x2B)
 548    (unknown data:  000 / 0x00)
 549      0     0x93    9        3       74      70
 553      0     0x90    9        0       74     115
 557      0     0x99    9        9       36      78
 561      0     0x9C    9       12       36      78
 565      1     0x99    9        9       38     115
 569      0     0x9D    9       13       38     115
 573      0     0x92    9        2       60      47
 577    (unknown data:  000 / 0x00)
 578    (unknown data:  074 / 0x4A)
 579    (unknown data:  078 / 0x4E)
 580    (unknown data:  000 / 0x00)
 581    (unknown data:  065 / 0x41)
 582    (unknown data:  068 / 0x44)
 583    (unknown data:  000 / 0x00)
 584    (unknown data:  069 / 0x45)
 585    (unknown data:  074 / 0x4A)
 586      0     0x99    9        9       46      78
 590      1     0x91    9        1       31      86
 594      0     0x9B    9       11       43     115
 598      5     0x99    9        9       36       0
 602      0     0x9C    9       12       36       0
 606      0     0x99    9        9       38       0
 610      0     0x9D    9       13       38       0
 614      1     0x92    9        2       65       0
 618    (unknown data:  000 / 0x00)
 619    (unknown data:  074 / 0x4A)
 620    (unknown data:  000 / 0x00)
 621    (unknown data:  001 / 0x01)
 622    (unknown data:  069 / 0x45)
 623    (unknown data:  000 / 0x00)
 624      0     0x99    9        9       46       0
 628      0     0x92    9        2       60       0
 632      2     0x93    9        3       74       0
 636      0     0x90    9        0       74       0
 640      1     0x91    9        1       31       0
 644      0     0x9B    9       11       43       0
 648     10     0x99    9        9       38     115
 652      0     0x9D    9       13       38     115
 656      0     0x99    9        9       36      86
 660      0     0x9C    9       12       36      86
 664      1     0x92    9        2       64      78
 668    (unknown data:  000 / 0x00)
 669    (unknown data:  072 / 0x48)
 670    (unknown data:  078 / 0x4E)
 671    (unknown data:  000 / 0x00)
 672    (unknown data:  067 / 0x43)
 673    (unknown data:  076 / 0x4C)
 674    (unknown data:  000 / 0x00)
 675    (unknown data:  060 / 0x3C)
 676    (unknown data:  058 / 0x3A)
 677      0     0x99    9        9       46      58
 681      0     0x91    9        1       36      72
 685      0     0x9B    9       11       48     115
 689      1     0x92    9        2       48      66
 693      0     0x93    9        3       72      66
 697      0     0x90    9        0       72     115
 701      4     0x99    9        9       46       0
 705      0     0x92    9        2       72       0
 709      1     0x99    9        9       38       0
 713      0     0x9D    9       13       38       0
 717      0     0x99    9        9       36       0
 721      0     0x9C    9       12       36       0
 725      0     0x99    9        9       42      72
 729      0     0x92    9        2       64       0
 733    (unknown data:  001 / 0x01)
 734    (unknown data:  060 / 0x3C)
 735    (unknown data:  000 / 0x00)
 736      0     0x93    9        3       72       0
 740      0     0x90    9        0       72       0
 744      1     0x92    9        2       67       0
 748    (unknown data:  000 / 0x00)
 749    (unknown data:  048 / 0x30)
 750    (unknown data:  000 / 0x00)
 751      1     0x91    9        1       36       0
 755      0     0x9B    9       11       48       0
 759      8     0x99    9        9       42       0
 763    (unknown data:  003 / 0x03)
 764    (unknown data:  038 / 0x26)
 765    (unknown data:  086 / 0x56)
 766      0     0x9D    9       13       38      86
 770      1     0x99    9        9       38       0
 774      0     0x9D    9       13       38       0
 778      1     0x94    9        4       79      43
 782      0     0x93    9        3       79      43
 786      0     0x90    9        0       79     115
 790      0     0x9A    9       10       79     115
 794      1     0x99    9        9       46      78
 798      1     0x94    9        4       81      72
 802      0     0x93    9        3       81      72
 806      0     0x90    9        0       81     115
 810      0     0x9A    9       10       81     115
 814      0     0x99    9        9       38      98
 818      0     0x9D    9       13       38      98
 822      2     0x94    9        4       83      40
 826      0     0x93    9        3       83      40
 830      0     0x90    9        0       83     115
 834      0     0x9A    9       10       83     115
 838      1     0x94    9        4       79       0
 842      0     0x93    9        3       79       0
 846      0     0x90    9        0       79       0
 850      0     0x9A    9       10       79       0
 854      0     0x99    9        9       38       0
 858      0     0x9D    9       13       38       0
 862      1     0x99    9        9       42      86
 866      1     0x93    9        3       84      74
 870      0     0x99    9        9       46       0
 874      0     0x90    9        0       84     115
 878      0     0x94    9        4       84      74
 882      0     0x9A    9       10       84     115
 886      1     0x99    9        9       36     125
 890      0     0x9C    9       12       36     125
 894      0     0x94    9        4       81       0
 898      0     0x93    9        3       81       0
 902      0     0x90    9        0       81       0
 906      0     0x9A    9       10       81       0
 910      1     0x91    9        1       36      80
 914      0     0x99    9        9       73      98
 918      0     0x9B    9       11       48     115
 922      0     0x94    9        4       83       0
 926      0     0x93    9        3       83       0
 930      0     0x90    9        0       83       0
 934      0     0x9A    9       10       83       0
 938      4     0x94    9        4       84       0
 942      0     0x93    9        3       84       0
 946      0     0x90    9        0       84       0
 950      0     0x9A    9       10       84       0
 954      1     0x99    9        9       42       0
 958      2     0x91    9        1       36       0
 962      0     0x9B    9       11       48       0
 966      2     0x99    9        9       36       0
 970      0     0x9C    9       12       36       0
 974      0     0xB2    B        2        7       0
 978      5     0x99    9        9       73       0
 982      6     0xFC    F       12


Reply via email to