/* Decompresse un bloc en tenant compte de la resynchronisation */ void unpack_block_sync(FILE *f, scan_desc_t *scan, uint16_t RI, uint32_t i, int32_t *bck_freq_qzz) { static uint32_t nb_calls = 0; nb_calls++; unpack_block(f,scan,i,bck_freq_qzz); if (RI != 0 && nb_calls % RI == 0) { uint32_t cpt = 0; uint8_t oct = read_byte(&cpt,f); if (scan->window == 0xff) { assert(oct == 0x00); oct = read_byte(&cpt,f); scan->window = 0; } if (oct != 0xff) { printf("\n*** ERREUR: marqueur attendu (RST) ***\n"); return; } oct = read_byte(&cpt,f); if (oct == 0xd9) { printbody("\nEnd of Image (EOI): fin du décodage\n"); return; } else { uint8_t num = oct % 16; if (num == 0) { printbody(" Marqueur RST%u",num); } else if (num == 7) { printbody(" RST%u\n",num); } else { printbody(" RST%u",num); } } assert((oct % 16) == ((nb_calls / RI) - 1) % 8); scan->pred[0] = 0; scan->pred[1] = 0; scan->pred[2] = 0; scan->bit_count = 0; } }
static int med3_load(struct module_data *m, HIO_HANDLE *f, const int start) { struct xmp_module *mod = &m->mod; int i, j; uint32 mask; int transp, sliding; LOAD_INIT(); hio_read32b(f); set_type(m, "MED 2.00 MED3"); mod->ins = mod->smp = 32; if (instrument_init(mod) < 0) return -1; /* read instrument names */ for (i = 0; i < 32; i++) { uint8 c, buf[40]; for (j = 0; j < 40; j++) { c = hio_read8(f); buf[j] = c; if (c == 0) break; } instrument_name(mod, i, buf, 32); if (subinstrument_alloc(mod, i, 1) < 0) return -1; } /* read instrument volumes */ mask = hio_read32b(f); for (i = 0; i < 32; i++, mask <<= 1) { mod->xxi[i].sub[0].vol = mask & MASK ? hio_read8(f) : 0; mod->xxi[i].sub[0].pan = 0x80; mod->xxi[i].sub[0].fin = 0; mod->xxi[i].sub[0].sid = i; } /* read instrument loops */ mask = hio_read32b(f); for (i = 0; i < 32; i++, mask <<= 1) { mod->xxs[i].lps = mask & MASK ? hio_read16b(f) : 0; } /* read instrument loop length */ mask = hio_read32b(f); for (i = 0; i < 32; i++, mask <<= 1) { uint32 lsiz = mask & MASK ? hio_read16b(f) : 0; mod->xxs[i].len = mod->xxs[i].lps + lsiz; mod->xxs[i].lpe = mod->xxs[i].lps + lsiz; mod->xxs[i].flg = lsiz > 1 ? XMP_SAMPLE_LOOP : 0; } mod->chn = 4; mod->pat = hio_read16b(f); mod->trk = mod->chn * mod->pat; mod->len = hio_read16b(f); hio_read(mod->xxo, 1, mod->len, f); mod->spd = hio_read16b(f); if (mod->spd > 10) { mod->bpm = 125 * mod->spd / 33; mod->spd = 6; } transp = hio_read8s(f); hio_read8(f); /* flags */ sliding = hio_read16b(f); /* sliding */ hio_read32b(f); /* jumping mask */ hio_seek(f, 16, SEEK_CUR); /* rgb */ /* read midi channels */ mask = hio_read32b(f); for (i = 0; i < 32; i++, mask <<= 1) { if (mask & MASK) hio_read8(f); } /* read midi programs */ mask = hio_read32b(f); for (i = 0; i < 32; i++, mask <<= 1) { if (mask & MASK) hio_read8(f); } MODULE_INFO(); D_(D_INFO "Sliding: %d", sliding); D_(D_INFO "Play transpose: %d", transp); if (sliding == 6) m->quirk |= QUIRK_VSALL | QUIRK_PBALL; for (i = 0; i < 32; i++) mod->xxi[i].sub[0].xpo = transp; if (pattern_init(mod) < 0) return -1; /* Load and convert patterns */ D_(D_INFO "Stored patterns: %d", mod->pat); for (i = 0; i < mod->pat; i++) { uint32 *conv; uint8 b, tracks; uint16 convsz; if (pattern_tracks_alloc(mod, i, 64) < 0) return -1; tracks = hio_read8(f); b = hio_read8(f); convsz = hio_read16b(f); conv = calloc(1, convsz + 16); if (conv == NULL) return -1; if (b & M0F_LINEMSK00) *conv = 0L; else if (b & M0F_LINEMSK0F) *conv = 0xffffffff; else *conv = hio_read32b(f); if (b & M0F_LINEMSK10) *(conv + 1) = 0L; else if (b & M0F_LINEMSK1F) *(conv + 1) = 0xffffffff; else *(conv + 1) = hio_read32b(f); if (b & M0F_FXMSK00) *(conv + 2) = 0L; else if (b & M0F_FXMSK0F) *(conv + 2) = 0xffffffff; else *(conv + 2) = hio_read32b(f); if (b & M0F_FXMSK10) *(conv + 3) = 0L; else if (b & M0F_FXMSK1F) *(conv + 3) = 0xffffffff; else *(conv + 3) = hio_read32b(f); hio_read(conv + 4, 1, convsz, f); if (unpack_block(m, i, (uint8 *)conv) < 0) { free(conv); return -1; } free(conv); } /* Load samples */ D_(D_INFO "Instruments: %d", mod->ins); mask = hio_read32b(f); for (i = 0; i < 32; i++, mask <<= 1) { if (~mask & MASK) continue; mod->xxi[i].nsm = 1; mod->xxs[i].len = hio_read32b(f); if (mod->xxs[i].len == 0) mod->xxi[i].nsm = 0; if (hio_read16b(f)) /* type */ continue; D_(D_INFO "[%2X] %-32.32s %04x %04x %04x %c V%02x ", i, mod->xxi[i].name, mod->xxs[i].len, mod->xxs[i].lps, mod->xxs[i].lpe, mod->xxs[i].flg & XMP_SAMPLE_LOOP ? 'L' : ' ', mod->xxi[i].sub[0].vol); if (load_sample(m, f, 0, &mod->xxs[i], NULL) < 0) return -1; } return 0; }
void exchange(double *tp, double *tm, double *tu) { int f, s, sp, fp, i, j[25], l, rb, lev, block_size, type, type1, par[25], start[25]; double t1, t2, t3, t4; MPI_Status status; block_size = 45 + num_vars*x_block_size*y_block_size*z_block_size; type = 40; type1 = 41; par[0] = 1; lev = 0; while (par[lev] < num_pes) { par[lev+1] = 2*par[lev]; lev++; } j[l = 0] = 0; start[0] = 0; while(j[0] < 2) { if (l == lev) { t3 = t4 = 0.0; t1 = timer(); sp = fp = s = f = 0; // The sense of to and from are reversed in this routine. They are // related to moving the dots from where they ended up back to the // processors that they came from and blocks are moved in reverse. while (s < from[start[l]] || f < to[start[l]]) { if (f < to[start[l]]) { if (num_active < max_num_blocks) { MPI_Irecv(recv_buff, block_size, MPI_DOUBLE, start[l], type, MPI_COMM_WORLD, request); rb = 1; } else rb = 0; MPI_Send(&rb, 1, MPI_INTEGER, start[l], type1, MPI_COMM_WORLD); } if (s < from[start[l]]) { MPI_Recv(&i, 1, MPI_INTEGER, start[l], type1, MPI_COMM_WORLD, &status); if (i) { while (sp < max_active_block && blocks[sp].number < 0 || (blocks[sp].number >= 0 && (blocks[sp].new_proc != start[l] || blocks[sp].new_proc == my_pe))) sp++; t2 = timer(); pack_block(sp); t3 += timer() - t2; num_active--; local_num_blocks[blocks[sp].level]--; del_sorted_list(blocks[sp].number, blocks[sp].level); blocks[sp].number = -1; MPI_Send(send_buff, block_size, MPI_DOUBLE, start[l], type, MPI_COMM_WORLD); if (fp > sp) fp = sp; sp++; from[start[l]]--; } else s = from[start[l]]; } if (f < to[start[l]]) { if (rb) { while (fp < max_num_blocks && blocks[fp].number >= 0) fp++; if (fp == max_num_blocks) if (num_active == max_num_blocks) { printf("ERROR: exchange - need more blocks\n"); exit(-1); } else { // there is at least one free block fp = 0; while (blocks[fp].number >= 0) fp++; } MPI_Wait(request, &status); t2 = timer(); unpack_block(fp); t4 += timer() - t2; if ((fp+1) > max_active_block) max_active_block = fp + 1; num_active++; local_num_blocks[blocks[fp].level]++; add_sorted_list(fp, blocks[fp].number, blocks[fp].level); fp++; to[start[l]]--; } else f = to[start[l]]; } } *tm += timer() - t1 - t3 - t4; *tp += t3; *tu += t4; l--; j[l]++; } else if (j[l] == 0) { j[l+1] = 0; if (my_pe & par[l]) if (start[l]+par[l] < num_pes) start[l+1] = start[l] + par[l]; else { start[l+1] = start[l]; j[l] = 1; } else start[l+1] = start[l]; l++; } else if (j[l] == 1) { j[l+1] = 0; if (my_pe & par[l]) { start[l+1] = start[l]; l++; } else if (start[l]+par[l] < num_pes) { start[l+1] = start[l] + par[l]; l++; } else { l--; j[l]++; } } else { l--; j[l]++; } } }
static int med3_load(struct xmp_context *ctx, FILE *f, const int start) { struct xmp_player_context *p = &ctx->p; struct xmp_mod_context *m = &p->m; int i, j; uint32 mask; int transp, sliding; LOAD_INIT(); read32b(f); strcpy(m->type, "MED3 (MED 2.00)"); m->xxh->ins = m->xxh->smp = 32; INSTRUMENT_INIT(); /* read instrument names */ for (i = 0; i < 32; i++) { uint8 c, buf[40]; for (j = 0; j < 40; j++) { c = read8(f); buf[j] = c; if (c == 0) break; } copy_adjust(m->xxih[i].name, buf, 32); m->xxi[i] = calloc(sizeof(struct xxm_instrument), 1); } /* read instrument volumes */ mask = read32b(f); for (i = 0; i < 32; i++, mask <<= 1) { m->xxi[i][0].vol = mask & MASK ? read8(f) : 0; m->xxi[i][0].pan = 0x80; m->xxi[i][0].fin = 0; m->xxi[i][0].sid = i; } /* read instrument loops */ mask = read32b(f); for (i = 0; i < 32; i++, mask <<= 1) { m->xxs[i].lps = mask & MASK ? read16b(f) : 0; } /* read instrument loop length */ mask = read32b(f); for (i = 0; i < 32; i++, mask <<= 1) { uint32 lsiz = mask & MASK ? read16b(f) : 0; m->xxs[i].len = m->xxs[i].lps + lsiz; m->xxs[i].lpe = m->xxs[i].lps + lsiz; m->xxs[i].flg = lsiz > 1 ? WAVE_LOOPING : 0; } m->xxh->chn = 4; m->xxh->pat = read16b(f); m->xxh->trk = m->xxh->chn * m->xxh->pat; m->xxh->len = read16b(f); fread(m->xxo, 1, m->xxh->len, f); m->xxh->tpo = read16b(f); if (m->xxh->tpo > 10) { m->xxh->bpm = 125 * m->xxh->tpo / 33; m->xxh->tpo = 6; } transp = read8s(f); read8(f); /* flags */ sliding = read16b(f); /* sliding */ read32b(f); /* jumping mask */ fseek(f, 16, SEEK_CUR); /* rgb */ /* read midi channels */ mask = read32b(f); for (i = 0; i < 32; i++, mask <<= 1) { if (mask & MASK) read8(f); } /* read midi programs */ mask = read32b(f); for (i = 0; i < 32; i++, mask <<= 1) { if (mask & MASK) read8(f); } MODULE_INFO(); reportv(ctx, 0, "Sliding : %d\n", sliding); reportv(ctx, 0, "Play transpose : %d semitones\n", transp); if (sliding == 6) m->quirk |= XMP_QRK_VSALL | XMP_QRK_PBALL; for (i = 0; i < 32; i++) m->xxi[i][0].xpo = transp; PATTERN_INIT(); /* Load and convert patterns */ reportv(ctx, 0, "Stored patterns: %d ", m->xxh->pat); for (i = 0; i < m->xxh->pat; i++) { uint32 *conv; uint8 b, tracks; uint16 convsz; PATTERN_ALLOC(i); m->xxp[i]->rows = 64; TRACK_ALLOC(i); tracks = read8(f); b = read8(f); convsz = read16b(f); conv = calloc(1, convsz + 16); assert(conv); if (b & M0F_LINEMSK00) *conv = 0L; else if (b & M0F_LINEMSK0F) *conv = 0xffffffff; else *conv = read32b(f); if (b & M0F_LINEMSK10) *(conv + 1) = 0L; else if (b & M0F_LINEMSK1F) *(conv + 1) = 0xffffffff; else *(conv + 1) = read32b(f); if (b & M0F_FXMSK00) *(conv + 2) = 0L; else if (b & M0F_FXMSK0F) *(conv + 2) = 0xffffffff; else *(conv + 2) = read32b(f); if (b & M0F_FXMSK10) *(conv + 3) = 0L; else if (b & M0F_FXMSK1F) *(conv + 3) = 0xffffffff; else *(conv + 3) = read32b(f); fread(conv + 4, 1, convsz, f); unpack_block(ctx, i, (uint8 *)conv); free(conv); reportv(ctx, 0, "."); } reportv(ctx, 0, "\n"); /* Load samples */ reportv(ctx, 0, "Instruments : %d ", m->xxh->ins); reportv(ctx, 1, "\n Instrument name Len LBeg LEnd L Vol"); mask = read32b(f); for (i = 0; i < 32; i++, mask <<= 1) { if (~mask & MASK) continue; m->xxs[i].len = read32b(f); if (read16b(f)) /* type */ continue; m->xxih[i].nsm = !!(m->xxs[i].len); reportv(ctx, 1, "\n[%2X] %-32.32s %04x %04x %04x %c V%02x ", i, m->xxih[i].name, m->xxs[i].len, m->xxs[i].lps, m->xxs[i].lpe, m->xxs[i].flg & WAVE_LOOPING ? 'L' : ' ', m->xxi[i][0].vol); xmp_drv_loadpatch(ctx, f, m->xxi[i][0].sid, m->c4rate, 0, &m->xxs[m->xxi[i][0].sid], NULL); reportv(ctx, 0, "."); } reportv(ctx, 0, "\n"); return 0; }