bool NSFSoundStream::open(const std::string& fileName) { sf::Lock lock(mutex); if(!FileSystem::exists(fileName)) { return false; } int length = 0; auto fs = FileSystem::openFileRead(fileName); fs->seekg (0, std::ios::end); length = static_cast<int>(fs->tellg()); fs->seekg (0, std::ios::beg); std::unique_ptr<char[]> nsfFileBuffer(new char[length]); fs->read(nsfFileBuffer.get(), length); // To honor the contract of returning false on failure, // catch these exceptions and return false instead? Good/bad? try { gme_type_t file_type = gme_identify_extension(fileName.c_str()); if(!file_type) { return false; } for(std::size_t i = 0; i < samplerCount; ++i) { auto sampleEmu = std::shared_ptr<Music_Emu>(file_type->new_emu()); if(!sampleEmu) { return false; } // Must set sample rate before loading data handleError(sampleEmu->set_sample_rate(SAMPLE_RATE)); handleError(gme_load_data(sampleEmu.get(), nsfFileBuffer.get(), length)); sampleEmu->start_track(-1); sampleEmu->ignore_silence(false); auto sampleBuffer = std::make_shared<std::vector<short>>(masterBufferSize); std::fill(std::begin(*sampleBuffer), std::end(*sampleBuffer), 0); availableSamplers.push(std::make_pair(sampleEmu, sampleBuffer)); // sampleEmus.push_back(std::move(sampleEmu)); } trackInfo.reset(new track_info_t()); } catch(std::runtime_error& ex) { HIKARI_LOG(debug) << ex.what(); return false; } initialize(2, SAMPLE_RATE); //setCurrentTrack(0); return true; }
blargg_err_t Music_Emu::seek( int msec ) { int time = msec_to_samples( msec ); if ( time < track_filter.sample_count() ) { RETURN_ERR( start_track( current_track_ ) ); if ( fade_set ) set_fade( length_msec, fade_msec ); } return skip( time - track_filter.sample_count() ); }
void music_set_enabled(int newstate) { if (newstate != settings->music_enabled) { stat("music_set_enabled(%d)", newstate); settings->music_enabled = newstate; bool play = should_music_play(cursong, newstate); if (play != org_is_playing()) { if (play) start_track(cursong); else org_stop(); } } }
void music(int songno) { if (songno == cursong) return; lastsong = cursong; cursong = songno; stat(" >> music(%d)", songno); if (songno != 0 && !should_music_play(songno, settings->music_enabled)) { stat("Not playing track %d because music_enabled is %d", songno, settings->music_enabled); org_stop(); return; } start_track(songno); }
void music(int songno) { org_stop(); start_track(songno); }
// YEAHH!!! void BaseD::reload(char **paths/*=NULL*/, int numpaths/*=0*/) { char *path=NULL; bool using_playlist=false; if (!paths) { DEBUGLOG("A"); using_playlist=true; if (g_cfg.playlist[g_cur_entry]) path = g_cfg.playlist[g_cur_entry]; else path = NULL; } else { DEBUGLOG("B"); g_cur_entry = 0; g_cfg.playlist = paths; g_cfg.num_files = numpaths; path = g_cfg.playlist[g_cur_entry]; } //DEBUGLOG("path = %d\n", path); if (path == NULL) { //using_playlist = false; player->has_no_song = true; return; } DEBUGLOG("g_cfg.playlist = %lx\n", (uintptr_t)g_cfg.playlist); DEBUGLOG("g_cur_entry = %d", g_cur_entry); DEBUGLOG("g_cfg.playlist[g_cur_entry] = %s\n", g_cfg.playlist[g_cur_entry]); #ifdef _WIN32 g_real_filename = strrchr(path, '\\'); #else g_real_filename = strrchr(path, '/'); #endif if (!g_real_filename) { g_real_filename = path; } else { // skip path sep g_real_filename++; } //main_window->reload(); // Load file BaseD::path = path; handle_error( player->load_file( path ) ); IAPURAM = player->spc_emu()->ram(); //Memory::IAPURAM = IAPURAM; // report::memsurface.init report::memsurface.clear(); memset(report::used, 0, sizeof(report::used)); memset(report::used2, 0, sizeof(report::used2)); //if (!mouseover_hexdump_area.address)mouseover_hexdump_area.address =0; report::last_pc = -1; player->mute_voices(voice_control.muted); start_track( 1, path ); // voice_control.was_keyed_on = 0; player->ignore_silence(); // update Window Title long seconds = player->track_info().length / 1000; const char* game = player->track_info().game; if ( !*game ) { // extract filename game = strrchr( path, '\\' ); // DOS if ( !game ) game = strrchr( path, '/' ); // UNIX if ( !game ) game = path; else game++; // skip path separator } //main_window->is_onetime_draw_necessary=true; update_track_tag(); if (grand_mode == MAIN) main_window->draw_track_tag(); char title [512]; //if (using_playlist) //{ sprintf( title, "%s: %d/%d %s (%ld:%02ld)", game, g_cur_entry+1, g_cfg.num_files, player->track_info().song, seconds / 60, seconds % 60 ); /*} else { sprintf( title, "%s: %d/%d %s (%ld:%02ld)", game, 1, 1, player->track_info().song, seconds / 60, seconds % 60 ); }*/ SDL_SetWindowTitle(sdlWindow, title); }
int main( int argc, char** argv ) { init(); // Load file const char* path = (argc > 1 ? argv [argc - 1] : "test.nsf"); handle_error( player->load_file( path ) ); start_track( 1, path ); // Main loop int track = 1; double tempo = 1.0; bool running = true; double stereo_depth = 0.0; int muting_mask = 0; while ( running ) { SDL_Delay( 1000 / 100 ); // Update scope scope->draw( scope_buf, scope_width, 2 ); // Automatically go to next track when current one ends if ( player->track_ended() ) { if ( track < player->track_count() ) start_track( ++track, path ); else player->pause( paused = true ); } // Handle keyboard input SDL_Event e; while ( SDL_PollEvent( &e ) ) { switch ( e.type ) { case SDL_QUIT: running = false; break; case SDL_KEYDOWN: int key = e.key.keysym.sym; switch ( key ) { case SDLK_q: case SDLK_ESCAPE: // quit running = false; break; case SDLK_LEFT: // prev track if ( !paused && !--track ) track = 1; start_track( track, path ); break; case SDLK_RIGHT: // next track if ( track < player->track_count() ) start_track( ++track, path ); break; case SDLK_MINUS: // reduce tempo tempo -= 0.1; if ( tempo < 0.1 ) tempo = 0.1; player->set_tempo( tempo ); break; case SDLK_EQUALS: // increase tempo tempo += 0.1; if ( tempo > 2.0 ) tempo = 2.0; player->set_tempo( tempo ); break; case SDLK_SPACE: // toggle pause paused = !paused; player->pause( paused ); break; case SDLK_e: // toggle echo stereo_depth += 0.2; if ( stereo_depth > 0.5 ) stereo_depth = 0; player->set_stereo_depth( stereo_depth ); break; case SDLK_0: // reset tempo and muting tempo = 1.0; muting_mask = 0; player->set_tempo( tempo ); player->mute_voices( muting_mask ); break; default: if ( SDLK_1 <= key && key <= SDLK_9 ) // toggle muting { muting_mask ^= 1 << (key - SDLK_1); player->mute_voices( muting_mask ); } } } } } // Cleanup delete player; delete scope; return 0; }