Пример #1
0
static int
aoplug_init (DB_fileinfo_t *_info, DB_playItem_t *it) {
    aoplug_info_t *info = (aoplug_info_t *)_info;

    _info->fmt.bps = 16;
    _info->fmt.channels = 2;
    _info->fmt.samplerate = deadbeef->conf_get_int ("synth.samplerate", 44100);
    _info->fmt.channelmask = _info->fmt.channels == 1 ? DDB_SPEAKER_FRONT_LEFT : (DDB_SPEAKER_FRONT_LEFT | DDB_SPEAKER_FRONT_RIGHT);
    _info->readpos = 0;
    _info->plugin = &plugin;
    info->duration = deadbeef->pl_get_item_duration (it);

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

    info->filesize = deadbeef->fgetlength (file);
    info->filebuffer = malloc (info->filesize);
    if (!info->filebuffer) {
		fprintf(stderr, "psf: could not allocate %d bytes of memory\n", (int)info->filesize);
		deadbeef->fclose (file);
        return -1;
    }

	if (deadbeef->fread(info->filebuffer, 1, info->filesize, file) != info->filesize) {
        deadbeef->pl_lock ();
		fprintf(stderr, "psf: file read error: %s\n", deadbeef->pl_find_meta (it, ":URI"));
		deadbeef->pl_unlock ();
		deadbeef->fclose (file);
        return -1;
    }
    deadbeef->fclose (file);

    info->type = ao_identify (info->filebuffer);
    if (info->type < 0) {
        fprintf (stderr, "psf: ao_identify failed\n");
        return -1;
    }

    deadbeef->pl_lock ();
    info->decoder = ao_start (info->type, deadbeef->pl_find_meta (it, ":URI"), (uint8 *)info->filebuffer, info->filesize);
    deadbeef->pl_unlock ();
    if (!info->decoder) {
        fprintf (stderr, "psf: ao_start failed\n");
        return -1;
    }

    return 0;
}
Пример #2
0
static int audio_adec_start(AIO_ATTR_S * pstAioAttr)
{
    HI_S32 s32Ret= HI_SUCCESS;
    ADEC_CHN    AdChn = 0;
    AUDIO_DEV   AoDev = 0;
    AO_CHN      AoChn = 0;

    s32Ret = adec_start(AdChn, get_payload_type());
    CHECK(s32Ret == HI_SUCCESS, HI_FAILURE, "Error with %#x.\n", s32Ret);

    s32Ret = ao_start(AoDev, AoChn, pstAioAttr);
    CHECK(s32Ret == HI_SUCCESS, HI_FAILURE, "Error with %#x.\n", s32Ret);

    s32Ret = ao_bind_adec(AoDev, AoChn, AdChn);
    CHECK(s32Ret == HI_SUCCESS, HI_FAILURE, "Error with %#x.\n", s32Ret);

    return s32Ret;
}
Пример #3
0
static DB_playItem_t *
aoplug_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname) {
    DB_FILE *fp = deadbeef->fopen (fname);
    if (!fp) {
        trace ("psf: failed to fopen %s\n", fname);
        return NULL;
    }

    size_t size = deadbeef->fgetlength (fp);
    char *buffer = malloc (size);
    if (!buffer) {
        deadbeef->fclose (fp);
		fprintf(stderr, "psf: could not allocate %d bytes of memory\n", (int)size);
        return NULL;
    }

	if (deadbeef->fread(buffer, 1, size, fp) != size) {
        deadbeef->fclose (fp);
        free (buffer);
		fprintf(stderr, "psf: file read error: %s\n", fname);
        return NULL;
    }

    deadbeef->fclose (fp);

    int type = ao_identify (buffer);
    if (type < 0) {
        free (buffer);
        return NULL;
    }

    void *dec = ao_start (type, fname, (uint8*)buffer, size);
    if (!dec) {
        free (buffer);
        return NULL;
    }
    ao_display_info info;
    memset (&info, 0, sizeof (info));
    int have_info = 0;
    if (ao_get_info (type, dec, &info) == AO_SUCCESS) {
        have_info = 1;
    }

    ao_stop (type, dec);
    dec = NULL;

	free (buffer);
	
    DB_playItem_t *it = deadbeef->pl_item_alloc_init (fname, plugin.plugin.id);
    const char *ext = fname + strlen (fname);
    while (*ext != '.' && ext > fname) {
        ext--;
    }
    if (*ext == '.') {
        ext++;
        if (!strcasecmp (ext, "psf") || !strcasecmp (ext, "minipsf")) {
            deadbeef->pl_add_meta (it, ":FILETYPE", "PSF");
        }
        else if (!strcasecmp (ext, "psf2") || !strcasecmp (ext, "minipsf2")) {
            deadbeef->pl_add_meta (it, ":FILETYPE", "PSF2");
        }
        else if (!strcasecmp (ext, "spu")) {
            deadbeef->pl_add_meta (it, ":FILETYPE", "SPU");
        }
        else if (!strcasecmp (ext, "ssf") || !strcasecmp (ext, "minissf")) {
            deadbeef->pl_add_meta (it, ":FILETYPE", "SSF");
        }
        else if (!strcasecmp (ext, "qsf") || !strcasecmp (ext, "miniqsf")) {
            deadbeef->pl_add_meta (it, ":FILETYPE", "QSF");
        }
        else if (!strcasecmp (ext, "dsf") || !strcasecmp (ext, "minidsf")) {
            deadbeef->pl_add_meta (it, ":FILETYPE", "DSF");
        }
    }
    else {
        deadbeef->pl_add_meta (it, ":FILETYPE", "PSF");
    }

    float duration = 120;
    float fade = 0;

    if (have_info) {
        int i;
        for (i = 1; i < 9; i++) {
            if (!strncasecmp (info.title[i], "Length: ", 8)) {
                int min;
                float sec;
                if (sscanf (info.info[i], "%d:%f", &min, &sec) == 2) {
                    duration = min * 60 + sec;
                }
                else if (sscanf (info.info[i], "%f", &sec) == 1) {
                    duration = sec;
                }
                aoplug_add_meta (it, NULL, info.info[i], info.title[i]);
            }
            else if (!strncasecmp (info.title[i], "Name: ", 6) || !strncasecmp (info.title[i], "Song: ", 6)) {
                aoplug_add_meta (it, "title", info.info[i], info.title[i]);
            }
            else if (!strncasecmp (info.title[i], "Game: ", 6)) {
                aoplug_add_meta (it, "album", info.info[i], info.title[i]);
            }
            else if (!strncasecmp (info.title[i], "Artist: ", 8)) {
                aoplug_add_meta (it, "artist", info.info[i], info.title[i]);
            }
            else if (!strncasecmp (info.title[i], "Copyright: ", 11)) {
                aoplug_add_meta (it, "copyright", info.info[i], info.title[i]);
            }
            else if (!strncasecmp (info.title[i], "Year: ", 6)) {
                aoplug_add_meta (it, "year", info.info[i], info.title[i]);
            }
            else if (!strncasecmp (info.title[i], "Fade: ", 6)) {
                fade = atof (info.info[i]);
                aoplug_add_meta (it, "fade", info.info[i], info.title[i]);
            }
            else {
                char *colon = strchr (info.title[i], ':');
                char name[colon-info.title[i]+1];
                memcpy (name, info.title[i], colon-info.title[i]);
                name[colon-info.title[i]] = 0;
                aoplug_add_meta (it, name, info.info[i], info.title[i]);
            }
        }
    }
    deadbeef->plt_set_item_duration (plt, it, duration+fade);
    deadbeef->pl_add_meta (it, "title", NULL);
    after = deadbeef->plt_insert_item (plt, after, it);
    deadbeef->pl_item_unref (it);
    return after;
}