#169773 - hacker013 - Mon Aug 03, 2009 11:22 am
Heey everybody,
I'm trying to get smf files working with nitro engine 6.0. So I changed to code so that it uses textures and libnds timers (and ripped out the palib stuff) but when I fade out to black (to start the movie), it stays black. Maybe see you guys what i'm doing wrong, here is my code:
UZSmf.h
UZSmf.c
I didn't start on the sound decoding yet so it just skips the sound part. I was thinking about using discostew wave streamer for that or just replace the sound from smf with ogg and use tremolo for it. But it would be great if you can help me find the bug ^^. Excuse me for the mess in my code :(
_________________
Website / Blog
Let the nds be with you.
I'm trying to get smf files working with nitro engine 6.0. So I changed to code so that it uses textures and libnds timers (and ripped out the palib stuff) but when I fade out to black (to start the movie), it stays black. Maybe see you guys what i'm doing wrong, here is my code:
UZSmf.h
Code: |
#ifdef UZ_USE_SMF #ifndef __UZ_SMF_H_ #define __UZ_SMF_H_ #include <UZMain.h> #include <stdio.h> #include <gba-jpeg-decode.h> void smfPlay(char * filename); void smfInit(); // for loading jpg... unsigned short screen_bitmap[49152]; NE_Material* texture; struct VIDEO_HEADER { short height; int framecount; int vidoffset; int taboffset; } vidhead; char * buffer; u32 frame_offset; u16 frame_count; u16 pixSize; char* pixBuf; u32 rawSize; // 22050/12 = 1/12 second of sound? u32 audio_offset; //was 58 u16 sndBufPointer; FILE* vidFile; //int zoom=256; //int zoom1=256; #endif #endif |
UZSmf.c
Code: |
#ifdef UZ_USE_SMF #include <UZSmf.h> void drawTexture() { NE_2DViewInit(); GFX_POLY_FORMAT = POLY_ALPHA(31) | POLY_ID(1) | NE_CULL_NONE; NE_2DDrawTexturedQuad(0,0,256,192,1,texture); } void decodeSound() { if(vidhead.framecount >= frame_count) { sndBufPointer++; if (sndBufPointer == 4) sndBufPointer = 0; audio_offset=(58+(float)1837.5*(frame_count+6)); // 1837.5 = 22050/12 audio_offset = audio_offset >>1 <<1; // must be even number for some reason. fseek (vidFile , audio_offset , SEEK_SET); fread(&buffer[sndBufPointer * rawSize],1,rawSize,vidFile); timerStart(0, ClockDivider_1024, 512, decodeSound); } } void decodeFrame() { if(vidhead.framecount >= frame_count) { fseek(vidFile , frame_offset, SEEK_SET); fread(&pixSize,2,1,vidFile); memset(pixBuf,0,16000); // 98304 fread(pixBuf, 1, pixSize, vidFile); frame_offset+=2+pixSize; memset(screen_bitmap,0,98304); // 98304 if(!JPEG_DecompressImage((u8*)pixBuf, &screen_bitmap[256*((192-vidhead.height)/2)+0], 256, 192)) { UZ_ERROR("Failed to decompres frame!"); } if(!NE_MaterialTexLoad(texture, GL_RGB, 256, 192, TEXGEN_TEXCOORD, &screen_bitmap)) { UZ_ERROR("Failed to load texture!"); } frame_count++; timerStart(1, ClockDivider_1024, 85, decodeFrame); } } void smfPlay(char * filename) { rawSize = 11500; // 22050/12 = 1/12 second of sound? audio_offset = 0; //was 58 sndBufPointer = 0; //frame_offset; frame_count=0; pixSize=0; pixBuf = (char*) malloc(16000); buffer = (char*) malloc(sizeof(char)*rawSize*4); if(pixBuf==NULL) { UZ_ERROR("Failed to allocate pixBuffer!"); } if(buffer==NULL) { UZ_ERROR("Failed to allocate buffer!"); } int frm_number[250]; // 250 frame numbers for progress bar int frm_offset[250]; // 250 locations for progress bar FILE* vidFile; vidFile = fopen (filename, "rb"); //rb = read if(vidFile==NULL) { char str[256]; sprintf(str, "Failed to open smf file: %s", filename); UZ_ERROR(str); } // read the file header fread(&vidhead.height,2,1,vidFile); // either 192 or 144 fread(&vidhead.framecount,4,1,vidFile); fread(&vidhead.vidoffset,4,1,vidFile); fread(&vidhead.taboffset,4,1,vidFile); // read the progress bar data fseek (vidFile , vidhead.taboffset , SEEK_SET); fread(&frm_offset[0],4,250,vidFile); fread(&frm_number[0],4,250,vidFile); frame_offset = vidhead.vidoffset; //Create texture texture = NE_MaterialCreate(); //Set Timers //timerStart(0, ClockDivider_1, 512, decodeSound); //timerStart(1, ClockDivider_1, 85, decodeFrame); decodeSound(); decodeFrame(); while(vidhead.framecount >= frame_count) { //Draw Screens UZ_Process(NULL, drawTexture); UZ_WaitForVBL(); } fclose(vidFile); NE_MaterialDelete(texture); free(pixBuf); free(buffer); //Disable Timer } void smfInit() { } #endif |
I didn't start on the sound decoding yet so it just skips the sound part. I was thinking about using discostew wave streamer for that or just replace the sound from smf with ogg and use tremolo for it. But it would be great if you can help me find the bug ^^. Excuse me for the mess in my code :(
_________________
Website / Blog
Let the nds be with you.