コード例 #1
0
ファイル: dro.cpp プロジェクト: Alexey-Yakovenko/deadbeef
bool CdroPlayer::load(const char *filename, const CFileProvider &fp)
{
  binistream *f = fp.open(filename); if(!f) return false;
  char id[8];
  unsigned long i;

  // file validation section
  f->readString(id, 8);
  if(strncmp(id,"DBRAWOPL",8)) { fp.close (f); return false; }
  int version = f->readInt(4);	// not very useful just yet
  if(version != 0x10000) { fp.close(f); return false; }

  // load section
  mstotal = f->readInt(4);	// Total milliseconds in file
  length = f->readInt(4);	// Total data bytes in file
  data = new unsigned char [length];

  f->ignore(1);			// Type of opl data this can contain - ignored
  for (i=0;i<3;i++)
  	data[i]=f->readInt(1);

  if ((data[0] == 0) || (data[1] == 0) || (data[2] == 0)) {
  	// Some early .DRO files only used one byte for the hardware type, then
  	// later changed to four bytes with no version number change.  If we're
  	// here then this is a later (more popular) file with the full four bytes
  	// for the hardware-type.
  	i = 0; // so ignore the three bytes we just read and start again
  }
  for (;i<length;i++)
    data[i]=f->readInt(1);
  fp.close(f);
  rewind(0);
  return true;
}
コード例 #2
0
ファイル: dro.cpp プロジェクト: EQ4/adplug
bool CdroPlayer::load(const std::string &filename, const CFileProvider &fp)
{
	binistream *f = fp.open(filename);
	if (!f) return false;

	char id[8];
	f->readString(id, 8);
	if (strncmp(id, "DBRAWOPL", 8)) {
		fp.close(f);
		return false;
	}
	int version = f->readInt(4);
	if (version != 0x10000) {
		fp.close(f);
		return false;
	}

	f->ignore(4);	// Length in milliseconds
	this->iLength = f->readInt(4); // stored in file as number of bytes

	this->data = new uint8_t[this->iLength];

	unsigned long i;
	// Some early .DRO files only used one byte for the hardware type, then
  	// later changed to four bytes with no version number change.
	// OPL type (0 == OPL2, 1 == OPL3, 2 == Dual OPL2)
	f->ignore(1);	// Type of opl data this can contain - ignored
	for (i = 0; i < 3; i++) {
  		data[i]=f->readInt(1);
	}

	if ((data[0] == 0) || (data[1] == 0) || (data[2] == 0)) {
		// If we're here then this is a later (more popular) file with
		// the full four bytes for the hardware-type.
  		i = 0; // so ignore the three bytes we just read and start again
	}

	// Read the OPL data.
	for (; i < this->iLength; i++) {
		data[i]=f->readInt(1);
	}

	fp.close(f);
	rewind(0);

	return true;
}
コード例 #3
0
ファイル: cmf.cpp プロジェクト: firodj/adplug
bool CcmfPlayer::load(const std::string &filename, const CFileProvider &fp)
{
  binistream *f = fp.open(filename); if(!f) return false;

	char cSig[4];
	f->readString(cSig, 4);
	if (
		(cSig[0] != 'C') ||
		(cSig[1] != 'T') ||
		(cSig[2] != 'M') ||
		(cSig[3] != 'F')
	) {
		// Not a CMF file
		fp.close(f);
		return false;
	}
	uint16_t iVer = f->readInt(2);
	if ((iVer != 0x0101) && (iVer != 0x0100)) {
		AdPlug_LogWrite("CMF file is not v1.0 or v1.1 (reports %d.%d)\n", iVer >> 8 , iVer & 0xFF);
		fp.close(f);
		return false;
	}
コード例 #4
0
ファイル: dro2.cpp プロジェクト: Kinglions/modizer
bool Cdro2Player::load(const std::string &filename, const CFileProvider &fp)
{
	binistream *f = fp.open(filename);
	if (!f) return false;

	char id[8];
	f->readString(id, 8);
	if (strncmp(id, "DBRAWOPL", 8)) {
		fp.close(f);
		return false;
	}
	int version = f->readInt(4);
//    printf("dro2 version: %X\n",version);
    if (version != 0x2) {
		fp.close(f);
		return false;
	}

	this->iLength = f->readInt(4) * 2; // stored in file as number of byte pairs
	f->ignore(4);	// Length in milliseconds
	f->ignore(1);	/// OPL type (0 == OPL2, 1 == Dual OPL2, 2 == OPL3)
	int iFormat = f->readInt(1);
	if (iFormat != 0) {
		fp.close(f);
		return false;
	}
	int iCompression = f->readInt(1);
	if (iCompression != 0) {
		fp.close(f);
		return false;
	}
	this->iCmdDelayS = f->readInt(1);
	this->iCmdDelayL = f->readInt(1);
	this->iConvTableLen = f->readInt(1);

	this->piConvTable = new uint8_t[this->iConvTableLen];
	f->readString((char *)this->piConvTable, this->iConvTableLen);

	this->data = new uint8_t[this->iLength];
	f->readString((char *)this->data, this->iLength);

	fp.close(f);
	rewind(0);

	return true;
}
コード例 #5
0
ファイル: hsc.cpp プロジェクト: OPLx/adplug
bool ChscPlayer::load(const std::string &filename, const CFileProvider &fp)
{
  binistream	*f = fp.open(filename);
  int		i;

  // file validation section
  if (
    !f
    || !fp.extension(filename, ".hsc")
    || fp.filesize(f) > (59187 + 1)  // +1 is for some files that have a trailing 0x00 on the end
    || fp.filesize(f) < (1587 + 1152) // no 0x00 byte here as this is the smallest possible size
  ) {
    AdPlug_LogWrite("ChscPlayer::load(\"%s\"): Not a HSC file!\n", filename.c_str());
    fp.close(f);
    return false;
  }

  int total_patterns_in_hsc = (fp.filesize(f) - 1587) / 1152;

  // load section
  for(i=0;i<128*12;i++)		// load instruments
    *((unsigned char *)instr + i) = f->readInt(1);
  for (i=0;i<128;i++) {			// correct instruments
    instr[i][2] ^= (instr[i][2] & 0x40) << 1;
    instr[i][3] ^= (instr[i][3] & 0x40) << 1;
    instr[i][11] >>= 4;			// slide
  }
  for(i=0;i<51;i++) {	// load tracklist
    song[i] = f->readInt(1);
    // if out of range, song ends here
    if (
      ((song[i] & 0x7F) > 0x31)
      || ((song[i] & 0x7F) >= total_patterns_in_hsc)
    ) song[i] = 0xFF;
  }
  for(i=0;i<50*64*9;i++)			// load patterns
    *((char *)patterns + i) = f->readInt(1);

  fp.close(f);
  rewind(0);					// rewind module
  return true;
}
コード例 #6
0
ファイル: hsp.cpp プロジェクト: Alexey-Yakovenko/deadbeef
bool ChspLoader::load(const char *filename, const CFileProvider &fp)
{
  binistream	*f = fp.open(filename); if(!f) return false;
  unsigned long	i, j, orgsize, filesize;
  unsigned char	*cmp, *org;

  // file validation section
  if(!fp.extension(filename, ".hsp")) { fp.close(f); return false; }

  filesize = fp.filesize(f);
  orgsize = f->readInt(2);
  if(orgsize > 59187) { fp.close(f); return false; }

  // load section
  cmp = new unsigned char[filesize];
  for(i = 0; i < filesize; i++) cmp[i] = f->readInt(1);
  fp.close(f);

  org = new unsigned char[orgsize];
  for(i = 0, j = 0; i < filesize; j += cmp[i], i += 2) {	// RLE decompress
    if(j >= orgsize) break;	// memory boundary check
    memset(org + j, cmp[i + 1], j + cmp[i] < orgsize ? cmp[i] : orgsize - j - 1);
  }
  delete [] cmp;

  memcpy(instr, org, 128 * 12);		// instruments
  for(i = 0; i < 128; i++) {		// correct instruments
    instr[i][2] ^= (instr[i][2] & 0x40) << 1;
    instr[i][3] ^= (instr[i][3] & 0x40) << 1;
    instr[i][11] >>= 4;		// slide
  }
  memcpy(song, org + 128 * 12, 51);	// tracklist
  memcpy(patterns, org + 128 * 12 + 51, orgsize - 128 * 12 - 51);	// patterns
  delete [] org;

  rewind(0);
  return true;
}
コード例 #7
0
ファイル: dmo.cpp プロジェクト: bakyeono/hexa-map-rpg
bool CdmoLoader::load(const std::string &filename, const CFileProvider &fp)
{
  int i,j;
  binistream *f;

  // check header
  dmo_unpacker *unpacker = new dmo_unpacker;
  unsigned char chkhdr[16];

  if(!fp.extension(filename, ".dmo")) return false;
  f = fp.open(filename); if(!f) return false;

  f->readString((char *)chkhdr, 16);

  if (!unpacker->decrypt(chkhdr, 16))
    {
      delete unpacker;
      fp.close(f);
      return false;
    }

  // get file size
  long packed_length = fp.filesize(f);
  f->seek(0);

  unsigned char *packed_module = new unsigned char [packed_length];

  // load file
  f->readString((char *)packed_module, packed_length);
  fp.close(f);

  // decrypt
  unpacker->decrypt(packed_module,packed_length);

  long unpacked_length = 0x2000 * ARRAY_AS_WORD(packed_module, 12);
  unsigned char *module = new unsigned char [unpacked_length];

  // unpack
  if (!unpacker->unpack(packed_module+12,module,unpacked_length))
    {
      delete unpacker;
      delete [] packed_module;
      delete [] module;
      return false;
    }

  delete unpacker;
  delete [] packed_module;

  // "TwinTeam" - signed ?
  if (memcmp(module,"TwinTeam Module File""\x0D\x0A",22))
    {
      delete module;
      return false;
    }

  // load header
  binisstream	uf(module, unpacked_length);
  uf.setFlag(binio::BigEndian, false); uf.setFlag(binio::FloatIEEE);

  memset(&header,0,sizeof(s3mheader));

  uf.ignore(22);				// ignore DMO header ID string
  uf.readString(header.name, 28);

  uf.ignore(2);				// _unk_1
  header.ordnum  = uf.readInt(2);
  header.insnum  = uf.readInt(2);
  header.patnum  = uf.readInt(2);
  uf.ignore(2);				// _unk_2
  header.is      = uf.readInt(2);
  header.it      = uf.readInt(2);

  memset(header.chanset,0xFF,32);

  for (i=0;i<9;i++)
    header.chanset[i] = 0x10 + i;

  uf.ignore(32);				// ignore panning settings for all 32 channels

  // load orders
  for(i = 0; i < 256; i++) orders[i] = uf.readInt(1);

  orders[header.ordnum] = 0xFF;

  // load pattern lengths
  unsigned short my_patlen[100];
  for(i = 0; i < 100; i++) my_patlen[i] = uf.readInt(2);

  // load instruments
  for (i = 0; i < header.insnum; i++)
    {
      memset(&inst[i],0,sizeof(s3minst));

      uf.readString(inst[i].name, 28);

      inst[i].volume = uf.readInt(1);
      inst[i].dsk    = uf.readInt(1);
      inst[i].c2spd  = uf.readInt(4);
      inst[i].type   = uf.readInt(1);
      inst[i].d00    = uf.readInt(1);
      inst[i].d01    = uf.readInt(1);
      inst[i].d02    = uf.readInt(1);
      inst[i].d03    = uf.readInt(1);
      inst[i].d04    = uf.readInt(1);
      inst[i].d05    = uf.readInt(1);
      inst[i].d06    = uf.readInt(1);
      inst[i].d07    = uf.readInt(1);
      inst[i].d08    = uf.readInt(1);
      inst[i].d09    = uf.readInt(1);
      inst[i].d0a    = uf.readInt(1);
      /*
       * Originally, riven sets d0b = d0a and ignores 1 byte in the
       * stream, but i guess this was a typo, so i read it here.
       */
      inst[i].d0b    = uf.readInt(1);
    }

  // load patterns
  for (i = 0; i < header.patnum; i++) {
    long cur_pos = uf.pos();

    for (j = 0; j < 64; j++) {
      while (1) {
	unsigned char token = uf.readInt(1);

	if (!token)
	  break;

	unsigned char chan = token & 31;

	// note + instrument ?
	if (token & 32) {
	  unsigned char bufbyte = uf.readInt(1);

	  pattern[i][j][chan].note = bufbyte & 15;
	  pattern[i][j][chan].oct = bufbyte >> 4;
	  pattern[i][j][chan].instrument = uf.readInt(1);
	}

	// volume ?
	if (token & 64)
	  pattern[i][j][chan].volume = uf.readInt(1);

	// command ?
	if (token & 128) {
	  pattern[i][j][chan].command = uf.readInt(1);
	  pattern[i][j][chan].info = uf.readInt(1);
	}
      }
    }

    uf.seek(cur_pos + my_patlen[i]);
  }
コード例 #8
0
ファイル: adtrack.cpp プロジェクト: EQ4/adplug
bool CadtrackLoader::load(const std::string &filename, const CFileProvider &fp)
{
  binistream *f = fp.open(filename); if(!f) return false;
  binistream *instf;
  char note[2];
  unsigned short rwp;
  unsigned char chp, octave, pnote = 0;
  int i,j;
  AdTrackInst myinst;

  // file validation
  if(!fp.extension(filename, ".sng") || fp.filesize(f) != 36000)
    { fp.close(f); return false; }

  // check for instruments file
  std::string instfilename(filename, 0, filename.find_last_of('.'));
  instfilename += ".ins";
  AdPlug_LogWrite("CadtrackLoader::load(,\"%s\"): Checking for \"%s\"...\n",
		  filename.c_str(), instfilename.c_str());
  instf = fp.open(instfilename);
  if(!instf || fp.filesize(instf) != 468) { fp.close(f); return false; }

  // give CmodPlayer a hint on what we're up to
  realloc_patterns(1,1000,9); realloc_instruments(9); realloc_order(1);
  init_trackord(); flags = NoKeyOn;
  (*order) = 0; length = 1; restartpos = 0; bpm = 120; initspeed = 3;

  // load instruments from instruments file
  for(i=0;i<9;i++) {
    for(j=0;j<2;j++) {
      myinst.op[j].appampmod = instf->readInt(2);
      myinst.op[j].appvib = instf->readInt(2);
      myinst.op[j].maintsuslvl = instf->readInt(2);
      myinst.op[j].keybscale = instf->readInt(2);
      myinst.op[j].octave = instf->readInt(2);
      myinst.op[j].freqrisevollvldn = instf->readInt(2);
      myinst.op[j].softness = instf->readInt(2);
      myinst.op[j].attack = instf->readInt(2);
      myinst.op[j].decay = instf->readInt(2);
      myinst.op[j].release = instf->readInt(2);
      myinst.op[j].sustain = instf->readInt(2);
      myinst.op[j].feedback = instf->readInt(2);
      myinst.op[j].waveform = instf->readInt(2);
    }
    convert_instrument(i, &myinst);
  }
  fp.close(instf);

  // load file
  for(rwp=0;rwp<1000;rwp++)
    for(chp=0;chp<9;chp++) {
      // read next record
      f->readString(note, 2); octave = f->readInt(1); f->ignore();
      switch(*note) {
      case 'C': if(note[1] == '#') pnote = 2; else pnote = 1; break;
      case 'D': if(note[1] == '#') pnote = 4; else pnote = 3; break;
      case 'E': pnote = 5; break;
      case 'F': if(note[1] == '#') pnote = 7; else pnote = 6; break;
      case 'G': if(note[1] == '#') pnote = 9; else pnote = 8; break;
      case 'A': if(note[1] == '#') pnote = 11; else pnote = 10; break;
      case 'B': pnote = 12; break;
      case '\0':
	if(note[1] == '\0')
	  tracks[chp][rwp].note = 127;
	else {
	  fp.close(f);
	  return false;
	}
	break;
      default: fp.close(f); return false;
      }
      if((*note) != '\0') {
	tracks[chp][rwp].note = pnote + (octave * 12);
	tracks[chp][rwp].inst = chp + 1;
      }
    }

  fp.close(f);
  rewind(0);
  return true;
}
コード例 #9
0
ファイル: cff.cpp プロジェクト: EQ4/adplug
bool CcffLoader::load(const std::string &filename, const CFileProvider &fp)
{
  binistream *f = fp.open(filename); if(!f) return false;
  const unsigned char conv_inst[11] = { 2,1,10,9,4,3,6,5,0,8,7 };
  const unsigned short conv_note[12] = { 0x16B, 0x181, 0x198, 0x1B0, 0x1CA, 0x1E5, 0x202, 0x220, 0x241, 0x263, 0x287, 0x2AE };

  int i,j,k,t=0;

  // '<CUD-FM-File>' - signed ?
  f->readString(header.id, 16);
  header.version = f->readInt(1); header.size = f->readInt(2);
  header.packed = f->readInt(1); f->readString((char *)header.reserved, 12);
  if (memcmp(header.id,"<CUD-FM-File>""\x1A\xDE\xE0",16))
    { fp.close(f); return false; }

  unsigned char *module = new unsigned char [0x10000];

  // packed ?
  if (header.packed)
    {
      cff_unpacker *unpacker = new cff_unpacker;

      unsigned char *packed_module = new unsigned char [header.size + 4];

      memset(packed_module,0,header.size + 4);

      f->readString((char *)packed_module, header.size);
      fp.close(f);

      if (!unpacker->unpack(packed_module,module))
	{
	  delete unpacker;
	  delete [] packed_module;
	  delete [] module;
	  return false;
	}

      delete unpacker;
      delete [] packed_module;

      if (memcmp(&module[0x5E1],"CUD-FM-File - SEND A POSTCARD -",31))
	{
	  delete [] module;
	  return false;
	}
    }
  else
    {
      f->readString((char *)module, header.size);
      fp.close(f);
    }

  // init CmodPlayer
  realloc_instruments(47);
  realloc_order(64);
  realloc_patterns(36,64,9);
  init_notetable(conv_note);
  init_trackord();

  // load instruments
  for (i=0;i<47;i++)
    {
      memcpy(&instruments[i],&module[i*32],sizeof(cff_instrument));

      for (j=0;j<11;j++)
	inst[i].data[conv_inst[j]] = instruments[i].data[j];

      instruments[i].name[20] = 0;
    }

  // number of patterns
  nop = module[0x5E0];

  // load title & author
  memcpy(song_title,&module[0x614],20);
  memcpy(song_author,&module[0x600],20);

  // load order
  memcpy(order,&module[0x628],64);

  // load tracks
  for (i=0;i<nop;i++)
    {
      unsigned char old_event_byte2[9];

      memset(old_event_byte2,0,9);

      for (j=0;j<9;j++)
	{
	  for (k=0;k<64;k++)
	    {
	      cff_event *event = (cff_event *)&module[0x669 + ((i*64+k)*9+j)*3];

	      // convert note
	      if (event->byte0 == 0x6D)
		tracks[t][k].note = 127;
	      else
		if (event->byte0)
		  tracks[t][k].note = event->byte0;

	      if (event->byte2)
		old_event_byte2[j] = event->byte2;

	      // convert effect
	      switch (event->byte1)
		{
		case 'I': // set instrument
		  tracks[t][k].inst = event->byte2 + 1;
		  tracks[t][k].param1 = tracks[t][k].param2 = 0;
		  break;

		case 'H': // set tempo
		  tracks[t][k].command = 7;
		  if (event->byte2 < 16)
		    {
		      tracks[t][k].param1 = 0x07;
		      tracks[t][k].param2 = 0x0D;
		    }
		  break;

		case 'A': // set speed
		  tracks[t][k].command = 19;
		  tracks[t][k].param1  = event->byte2 >> 4;
		  tracks[t][k].param2  = event->byte2 & 15;
		  break;

		case 'L': // pattern break
		  tracks[t][k].command = 13;
		  tracks[t][k].param1  = event->byte2 >> 4;
		  tracks[t][k].param2  = event->byte2 & 15;
		  break;

		case 'K': // order jump
		  tracks[t][k].command = 11;
		  tracks[t][k].param1  = event->byte2 >> 4;
		  tracks[t][k].param2  = event->byte2 & 15;
		  break;

		case 'M': // set vibrato/tremolo
		  tracks[t][k].command = 27;
		  tracks[t][k].param1  = event->byte2 >> 4;
		  tracks[t][k].param2  = event->byte2 & 15;
		  break;

		case 'C': // set modulator volume
		  tracks[t][k].command = 21;
		  tracks[t][k].param1 = (0x3F - event->byte2) >> 4;
		  tracks[t][k].param2 = (0x3F - event->byte2) & 15;
		  break;

		case 'G': // set carrier volume
		  tracks[t][k].command = 22;
		  tracks[t][k].param1 = (0x3F - event->byte2) >> 4;
		  tracks[t][k].param2 = (0x3F - event->byte2) & 15;
		  break;

		case 'B': // set carrier waveform
		  tracks[t][k].command = 25;
		  tracks[t][k].param1  = event->byte2;
		  tracks[t][k].param2  = 0x0F;
		  break;

		case 'E': // fine frequency slide down
		  tracks[t][k].command = 24;
		  tracks[t][k].param1  = old_event_byte2[j] >> 4;
		  tracks[t][k].param2  = old_event_byte2[j] & 15;
		  break;

		case 'F': // fine frequency slide up
		  tracks[t][k].command = 23;
		  tracks[t][k].param1  = old_event_byte2[j] >> 4;
		  tracks[t][k].param2  = old_event_byte2[j] & 15;
		  break;

		case 'D': // fine volume slide
		  tracks[t][k].command = 14;
		  if (old_event_byte2[j] & 15)
		    {
		      // slide down
		      tracks[t][k].param1 = 5;
		      tracks[t][k].param2 = old_event_byte2[j] & 15;
		    }
		  else
		    {
		      // slide up
		      tracks[t][k].param1 = 4;
		      tracks[t][k].param2 = old_event_byte2[j] >> 4;
		    }
		  break;

		case 'J': // arpeggio
		  tracks[t][k].param1  = old_event_byte2[j] >> 4;
		  tracks[t][k].param2  = old_event_byte2[j] & 15;
		  break;
		}
	    }

	  t++;
	}
    }

  delete [] module;

  // order loop
  restartpos = 0;

  // order length
  for (i=0;i<64;i++)
    {
      if (order[i] >= 0x80)
	{
	  length = i;
	  break;
	}
    }

  // default tempo
  bpm = 0x7D;

  rewind(0);

  return true;	
}
コード例 #10
0
ファイル: a2m.cpp プロジェクト: OPLx/adplug
bool Ca2mLoader::load(const std::string &filename, const CFileProvider &fp)
{
  binistream *f = fp.open(filename); if(!f) return false;
  char id[10];
  int i,j,k,t;
  unsigned int l;
  unsigned char *org = NULL, *orgptr, flags = 0, numpats, version;
  unsigned long crc, alength;
  unsigned short len[9], *secdata, *secptr;
  const unsigned char convfx[16] = {0,1,2,23,24,3,5,4,6,9,17,13,11,19,7,14};
  const unsigned char convinf1[16] = {0,1,2,6,7,8,9,4,5,3,10,11,12,13,14,15};
  const unsigned char newconvfx[] = {0,1,2,3,4,5,6,23,24,21,10,11,17,13,7,19,
				     255,255,22,25,255,15,255,255,255,255,255,
				     255,255,255,255,255,255,255,255,14,255};

  // read header
  f->readString(id, 10); crc = f->readInt(4);
  version = f->readInt(1); numpats = f->readInt(1);

  // file validation section
  if(strncmp(id,"_A2module_",10) || (version != 1 && version != 5 &&
				     version != 4 && version != 8)) {
    fp.close(f);
    return false;
  }

  // load, depack & convert section
  nop = numpats; length = 128; restartpos = 0;
  if(version < 5) {
    for(i=0;i<5;i++) len[i] = f->readInt(2);
    t = 9;
  } else {	// version >= 5
    for(i=0;i<9;i++) len[i] = f->readInt(2);
    t = 18;
  }

  // block 0
  secdata = new unsigned short [len[0] / 2];
  if(version == 1 || version == 5) {
    for(i=0;i<len[0]/2;i++) secdata[i] = f->readInt(2);
    org = new unsigned char [MAXBUF]; orgptr = org;
    sixdepak(secdata,org,len[0]);
  } else {
    orgptr = (unsigned char *)secdata;
    for(i=0;i<len[0];i++) orgptr[i] = f->readInt(1);
  }
  memcpy(songname,orgptr,43); orgptr += 43;
  memcpy(author,orgptr,43); orgptr += 43;
  memcpy(instname,orgptr,250*33); orgptr += 250*33;

  for(i=0;i<250;i++) {	// instruments
    inst[i].data[0] = *(orgptr+i*13+10);
    inst[i].data[1] = *(orgptr+i*13);
    inst[i].data[2] = *(orgptr+i*13+1);
    inst[i].data[3] = *(orgptr+i*13+4);
    inst[i].data[4] = *(orgptr+i*13+5);
    inst[i].data[5] = *(orgptr+i*13+6);
    inst[i].data[6] = *(orgptr+i*13+7);
    inst[i].data[7] = *(orgptr+i*13+8);
    inst[i].data[8] = *(orgptr+i*13+9);
    inst[i].data[9] = *(orgptr+i*13+2);
    inst[i].data[10] = *(orgptr+i*13+3);

    if(version < 5)
      inst[i].misc = *(orgptr+i*13+11);
    else {	// version >= 5 -> OPL3 format
      int pan = *(orgptr+i*13+11);

      if(pan)
	inst[i].data[0] |= (pan & 3) << 4;	// set pan
      else
	inst[i].data[0] |= 48;			// enable both speakers
    }

    inst[i].slide = *(orgptr+i*13+12);
  }

  orgptr += 250*13;
  memcpy(order,orgptr,128); orgptr += 128;
  bpm = *orgptr; orgptr++;
  initspeed = *orgptr; orgptr++;
  if(version >= 5) flags = *orgptr;
  if(version == 1 || version == 5) delete [] org;
  delete [] secdata;

  // blocks 1-4 or 1-8
  alength = len[1];
  for(i = 0; i < (version < 5 ? numpats / 16 : numpats / 8); i++)
    alength += len[i+2];

  secdata = new unsigned short [alength / 2];
  if(version == 1 || version == 5) {
    for(l=0;l<alength/2;l++) secdata[l] = f->readInt(2);
    org = new unsigned char [MAXBUF * (numpats / (version == 1 ? 16 : 8) + 1)];
    orgptr = org; secptr = secdata;
    orgptr += sixdepak(secptr,orgptr,len[1]); secptr += len[1] / 2;
    if(version == 1) {
      if(numpats > 16)
	orgptr += sixdepak(secptr,orgptr,len[2]); secptr += len[2] / 2;
      if(numpats > 32)
	orgptr += sixdepak(secptr,orgptr,len[3]); secptr += len[3] / 2;
      if(numpats > 48)
	sixdepak(secptr,orgptr,len[4]);
    } else {
      if(numpats > 8)
	orgptr += sixdepak(secptr,orgptr,len[2]); secptr += len[2] / 2;
      if(numpats > 16)
	orgptr += sixdepak(secptr,orgptr,len[3]); secptr += len[3] / 2;
      if(numpats > 24)
	orgptr += sixdepak(secptr,orgptr,len[4]); secptr += len[4] / 2;
      if(numpats > 32)
	orgptr += sixdepak(secptr,orgptr,len[5]); secptr += len[5] / 2;
      if(numpats > 40)
	orgptr += sixdepak(secptr,orgptr,len[6]); secptr += len[6] / 2;
      if(numpats > 48)
	orgptr += sixdepak(secptr,orgptr,len[7]); secptr += len[7] / 2;
      if(numpats > 56)
	sixdepak(secptr,orgptr,len[8]);
    }
    delete [] secdata;
  } else {
    org = (unsigned char *)secdata;
    for(l=0;l<alength;l++) org[l] = f->readInt(1);
  }

  if(version < 5) {
    for(i=0;i<numpats;i++)
      for(j=0;j<64;j++)
	for(k=0;k<9;k++) {
	  struct Tracks	*track = &tracks[i * 9 + k][j];
	  unsigned char	*o = &org[i*64*t*4+j*t*4+k*4];

	  track->note = o[0] == 255 ? 127 : o[0];
	  track->inst = o[1];
	  track->command = convfx[o[2]];
	  track->param2 = o[3] & 0x0f;
	  if(track->command != 14)
	    track->param1 = o[3] >> 4;
	  else {
	    track->param1 = convinf1[o[3] >> 4];
	    if(track->param1 == 15 && !track->param2) {	// convert key-off
	      track->command = 8;
	      track->param1 = 0;
	      track->param2 = 0;
	    }
	  }
	  if(track->command == 14) {
	    switch(track->param1) {
	    case 2: // convert define waveform
	      track->command = 25;
	      track->param1 = track->param2;
	      track->param2 = 0xf;
	      break;
	    case 8: // convert volume slide up
	      track->command = 26;
	      track->param1 = track->param2;
	      track->param2 = 0;
	      break;
	    case 9: // convert volume slide down
	      track->command = 26;
	      track->param1 = 0;
	      break;
	    }
	  }
	}
  } else {	// version >= 5
コード例 #11
0
ファイル: mad.cpp プロジェクト: Kinglions/modizer
bool CmadLoader::load(const std::string &filename, const CFileProvider &fp)
{
  binistream *f = fp.open(filename); if(!f) return false;
  const unsigned char conv_inst[10] = { 2,1,10,9,4,3,6,5,8,7 };
  unsigned int i, j, k, t = 0;

  // 'MAD+' - signed ?
  char id[4]; f->readString(id, 4);
  if (strncmp(id,"MAD+",4)) { fp.close(f); return false; }

  // load instruments
  for(i = 0; i < 9; i++) {
    f->readString(instruments[i].name, 8);
    for(j = 0; j < 12; j++) instruments[i].data[j] = f->readInt(1);
  }

  f->ignore(1);

  // data for Protracker
  length = f->readInt(1); nop = f->readInt(1); timer = f->readInt(1);

  // init CmodPlayer
  realloc_instruments(9);
  realloc_order(length);
  realloc_patterns(nop,32,9);
  init_trackord();

  // load tracks
  for(i = 0; i < nop; i++)
    for(k = 0; k < 32; k++)
      for(j = 0; j < 9; j++) {
	t = i * 9 + j;

	// read event
	unsigned char event = f->readInt(1);

	// convert event
	if (event < 0x61)
	  tracks[t][k].note = event;
	if (event == 0xFF) // 0xFF: Release note
	  tracks[t][k].command = 8;
	if (event == 0xFE) // 0xFE: Pattern Break
	  tracks[t][k].command = 13;
      }

  // load order
  for(i = 0; i < length; i++) order[i] = f->readInt(1) - 1;

  fp.close(f);

  // convert instruments
  for(i = 0; i < 9; i++)
    for(j = 0; j < 10; j++)
      inst[i].data[conv_inst[j]] = instruments[i].data[j];

  // data for Protracker
  restartpos = 0;
  initspeed = 1;

  rewind(0);
  return true;
}
コード例 #12
0
ファイル: dfm.cpp プロジェクト: EQ4/adplug
bool CdfmLoader::load(const std::string &filename, const CFileProvider &fp)
{
  binistream *f = fp.open(filename); if(!f) return false;
  unsigned char		npats,n,note,fx,c,r,param;
  unsigned int		i;
  const unsigned char	convfx[8] = {255,255,17,19,23,24,255,13};

  // file validation
  f->readString(header.id, 4);
  header.hiver = f->readInt(1); header.lover = f->readInt(1);
  if(strncmp(header.id,"DFM\x1a",4) || header.hiver > 1)
    { fp.close(f); return false; }

  // load
  restartpos = 0; flags = Standard; bpm = 0;
  init_trackord();
  f->readString(songinfo, 33);
  initspeed = f->readInt(1);
  for(i = 0; i < 32; i++)
    f->readString(instname[i], 12);
  for(i = 0; i < 32; i++) {
    inst[i].data[1] = f->readInt(1);
    inst[i].data[2] = f->readInt(1);
    inst[i].data[9] = f->readInt(1);
    inst[i].data[10] = f->readInt(1);
    inst[i].data[3] = f->readInt(1);
    inst[i].data[4] = f->readInt(1);
    inst[i].data[5] = f->readInt(1);
    inst[i].data[6] = f->readInt(1);
    inst[i].data[7] = f->readInt(1);
    inst[i].data[8] = f->readInt(1);
    inst[i].data[0] = f->readInt(1);
  }
  for(i = 0; i < 128; i++) order[i] = f->readInt(1);
  for(i = 0; i < 128 && order[i] != 128; i++) ; length = i;
  npats = f->readInt(1);
  for(i = 0; i < npats; i++) {
    n = f->readInt(1);
    for(r = 0; r < 64; r++)
      for(c = 0; c < 9; c++) {
	note = f->readInt(1);
	if((note & 15) == 15)
	  tracks[n*9+c][r].note = 127;	// key off
	else
	  tracks[n*9+c][r].note = ((note & 127) >> 4) * 12 + (note & 15);
	if(note & 128) {	// additional effect byte
	  fx = f->readInt(1);
	  if(fx >> 5 == 1)
	    tracks[n*9+c][r].inst = (fx & 31) + 1;
	  else {
	    tracks[n*9+c][r].command = convfx[fx >> 5];
	    if(tracks[n*9+c][r].command == 17) {	// set volume
	      param = fx & 31;
	      param = 63 - param * 2;
	      tracks[n*9+c][r].param1 = param >> 4;
	      tracks[n*9+c][r].param2 = param & 15;
	    } else {
	      tracks[n*9+c][r].param1 = (fx & 31) >> 4;
	      tracks[n*9+c][r].param2 = fx & 15;
	    }
	  }
コード例 #13
0
ファイル: lds.cpp プロジェクト: EQ4/adplug
bool CldsPlayer::load(const std::string &filename, const CFileProvider &fp)
{
  binistream	*f;
  unsigned int	i, j;
  SoundBank	*sb;

  // file validation section (actually just an extension check)
  if(!fp.extension(filename, ".lds")) return false;
  f = fp.open(filename); if(!f) return false;

  // file load section (header)
  mode = f->readInt(1);
  if(mode > 2) { fp.close(f); return false; }
  speed = f->readInt(2);
  tempo = f->readInt(1);
  pattlen = f->readInt(1);
  for(i = 0; i < 9; i++) chandelay[i] = f->readInt(1);
  regbd = f->readInt(1);

  // load patches
  numpatch = f->readInt(2);
  soundbank = new SoundBank[numpatch];
  for(i = 0; i < numpatch; i++) {
    sb = &soundbank[i];
    sb->mod_misc = f->readInt(1); sb->mod_vol = f->readInt(1);
    sb->mod_ad = f->readInt(1); sb->mod_sr = f->readInt(1);
    sb->mod_wave = f->readInt(1); sb->car_misc = f->readInt(1);
    sb->car_vol = f->readInt(1); sb->car_ad = f->readInt(1);
    sb->car_sr = f->readInt(1); sb->car_wave = f->readInt(1);
    sb->feedback = f->readInt(1); sb->keyoff = f->readInt(1);
    sb->portamento = f->readInt(1); sb->glide = f->readInt(1);
    sb->finetune = f->readInt(1); sb->vibrato = f->readInt(1);
    sb->vibdelay = f->readInt(1); sb->mod_trem = f->readInt(1);
    sb->car_trem = f->readInt(1); sb->tremwait = f->readInt(1);
    sb->arpeggio = f->readInt(1);
    for(j = 0; j < 12; j++) sb->arp_tab[j] = f->readInt(1);
    sb->start = f->readInt(2); sb->size = f->readInt(2);
    sb->fms = f->readInt(1); sb->transp = f->readInt(2);
    sb->midinst = f->readInt(1); sb->midvelo = f->readInt(1);
    sb->midkey = f->readInt(1); sb->midtrans = f->readInt(1);
    sb->middum1 = f->readInt(1); sb->middum2 = f->readInt(1);
  }

  // load positions
  numposi = f->readInt(2);
  positions = new Position[9 * numposi];
  for(i = 0; i < numposi; i++)
    for(j = 0; j < 9; j++) {
      /*
       * patnum is a pointer inside the pattern space, but patterns are 16bit
       * word fields anyway, so it ought to be an even number (hopefully) and
       * we can just divide it by 2 to get our array index of 16bit words.
       */
      positions[i * 9 + j].patnum = f->readInt(2) / 2;
      positions[i * 9 + j].transpose = f->readInt(1);
    }

  AdPlug_LogWrite("CldsPlayer::load(\"%s\",fp): loading LOUDNESS file: mode = "
		  "%d, pattlen = %d, numpatch = %d, numposi = %d\n",
		  filename.c_str(), mode, pattlen, numpatch, numposi);

  // load patterns
  f->ignore(2);		// ignore # of digital sounds (not played by this player)
  patterns = new unsigned short[(fp.filesize(f) - f->pos()) / 2 + 1];
  for(i = 0; !f->eof(); i++)
    patterns[i] = f->readInt(2);

  fp.close(f);
  rewind(0);
  return true;
}
コード例 #14
0
ファイル: dro.cpp プロジェクト: wothke/adplug-2.2.1
char CdroPlayer::load(const std::string &filename, const CFileProvider &fp)
{
	binistream *f = fp.open(filename);
	if (!f) return false;

	char id[8];
  f->readString(id, 8);
	if (strncmp(id, "DBRAWOPL", 8)) {
		fp.close(f);
		return false;
	}
	int version = f->readInt(4);
	if (version != 0x10000) {
		fp.close(f);
		return false;
	}

	f->ignore(4);	// Length in milliseconds
	this->iLength = f->readInt(4); // stored in file as number of bytes

	this->data = new uint8_t[this->iLength];

	unsigned long i;
  	// Some early .DRO files only used one byte for the hardware type, then
  	// later changed to four bytes with no version number change.
	// OPL type (0 == OPL2, 1 == OPL3, 2 == Dual OPL2)
	f->ignore(1);	// Type of opl data this can contain - ignored
	for (i = 0; i < 3; i++) {
  		this->data[i]=f->readInt(1);
	}

	if (this->data[0] == 0 || this->data[1] == 0 || this->data[2] == 0) {
		// If we're here then this is a later (more popular) file with
		// the full four bytes for the hardware-type.
  	i = 0; // so ignore the three bytes we just read and start again
  }

	// Read the OPL data.
	for (; (int)i < this->iLength; i++) {
		this->data[i]=f->readInt(1);
	}

	title[0] = 0;
	author[0] = 0;
	desc[0] = 0;
	int tagsize = fp.filesize(f) - f->pos();

	if (tagsize >= 3)
	{
		// The arbitrary Tag Data section begins here.
		if ((uint8_t)f->readInt(1) != 0xFF ||
			(uint8_t)f->readInt(1) != 0xFF ||
			(uint8_t)f->readInt(1) != 0x1A)
		{
			// Tag data does not present or truncated.
			goto end_section;
		}

		// "title" is maximum 40 characters long.
		f->readString(title, 40, 0);

		// Skip "author" if Tag marker byte is missing.
		if (f->readInt(1) != 0x1B) {
			f->seek(-1, binio::Add);
			goto desc_section;
		}

		// "author" is maximum 40 characters long.
		f->readString(author, 40, 0);

desc_section:
		// Skip "desc" if Tag marker byte is missing.
		if (f->readInt(1) != 0x1C) {
			goto end_section;
		}

		// "desc" is now maximum 1023 characters long (it was 140).
		f->readString(desc, 1023, 0);
	}

end_section:
  fp.close(f);
  rewind(0);
  return true;
}
コード例 #15
0
ファイル: rol.cpp プロジェクト: firodj/adplug
//---------------------------------------------------------
bool CrolPlayer::load(const std::string & filename, const CFileProvider & fp)
{
    binistream *f = fp.open(filename);

    if (!f)
    {
        return false;
    }

    char *fn = new char[filename.length()+13];
    int i;
    std::string bnk_filename;

    AdPlug_LogWrite("*** CrolPlayer::load(f, \"%s\") ***\n", filename.c_str());
    strcpy(fn,filename.data());
    for (i = strlen(fn) - 1; i >= 0; i--)
    {
        if (fn[i] == '/' || fn[i] == '\\')
        {
            break;
        }
    }
    strcpy(fn+i+1,"standard.bnk");
    bnk_filename = fn;
    delete [] fn;
    AdPlug_LogWrite("bnk_filename = \"%s\"\n",bnk_filename.c_str());

    mpROLHeader = new SRolHeader;
    memset(mpROLHeader, 0, sizeof(SRolHeader));

    mpROLHeader->version_major = static_cast<uint16_t>(f->readInt(2));
    mpROLHeader->version_minor = static_cast<uint16_t>(f->readInt(2));

    // Version check
    if ((mpROLHeader->version_major != skVersionMinor) || (mpROLHeader->version_minor != skVersionMajor))
    {
        AdPlug_LogWrite("Unsupported file version %d.%d or not a ROL file!\n",
                        mpROLHeader->version_major, mpROLHeader->version_minor);
        AdPlug_LogWrite("--- CrolPlayer::load ---\n");
        fp.close(f);
        return false;
    }

    f->seek(ROL_UNSUED0_SIZE, binio::Add); // Seek past 'SRolHeader.unused' field of header

    mpROLHeader->ticks_per_beat    = static_cast<uint16_t>(f->readInt(2));
    mpROLHeader->beats_per_measure = static_cast<uint16_t>(f->readInt(2));
    mpROLHeader->edit_scale_y      = static_cast<uint16_t>(f->readInt(2));
    mpROLHeader->edit_scale_x      = static_cast<uint16_t>(f->readInt(2));

    f->seek(ROL_UNUSED1_SIZE, binio::Add); // Seek past 'SRolHeader.(unused1)' field of the header.

    mpROLHeader->mode = static_cast<uint8_t>(f->readInt(1));

    f->seek(ROL_UNUSED2_SIZE + ROL_FILLER0_SIZE + ROL_FILLER1_SIZE, binio::Add); // Seek past 'SRolHeader.(unused2, filler0, filler1)' field of header

    mpROLHeader->basic_tempo = static_cast<float>(f->readFloat(binio::Single));

    load_tempo_events(f);

    mTimeOfLastNote = 0;

    if (load_voice_data(f, bnk_filename, fp) != true)
    {
      AdPlug_LogWrite("CrolPlayer::load_voice_data(f) failed!\n");
      AdPlug_LogWrite("--- CrolPlayer::load ---\n");

      fp.close(f);
      return false;
    }

    fp.close(f);

    rewind(0);
    AdPlug_LogWrite("--- CrolPlayer::load ---\n");
    return true;
}