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
void USoundMod::Parse(class FAudioDevice* AudioDevice, const UPTRINT NodeWaveInstanceHash, FActiveSound& ActiveSound, const FSoundParseParameters& ParseParams, TArray<FWaveInstance*>& WaveInstances)
{
	FWaveInstance* WaveInstance = ActiveSound.FindWaveInstance(NodeWaveInstanceHash);

	// Create a new WaveInstance if this SoundWave doesn't already have one associated with it.
	if (WaveInstance == NULL)
	{
		const int32 SampleRate = 44100;

		// Create a new wave instance and associate with the ActiveSound
		WaveInstance = new FWaveInstance(&ActiveSound);
		WaveInstance->WaveInstanceHash = NodeWaveInstanceHash;
		ActiveSound.WaveInstances.Add(NodeWaveInstanceHash, WaveInstance);

		// Create streaming wave object
		USoundModWave* ModWave = NewObject<USoundModWave>();
		ModWave->SampleRate = SampleRate;
		ModWave->NumChannels = 2;
		ModWave->Duration = INDEFINITELY_LOOPING_DURATION;
		ModWave->bLooping = bLooping;

		if (ResourceData == NULL)
		{
			RawData.GetCopy((void**)&ResourceData, true);
		}

		ModWave->xmpContext = xmp_create_context();
		xmp_load_module_from_memory(ModWave->xmpContext, ResourceData, RawData.GetBulkDataSize());
		xmp_start_player(ModWave->xmpContext, SampleRate, 0);

		WaveInstance->WaveData = ModWave;
	}

	WaveInstance->WaveData->Parse(AudioDevice, NodeWaveInstanceHash, ActiveSound, ParseParams, WaveInstances);
}
Esempio n. 3
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. 4
0
static int S_XMP_StartPlay (snd_stream_t *stream)
{
	int fmt = 0;

	if (stream->info.channels == 1)
		fmt |= XMP_FORMAT_MONO;
	if (stream->info.width == 1)
		fmt |= XMP_FORMAT_8BIT|XMP_FORMAT_UNSIGNED;

	return xmp_start_player((xmp_context)stream->priv, stream->info.rate, fmt);
}
Esempio n. 5
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. 6
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. 8
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. 9
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;
}
Esempio n. 10
0
/**
 * Play music from the specified file.
 *
 * @param fileName Name of a file containing music data.
 */
void playMusic (const char * fileName) {

	File *file;
	unsigned char *psmData;
	int size;
	bool loadOk = false;

#ifdef USE_MODPLUG
	ModPlug_Settings settings;
#endif

	// Stop any existing music playing
	stopMusic();


	// Load the music file

	try {

		file = new File(fileName, false);

	} catch (int e) {

		return;

	}

	// Find the size of the file
	size = file->getSize();

	// Read the entire file into memory
	file->seek(0, true);
	psmData = file->loadBlock(size);

	delete file;


#ifdef USE_MODPLUG

	// Set up libmodplug

	settings.mFlags = MUSIC_FLAGS;
	settings.mChannels = audioSpec.channels;

	if ((audioSpec.format == AUDIO_U8) || (audioSpec.format == AUDIO_S8))
		settings.mBits = 8;
	else settings.mBits = 16;

	settings.mFrequency = audioSpec.freq;
	settings.mResamplingMode = MUSIC_RESAMPLEMODE;
	settings.mReverbDepth = 25;
	settings.mReverbDelay = 40;
	settings.mBassAmount = 50;
	settings.mBassRange = 10;
	settings.mSurroundDepth = 50;
	settings.mSurroundDelay = 40;
	settings.mLoopCount = -1;

	ModPlug_SetSettings(&settings);

	// Load the file into libmodplug
	musicFile = ModPlug_Load(psmData, size);
	loadOk = (musicFile != NULL);

#elif defined(USE_XMP)

	// Load the file into libxmp
	loadOk = (xmp_load_module_from_memory(xmpC, psmData, size) == 0);

#endif

	delete[] psmData;

	if (!loadOk) {

		logError("Could not play music file", fileName);

		return;

	}

#ifdef USE_XMP
	int playerFlags = 0;

	if ((audioSpec.format == AUDIO_U8) || (audioSpec.format == AUDIO_S8))
		playerFlags = playerFlags & XMP_FORMAT_8BIT;

	if ((audioSpec.format == AUDIO_U8) || (audioSpec.format == AUDIO_U16)
		|| (audioSpec.format == AUDIO_U16MSB) || (audioSpec.format == AUDIO_U16LSB))
		playerFlags = playerFlags & XMP_FORMAT_UNSIGNED;

	if (audioSpec.channels == 1)
		playerFlags = playerFlags & XMP_FORMAT_MONO;

	xmp_start_player(xmpC, audioSpec.freq, playerFlags);
	xmp_set_player(xmpC, XMP_PLAYER_INTERP, MUSIC_INTERPOLATION);
#  ifdef MUSIC_EFFECTS
	xmp_set_player(xmpC, XMP_PLAYER_DSP, MUSIC_EFFECTS);
#  endif

#endif

	// Start the audio playing
	SDL_PauseAudio(0);

	return;

}