Exemple #1
0
int main(int argc, char *argv[])
{
	float *buffer;
	unsigned int len;
	unsigned int frate;
	FILE *f;
	decoder_handle handle;
	if(argc != 3) {
		printf("USAGE: %s <MP3 File> <Output file>\n", argv[0]);
		exit(-1);
	}
	f = fopen(argv[2], "w");
	if(!f) {
		printf("Cannot create %s\n", argv[2]);
		exit(-1);
	}

	if(decoder_init(&handle)) {
		printf("Cound not initialize decoder\n");
		goto init_failed;
	}
	if(decoder_open(handle, argv[1])) {
		printf("Could not open %s to decode\n", argv[1]);
		goto open_failed;
	}
	if(decoder_start(handle)) {
		printf("Could not start decoding\n");
		goto start_failed;
	}
	while(1) {
		decoder_data_pull(handle, &buffer, &len, &frate);
		if(len == 0)
			break;
		if(write(fileno(f), buffer, len * sizeof(float)) != len * sizeof(float)) {
			printf("Write failed\n");
		}

		free(buffer);
	}
init_failed:
	fclose(f);
start_failed:
	if(decoder_close(handle)) {
		printf("Closing decoder handle failed\n");
	}
open_failed:
	decoder_exit(handle);

	return 0;

}
Exemple #2
0
int file_open(struct file_handle **handle, const char *name)
{
	struct file_handle *h;

	/* Alloc structure */
	*handle = malloc(sizeof(struct file_handle));
	if(*handle == NULL)
		return -1;
	h = *handle;

	/* Connect and get header from server */
	h->fp = fopen(name, "rb");
	if(h->fp == NULL)
		return -1;

	/* Detect file format and codec */

	/* Open decoder */
	decoder_open(&h->dec, 2, &file_read_stream, h);

	return 0;
}
static DB_playItem_t *
example_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname) {
    // open file
    DB_FILE *fp = deadbeef->fopen (fname);
    if (!fp) {
        trace ("example: failed to fopen %s\n", fname);
        return NULL;
    }

    // decoder_* functions are imaginary -- you should replace them with real
    // decoder library calls
    decoder_info_t *di = decoder_open ();
    if (!di) {
        trace ("example: failed to init decoder\n");
        return NULL;
    }
    // read track info/tags
    track_info_t ti;
    if (decoder_read_info (&ti) < 0) {
        trace ("example: failed to read info\n");
        decoder_free (di);
        return NULL;
    }

    // replace "example" with your file type (e.g. MP3, WAV, etc)
    const char *ft = "example";

    // no cuesheet, prepare track for addition
    DB_playItem_t *it = deadbeef->pl_item_alloc_init (fname, plugin.plugin.id);

    deadbeef->pl_replace_meta (it, ":FILETYPE", ft);
    deadbeef->plt_set_item_duration (plt, it, (float)ti.total_num_samples/ti.samplerate);

    // now we should have track duration, and can try loading cuesheet
    // 1st try embedded cuesheet
    if (ti.embeddedcuesheet[0]) {
        DB_playItem_t *cue = deadbeef->plt_insert_cue_from_buffer (plt, after, it, ti.embeddedcuesheet, strlen (ti.embeddedcuesheet), ti.total_num_samples, ti.samplerate);
        if (cue) {
            deadbeef->pl_item_unref (it);
            deadbeef->pl_item_unref (cue);
            // cuesheet loaded
            decoder_free (di);
            return cue;
        }
    }

    // embedded cuesheet not found, try external one
    DB_playItem_t *cue = deadbeef->plt_insert_cue (plt, after, it, ti.total_num_samples, ti.samplerate);
    if (cue) {
        // cuesheet loaded
        deadbeef->pl_item_unref (it);
        deadbeef->pl_item_unref (cue);
        decoder_free (di);
        return cue;
    }


    // add metainfo
    if (!strlen (ti.title)) {
        // title is empty, this call will set track title to filename without extension
        deadbeef->pl_add_meta (it, "title", NULL);
    }
    else {
        deadbeef->pl_add_meta (it, "title", ti.title);
    }
    deadbeef->pl_add_meta (it, "artist", ti.artist);
    // ... etc ...

    // free decoder
    decoder_free (di);

    // now the track is ready, insert into playlist
    after = deadbeef->plt_insert_item (plt, after, it);
    deadbeef->pl_item_unref (it);
    return after;
}
Exemple #4
0
int spectgen_open(spectgen_handle *_handle, char *fname, unsigned int window_size, unsigned int step_size, scale_t scale, spect_method_t method, unsigned int *_nbands)
{
	struct spectgen_struct *handle;
	int nbands;

	*_handle = NULL;

	if(!_nbands)
	      return -1;

	if(!window_size || !step_size)
	      return -1;
	if(step_size > window_size)
	      return -1;

	nbands = *_nbands;
	if(nbands == 0)
		*_nbands = nbands = (window_size / 2) + 1;

	handle = (struct spectgen_struct *)
	    malloc(sizeof(struct spectgen_struct));
	if(!handle)
	      return -1;

	handle->session = spectgen_session_get(window_size, scale, nbands, method, handle, spectgen_worker);
	if(!handle->session)
	      goto session_creation_failed;

	handle->step_size = step_size;
	handle->average_frate = 0;
	handle->total_samples = 0;

	strncpy(handle->filename, fname, 256);
	handle->filename[255] = '\0';

	if(q_init(&handle->queue))
	      goto q_init_failed;

	handle->leftover = (float *)malloc(sizeof(float) * handle->session->window_size);
	if(!handle->leftover)
	      goto leftover_failed;


	handle->barkband_table = (unsigned int *)malloc(sizeof(unsigned int) * 
				handle->session->numfreqs);
	if(!handle->barkband_table)
	      goto barkband_table_failed;

	if(decoder_open(handle->session->d_handle, handle->filename))
		goto open_failed;

	handle->barkband_table_inited = 0;
	*_handle = handle;
	return 0;

open_failed:
	printf("Open failed\n");
	free(handle->barkband_table);
barkband_table_failed:
	printf("barkband table failed\n");
	free(handle->leftover);
leftover_failed:
	printf("leftover failed\n");
	q_destroy(&handle->queue);
q_init_failed:
	printf("qinit failed\n");
	spectgen_session_put(handle->session);
session_creation_failed:
	printf("session failed\n");
	free(handle);
	return -1;
}