Esempio n. 1
0
BBString * bmx_gme_open_file( MaxMusicEmu * emu, BBString * path, long sample_rate) {

	char *p = bbStringToCString( path );
	BBString * ret = bbStringFromCString(gme_open_file(p, &emu->emu, sample_rate));
	bbMemFree( p );
	
	return ret;
}
Esempio n. 2
0
int sound_add_from_gme(string filename, int track) {

	Music_Emu *emu;
	handle_error( gme_open_file(filename.c_str(), &emu, 44100) );
	if (!emu)
		return -1;

	handle_error( gme_start_track(emu, track - 1) );

	const int sid = enigma::sound_allocate();
	gme_callback *userdata = new gme_callback;
	userdata->emu = emu;
	userdata->track = track;

	return enigma::sound_add_from_stream(sid,(size_t (*)(void*, void*, size_t))callback,(void (*)(void*,float))seek,(void (*)(void*))cleanup,(void*)userdata)?-1:sid;
}
Esempio n. 3
0
blargg_err_t Music_Player::load_file( const char* path )
{
	stop();
	
	RETURN_ERR( gme_open_file( path, &emu_, sample_rate ) );
	
	char m3u_path [256 + 5];
	strncpy( m3u_path, path, 256 );
	m3u_path [256] = 0;
	char* p = strrchr( m3u_path, '.' );
	if ( !p )
		p = m3u_path + strlen( m3u_path );
	strcpy( p, ".m3u" );
	if ( emu_->load_m3u( m3u_path ) ) { } // ignore error
	
	return 0;
}
Esempio n. 4
0
/**
 * NOT USED
 */
void
Java_com_example_subtle_SoundMachine_convertToWave( JNIEnv* env, jobject callingObject, jstring fromPath, jstring toPath )
{
	/* Buffer Size */
	int buf_size = 1024; /* can be any multiple of 2 */

	/* Grab Paths */
	const char *from_path = (*env)->GetStringUTFChars(env, fromPath, 0);
	const char *to_path = (*env)->GetStringUTFChars(env, toPath, 0);

	/* Open music file in new emulator */
	Music_Emu* emu;
	handle_error( gme_open_file( from_path, &emu, SAMPLE_RATE ) );

	/* Get Track Info */
	gme_info_t* track_info = NULL;
	handle_error( gme_track_info( emu, &track_info, TRACK ) );

	/* Start track */
	handle_error( gme_start_track( emu, TRACK ) );

	/* Begin writing to wave file */
	wave_open( SAMPLE_RATE, to_path );
	wave_enable_stereo();

	/* Output to Wave */
	while ( gme_tell( emu ) < track_info->play_length )
	{
		/* Sample buffer */
		short buf [buf_size];

		/* Fill sample buffer */
		handle_error( gme_play( emu, buf_size, buf ) );

		/* Write samples to wave file */
		wave_write( buf, buf_size );
	}

	/* Cleanup */
	gme_free_info( track_info );
	(*env)->ReleaseStringUTFChars(env, fromPath, from_path);
	(*env)->ReleaseStringUTFChars(env, toPath, to_path);
	gme_delete( emu );
	wave_close();
}
Esempio n. 5
0
JNIEXPORT jlong JNICALL Java_com_ssb_droidsound_plugins_GMEPlugin_N_1loadFile(JNIEnv *env, jobject obj, jstring fname)
{
	jboolean iscopy;
	const char *s = env->GetStringUTFChars(fname, &iscopy);
	Music_Emu *emu = NULL;
	jlong rc = 0;
	gme_err_t err = gme_open_file(s, &emu, 44100);

	__android_log_print(ANDROID_LOG_VERBOSE, "GMEPlugin", "Loading from file '%s' => %s", s, err ? err : "OK");

	if(!err) {
		rc = setUp(emu);
	}
	env->ReleaseStringUTFChars(fname, s);

	return rc;

}
Esempio n. 6
0
blargg_err_t SFPlayer::Initialize(const char* filename, bool allow_overlapping, long samples)
{
	sample_rate = 44100;
	overlapping = allow_overlapping;

	RETURN_ERR(gme_open_file(filename, &emulator, sample_rate));

	sf::SoundStream::stop();
	int min_size = sample_rate * 2 / FILL_RATE;
	buffer_size = 512;
	while (buffer_size < min_size)
		buffer_size *= 2;
	this->samples = new sf::Int16[samples];

	initialize(2, sample_rate);

	return 0;
}
Esempio n. 7
0
File: basics.c Progetto: STJr/SRB2
int main(int argc, char *argv[])
{
	const char *filename = "test.nsf"; /* Default file to open */
	if ( argc >= 2 )
		filename = argv[1];

	long sample_rate = 44100; /* number of samples per second */
	/* index of track to play (0 = first) */
	int track = argc >= 3 ? atoi(argv[2]) : 0;
	
	/* Open music file in new emulator */
	Music_Emu* emu;
	handle_error( gme_open_file( filename, &emu, sample_rate ) );
	
	/* Start track */
	handle_error( gme_start_track( emu, track ) );
	
	/* Begin writing to wave file */
	wave_open( sample_rate, "out.wav" );
	wave_enable_stereo();
	
	/* Record 10 seconds of track */
	while ( gme_tell( emu ) < 10 * 1000L )
	{
		/* Sample buffer */
		#define buf_size 1024 /* can be any multiple of 2 */
		short buf [buf_size];
		
		/* Fill sample buffer */
		handle_error( gme_play( emu, buf_size, buf ) );
		
		/* Write samples to wave file */
		wave_write( buf, buf_size );
	}
	
	/* Cleanup */
	gme_delete( emu );
	wave_close();
	
	return 0;
}
Esempio n. 8
0
jint Java_de_illogical_modo_SpcDecoder_spcLoadFile(JNIEnv* env, jclass clazz, jstring path)
{	
	char cpath[1024];
	memset(cpath, 0, 1024);

	int clen = (*env)->GetStringLength(env, path);
	if (clen > 1023)
		return 0;
	(*env)->GetStringUTFRegion(env, path, 0, clen, cpath);

	gme_err_t err = gme_open_file(cpath, &emu, 44100);
	
	if (err != NULL)
	{
		emu = NULL;
	}
	else
	{
		gme_start_track(emu, 0);
	}
	
	return emu != NULL;
}
Esempio n. 9
0
void
Java_com_example_subtle_SoundMachine_fillBuffer( JNIEnv* env, jobject callingObject, jstring filePath, jshortArray bufferArray, jint myID )
{
	/* Grab File Path */
	const char *file_path = (*env)->GetStringUTFChars(env, filePath, 0);

	/* Get Class Information */
	jclass thisClass = (*env)->GetObjectClass(env, callingObject);

	/* Open music file in new emulator */
	Music_Emu* emu;
	handle_error( gme_open_file( file_path, &emu, SAMPLE_RATE ) );

	/* Get Track Info */
	gme_info_t* track_info = NULL;
	handle_error( gme_track_info( emu, &track_info, TRACK ) );

	/* Start track */
	handle_error( gme_start_track( emu, TRACK ) );

	/* Start Filling Buffer */
	jshort current_state = 0;
	jfieldID fid_playback_command = (*env)->GetFieldID(env, thisClass, "JNIPlaybackCommand", "I");
	jfieldID fid_active_thread = (*env)->GetFieldID(env, thisClass, "activeThreadID", "I");
	jfieldID fid_seek_to = (*env)->GetFieldID(env, thisClass, "seekTo", "I");
	jmethodID mid_write = (*env)->GetMethodID(env, thisClass, "fillBufferCallback", "(I)V");
	jsize buffer_size = (*env)->GetArrayLength( env, bufferArray );
	jshort *buffer_pointer;
	jint command;
	jint currentPosition;
	jint activeID;
	jint seekTo;
	while ( 1 )
	{
		/**
		 * Read Control Commands
		 */
		/* Get Control Command */
		command = (*env)->GetIntField(env, callingObject, fid_playback_command);

		/* Get Active Thread ID */
		activeID = (*env)->GetIntField(env, callingObject, fid_active_thread);

		/* Get Seek To */
		seekTo = (*env)->GetIntField(env, callingObject, fid_seek_to);

		/**
		 * Respond to Control Commands
		 */
		if ( activeID != myID || command == SIG_STOP ) { // stop or new track is now playing
			/* Exit */
			break;
		} else if (seekTo != SEEK_STATUS_NOT_SEEKING) {
			/* Seek */
			handle_error( gme_seek ( emu, seekTo ) );

			/* Report Seek */
			(*env)->CallVoidMethod(env, callingObject, mid_write, SEEK_STATUS_FINISHED_SEEKING);
		} else if ( command == SIG_PLAY ) {
			/* If We Finish, Kill Thread */
			if (gme_tell( emu ) >= track_info->play_length) {
				/* Write Buffer */
				(*env)->CallVoidMethod(env, callingObject, mid_write, track_info->play_length); // Finished Track

				/* Exit */
				break;
			}

			/* Get Java Buffer */
			buffer_pointer = (*env)->GetShortArrayElements( env, bufferArray, NULL );

			/* Fill sample buffer */
			handle_error( gme_play( emu, buffer_size, buffer_pointer ) );

			/* Release Java Buffer */
			(*env)->ReleaseShortArrayElements( env, bufferArray, buffer_pointer, 0 );

			/* Get Current Position */
			currentPosition = gme_tell( emu );

			/* Write Buffer */
			(*env)->CallVoidMethod(env, callingObject, mid_write, currentPosition);
		} else if ( command == SIG_PAUSE ) {
			/* Get Current Position */
			currentPosition = gme_tell( emu );

			/* Write Buffer */
			(*env)->CallVoidMethod(env, callingObject, mid_write, currentPosition);

			/* Sleep */
			sleep(.1);
		}
	}

	/* Cleanup */
	(*env)->ReleaseStringUTFChars(env, filePath, file_path);
	gme_free_info( track_info );
	gme_delete( emu );
}
Esempio n. 10
0
void
Java_com_example_subtle_SNESTrack_loadTrackInfo( JNIEnv* env, jobject callingObject, jstring filePath )
{
	/* Grab File Path */
	const char *file_path = (*env)->GetStringUTFChars(env, filePath, 0);

	/* Load Emulator */
	Music_Emu* emu;
	handle_error( gme_open_file( file_path, &emu, SAMPLE_RATE ) );

	/* Get Track Info */
	gme_info_t* track_info = NULL;
	handle_error( gme_track_info( emu, &track_info, TRACK ) );

	/* Get Class Information */
	jclass thisClass = (*env)->GetObjectClass(env, callingObject);

	/* Return Track Play Length */
	jfieldID fid_track_play_length = (*env)->GetFieldID(env, thisClass, "playLength", "I");
	(*env)->SetIntField(env, callingObject, fid_track_play_length, track_info->play_length);

	/* Return Track Length */
	jfieldID fid_track_length = (*env)->GetFieldID(env, thisClass, "length", "I");
	(*env)->SetIntField(env, callingObject, fid_track_length, track_info->length);

	/* Return Track Name */
	jfieldID fid_track_name = (*env)->GetFieldID(env, thisClass, "trackName", "Ljava/lang/String;");
	jstring track_name = (*env)->NewStringUTF(env, track_info->song);
	(*env)->SetObjectField(env, callingObject, fid_track_name, track_name);

	/* Return Game Name */
	jfieldID fid_game_name = (*env)->GetFieldID(env, thisClass, "gameName", "Ljava/lang/String;");
	jstring game_name = (*env)->NewStringUTF(env, track_info->game);
	(*env)->SetObjectField(env, callingObject, fid_game_name, game_name);

	/* Return System Name */
	jfieldID fid_system_name = (*env)->GetFieldID(env, thisClass, "systemName", "Ljava/lang/String;");
	jstring system_name = (*env)->NewStringUTF(env, track_info->system);
	(*env)->SetObjectField(env, callingObject, fid_system_name, system_name);

	/* Return Author Name */
	jfieldID fid_author_name = (*env)->GetFieldID(env, thisClass, "authorName", "Ljava/lang/String;");
	jstring author_name = (*env)->NewStringUTF(env, track_info->author);
	(*env)->SetObjectField(env, callingObject, fid_author_name, author_name);

	/* Return Copyright */
	jfieldID fid_copyright = (*env)->GetFieldID(env, thisClass, "copyright", "Ljava/lang/String;");
	jstring copyright = (*env)->NewStringUTF(env, track_info->copyright);
	(*env)->SetObjectField(env, callingObject, fid_copyright, copyright);

	/* Return Comment */
	jfieldID fid_comment = (*env)->GetFieldID(env, thisClass, "comment", "Ljava/lang/String;");
	jstring comment = (*env)->NewStringUTF(env, track_info->comment);
	(*env)->SetObjectField(env, callingObject, fid_comment, comment);

	/* Return Dumper */
	jfieldID fid_dumper = (*env)->GetFieldID(env, thisClass, "dumper", "Ljava/lang/String;");
	jstring dumper = (*env)->NewStringUTF(env, track_info->dumper);
	(*env)->SetObjectField(env, callingObject, fid_dumper, dumper);

	/* Cleanup */
	(*env)->ReleaseStringUTFChars(env, filePath, file_path);
	gme_free_info( track_info );
	gme_delete( emu );
}