示例#1
0
文件: main.cpp 项目: notnotme/nwancat
// rulez nyan scene
int main(int argc, char **argv)
{
	bool nyaning = true;

	// self explain
	nyan();
	MP3Player_PlayBuffer(nyannyannyan_mp3, nyannyannyan_mp3_size, NULL);

	VIDEO_SetBlack(FALSE);
	while(nyaning)
	{
		u64 cticks = ticks_to_millisecs(gettime());
		// Loop the sound if ended
		if(!MP3Player_IsPlaying()) MP3Player_PlayBuffer(nyannyannyan_mp3, nyannyannyan_mp3_size, NULL);
		//Check wiimote input
		WPAD_ScanPads();
		u32 pressed = WPAD_ButtonsDown(0);
		if (pressed & WPAD_BUTTON_HOME) nyaning = false;
		// blackscreen until 3,8s like the youtube video (not extreme precison ;))
		if(cticks < startTime+3900) continue;
		// bkg frame counter (tick each 100ms)
		if(cticks > bkgTimeCounter+100)
		{
			bkgTimeCounter = cticks;
			currentBkgStep = (currentBkgStep+1) % BKG_STEP;
		}
		// nyan frame counter (tick each 60ms)
		if(cticks > nyanTimeCounter+60)
		{
			nyanTimeCounter = cticks;
			currentNyanStep = (currentNyanStep+1) % NYAN_STEP;
		}
		// Set the 2d matrix
		guMtxIdentity(GXmodelView2D);
		GX_LoadPosMtxImm(GXmodelView2D, GX_PNMTX0);

		// nyan
		f32 move =  delta % BKG_SIZE;
		f32 x = -move;
		while(x < rmode->fbWidth)
		{
			drawBkgSprite(x, currentBkgStep);
			x += BKG_SIZE;
		}

		// nyan nyan
		drawNyan(-5, 240 - ((NYAN_HEIGHT*8)/2), currentNyanStep);

		// Copy & switch fb
		GX_DrawDone();
		GX_CopyDisp(xfb[wichFb], GX_TRUE);
		VIDEO_SetNextFramebuffer(xfb[wichFb]);
		VIDEO_Flush();
		VIDEO_WaitVSync();
		wichFb ^= 1;
		delta += 8;
	}

	return 0;
}
示例#2
0
void Music_Loop()
{
	if (music_format != FORMAT_MP3) return;
	if (!music_f || MP3Player_IsPlaying()) return;
	//dbg_printf("Looping mp3\n");
	CFG.debug = 0;
	_Music_Stop();
	_Music_Start();
}
///<summary>
/// Plays the audio over and over again ad infinitium.
///</summary>	
void WiiAudioMp3::playLooped()
{
	ASSERT(myAudioBuffer != NULL);
	if(myAudioBuffer != NULL)
	{
		if(MP3Player_IsPlaying() == false)
		{			
			MP3Player_PlayBuffer(myAudioBuffer, myBufferSize, NULL);
		}
	}
}
示例#4
0
void _Music_Start()
{
	int ret;

	// always init SND, so banner sounds play if music disabled
	ASND_Init();
	ASND_Pause(0);

	if (CFG.music == 0) {
		dbg_printf(gt("Music: Disabled"));
		dbg_printf("\n");
		return;
	} else {
		dbg_printf(gt("Music: Enabled"));
		dbg_printf("\n");
	}
	
	was_playing = false;

	//get a music file
	ret = get_music_file();
	if (ret==0) return;

	if (music_format == FORMAT_MP3) {

		MP3Player_Init();
		MP3Player_Volume(0x80); // of 255
		//ret = MP3Player_PlayBuffer(music_buf, music_size, NULL);
		ret = MP3Player_PlayFile(music_f, mp3_reader, NULL);
		dbg_printf("mp3 play: %s (%d)\n", ret? gt("ERROR"):gt("OK"), ret);
		if (ret) goto err_play;
		usleep(10000); // wait 10ms and verify if playing
		if (!MP3Player_IsPlaying()) {
			err_play:
			printf(gt("Error playing %s"), music_fname);
			printf("\n");
			Music_Stop();
			sleep(1);
		}

	} else {

		music_buf = malloc(music_size);
		if (!music_buf) {
			printf(gt("music file too big (%d) %s"), music_size, music_fname);
			printf("\n");
			sleep(1);
			music_format = 0;
			return;
		}
		//printf("Loading...\n");
		ret = fread(music_buf, music_size, 1, music_f);
		//printf("size: %d %d\n", music_size, ret); sleep(2);
		fclose(music_f);
		music_f = NULL;
		if (ret != 1) {
			printf(gt("error reading: %s (%d)"), music_fname, music_size); printf("\n"); sleep(2);
			free(music_buf);
			music_buf = NULL;
			music_size = 0;
			music_format = 0;
			return;
		}
		MODPlay_Init(&mod);
		ret = MODPlay_SetMOD(&mod, music_buf);
		dbg_printf("mod play: %s (%d)\n", ret?gt("ERROR"):gt("OK"), ret);
		if (ret < 0 ) {
			Music_Stop();
		} else  {
			MODPlay_SetVolume(&mod, 32,32); // fix the volume to 32 (max 64)
			MODPlay_Start(&mod); // Play the MOD
		}
	}
}
示例#5
0
文件: mp3.c 项目: emukidid/swiss-gc
int play_mp3(file_handle *file, int numFiles, int curMP3) {
	int ret = PLAYER_NEXT;
	file->offset = 0;
	MP3Player_PlayFile(file, &mp3Reader, NULL);
	uiDrawObj_t* player = NULL;
	while(MP3Player_IsPlaying() || ret == PLAYER_PAUSE ) {
	
		u32 buttons = PAD_ButtonsHeld(0);
		if(buttons & PAD_BUTTON_B) {			// Stop
			while((PAD_ButtonsHeld(0) & PAD_BUTTON_B)){VIDEO_WaitVSync();};
			MP3Player_Stop();
			ret = PLAYER_STOP;
		}
		else if(buttons & PAD_BUTTON_START) {	// Pause
			while((PAD_ButtonsHeld(0) & PAD_BUTTON_START)){VIDEO_WaitVSync();};
			if(ret != PLAYER_PAUSE) {
				MP3Player_Stop();
				ret = PLAYER_PAUSE;
			}
			else {
				MP3Player_PlayFile(file, &mp3Reader, NULL);	// Unpause
				ret = PLAYER_NEXT;
			}
		}
		else if(buttons & PAD_BUTTON_X) {		// VOL+
			if(volume!=255) volume++;
			MP3Player_Volume(volume);
		}
		else if(buttons & PAD_BUTTON_Y) {		// VOL-
			if(volume!=0) volume--;
			MP3Player_Volume(volume);
		}
		else if(buttons & PAD_TRIGGER_R) {		// Next
			MP3Player_Stop();
			ret = PLAYER_NEXT;
		}
		else if(buttons & PAD_TRIGGER_L) {		// Previous
			MP3Player_Stop();
			ret = PLAYER_PREV;
		}
		else if(buttons & PAD_BUTTON_RIGHT) {		// Fwd
			MP3Player_Stop();
			if(file->offset+0x8000 < file->size) {
				file->offset += 0x8000;
				MP3Player_PlayFile(file, &mp3Reader, NULL);
			}
			else {
				ret = PLAYER_NEXT;
				break;
			}
		}
		else if(buttons & PAD_BUTTON_LEFT) {		// Rewind
			MP3Player_Stop();
			if(file->offset-0x10000 > 0) file->offset -= 0x10000;
			else file->offset = 0;
			MP3Player_PlayFile(file, &mp3Reader, NULL);
		}
		else if(buttons & PAD_TRIGGER_Z) {		// Toggle Shuffle
			while((PAD_ButtonsHeld(0) & PAD_TRIGGER_Z)){VIDEO_WaitVSync();};
			useShuffle ^=1;
		}
		uiDrawObj_t* display = updatescreen_mp3(file, ret, numFiles, curMP3);
		if(player != NULL) {
			DrawDispose(player);
		}
		DrawPublish(display);
		player = display;
		usleep(5000);
	}
	if(player != NULL)
		DrawDispose(player);
	return ret;
}
///<summary>
/// Returns true if the audio is currently being played, otherwise false...
///</summary>	
bool WiiAudioMp3::isPlaying()
{
	return MP3Player_IsPlaying();
}