Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //main.c
- #include <stdio.h>
- #include "ds2io.h"
- #include "ds2_cpu.h"
- #include "ds2_malloc.h"
- #include "fs_api.h"
- #include "key.h"
- #include <math.h>
- #include "gba-jpeg-decode.h"
- //#include "wave.h"
- struct rtc Date;
- short * Audio_Buf_Addr = NULL;
- struct rtc Date;
- void load_jpg(void *jpeg, char width, char height) {
- JPEG_DecompressImage((u8*)jpeg, &((unsigned short*)down_screen_addr)[256*height+width], 256, 192);
- }
- FILE* vidFile;
- struct VIDEO_HEADER
- {
- int height;
- int framecount;
- int samplesize;
- } vidhead;
- int framecounter=0;
- void timerhandle(unsigned int arg)
- {
- // sti();
- // printf("T %d\n", GetSysTime());
- framecounter++;
- }
- /*==========================================
- Copies stereo and or mono data to the
- ds two io layer
- ===========================================*/
- void Transfer_Stream(void *data, char channels)
- {
- if(NULL != Audio_Buf_Addr && data != NULL)
- {
- short *src = (short*)data;
- short *dst0 = Audio_Buf_Addr;
- short *dst1 = Audio_Buf_Addr + audio_samples_per_trans;
- int n=0;
- while(n++ < audio_samples_per_trans)
- {
- switch(channels)
- {
- case 2://stereo
- *dst0++ = *src++;
- *dst1++ = *src++;
- break;
- case 1://mono
- *dst0++ = *src++;
- break;
- }
- }
- }
- }
- void play_smf(char * filename)
- {
- u16 frame_count=0;
- u16 pixSize=0;
- char* pixBuf = (char*) malloc(16000);
- int old_sec = 0;
- int fps=0;
- int framespeed = 10000 / 24;
- FILE* vidFile;
- vidFile = fopen (filename, "rb"); //rb = read
- pixBuf = (char*) malloc(16000);
- fread(&vidhead.height,4,1,vidFile);
- fread(&vidhead.framecount,4,1,vidFile);
- fread(&vidhead.samplesize,4,1,vidFile);
- //Interrupt period =1s
- initTimer(1, 100, timerhandle, 0);
- runTimer(1);
- // sound
- short* sndBuf = NULL;
- int sndptr = 0;
- short* ConvertBuf = (short*)calloc(audio_samples_per_trans, 4);
- short* FinalBuf =(short*)calloc(audio_samples_per_trans, 4);
- sndBuf = (short*)calloc(audio_samples_per_trans, 4);
- ds2_setVolume(127);
- unsigned short *audio_buffer_addr;
- int buffNum = 0;
- while(vidhead.framecount >= frame_count)
- {
- // replace the fread(audiobuf, 1, len, fp) from the wave example with this ?
- int i=0;
- for(i=0; i<audio_samples_per_trans*2; i++){
- FinalBuf[i] = sndBuf[i+(audio_samples_per_trans * 2 * buffNum)];
- }
- //
- Audio_Buf_Addr = (short*)ds2_getAudiobuff();
- Transfer_Stream(FinalBuf, 2);
- ds2_updateAudio();
- buffNum++;
- // when the whole sample has transfered, load next sample and video frame
- if(buffNum >= vidhead.samplesize / (audio_samples_per_trans*2)){
- buffNum=0;
- // if(framecounter >= framespeed){
- framecounter=0;
- fread(&pixSize,4,1,vidFile);
- fread(pixBuf, 1, pixSize, vidFile);
- fread(sndBuf,1,vidhead.samplesize,vidFile);
- load_jpg(pixBuf,256,(192-vidhead.height)>>1);
- frame_count++;
- fps++;
- ds2_flipScreen(DOWN_SCREEN, 1);
- ds2_getTime(&Date);
- if(Date.seconds != old_sec){
- printf("%d fps\n",fps);
- fps=0;
- old_sec=Date.seconds;
- }
- }//framecounter
- do {
- audio_buffer_addr = (unsigned short*)ds2_getAudiobuff();
- } while(NULL == audio_buffer_addr);
- }
- fclose (vidFile);
- }
- ////////////////////////////////////////////////////////////////////////////////
- void main(int argc, char* argv[])
- {
- ds2_setCPUclocklevel(6);
- play_smf("video.smf");
- while(1)
- {
- //ds2_flipScreen(DOWN_SCREEN, 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment