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; }
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); }
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; }
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; }
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; }
static void play_file(char *filename) { int channelcnt = 1; FILE *f; struct xmp_options *opt; int lret; GtkTextIter start, end; AFormat fmt; int nch; opt = xmp_get_options(ctx); _D("play_file: %s", filename); stop(); /* sanity check */ if ((f = fopen(filename,"rb")) == 0) { playing = 0; return; } fclose(f); gtk_text_buffer_get_start_iter(text1b, &start); gtk_text_buffer_get_end_iter(text1b, &end); gtk_text_buffer_delete(text1b, &start, &end); xmp_plugin_audio_error = FALSE; playing = 1; opt->resol = 8; opt->verbosity = 3; opt->drv_id = "callback"; switch (xmp_cfg.mixing_freq) { case 1: opt->freq = 22050; /* 1:2 mixing freq */ break; case 2: opt->freq = 11025; /* 1:4 mixing freq */ break; default: opt->freq = 44100; /* standard mixing freq */ break; } if (xmp_cfg.force8bit == 0) opt->resol = 16; if (xmp_cfg.force_mono == 0) { channelcnt = 2; opt->outfmt &= ~XMP_FMT_MONO; } else { opt->outfmt |= XMP_FMT_MONO; } if (xmp_cfg.interpolation == 1) opt->flags |= XMP_CTL_ITPT; else opt->flags &= ~XMP_CTL_ITPT; if (xmp_cfg.filter == 1) opt->flags |= XMP_CTL_FILTER; else opt->flags &= ~XMP_CTL_FILTER; opt->mix = xmp_cfg.pan_amplitude; fmt = opt->resol == 16 ? FMT_S16_NE : FMT_U8; nch = opt->outfmt & XMP_FMT_MONO ? 1 : 2; if (audio_open) xmp_ip.output->close_audio(); if (!xmp_ip.output->open_audio(fmt, opt->freq, nch)) { xmp_plugin_audio_error = TRUE; return; } audio_open = TRUE; xmp_open_audio(ctx); pipe(fd_info); fd_old2 = dup (fileno (stderr)); dup2(fd_info[1], fileno (stderr)); fflush(stderr); pthread_create(&catch_thread, NULL, catch_info, NULL); _D("*** loading: %s", filename); pthread_mutex_lock(&load_mutex); lret = xmp_load_module(ctx, filename); pthread_mutex_unlock(&load_mutex); if (lret < 0) { xmp_ip.set_info_text("Error loading mod"); playing = 0; return; } _D("joining catch thread"); pthread_join(catch_thread, NULL); _D("joined"); dup2(fileno(stderr), fd_old2); gtk_adjustment_set_value(GTK_TEXT_VIEW(text1)->vadjustment, 0.0); close(fd_info[0]); close(fd_info[1]); _D ("before panel update"); xmp_cfg.time = lret; //xmpi_scan_module((struct xmp_context *)ctx); xmp_get_module_info(ctx, &ii->mi); strcpy(ii->filename, ""); new_module = 1; _D("after panel update"); memcpy(&xmp_cfg.mod_info, &ii->mi, sizeof (ii->mi)); xmp_ip.set_info(ii->mi.name, lret, 0, opt->freq, channelcnt); pthread_create(&decode_thread, NULL, play_loop, NULL); }
static void play_file(InputPlayback *ipb) { char *filename = ipb->filename; int channelcnt = 1; FILE *f; struct xmp_options *opt; int lret; GtkTextIter start, end; opt = xmp_get_options(ctx); /* Sorry, no VFS support */ if (memcmp(filename, "file://", 7) == 0) /* Audacious 1.4.0 */ filename += 7; _D("play_file: %s", filename); stop(ipb); /* sanity check */ if ((f = fopen(filename,"rb")) == 0) { ipb->playing = 0; return; } fclose(f); gtk_text_buffer_get_start_iter(text1b, &start); gtk_text_buffer_get_end_iter(text1b, &end); gtk_text_buffer_delete(text1b, &start, &end); xmp_plugin_audio_error = FALSE; ipb->playing = 1; opt->resol = 8; opt->verbosity = 3; opt->drv_id = "callback"; switch (xmp_cfg.mixing_freq) { case 1: opt->freq = 22050; /* 1:2 mixing freq */ break; case 2: opt->freq = 11025; /* 1:4 mixing freq */ break; default: opt->freq = 44100; /* standard mixing freq */ break; } if (xmp_cfg.force8bit == 0) opt->resol = 16; if (xmp_cfg.force_mono == 0) { channelcnt = 2; opt->outfmt &= ~XMP_FMT_MONO; } else { opt->outfmt |= XMP_FMT_MONO; } if (xmp_cfg.interpolation == 1) opt->flags |= XMP_CTL_ITPT; else opt->flags &= ~XMP_CTL_ITPT; if (xmp_cfg.filter == 1) opt->flags |= XMP_CTL_FILTER; else opt->flags &= ~XMP_CTL_FILTER; opt->mix = xmp_cfg.pan_amplitude; play_data.ipb = ipb; play_data.fmt = opt->resol == 16 ? FMT_S16_NE : FMT_U8; play_data.nch = opt->outfmt & XMP_FMT_MONO ? 1 : 2; if (audio_open) ipb->output->close_audio(); if (!ipb->output->open_audio(play_data.fmt, opt->freq, play_data.nch)) { ipb->error = TRUE; xmp_plugin_audio_error = TRUE; return; } audio_open = TRUE; xmp_open_audio(ctx); pipe(fd_info); fd_old2 = dup (fileno (stderr)); dup2(fd_info[1], fileno (stderr)); fflush(stderr); catch_thread = g_thread_create(catch_info, NULL, TRUE, NULL); _D("*** loading: %s", filename); g_static_mutex_lock(&load_mutex); lret = xmp_load_module(ctx, filename); g_static_mutex_unlock(&load_mutex); if (lret < 0) { xmp_ip.set_info_text("Error loading mod"); ipb->playing = 0; return; } _D("joining catch thread"); g_thread_join(catch_thread); _D("joined"); dup2(fileno(stderr), fd_old2); gtk_adjustment_set_value(GTK_TEXT_VIEW(text1)->vadjustment, 0.0); close(fd_info[0]); close(fd_info[1]); _D ("before panel update"); xmp_cfg.time = lret; //xmpi_scan_module((struct xmp_context *)ctx); xmp_get_module_info(ctx, &ii->mi); strcpy(ii->filename, ""); new_module = 1; _D("after panel update"); memcpy(&xmp_cfg.mod_info, &ii->mi, sizeof (ii->mi)); #if __AUDACIOUS_PLUGIN_API__ >= 2 ipb->set_params(ipb, ii->mi.name, lret, 0, opt->freq, channelcnt); ipb->playing = 1; ipb->eof = 0; ipb->error = FALSE; decode_thread = g_thread_self(); ipb->set_pb_ready(ipb); play_loop(ipb); #else xmp_ip.set_info(ii->mi.name, lret, 0, opt->freq, channelcnt); decode_thread = g_thread_create(play_loop, ipb, TRUE, NULL); #endif }
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; }