static void gst_nsfdec_class_init (GstNsfDec * klass) { GObjectClass *gobject_class; gobject_class = (GObjectClass *) klass; parent_class = GST_ELEMENT_CLASS (g_type_class_peek_parent (klass)); gobject_class->finalize = gst_nsfdec_finalize; gobject_class->set_property = gst_nsfdec_set_property; gobject_class->get_property = gst_nsfdec_get_property; g_object_class_install_property (gobject_class, PROP_TUNE, g_param_spec_int ("tune", "tune", "tune", 1, 100, 1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (gobject_class, PROP_FILTER, g_param_spec_enum ("filter", "filter", "filter", GST_TYPE_NSF_FILTER, NSF_FILTER_NONE, G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS)); GST_DEBUG_CATEGORY_INIT (nsfdec_debug, "nsfdec", 0, "NES sound file (nsf) decoder"); nsf_init (); }
__declspec(dllexport) void* DLL_LoadNSF(const char* szFileName) { nsf_init(); log_init(); nsf_t* result = nsf_load(const_cast<char*>(szFileName),NULL,0); return result; }
/* Called when the plugin is loaded */ static void nosefart_init(void) { int r, frq; pdebug("nsf : nosefart plugin\n"); nsf_init(); memset(&app, 0 , sizeof(app)); play_thread = 0; }
int main(int argc, char *argv[]) { int i, j = 0; int create_flag = 0; const unsigned char *user = 0, *group = 0, *workdir = 0; int restart_flag = 0; char **argv_restart = 0; int pid; time_t server_start_time = 0; hr_set_symbolic_action_table(NEW_SRV_ACTION_LAST, ns_symbolic_action_table, ns_submit_button_labels, 0); time(&server_start_time); start_set_self_args(argc, argv); /* certain options should be removed for restart */ XCALLOC(argv_restart, argc + 2); argv_restart[j++] = argv[0]; params.program_name = argv[0]; for (i = 1; i < argc; ) { if (!strcmp(argv[i], "-D")) { params.daemon_mode_flag = 1; i++; } else if (!strcmp(argv[i], "-f")) { params.force_socket_flag = 1; argv_restart[j++] = argv[i]; i++; } else if (!strcmp(argv[i], "--create")) { create_flag = 1; i++; } else if (!strcmp(argv[i], "-u")) { if (++i >= argc) startup_error("invalid usage"); user = argv[i++]; } else if (!strcmp(argv[i], "-g")) { if (++i >= argc) startup_error("invalid usage"); group = argv[i++]; } else if (!strcmp(argv[i], "-C")) { if (++i >= argc) startup_error("invalid usage"); workdir = argv[i++]; } else if (!strcmp(argv[i], "-R")) { params.restart_mode_flag = 1; ++i; } else if (!strcmp(argv[i], "--")) { argv_restart[j++] = argv[i]; i++; break; } else if (argv[i][0] == '-') { startup_error("invalid option `%s'", argv[i]); } else break; } argv_restart[j++] = "-R"; if (i < argc) { argv_restart[j++] = argv[i]; ejudge_xml_path = argv[i++]; } if (i != argc) startup_error("invalid number of parameters"); argv_restart[j] = 0; start_set_args(argv_restart); if (!(pid = start_find_process("ej-contests", 0))) { params.force_socket_flag = 1; } else if (pid > 0) { fprintf(stderr, "%s: is already running as pid %d\n", argv[0], pid); return 1; } if (start_prepare(user, group, workdir) < 0) return 1; if (workdir && *workdir) { if (chdir(workdir) < 0) { err("cannot change directory to %s", workdir); return 1; } } #if defined EJUDGE_XML_PATH if (!ejudge_xml_path) ejudge_xml_path = EJUDGE_XML_PATH; #endif /* EJUDGE_XML_PATH */ if (!ejudge_xml_path) startup_error("configuration file is not specified"); ejudge_config = ejudge_cfg_parse(ejudge_xml_path, 0); if (!ejudge_config) return 1; if (contests_set_directory(ejudge_config->contests_dir) < 0) return 1; l10n_prepare(ejudge_config->l10n, ejudge_config->l10n_dir); if (!strcasecmp(EJUDGE_CHARSET, "UTF-8")) utf8_mode = 1; #if defined EJUDGE_NEW_SERVER_SOCKET if (!ejudge_config->new_server_socket) ejudge_config->new_server_socket = xstrdup(EJUDGE_NEW_SERVER_SOCKET); #endif if (!ejudge_config->new_server_socket) ejudge_config->new_server_socket=xstrdup(EJUDGE_NEW_SERVER_SOCKET_DEFAULT); #if defined EJUDGE_CONTESTS_HOME_DIR if (!ejudge_config->contests_home_dir) ejudge_config->contests_home_dir = xstrdup(EJUDGE_CONTESTS_HOME_DIR); #endif setup_log_file(); info("ej-contests %s, compiled %s", compile_version, compile_date); params.socket_path = ejudge_config->new_server_socket; params.log_path = ejudge_config->new_server_log; if (load_plugins() < 0) return 1; // initialize the default plugin if (nsdb_default->iface->open(nsdb_default->data) < 0) { startup_error("default plugin failed to open its connection"); return 1; } if (create_flag) { if (nsdb_default->iface->create(nsdb_default->data) < 0) { startup_error("database creation failed"); return 1; } if (nsdb_default->iface->close(nsdb_default->data) < 0) { startup_error("database closing failed"); return 1; } return 0; } if (nsdb_default->iface->check(nsdb_default->data) <= 0) { startup_error("default plugin failed to check its data"); return 1; } if (!(state = nsf_init(¶ms, 0, server_start_time))) return 1; if (nsf_prepare(state) < 0) return 1; nsf_main_loop(state); restart_flag = nsf_is_restart_requested(state); ns_unload_contests(); nsf_cleanup(state); nsdb_default->iface->close(nsdb_default->data); if (restart_flag) start_restart(); return 0; }
static void nsf_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { nsf_decoder_t *this = (nsf_decoder_t *) this_gen; audio_buffer_t *audio_buffer; if (buf->decoder_flags & BUF_FLAG_HEADER) { /* When the engine sends a BUF_FLAG_HEADER flag, it is time to initialize * the decoder. The buffer element type has 4 decoder_info fields, * 0..3. Field 1 is the sample rate. Field 2 is the bits/sample. Field * 3 is the number of channels. */ this->sample_rate = buf->decoder_info[1]; this->bits_per_sample = buf->decoder_info[2]; this->channels = buf->decoder_info[3]; /* take this opportunity to initialize stream/meta information */ this->stream->meta_info[XINE_META_INFO_AUDIOCODEC] = strdup("NES Music (Nosefart)"); this->song_number = buf->content[4]; /* allocate a buffer for the file */ this->nsf_size = BE_32(&buf->content[0]); this->nsf_file = xine_xmalloc(this->nsf_size); this->nsf_index = 0; /* peform any other required initialization */ this->last_pts = -1; this->iteration = 0; return; } /* accumulate chunks from the NSF file until whole file is received */ if (this->nsf_index < this->nsf_size) { xine_fast_memcpy(&this->nsf_file[this->nsf_index], buf->content, buf->size); this->nsf_index += buf->size; if (this->nsf_index == this->nsf_size) { /* file has been received, proceed to initialize engine */ nsf_init(); this->nsf = nsf_load(NULL, this->nsf_file, this->nsf_size); if (!this->nsf) { printf ("nsf: could not initialize NSF\n"); /* make the decoder return on every subsequent buffer */ this->nsf_index = 0; } this->nsf->current_song = this->song_number; nsf_playtrack(this->nsf, this->nsf->current_song, this->sample_rate, this->bits_per_sample, this->channels); } return; } /* if the audio output is not open yet, open the audio output */ if (!this->output_open) { this->output_open = this->stream->audio_out->open( this->stream->audio_out, this->stream, this->bits_per_sample, this->sample_rate, (this->channels == 2) ? AO_CAP_MODE_STEREO : AO_CAP_MODE_MONO); } /* if the audio still isn't open, do not go any further with the decode */ if (!this->output_open) return; /* check if a song change was requested */ if (buf->decoder_info[1]) { this->nsf->current_song = buf->decoder_info[1]; nsf_playtrack(this->nsf, this->nsf->current_song, this->sample_rate, this->bits_per_sample, this->channels); } /* time to decode a frame */ if (this->last_pts != -1) { /* process a frame */ nsf_frame(this->nsf); /* get an audio buffer */ audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); if (audio_buffer->mem_size == 0) { printf ("nsf: Help! Allocated audio buffer with nothing in it!\n"); return; } apu_process(audio_buffer->mem, this->sample_rate / this->nsf->playback_rate); audio_buffer->vpts = buf->pts; audio_buffer->num_frames = this->sample_rate / this->nsf->playback_rate; this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); } this->last_pts = buf->pts; }