Exemple #1
0
ayemu_vtx_t * ayemu_vtx_load_from_file(const char *filename)
{
  size_t size;
#ifdef __MINGW32__
  SYSTEM_INFO si;
  GetSystemInfo(&si);
  const size_t page_size = (size_t) si.dwPageSize;
#else
  const size_t page_size = (size_t) sysconf (_SC_PAGESIZE);
#endif
  int fd;
  struct stat st;
  ayemu_vtx_t *ret;

  // printf("Page size is %d\n", page_size);

  if (stat(filename, &st) != 0) {
    fprintf(stderr, "Can't stat file %s: %s\n", filename, strerror(errno));
    return NULL;
  }
  size = st.st_size;

  fd = open(filename, O_RDONLY, 0);
  if (fd == 0) {
    fprintf(stderr, "Can't open file %s: %s\n", filename, strerror(errno));
    return NULL;
  }

  size_t data_len = (size / page_size + 1) * page_size;

  char *data = mmap(NULL, data_len, PROT_READ, MAP_PRIVATE, fd, 0);
  if (data == (void*)(-1)) {
    fprintf(stderr, "Can't mmap file %s: %s\n", filename, strerror(errno));
    return NULL;
  }

  ret = ayemu_vtx_load(data, size);

  if (munmap(data, data_len) != 0) {
    fprintf(stderr, "Can't munmmap file %s: %s\n", filename, strerror(errno));
  }

  return ret;
}
Exemple #2
0
static int
vtx_init (DB_fileinfo_t *_info, DB_playItem_t *it) {
    // prepare to decode the track
    // return -1 on failure
    vtx_info_t *info = (vtx_info_t *)_info;
    
    size_t sz = 0;
    char *buf = NULL;

    deadbeef->pl_lock ();
    DB_FILE *fp = deadbeef->fopen (deadbeef->pl_find_meta (it, ":URI"));
    deadbeef->pl_unlock ();
    if (!fp) {
        trace ("vtx: failed to open file %s\n", deadbeef->pl_find_meta (it, ":URI"));
        return -1;
    }

    sz = deadbeef->fgetlength (fp);
    if (sz <= 0) {
        trace ("vtx: bad file size\n");
        return -1;
    }

    buf = malloc (sz);
    if (!buf) {
        trace ("vtx: out of memory\n");
        return -1;
    }
    if (deadbeef->fread (buf, 1, sz, fp) != sz) {
        trace ("vtx: read failed\n");
        free (buf);
        return -1;
    }

    info->decoder = ayemu_vtx_load (buf, sz);
    if (!info->decoder) {
        trace ("vtx: ayemu_vtx_load failed\n");
        free (buf);
        return -1;
    }
    trace ("vtx: data=%p, size=%d\n", info->decoder->regdata, info->decoder->regdata_size);

    free (buf);

    ayemu_init (&info->ay);
    ayemu_set_chip_type (&info->ay, info->decoder->chiptype, NULL);
    ayemu_set_chip_freq (&info->ay, info->decoder->chipFreq);
    ayemu_set_stereo (&info->ay, info->decoder->stereo, NULL);

    int samplerate = deadbeef->conf_get_int ("synth.samplerate", 44100);

    info->left = 0;
    info->vtx_pos = 0;
    _info->plugin = &plugin;
    _info->fmt.bps = deadbeef->conf_get_int ("vtx.bps", 16);;
    if (_info->fmt.bps != 16 && _info->fmt.bps != 8) {
        _info->fmt.bps = 16;
    }
    _info->fmt.channels = 2;
    _info->fmt.samplerate = samplerate;
    _info->fmt.channelmask = _info->fmt.channels == 1 ? DDB_SPEAKER_FRONT_LEFT : (DDB_SPEAKER_FRONT_LEFT | DDB_SPEAKER_FRONT_RIGHT);
    _info->readpos = 0;

    ayemu_set_sound_format (&info->ay, samplerate, _info->fmt.channels, _info->fmt.bps);

    info->rate = _info->fmt.channels * _info->fmt.bps / 8;
    return 0;
}