Esempio n. 1
0
int main(int argc, char **argv)
{
	xmp_context ctx1, ctx2;
	struct xmp_module_info mi1, mi2;
	int res1, res2;

	/* create player 1 */
	ctx1 = xmp_create_context();

	if (xmp_load_module(ctx1, argv[1]) < 0) {
		fprintf(stderr, "%s: error loading %s\n", argv[0], argv[1]);
		exit(1);
	}
	xmp_start_player(ctx1, 44100, 0);
	xmp_get_module_info(ctx1, &mi1);
	printf("1: %s (%s)\n", mi1.mod->name, mi1.mod->type);

	/* play a bit of file 1 */
	res1 = xmp_play_frame(ctx1);

	/* create player 2 */
	ctx2 = xmp_create_context();

	if (xmp_load_module(ctx2, argv[2]) < 0) {
		fprintf(stderr, "%s: error loading %s\n", argv[0], argv[2]);
		exit(1);
	}
	xmp_start_player(ctx2, 44100, 0);
	xmp_get_module_info(ctx2, &mi2);
	printf("2: %s (%s)\n", mi2.mod->name, mi2.mod->type);

	/* play file 2 */
	res2 = xmp_play_frame(ctx2);

	/* play file 1 again */
	res1 = xmp_play_frame(ctx1);
	
	/* close player 1 */
	xmp_end_player(ctx1);

	/* play file 2 again */
	res1 = xmp_play_frame(ctx2);

	/* close player 2 */
	xmp_end_player(ctx2);

	xmp_release_module(ctx1);
	xmp_release_module(ctx2);

	xmp_free_context(ctx1);
	xmp_free_context(ctx2);

	return 0;
}
Esempio n. 2
0
File: play.c Progetto: bor0/xmp
int main() {
    xmp_context ctx;
    struct xmp_frame_info fi;
    int i, j;

    FILE *t = fopen("test.tmp", "wb+");

    ctx = xmp_create_context();
    xmp_load_module(ctx, "../tests/3d.mod");
    xmp_start_player(ctx, 44100, 0);

    for (i=0;i<300;i++) {
        xmp_play_frame(ctx);
        xmp_get_frame_info(ctx, &fi);
        for (j=0;j<fi.buffer_size;j++) {
            fputc(((char *)fi.buffer)[j], t);
        }
    }
    printf("Dumped sound to `test.tmp`\n");
    xmp_end_player(ctx);
    xmp_release_module(ctx);
    xmp_free_context(ctx);

    fclose(t);

    printf("Start playing...\n");
    system("aplay test.tmp --rate=44100 -f cd");
    printf("Deleting file...\n");
    unlink("test.tmp");

    return 0;
}
Esempio n. 3
0
/**
 * Stop the current music.
 */
void stopMusic () {

	// Stop the music playing
	SDL_PauseAudio(~0);

#if defined(USE_MODPLUG)

	if (musicFile) {

		ModPlug_Unload(musicFile);
		musicFile = NULL;

	}

#elif defined(USE_XMP)

	int state = xmp_get_player(xmpC, XMP_PLAYER_STATE);
	if (state == XMP_STATE_LOADED || state == XMP_STATE_PLAYING) {

		xmp_end_player(xmpC);
		xmp_release_module(xmpC);

	}

#endif

	SDL_PauseAudio(0);

	return;

}
Esempio n. 4
0
File: load.c Progetto: visy/turha
void xmp_release_module(xmp_context opaque)
{
	struct context_data *ctx = (struct context_data *)opaque;
	struct module_data *m = &ctx->m;
	struct xmp_module *mod = &m->mod;
	int i;

	/* can't test this here, we must call release_module to clean up
	 * load errors
	if (ctx->state < XMP_STATE_LOADED)
		return;
	 */

	if (ctx->state > XMP_STATE_LOADED)
		xmp_end_player(opaque);

	ctx->state = XMP_STATE_UNLOADED;

	D_(D_INFO "Freeing memory");

	release_module_extras(ctx);

	for (i = 0; i < mod->trk; i++)
		free(mod->xxt[i]);
	if (mod->trk > 0)
		free(mod->xxt);

	for (i = 0; i < mod->pat; i++)
		free(mod->xxp[i]);
	if (mod->pat > 0)
		free(mod->xxp);

	for (i = 0; i < mod->ins; i++) {
		free(mod->xxi[i].sub);
		free(mod->xxi[i].extra);
	}
	if (mod->ins > 0)
		free(mod->xxi);

	for (i = 0; i < mod->smp; i++) {
		if (mod->xxs[i].data != NULL)
			free(mod->xxs[i].data - 4);
	}
	if (mod->smp > 0)
		free(mod->xxs);

	if (m->scan_cnt) {
		for (i = 0; i < mod->len; i++)
			free(m->scan_cnt[i]);
		free(m->scan_cnt);
	}

	free(m->comment);

	D_("free dirname/basename");
	free(m->dirname);
	free(m->basename);

}
Esempio n. 5
0
static void S_XMP_CodecCloseStream (snd_stream_t *stream)
{
	xmp_context c = (xmp_context)stream->priv;
	xmp_end_player(c);
	xmp_release_module(c);
	xmp_free_context(c);
	S_CodecUtilClose(&stream);
}
Esempio n. 6
0
static qboolean S_XMP_CodecOpenStream (snd_stream_t *stream)
{
/* need to load the whole file into memory and pass it to libxmp
 * using xmp_load_module_from_memory() which requires libxmp >= 4.2.
 * libxmp-4.0/4.1 only have xmp_load_module() which accepts a file
 * name which isn't good with files in containers like paks, etc. */
	xmp_context c;
	byte *moddata;
	long len;
	int mark;

	c = xmp_create_context();
	if (c == NULL)
		return false;

	len = FS_filelength (&stream->fh);
	mark = Hunk_LowMark();
	moddata = (byte *) Hunk_Alloc(len);
	FS_fread(moddata, 1, len, &stream->fh);
	if (xmp_load_module_from_memory(c, moddata, len) != 0)
	{
		Con_DPrintf("Could not load module %s\n", stream->name);
		goto err1;
	}

	Hunk_FreeToLowMark(mark); /* free original file data */
	stream->priv = c;
	if (shm->speed > XMP_MAX_SRATE)
		stream->info.rate = 44100;
	else if (shm->speed < XMP_MIN_SRATE)
		stream->info.rate = 11025;
	else	stream->info.rate = shm->speed;
	stream->info.bits = shm->samplebits;
	stream->info.width = stream->info.bits / 8;
	stream->info.channels = shm->channels;

	if (S_XMP_StartPlay(stream) != 0)
		goto err2;
	/* percentual left/right channel separation, default is 70. */
	if (stream->info.channels == 2)
		if (xmp_set_player(c, XMP_PLAYER_MIX, 100) != 0)
			goto err3;
	/* interpolation type, default is XMP_INTERP_LINEAR */
	if (xmp_set_player(c, XMP_PLAYER_INTERP, XMP_INTERP_SPLINE) != 0)
		goto err3;

	return true;

err3:	xmp_end_player(c);
err2:	xmp_release_module(c);
err1:	xmp_free_context(c);
	return false;
}
Esempio n. 7
0
int main(int argc, char **argv)
{
	xmp_context ctx;
	struct xmp_module_info mi;
	struct xmp_frame_info fi;
	int i;

	ctx = xmp_create_context();

	if (sdl_init(ctx) < 0) {
		fprintf(stderr, "%s: can't initialize sound\n", argv[0]);
		exit(1);
	}

	for (i = 1; i < argc; i++) {
		if (xmp_load_module(ctx, argv[i]) < 0) {
			fprintf(stderr, "%s: error loading %s\n", argv[0],
				argv[i]);
			continue;
		}

		if (xmp_start_player(ctx, 44100, 0) == 0) {

			/* Show module data */

			xmp_get_module_info(ctx, &mi);
			printf("%s (%s)\n", mi.mod->name, mi.mod->type);

			/* Play module */

			playing = 1;
			SDL_PauseAudio(0);

			while (playing) {
				SDL_Delay(10);
				xmp_get_frame_info(ctx, &fi);
				printf("%3d/%3d %3d/%3d\r", fi.pos,
					mi.mod->len, fi.row, fi.num_rows);
				fflush(stdout);
			}
			xmp_end_player(ctx);
		}

		xmp_release_module(ctx);
		printf("\n");
	}

	xmp_free_context(ctx);

	sdl_deinit();

	return 0;
}
Esempio n. 8
0
int main(int argc, char **argv)
{
    xmp_context c;
    struct xmp_frame_info mi;
    FILE *f;

    /* The output raw file */
    f = fopen("out.raw", "wb");
    if (f == NULL) {
        fprintf(stderr, "can't open output file\n");
        exit(EXIT_FAILURE);
    }

    /* Create the player context */
    c = xmp_create_context();

    /* Load our module */
    if (xmp_load_module(c, argv[1]) != 0) {
        fprintf(stderr, "can't load module\n");
        exit(EXIT_FAILURE);
    }

    /* Play the module */
    xmp_start_player(c, 44100, 0);
    while (xmp_play_frame(c) == 0) {
        xmp_get_frame_info(c, &mi);

        if (mi.loop_count > 0)    /* exit before looping */
            break;

        fwrite(mi.buffer, mi.buffer_size, 1, stdout);  /* write audio data */
    }
    xmp_end_player(c);
    xmp_release_module(c);        /* unload module */
    xmp_free_context(c);          /* destroy the player context */

    fclose(f);

    exit(EXIT_SUCCESS);
}
static void _compare_mixer_data(char *mod, char *data, int loops, int ignore_rv)
{
	xmp_context opaque;
	struct context_data *ctx;
	struct module_data *m;
        struct player_data *p;
        struct mixer_voice *vi;
	struct xmp_frame_info fi;
	int time, row, frame, chan, period, note, ins, vol, pan, pos0, cutoff;
	char line[200];
	FILE *f;
	int i, voc, ret;

	f = fopen(data, "r");
	fail_unless(f != NULL, "can't open data file");

	opaque = xmp_create_context();
	fail_unless(opaque != NULL, "can't create context");

	ret = xmp_load_module(opaque, mod);
	fail_unless(ret == 0, "can't load module");

	ctx = (struct context_data *)opaque;
	m = &ctx->m;
	p = &ctx->p;

	xmp_start_player(opaque, 44100, 0);
	xmp_set_player(opaque, XMP_PLAYER_MIX, 100);

	while (1) {
		xmp_play_frame(opaque);
		xmp_get_frame_info(opaque, &fi);
		if (fi.loop_count >= loops)
			break;

		for (i = 0; i < m->mod.chn; i++) {
			struct xmp_channel_info *ci = &fi.channel_info[i];
			struct channel_data *xc = &p->xc_data[i];
			int num;

			voc = map_channel(p, i);
			if (voc < 0 || TEST_NOTE(NOTE_SAMPLE_END))
				continue;

			vi = &p->virt.voice_array[voc];

			fgets(line, 200, f);
			num = sscanf(line, "%d %d %d %d %d %d %d %d %d %d %d",
				&time, &row, &frame, &chan, &period,
				&note, &ins, &vol, &pan, &pos0, &cutoff);

			fail_unless(fi.time    == time,   "time mismatch");
			fail_unless(fi.row     == row,    "row mismatch");
			fail_unless(fi.frame   == frame,  "frame mismatch");
			fail_unless(i          == chan,   "channel mismatch");
			fail_unless(ci->period == period, "period mismatch");
			fail_unless(vi->note   == note,   "note mismatch");
			fail_unless(vi->ins    == ins,    "instrument");
			if (!ignore_rv) {
				fail_unless(vi->vol == vol, "volume mismatch");
				fail_unless(vi->pan == pan, "pan mismatch");
			}
			fail_unless(vi->pos0   == pos0,   "position mismatch");
			if (num >= 11) {
				fail_unless(vi->filter.cutoff == cutoff,
							  "cutoff mismatch");
			}
		}
		
	}

	fgets(line, 200, f);
	fail_unless(feof(f), "not end of data file");

	xmp_end_player(opaque);
	xmp_release_module(opaque);
	xmp_free_context(opaque);
}
Esempio n. 10
0
File: load.c Progetto: kacmem/zxtune
void xmp_release_module(xmp_context opaque)
{
	struct context_data *ctx = (struct context_data *)opaque;
	struct module_data *m = &ctx->m;
	struct xmp_module *mod = &m->mod;
	int i;

	if (ctx->state > XMP_STATE_LOADED)
		xmp_end_player(opaque);

	ctx->state = XMP_STATE_UNLOADED;

	D_(D_INFO "Freeing memory");

	release_module_extras(ctx);

	if (mod->xxt) {
		for (i = 0; i < mod->trk; i++) {
			free(mod->xxt[i]);
		}
		free(mod->xxt);
	}

	if (mod->xxp) {
		for (i = 0; i < mod->pat; i++) {
			free(mod->xxp[i]);
		}
		free(mod->xxp);
	}


	if (mod->xxi) {
		for (i = 0; i < mod->ins; i++) {
			free(mod->xxi[i].sub);
			free(mod->xxi[i].extra);
		}
		free(mod->xxi);
	}

	if (mod->xxs) {
		for (i = 0; i < mod->smp; i++) {
			if (mod->xxs[i].data != NULL)
				free(mod->xxs[i].data - 4);
		}
		free(mod->xxs);
	}

	if (m->scan_cnt) {
		for (i = 0; i < mod->len; i++) {
			free(m->scan_cnt[i]);
		}
		free(m->scan_cnt);
	}

	if (m->comment) {
		free(m->comment);
	}

	D_("free dirname/basename");
	free(m->dirname);
	free(m->basename);
}
Esempio n. 11
0
event_t *
fa_xmp_playfile(media_pipe_t *mp, FILE *f, char *errbuf, size_t errlen,
                int hold, const char *url, size_t size)
{
    event_t *e = NULL;
    xmp_context ctx = xmp_create_context();
    //  struct xmp_module_info mi;
    struct xmp_frame_info fi;
    char *u = mystrdupa(url);

    mp->mp_audio.mq_stream = 0;
    mp_configure(mp, MP_CAN_PAUSE | MP_CAN_SEEK,
                 MP_BUFFER_SHALLOW, 0, "tracks");
    mp_become_primary(mp);

    if(xmp_load_modulef(ctx, f, u, size) >= 0) {
        if(xmp_start_player(ctx, 44100, 0) == 0) {

            media_buf_t *mb = NULL;
            media_queue_t *mq = &mp->mp_audio;

            while(1) {

                if(mb == NULL) {

                    if(xmp_play_frame(ctx)) {
                        e = event_create_type(EVENT_EOF);
                        break;
                    }
                    xmp_get_frame_info(ctx, &fi);
                    if(fi.loop_count > 0) {
                        e = event_create_type(EVENT_EOF);
                        break;
                    }

                    mb = media_buf_alloc_unlocked(mp, fi.buffer_size);
                    mb->mb_data_type = MB_AUDIO;
                    mb->mb_channels = 2;
                    mb->mb_rate = 44100;
                    mb->mb_pts = fi.time * 1000;
                    mb->mb_drive_clock = 1;
                    memcpy(mb->mb_data, fi.buffer, fi.buffer_size);
                    mp_set_duration(mp, fi.total_time * 1000);
                }

                if((e = mb_enqueue_with_events(mp, mq, mb)) == NULL) {
                    mb = NULL; /* Enqueue succeeded */
                    continue;
                }

                if(event_is_type(e, EVENT_PLAYQUEUE_JUMP)) {
                    mp_flush(mp, 0);
                    break;

                } else if(event_is_action(e, ACTION_SKIP_BACKWARD) ||
                          event_is_action(e, ACTION_SKIP_FORWARD) ||
                          event_is_action(e, ACTION_STOP)) {
                    mp_flush(mp, 0);
                    break;
                }
                event_release(e);
            }
            xmp_end_player(ctx);
        } else {
            snprintf(errbuf, errlen, "XMP failed to start");
        }
    } else {
        snprintf(errbuf, errlen, "XMP Loading error");
    }
    //  prop_ref_dec(dur);
    xmp_free_context(ctx);
    return e;
}
Esempio n. 12
0
int main(int argc, char **argv)
{
	xmp_context ctx;
	struct xmp_module_info mi;
	struct xmp_frame_info fi;
	int row, pos, i;

	if (sound_init(44100, 2) < 0) {
		fprintf(stderr, "%s: can't initialize sound\n", argv[0]);
		exit(1);
	}

	ctx = xmp_create_context();

	for (i = 1; i < argc; i++) {
		if (xmp_load_module(ctx, argv[i]) < 0) {
			fprintf(stderr, "%s: error loading %s\n", argv[0],
				argv[i]);
			continue;
		}

		if (xmp_start_player(ctx, 44100, 0) == 0) {

			/* Show module data */

			xmp_get_module_info(ctx, &mi);
			printf("%s (%s)\n", mi.mod->name, mi.mod->type);

			/* Play module */

			row = pos = -1;
			while (xmp_play_frame(ctx) == 0) {
				xmp_get_frame_info(ctx, &fi);
				if (fi.loop_count > 0)
					break;

				sound_play(fi.buffer, fi.buffer_size);

				if (fi.pos != pos) {
					printf("\n%02x:%02x\n",
					       fi.pos, fi.pattern);
					pos = fi.pos;
					row = -1;
				}
				if (fi.row != row) {
					display_data(&mi, &fi);
					row = fi.row;
				}
			}
			xmp_end_player(ctx);
		}

		xmp_release_module(ctx);
		printf("\n");
	}

	xmp_free_context(ctx);
	sound_deinit();

	return 0;
}