Esempio n. 1
0
ayemu_vtx_t * ayemu_vtx_load(data_ptr_t buf, size_t size)
{
  ayemu_vtx_t *vtx;

  const char *data = read_header(buf, &vtx, size);

  if (! data) {
    fprintf(stderr, "ayemu_vtx_load: Cannot parse file header\n");
    return NULL;
  }

  // unpack data
  size -= (buf - data);

  if ((vtx->regdata = (unsigned char *) malloc (vtx->regdata_size)) == NULL) {
    fprintf (stderr, "ayemu_vtx_load_data: Can allocate %d bytes"
	     " for unpack register data\n", vtx->regdata_size);
    return NULL;
  }

  lh5_decode ((unsigned char*)data, vtx->regdata, vtx->regdata_size, size);

  vtx->frames = vtx->regdata_size / 14;

  return vtx;
}
Esempio n. 2
0
/** Read and encode lha data from .vtx file
 *
 * Return value: pointer to unpacked data or NULL
 * Note: you must call ayemu_vtx_open() first.
 */
char *ayemu_vtx_load_data (ayemu_vtx_t *vtx)
{
  char *packed_data;
  size_t packed_size;
  size_t buf_alloc;
  int c;

  if (vtx->fp == NULL) {
    fprintf(stderr, "ayemu_vtx_load_data: tune file not open yet (do you call ayemu_vtx_open first?)\n");
    return NULL;
  }
  packed_size = 0;
  buf_alloc = 4096;
  packed_data = (char *) malloc (buf_alloc);
  /* read packed AY register data to end of file. */
  while ((c = vfs_getc (vtx->fp)) != EOF) {
    if (buf_alloc < packed_size) {
      buf_alloc *= 2;
      packed_data = (char *) realloc (packed_data, buf_alloc);
      if (packed_data == NULL) {
	fprintf (stderr, "ayemu_vtx_load_data: Packed data out of memory!\n");
	vfs_fclose (vtx->fp);
	return NULL;
      }
    }
    packed_data[packed_size++] = c;
  }
  vfs_fclose (vtx->fp);
  vtx->fp = NULL;
  if ((vtx->regdata = (char *) malloc (vtx->hdr.regdata_size)) == NULL) {
    fprintf (stderr, "ayemu_vtx_load_data: Can allocate %d bytes for unpack register data\n", (int)(vtx->hdr.regdata_size));
    free (packed_data);
    return NULL;
  }
  lh5_decode ((unsigned char *)packed_data, (unsigned char *)(vtx->regdata), vtx->hdr.regdata_size, packed_size);
  free (packed_data);
  vtx->pos = 0;
  return vtx->regdata;
}