898 | | 0x00, // part/channel (offset 28) |
899 | | 0x01, 0x06, 0x02, 0x0a, 0x08, 0x09, 0x0d, 0x08, 0x04, 0x04, |
900 | | 0x04, 0x06, 0x02, 0x02, 0x03, 0x07, 0x0f, 0x0d, |
901 | | 0x05, 0x04, 0x0c, 0x00, 0x03, 0x01, 0x01, 0x00, |
902 | | 0x00, 0x00, 0x01, 0x01, 0x0e, 0x00, 0x02, 0x02, |
903 | | 0x01, 0x00, 0x01, 0x00, 0x01, 0x02, 0x00, 0x01, |
904 | | 0x08, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x00, |
905 | | 0x06, 0x02, 0x00, 0x00, 0x04, 0x00, 0x03, 0x02, |
906 | | 0x04, 0x00, 0x00, 0xf7, |
| 902 | 0x00, 0x01, // part/channel (offset 28) |
| 903 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 904 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 905 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 906 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 907 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 908 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 909 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 910 | 0x00, 0x00, 0xf7, |
912 | | byte * ptr; |
913 | | byte ticks, play_once; |
914 | | byte music_type, num_instr; |
915 | | byte *channel, *instr, *track; |
916 | | int i, ch; |
| 918 | static const byte freq2note[128] = { |
| 919 | /*128*/ 6, 6, 6, 6, |
| 920 | /*132*/ 7, 7, 7, 7, 7, 7, 7, |
| 921 | /*139*/ 8, 8, 8, 8, 8, 8, 8, 8, 8, |
| 922 | /*148*/ 9, 9, 9, 9, 9, 9, 9, 9, 9, |
| 923 | /*157*/ 10, 10, 10, 10, 10, 10, 10, 10, 10, |
| 924 | /*166*/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, |
| 925 | /*176*/ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, |
| 926 | /*186*/ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, |
| 927 | /*197*/ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, |
| 928 | /*209*/ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, |
| 929 | /*222*/ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, |
| 930 | /*235*/ 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, |
| 931 | /*249*/ 18, 18, 18, 18, 18, 18, 18 |
| 932 | }; |
| 933 | |
| 934 | static const uint16 num_steps_table[] = { |
| 935 | 1, 2, 4, 5, |
| 936 | 6, 7, 8, 9, |
| 937 | 10, 12, 14, 16, |
| 938 | 18, 21, 24, 30, |
| 939 | 36, 50, 64, 82, |
| 940 | 100, 136, 160, 192, |
| 941 | 240, 276, 340, 460, |
| 942 | 600, 860, 1200, 1600 |
| 943 | }; |
| 944 | int Scumm::convert_extraflags(byte * ptr, byte * src_ptr) { |
| 945 | int flags = src_ptr[0]; |
| 946 | |
| 947 | int t1, t2, t3, t4, time; |
| 948 | int v1, v2, v3; |
| 949 | |
| 950 | if (!(flags & 0x80)) |
| 951 | return -1; |
| 952 | |
| 953 | t1 = (src_ptr[1] & 0xf0) >> 3; |
| 954 | t2 = (src_ptr[2] & 0xf0) >> 3; |
| 955 | t3 = (src_ptr[3] & 0xf0) >> 3 | (flags & 0x40 ? 0x80 : 0); |
| 956 | t4 = (src_ptr[3] & 0x0f) << 1; |
| 957 | v1 = (src_ptr[1] & 0x0f); |
| 958 | v2 = (src_ptr[2] & 0x0f); |
| 959 | v3 = 31; |
| 960 | if ((flags & 0x7) == 0) { |
| 961 | v1 = v1 + 31 + 8; |
| 962 | v2 = v2 + 31 + 8; |
| 963 | } else { |
| 964 | v1 = v1 * 2 + 31; |
| 965 | v2 = v2 * 2 + 31; |
| 966 | } |
976 | | // Conver the ticks into a MIDI tempo. |
977 | | dw = (500000 * 256) / ticks; |
978 | | debug(4, " ticks = %d, speed = %ld", ticks, dw); |
979 | | |
980 | | // Write a tempo change SysEx |
981 | | memcpy(ptr, "\x00\xFF\x51\x03", 4); ptr += 4; |
982 | | *ptr++ = (byte)((dw >> 16) & 0xFF); |
983 | | *ptr++ = (byte)((dw >> 8) & 0xFF); |
984 | | *ptr++ = (byte)(dw & 0xFF); |
985 | | |
986 | | // Copy our hardcoded instrument table into it |
987 | | // Then, convert the instrument table as given in this song resource |
988 | | // And write it *over* the hardcoded table. |
989 | | // Note: we deliberately. |
990 | | |
991 | | /* now fill in the instruments */ |
992 | | for (i = 0; i < num_instr; i++) { |
993 | | ch = channel[i] - 1; |
994 | | |
995 | | debug(4, "Sound %d: instrument %d on channel %d.", |
996 | | idx, i, ch); |
997 | | |
998 | | memcpy(ptr, ADLIB_INSTR_MIDI_HACK, |
999 | | sizeof(ADLIB_INSTR_MIDI_HACK)); |
1000 | | |
1001 | | ptr[5] += ch; |
1002 | | ptr[28] += ch; |
1003 | | ptr[92] += ch; |
1004 | | |
1005 | | /* flags_1 */ |
1006 | | ptr[30 + 0] = (instr[i * 16 + 3] >> 4) & 0xf; |
1007 | | ptr[30 + 1] = instr[i * 16 + 3] & 0xf; |
1008 | | |
1009 | | /* oplvl_1 */ |
1010 | | ptr[30 + 2] = (instr[i * 16 + 4] >> 4) & 0xf; |
1011 | | ptr[30 + 3] = instr[i * 16 + 4] & 0xf; |
1012 | | |
1013 | | /* atdec_1 */ |
1014 | | ptr[30 + 4] = ((~instr[i * 16 + 5]) >> 4) & 0xf; |
1015 | | ptr[30 + 5] = (~instr[i * 16 + 5]) & 0xf; |
1016 | | |
1017 | | /* sustrel_1 */ |
1018 | | ptr[30 + 6] = ((~instr[i * 16 + 6]) >> 4) & 0xf; |
1019 | | ptr[30 + 7] = (~instr[i * 16 + 6]) & 0xf; |
1020 | | |
1021 | | /* waveform_1 */ |
1022 | | ptr[30 + 8] = (instr[i * 16 + 7] >> 4) & 0xf; |
1023 | | ptr[30 + 9] = instr[i * 16 + 7] & 0xf; |
1024 | | |
1025 | | /* flags_2 */ |
1026 | | ptr[30 + 10] = (instr[i * 16 + 8] >> 4) & 0xf; |
1027 | | ptr[30 + 11] = instr[i * 16 + 8] & 0xf; |
1028 | | |
1029 | | /* oplvl_2 */ |
1030 | | ptr[30 + 12] = (instr[i * 16 + 9] >> 4) & 0xf; |
1031 | | ptr[30 + 13] = instr[i * 16 + 9] & 0xf; |
1032 | | |
1033 | | /* atdec_2 */ |
1034 | | ptr[30 + 14] = ((~instr[i * 16 + 10]) >> 4) & 0xf; |
1035 | | ptr[30 + 15] = (~instr[i * 16 + 10]) & 0xf; |
1036 | | |
1037 | | /* sustrel_2 */ |
1038 | | ptr[30 + 16] = ((~instr[i * 16 + 11]) >> 4) & 0xf; |
1039 | | ptr[30 + 17] = (~instr[i * 16 + 11]) & 0xf; |
1040 | | |
1041 | | /* waveform_2 */ |
1042 | | ptr[30 + 18] = (instr[i * 16 + 12] >> 4) & 0xf; |
1043 | | ptr[30 + 19] = instr[i * 16 + 12] & 0xf; |
1044 | | |
1045 | | /* feedback */ |
1046 | | ptr[30 + 20] = (instr[i * 16 + 2] >> 4) & 0xf; |
1047 | | ptr[30 + 21] = instr[i * 16 + 2] & 0xf; |
1048 | | ptr += sizeof(ADLIB_INSTR_MIDI_HACK); |
| 1049 | src_ptr += 2; |
| 1050 | size -= 2; |
| 1051 | |
| 1052 | if (*src_ptr == 0x80) { |
| 1053 | // 0x80: is music; otherwise not. |
| 1054 | |
| 1055 | // The "speed" of the song |
| 1056 | ticks = *(src_ptr + 1); |
| 1057 | |
| 1058 | // Flag that tells us whether we should loop the song (0) or play it only once (1) |
| 1059 | play_once = *(src_ptr + 2); |
| 1060 | |
| 1061 | // Number of instruments used |
| 1062 | num_instr = *(src_ptr + 8); // Normally 8 |
| 1063 | |
| 1064 | // copy the pointer to instrument data |
| 1065 | channel = src_ptr + 9; |
| 1066 | instr = src_ptr + 0x11; |
| 1067 | |
| 1068 | // skip over the rest of the header and copy the MIDI data into a buffer |
| 1069 | src_ptr += 0x11 + 8 * 16; |
| 1070 | size -= 0x11 + 8 * 16; |
| 1071 | |
| 1072 | CHECK_HEAP |
| 1073 | |
| 1074 | track = src_ptr; |
| 1075 | |
| 1076 | // Conver the ticks into a MIDI tempo. |
| 1077 | dw = (500000 * 256) / ticks; |
| 1078 | debug(4, " ticks = %d, speed = %ld", ticks, dw); |
| 1079 | |
| 1080 | // Write a tempo change SysEx |
| 1081 | memcpy(ptr, "\x00\xFF\x51\x03", 4); ptr += 4; |
| 1082 | *ptr++ = (byte)((dw >> 16) & 0xFF); |
| 1083 | *ptr++ = (byte)((dw >> 8) & 0xFF); |
| 1084 | *ptr++ = (byte)(dw & 0xFF); |
| 1085 | |
| 1086 | // Copy our hardcoded instrument table into it |
| 1087 | // Then, convert the instrument table as given in this song resource |
| 1088 | // And write it *over* the hardcoded table. |
| 1089 | // Note: we deliberately. |
| 1090 | |
| 1091 | /* now fill in the instruments */ |
| 1092 | for (i = 0; i < num_instr; i++) { |
| 1093 | ch = channel[i] - 1; |
| 1094 | |
| 1095 | debug(4, "Sound %d: instrument %d on channel %d.", |
| 1096 | idx, i, ch); |
| 1097 | |
| 1098 | memcpy(ptr, ADLIB_INSTR_MIDI_HACK, |
| 1099 | sizeof(ADLIB_INSTR_MIDI_HACK)); |
| 1100 | |
| 1101 | ptr[5] += ch; |
| 1102 | ptr[28] += ch; |
| 1103 | ptr[92] += ch; |
| 1104 | |
| 1105 | /* flags_1 */ |
| 1106 | ptr[30 + 0] = (instr[i * 16 + 3] >> 4) & 0xf; |
| 1107 | ptr[30 + 1] = instr[i * 16 + 3] & 0xf; |
| 1108 | |
| 1109 | /* oplvl_1 */ |
| 1110 | ptr[30 + 2] = (instr[i * 16 + 4] >> 4) & 0xf; |
| 1111 | ptr[30 + 3] = instr[i * 16 + 4] & 0xf; |
| 1112 | |
| 1113 | /* atdec_1 */ |
| 1114 | ptr[30 + 4] = ((~instr[i * 16 + 5]) >> 4) & 0xf; |
| 1115 | ptr[30 + 5] = (~instr[i * 16 + 5]) & 0xf; |
| 1116 | |
| 1117 | /* sustrel_1 */ |
| 1118 | ptr[30 + 6] = ((~instr[i * 16 + 6]) >> 4) & 0xf; |
| 1119 | ptr[30 + 7] = (~instr[i * 16 + 6]) & 0xf; |
| 1120 | |
| 1121 | /* waveform_1 */ |
| 1122 | ptr[30 + 8] = (instr[i * 16 + 7] >> 4) & 0xf; |
| 1123 | ptr[30 + 9] = instr[i * 16 + 7] & 0xf; |
| 1124 | |
| 1125 | /* flags_2 */ |
| 1126 | ptr[30 + 10] = (instr[i * 16 + 8] >> 4) & 0xf; |
| 1127 | ptr[30 + 11] = instr[i * 16 + 8] & 0xf; |
| 1128 | |
| 1129 | /* oplvl_2 */ |
| 1130 | ptr[30 + 12] = (instr[i * 16 + 9] >> 4) & 0xf; |
| 1131 | ptr[30 + 13] = instr[i * 16 + 9] & 0xf; |
| 1132 | |
| 1133 | /* atdec_2 */ |
| 1134 | ptr[30 + 14] = ((~instr[i * 16 + 10]) >> 4) & 0xf; |
| 1135 | ptr[30 + 15] = (~instr[i * 16 + 10]) & 0xf; |
| 1136 | |
| 1137 | /* sustrel_2 */ |
| 1138 | ptr[30 + 16] = ((~instr[i * 16 + 11]) >> 4) & 0xf; |
| 1139 | ptr[30 + 17] = (~instr[i * 16 + 11]) & 0xf; |
| 1140 | |
| 1141 | /* waveform_2 */ |
| 1142 | ptr[30 + 18] = (instr[i * 16 + 12] >> 4) & 0xf; |
| 1143 | ptr[30 + 19] = instr[i * 16 + 12] & 0xf; |
| 1144 | |
| 1145 | /* feedback */ |
| 1146 | ptr[30 + 20] = (instr[i * 16 + 2] >> 4) & 0xf; |
| 1147 | ptr[30 + 21] = instr[i * 16 + 2] & 0xf; |
| 1148 | ptr += sizeof(ADLIB_INSTR_MIDI_HACK); |
| 1149 | } |
| 1150 | |
| 1151 | *ptr++ = 0; // delay 0; |
| 1152 | |
| 1153 | // Now copy the actual music data |
| 1154 | memcpy(ptr, track, size); |
| 1155 | ptr += size; |
| 1156 | |
| 1157 | if (!play_once) { |
| 1158 | // The song is meant to be looped. We achieve this by inserting just |
| 1159 | // before the song end a jump to the song start. More precisely we abuse |
| 1160 | // a S&M sysex, "maybe_jump" to achieve this effect. We could also |
| 1161 | // use a set_loop sysex, but it's a bit longer, a little more complicated, |
| 1162 | // and has no advantage either. |
| 1163 | |
| 1164 | // First, find the track end |
| 1165 | byte *end = ptr; |
| 1166 | ptr -= size; |
| 1167 | for (; ptr < end; ptr++) { |
| 1168 | if (*ptr == 0xff && *(ptr + 1) == 0x2f) |
| 1169 | break; |
| 1170 | } |
| 1171 | assert(ptr < end); |
| 1172 | |
| 1173 | // Now insert the jump. The jump offset is measured in ticks, and |
| 1174 | // each instrument definition spans 4 ticks... so we jump to tick |
| 1175 | // 8*4, although jumping to tick 0 would probably work fine, too. |
| 1176 | // Note: it's possible that some musics don't loop from the start... |
| 1177 | // in that case we'll have to figure out how the loop range is specified |
| 1178 | // and then how to handle it appropriately (if it's specified in |
| 1179 | // ticks, we are fine; but if it's a byte offset, it'll be nasty). |
| 1180 | const int jump_offset = 8 * 4; |
| 1181 | memcpy(ptr, "\xf0\x13\x7d\x30\00", 5); ptr += 5; // maybe_jump |
| 1182 | memcpy(ptr, "\x00\x00", 2); ptr += 2; // cmd -> 0 means always jump |
| 1183 | memcpy(ptr, "\x00\x00\x00\x00", 4); ptr += 4; // track -> there is only one track, 0 |
| 1184 | memcpy(ptr, "\x00\x00\x00\x01", 4); ptr += 4; // beat -> for now, 1 (first beat) |
| 1185 | // Ticks |
| 1186 | *ptr++ = (byte)((jump_offset >> 12) & 0x0F); |
| 1187 | *ptr++ = (byte)((jump_offset >> 8) & 0x0F); |
| 1188 | *ptr++ = (byte)((jump_offset >> 4) & 0x0F); |
| 1189 | *ptr++ = (byte)(jump_offset & 0x0F); |
| 1190 | memcpy(ptr, "\x00\xf7", 2); ptr += 2; // sysex end marker |
| 1191 | } |
| 1192 | // Finally we reinsert the end of song sysex, just in case |
| 1193 | memcpy(ptr, "\x00\xff\x2f\x00\x00", 5); ptr += 5; |
| 1194 | |
| 1195 | return 1; |
1073 | | // Now insert the jump. The jump offset is measured in ticks, and |
1074 | | // each instrument definition spans 4 ticks... so we jump to tick |
1075 | | // 8*4, although jumping to tick 0 would probably work fine, too. |
1076 | | // Note: it's possible that some musics don't loop from the start... |
1077 | | // in that case we'll have to figure out how the loop range is specified |
1078 | | // and then how to handle it appropriately (if it's specified in |
1079 | | // ticks, we are fine; but if it's a byte offset, it'll be nasty). |
1080 | | const int jump_offset = 8 * 4; |
1081 | | memcpy(ptr, "\xf0\x13\x7d\x30\00", 5); ptr += 5; // maybe_jump |
1082 | | memcpy(ptr, "\x00\x00", 2); ptr += 2; // cmd -> 0 means always jump |
1083 | | memcpy(ptr, "\x00\x00\x00\x00", 4); ptr += 4; // track -> there is only one track, 0 |
1084 | | memcpy(ptr, "\x00\x00\x00\x01", 4); ptr += 4; // beat -> for now, 1 (first beat) |
1085 | | // Ticks |
1086 | | *ptr++ = (byte)((jump_offset >> 12) & 0x0F); |
1087 | | *ptr++ = (byte)((jump_offset >> 8) & 0x0F); |
1088 | | *ptr++ = (byte)((jump_offset >> 4) & 0x0F); |
1089 | | *ptr++ = (byte)(jump_offset & 0x0F); |
1090 | | memcpy(ptr, "\x00\xf7", 2); ptr += 2; // sysex end marker |
| 1273 | |
| 1274 | switch (chunk_type) { |
| 1275 | case 1: |
| 1276 | /* Instrument definition */ |
| 1277 | memcpy(current_instr[ch], src_ptr+1, 14); |
| 1278 | src_ptr += 15; |
| 1279 | break; |
| 1280 | |
| 1281 | case 2: |
| 1282 | /* tone/parammodulation */ |
| 1283 | memcpy(ptr, ADLIB_INSTR_MIDI_HACK, |
| 1284 | sizeof(ADLIB_INSTR_MIDI_HACK)); |
| 1285 | |
| 1286 | ptr[5] += ch; |
| 1287 | ptr[28] += ch; |
| 1288 | ptr[92] += ch; |
| 1289 | |
| 1290 | /* flags_1 */ |
| 1291 | ptr[30 + 0] = (current_instr[ch][3] >> 4) & 0xf; |
| 1292 | ptr[30 + 1] = current_instr[ch][3] & 0xf; |
| 1293 | |
| 1294 | /* oplvl_1 */ |
| 1295 | ptr[30 + 2] = (current_instr[ch][4] >> 4) & 0xf; |
| 1296 | ptr[30 + 3] = current_instr[ch][4] & 0xf; |
| 1297 | |
| 1298 | /* atdec_1 */ |
| 1299 | ptr[30 + 4] = ((~current_instr[ch][5]) >> 4) & 0xf; |
| 1300 | ptr[30 + 5] = (~current_instr[ch][5]) & 0xf; |
| 1301 | |
| 1302 | /* sustrel_1 */ |
| 1303 | ptr[30 + 6] = ((~current_instr[ch][6]) >> 4) & 0xf; |
| 1304 | ptr[30 + 7] = (~current_instr[ch][6]) & 0xf; |
| 1305 | |
| 1306 | /* waveform_1 */ |
| 1307 | ptr[30 + 8] = (current_instr[ch][7] >> 4) & 0xf; |
| 1308 | ptr[30 + 9] = current_instr[ch][7] & 0xf; |
| 1309 | |
| 1310 | /* flags_2 */ |
| 1311 | ptr[30 + 10] = (current_instr[ch][8] >> 4) & 0xf; |
| 1312 | ptr[30 + 11] = current_instr[ch][8] & 0xf; |
| 1313 | |
| 1314 | /* oplvl_2 */ |
| 1315 | ptr[30 + 12] = ((current_instr[ch][9]) >> 4) & 0xf; |
| 1316 | ptr[30 + 13] = (current_instr[ch][9]) & 0xf; |
| 1317 | |
| 1318 | /* atdec_2 */ |
| 1319 | ptr[30 + 14] = ((~current_instr[ch][10]) >> 4) & 0xf; |
| 1320 | ptr[30 + 15] = (~current_instr[ch][10]) & 0xf; |
| 1321 | |
| 1322 | /* sustrel_2 */ |
| 1323 | ptr[30 + 16] = ((~current_instr[ch][11]) >> 4) & 0xf; |
| 1324 | ptr[30 + 17] = (~current_instr[ch][11]) & 0xf; |
| 1325 | |
| 1326 | /* waveform_2 */ |
| 1327 | ptr[30 + 18] = (current_instr[ch][12] >> 4) & 0xf; |
| 1328 | ptr[30 + 19] = current_instr[ch][12] & 0xf; |
| 1329 | |
| 1330 | /* feedback */ |
| 1331 | ptr[30 + 20] = (current_instr[ch][2] >> 4) & 0xf; |
| 1332 | ptr[30 + 21] = current_instr[ch][2] & 0xf; |
| 1333 | |
| 1334 | delay = mintime - curtime; |
| 1335 | curtime = mintime; |
| 1336 | |
| 1337 | |
| 1338 | |
| 1339 | { |
| 1340 | delay = convert_extraflags(ptr + 30 + 22, src_ptr + 1); |
| 1341 | delay2 = convert_extraflags(ptr + 30 + 40, src_ptr + 6); |
| 1342 | debug(4, "delays: %d / %d", delay, delay2); |
| 1343 | if (delay2 >= 0 && delay2 < delay) |
| 1344 | delay = delay2; |
| 1345 | if (delay == -1) |
| 1346 | delay = 0; |
| 1347 | } |
| 1348 | |
| 1349 | /* duration */ |
| 1350 | ptr[30 + 58] = 0; // ((delay * 17 / 63) >> 4) & 0xf; |
| 1351 | ptr[30 + 59] = 0; // (delay * 17 / 63) & 0xf; |
| 1352 | |
| 1353 | ptr += sizeof(ADLIB_INSTR_MIDI_HACK); |
| 1354 | |
| 1355 | olddelay = mintime - curtime; |
| 1356 | curtime = mintime; |
| 1357 | if (olddelay > 0x7f) { |
| 1358 | if (olddelay > 0x3fff) { |
| 1359 | *ptr++ = (olddelay >> 14) | 0x80; |
| 1360 | olddelay &= 0x3fff; |
| 1361 | } |
| 1362 | *ptr++ = (olddelay >> 7) | 0x80; |
| 1363 | olddelay &= 0x7f; |
| 1364 | } |
| 1365 | *ptr++ = olddelay; |
| 1366 | |
| 1367 | |
| 1368 | /* FIXME: delay factor found by try and error */ |
| 1369 | delay = (delay + 1) * 240 / 13; |
| 1370 | |
| 1371 | { |
| 1372 | int freq = ((current_instr[ch][1] & 3) << 8) |
| 1373 | | current_instr[ch][0]; |
| 1374 | freq <<= ((current_instr[ch][1] >> 2) & 7) + 1; |
| 1375 | int note = -11; |
| 1376 | while (freq >= 0x100) { |
| 1377 | note += 12; |
| 1378 | freq >>= 1; |
| 1379 | } |
| 1380 | debug(4, "Freq: %d (%x) Note: %d", freq, freq, note); |
| 1381 | if (freq < 0x80) |
| 1382 | note = 0; |
| 1383 | else |
| 1384 | note += freq2note[freq - 0x80]; |
| 1385 | |
| 1386 | debug(4, "Note: %d", note); |
| 1387 | if (note < 0) |
| 1388 | note = 0; |
| 1389 | else if (note > 127) |
| 1390 | note = 127; |
| 1391 | |
| 1392 | // Insert a note on event |
| 1393 | *ptr++ = 0x90 + ch; // key on channel |
| 1394 | *ptr++ = note; |
| 1395 | *ptr++ = 63; |
| 1396 | current_note[ch] = note; |
| 1397 | track_time[ch] = curtime + delay; |
| 1398 | } |
| 1399 | src_ptr += 11; |
| 1400 | break; |
| 1401 | |
| 1402 | case 0x80: |
| 1403 | track_time[ch] = -1; |
| 1404 | src_ptr ++; |
| 1405 | break; |
| 1406 | |
| 1407 | default: |
| 1408 | track_time[ch] = -1; |
| 1409 | } |
| 1410 | tracks[ch] = src_ptr; |