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 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 }