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; }
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); }
static void config_ok(GtkWidget *widget, gpointer data) { ConfigFile *cfg; gchar *filename; struct xmp_options *opt; opt = xmp_get_options(ctx); if (GTK_TOGGLE_BUTTON(Res_16)->active) xmp_cfg.force8bit = 0; if (GTK_TOGGLE_BUTTON(Res_8)->active) xmp_cfg.force8bit = 1; if (GTK_TOGGLE_BUTTON(Chan_ST)->active) xmp_cfg.force_mono = 0; if (GTK_TOGGLE_BUTTON(Chan_MO)->active) xmp_cfg.force_mono = 1; if (GTK_TOGGLE_BUTTON(Sample_44)->active) xmp_cfg.mixing_freq = 0; if (GTK_TOGGLE_BUTTON(Sample_22)->active) xmp_cfg.mixing_freq = 1; if (GTK_TOGGLE_BUTTON(Sample_11)->active) xmp_cfg.mixing_freq = 2; xmp_cfg.interpolation = !!GTK_TOGGLE_BUTTON(Interp_Check)->active; xmp_cfg.filter = !!GTK_TOGGLE_BUTTON(Filter_Check)->active; xmp_cfg.convert8bit = !!GTK_TOGGLE_BUTTON(Convert_Check)->active; xmp_cfg.modrange = !!GTK_TOGGLE_BUTTON(Modrange_Check)->active; xmp_cfg.fixloops = !!GTK_TOGGLE_BUTTON(Fixloops_Check)->active; xmp_cfg.pan_amplitude = (guchar)GTK_ADJUSTMENT(pansep_adj)->value; opt->mix = xmp_cfg.pan_amplitude; filename = g_strconcat(g_get_home_dir(), CONFIG_FILE, NULL); cfg = xmms_cfg_open_file(filename); if (!cfg) cfg = xmms_cfg_new(); #define CFGWRITEINT(x) xmms_cfg_write_int (cfg, "XMP", #x, xmp_cfg.x) CFGWRITEINT (mixing_freq); CFGWRITEINT (force8bit); CFGWRITEINT (convert8bit); CFGWRITEINT (modrange); CFGWRITEINT (fixloops); CFGWRITEINT (force_mono); CFGWRITEINT (interpolation); CFGWRITEINT (filter); CFGWRITEINT (pan_amplitude); xmms_cfg_write_file(cfg, filename); xmms_cfg_free(cfg); g_free(filename); gtk_widget_destroy(xmp_conf_window); }
static void config_ok(GtkWidget *widget, gpointer data) { ConfigDb *cfg; struct xmp_options *opt; opt = xmp_get_options(ctx); if (GTK_TOGGLE_BUTTON(Res_16)->active) xmp_cfg.force8bit = 0; if (GTK_TOGGLE_BUTTON(Res_8)->active) xmp_cfg.force8bit = 1; if (GTK_TOGGLE_BUTTON(Chan_ST)->active) xmp_cfg.force_mono = 0; if (GTK_TOGGLE_BUTTON(Chan_MO)->active) xmp_cfg.force_mono = 1; if (GTK_TOGGLE_BUTTON(Sample_44)->active) xmp_cfg.mixing_freq = 0; if (GTK_TOGGLE_BUTTON(Sample_22)->active) xmp_cfg.mixing_freq = 1; if (GTK_TOGGLE_BUTTON(Sample_11)->active) xmp_cfg.mixing_freq = 2; xmp_cfg.interpolation = !!GTK_TOGGLE_BUTTON(Interp_Check)->active; xmp_cfg.filter = !!GTK_TOGGLE_BUTTON(Filter_Check)->active; xmp_cfg.convert8bit = !!GTK_TOGGLE_BUTTON(Convert_Check)->active; xmp_cfg.modrange = !!GTK_TOGGLE_BUTTON(Modrange_Check)->active; xmp_cfg.fixloops = !!GTK_TOGGLE_BUTTON(Fixloops_Check)->active; xmp_cfg.pan_amplitude = (guchar)GTK_ADJUSTMENT(pansep_adj)->value; opt->mix = xmp_cfg.pan_amplitude; cfg = bmp_cfg_db_open(); #define CFGWRITEINT(x) bmp_cfg_db_set_int (cfg, "XMP", #x, xmp_cfg.x) CFGWRITEINT (mixing_freq); CFGWRITEINT (force8bit); CFGWRITEINT (convert8bit); CFGWRITEINT (modrange); CFGWRITEINT (fixloops); CFGWRITEINT (force_mono); CFGWRITEINT (interpolation); CFGWRITEINT (filter); CFGWRITEINT (pan_amplitude); bmp_cfg_db_close(cfg); gtk_widget_destroy(xmp_conf_window); }
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; }
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 }