예제 #1
0
파일: test3.c 프로젝트: bithorder/libxmp
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;
}
JNIEXPORT jint JNICALL
Java_org_helllabs_android_xmp_Xmp_init(JNIEnv *env, jobject obj)
{
	xmp_drv_register(&drv_smix);
	ctx = xmp_create_context();
	xmp_init(ctx, 0, NULL);
	opt = xmp_get_options(ctx);
	opt->verbosity = 0;

	xmp_register_event_callback(ctx, process_echoback, NULL);
	_playing = 0;

	opt->freq = 44100;
	opt->resol = 16;
	opt->outfmt &= ~XMP_FMT_MONO;
	opt->flags |= XMP_CTL_ITPT | XMP_CTL_FILTER;

	if (xmp_open_audio(ctx) < 0) {
		xmp_deinit(ctx);
		xmp_free_context(ctx);
		return -1;
	}

	return 0;
}
예제 #3
0
파일: play.c 프로젝트: 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;
}
예제 #4
0
파일: bmp.c 프로젝트: ProjectZeroSlackr/XMP
static void get_song_info(char *filename, char **title, int *length)
{
	xmp_context ctx2;
	int lret;
	struct xmp_module_info mi;
	struct xmp_options *opt;

	/* Create new context to load a file and get the length */

	ctx2 = xmp_create_context();
	opt = xmp_get_options(ctx2);
	opt->skipsmp = 1;	/* don't load samples */

	pthread_mutex_lock(&load_mutex);
	lret = xmp_load_module(ctx2, filename);
	pthread_mutex_unlock(&load_mutex);

	if (lret < 0) {
		xmp_free_context(ctx2);
		return;
	}

	*length = lret;
	xmp_get_module_info(ctx2, &mi);
	*title = g_strdup(mi.name);

	xmp_release_module(ctx2);
	xmp_free_context(ctx2);
}
예제 #5
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);
}
예제 #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;
}
예제 #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;
}
JNIEXPORT jobject JNICALL
Java_org_helllabs_android_xmp_Xmp_getModInfo(JNIEnv *env, jobject obj, jstring fname)
{
	const char *filename;
	int res;
	xmp_context ctx2;
	struct xmp_options *opt;
	struct xmp_module_info mi;
	jobject modInfo;
	jmethodID cid;
	jclass modInfoClass;
	jstring name, type;

	modInfoClass = (*env)->FindClass(env, "org/helllabs/android/xmp/ModInfo");
	if (modInfoClass == NULL)
		return NULL;


	filename = (*env)->GetStringUTFChars(env, fname, NULL);
	ctx2 = xmp_create_context();
	opt = xmp_get_options(ctx2);
	opt->skipsmp = 1;	/* don't load samples */
	res = xmp_load_module(ctx2, (char *)filename);
	(*env)->ReleaseStringUTFChars(env, fname, filename);
	if (res < 0) {
		xmp_free_context(ctx2);
		return NULL;
        }
	xmp_get_module_info(ctx2, &mi);
	xmp_release_module(ctx2);
	xmp_free_context(ctx2);

	/*__android_log_print(ANDROID_LOG_DEBUG, "libxmp", "%s", mi.name);
	__android_log_print(ANDROID_LOG_DEBUG, "libxmp", "%s", mi.type);*/

	name = (*env)->NewStringUTF(env, mi.name);
	type = (*env)->NewStringUTF(env, mi.type);

	cid = (*env)->GetMethodID(env, modInfoClass,
		"<init>",
		"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IIIIIIIII)V");

	modInfo = (*env)->NewObject(env, modInfoClass, cid,
		name, type, fname,
		mi.chn, mi.pat, mi.ins, mi.trk, mi.smp, mi.len,
		mi.bpm, mi.tpo, mi.time);

	return modInfo;
}
예제 #9
0
파일: bmp.c 프로젝트: ProjectZeroSlackr/XMP
static void init(void)
{
	ConfigFile *cfg;
	gchar *filename;

	ctx = xmp_create_context();

	xmp_cfg.mixing_freq = 0;
	xmp_cfg.convert8bit = 0;
	xmp_cfg.fixloops = 0;
	xmp_cfg.modrange = 0;
	xmp_cfg.force8bit = 0;
	xmp_cfg.force_mono = 0;
	xmp_cfg.interpolation = TRUE;
	xmp_cfg.filter = TRUE;
	xmp_cfg.pan_amplitude = 80;

#define CFGREADINT(x) xmms_cfg_read_int (cfg, "XMP", #x, &xmp_cfg.x)

	filename = g_strconcat(g_get_home_dir(), CONFIG_FILE, NULL);

	if ((cfg = xmms_cfg_open_file(filename))) {
		CFGREADINT(mixing_freq);
		CFGREADINT(force8bit);
		CFGREADINT(convert8bit);
		CFGREADINT(modrange);
		CFGREADINT(fixloops);
		CFGREADINT(force_mono);
		CFGREADINT(interpolation);
		CFGREADINT(filter);
		CFGREADINT(pan_amplitude);

		xmms_cfg_free(cfg);
	}

	file_info_box_build();

	xmp_init_callback(ctx, driver_callback);
	xmp_register_event_callback(x11_event_callback);

	memset(ii, 0, sizeof (ii));
	ii->wresult = 42;
}
예제 #10
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);
}
예제 #11
0
static void init(void)
{
	ConfigDb *cfg;

	ctx = xmp_create_context();

	xmp_cfg.mixing_freq = 0;
	xmp_cfg.convert8bit = 0;
	xmp_cfg.fixloops = 0;
	xmp_cfg.modrange = 0;
	xmp_cfg.force8bit = 0;
	xmp_cfg.force_mono = 0;
	xmp_cfg.interpolation = TRUE;
	xmp_cfg.filter = TRUE;
	xmp_cfg.pan_amplitude = 80;

#define CFGREADINT(x) bmp_cfg_db_get_int (cfg, "XMP", #x, &xmp_cfg.x)

	if ((cfg = bmp_cfg_db_open())) {
		CFGREADINT(mixing_freq);
		CFGREADINT(force8bit);
		CFGREADINT(convert8bit);
		CFGREADINT(modrange);
		CFGREADINT(fixloops);
		CFGREADINT(force_mono);
		CFGREADINT(interpolation);
		CFGREADINT(filter);
		CFGREADINT(pan_amplitude);

		bmp_cfg_db_close(cfg);
	}

	file_info_box_build();

	xmp_init_callback(ctx, driver_callback);
	xmp_register_event_callback(x11_event_callback);

	memset(ii, 0, sizeof (ii));
	ii->wresult = 42;
}
예제 #12
0
static Tuple *get_song_tuple(char *filename)
{
	Tuple *tuple;
	xmp_context ctx2;
	int lret;
	struct xmp_module_info mi;
	struct xmp_options *opt;

	strip_vfs(filename);		/* Sorry, no VFS support */

	tuple = aud_tuple_new_from_filename(filename);

	/* Create new context to load a file and get the length */

	ctx2 = xmp_create_context();
	opt = xmp_get_options(ctx2);
	opt->skipsmp = 1;	/* don't load samples */

	g_static_mutex_lock(&load_mutex);
	lret = xmp_load_module(ctx2, filename);
	g_static_mutex_unlock(&load_mutex);

	if (lret < 0) {
		xmp_free_context(ctx2);
		return NULL;
	}

	xmp_get_module_info(ctx2, &mi);

	aud_tuple_associate_string(tuple, FIELD_TITLE, NULL, mi.name);
	aud_tuple_associate_string(tuple, FIELD_CODEC, NULL, mi.type);
	aud_tuple_associate_int(tuple, FIELD_LENGTH, NULL, lret);

	xmp_release_module(ctx2);
	xmp_free_context(ctx2);

	return tuple;
}
예제 #13
0
파일: sound.cpp 프로젝트: przemub/openjazz
/**
 * Initialise audio.
 */
void openAudio () {

	SDL_AudioSpec asDesired;

#if defined(USE_MODPLUG)
	musicFile = NULL;
#elif defined(USE_XMP)
	xmpC = xmp_create_context();
#endif


	// Set up SDL audio

	asDesired.freq = SOUND_FREQ;
	asDesired.format = AUDIO_S16;
	asDesired.channels = 2;
#if defined(GP2X) || defined(PSP) || defined(_3DS)
	asDesired.samples = 512;
#else
	asDesired.samples = 2048;
#endif
	asDesired.callback = audioCallback;
	asDesired.userdata = NULL;

	if (SDL_OpenAudio(&asDesired, &audioSpec) < 0)
		logError("Unable to open audio", SDL_GetError());


	// Load sounds

	if (loadSounds("SOUNDS.000") != E_NONE) sounds = NULL;

	// Start audio for sfx to work
	SDL_PauseAudio(0);
	return;

}
예제 #14
0
파일: fa_xmp.c 프로젝트: whyz/showtime
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;
}
예제 #15
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;
}
예제 #16
0
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);
}
예제 #17
0
UObject* USoundModImporterFactory::FactoryCreateBinary
(
	UClass*				Class,
	UObject*			InParent,
	FName				Name,
	EObjectFlags		Flags,
	UObject*			Context,
	const TCHAR*		FileType,
	const uint8*&		Buffer,
	const uint8*		BufferEnd,
	FFeedbackContext*	Warn
)
{
	// if the sound already exists, remember the user settings
	USoundMod* ExistingSound = FindObject<USoundMod>(InParent, *Name.ToString());

	// TODO - Audio Threading. This needs to be sent to the audio device and wait on stopping the sounds
	TArray<UAudioComponent*> ComponentsToRestart;
	FAudioDevice* AudioDevice = GEngine->GetAudioDevice();
	if (AudioDevice && ExistingSound)
	{
		// TODO: Generalize the stop sounds function
		//AudioDevice->StopSoundsForReimport(ExistingSound, ComponentsToRestart);
	}

	bool bUseExistingSettings = bSoundModFactorySuppressImportOverwriteDialog;

	if (ExistingSound && !bUseExistingSettings && !GIsAutomationTesting)
	{
		DisplayOverwriteOptionsDialog(FText::Format(
			NSLOCTEXT("SoundModImporterFactory", "ImportOverwriteWarning", "You are about to import '{0}' over an existing sound."),
			FText::FromName(Name)));

		switch (OverwriteYesOrNoToAllState)
		{
			case EAppReturnType::Yes:
			case EAppReturnType::YesAll:
			{
				// Overwrite existing settings
				bUseExistingSettings = false;
				break;
			}
			case EAppReturnType::No:
			case EAppReturnType::NoAll:
			{
				// Preserve existing settings
				bUseExistingSettings = true;
				break;
			}
			default:
			{
				FEditorDelegates::OnAssetPostImport.Broadcast(this, NULL);
				return NULL;
			}
		}
	}

	// Reset the flag back to false so subsequent imports are not suppressed unless the code explicitly suppresses it
	bSoundModFactorySuppressImportOverwriteDialog = false;

	TArray<uint8> RawModData;
	RawModData.Empty(BufferEnd - Buffer);
	RawModData.AddUninitialized(BufferEnd - Buffer);
	FMemory::Memcpy(RawModData.GetData(), Buffer, RawModData.Num());

	// TODO: Validate that this is actually a mod file
	xmp_context xmpContext = xmp_create_context();
	if (xmp_load_module_from_memory(xmpContext, RawModData.GetData(), RawModData.Num()) != 0)
	{
		return NULL;
	}
	xmp_module_info xmpModuleInfo;
	xmp_get_module_info(xmpContext, &xmpModuleInfo);

	// Use pre-existing sound if it exists and we want to keep settings,
	// otherwise create new sound and import raw data.
	USoundMod* Sound = (bUseExistingSettings && ExistingSound) ? ExistingSound : NewObject<USoundMod>(InParent, Name, Flags);

	Sound->Duration = xmpModuleInfo.seq_data->duration / 1000.f;

	xmp_release_module(xmpContext);
	xmp_free_context(xmpContext);

	Sound->RawData.Lock(LOCK_READ_WRITE);
	void* LockedData = Sound->RawData.Realloc(BufferEnd - Buffer);
	FMemory::Memcpy(LockedData, Buffer, BufferEnd - Buffer);
	Sound->RawData.Unlock();

	FEditorDelegates::OnAssetPostImport.Broadcast(this, Sound);

	for (int32 ComponentIndex = 0; ComponentIndex < ComponentsToRestart.Num(); ++ComponentIndex)
	{
		ComponentsToRestart[ComponentIndex]->Play();
	}

	return Sound;
}