void OSPC_PlayBuffer(char *buff,int len,int release,int vol) { int i,j,pollcpt; char str[256]; SPC_ID666 *id; char *emulator[3]={"Unknown","Zsnes","Snes9x"}; uint8 *scr; OSPC_Init(); if (i=OSPC_LoadBuffer(buff,len)) { sprintf(str,"Error at SPC loading, code : %d",i); msgBoxLines(str,60); //gp32_pause(); //GpAppExit(); return; } OSPC_id=OSPC_GetID666(spc_data); OSPC_sound_fd = sceAudioChReserve( -1, 1024, 0 ); OSPC_exit=0; OSPC_volume=vol; OSPC_thread = sceKernelCreateThread( "OSPC Thread", (SceKernelThreadEntry)OSPC_PlayThread, 0x8, 256*1024, 0, 0 ); if (OSPC_thread<0) { msgBoxLines("Cannot create OSPC playback thread",60); } else { //init start time sceKernelLibcGettimeofday( &OSPC_start_time, 0 ); sceKernelStartThread( OSPC_thread, 0, 0 ); if (release) return; for (;;) { pgWaitV(); if (get_pad()) break; } OSPC_exit=1; sceKernelWaitThreadEnd( OSPC_thread, NULL ); sceKernelDeleteThread( OSPC_thread ); OSPC_thread=-1; } sceAudioChRelease( OSPC_sound_fd ); OSPC_Stop(); OSPC_Close(); if (OSPC_id) free(OSPC_id); }
static event_t * openspc_play(media_pipe_t *mp, AVIOContext *avio, char *errbuf, size_t errlen) { media_queue_t *mq = &mp->mp_audio; #error fa_fsize can return -1 .. deal with it size_t r, siz = fa_fsize(fh); uint8_t *buf = malloc(siz); media_buf_t *mb = NULL; event_t *e; int hold = 0, lost_focus = 0; int sample = 0; unsigned int duration = INT32_MAX; mp_set_playstatus_by_hold(mp, hold, NULL); mp->mp_audio.mq_stream = 0; fa_seek(fh, 0, SEEK_SET); r = fa_read(fh, buf, siz); fa_close(fh); if(r != siz) { free(buf); snprintf(errbuf, errlen, "openspc: Unable to read file"); return NULL; } if(OSPC_Init(buf, siz)) { free(buf); snprintf(errbuf, errlen, "openspc: Unable to initialize file"); return NULL; } if(!memcmp("v0.30", buf + 0x1c, 4) && buf[0x23] == 0x1a) { char str[4]; memcpy(str, buf + 0xa9, 3); str[3] = 0; duration = atoi(str) * 32000; } mp_set_play_caps(mp, MP_PLAY_CAPS_PAUSE); mp_become_primary(mp); while(1) { if(mb == NULL) { if(sample > duration) { while((e = mp_wait_for_empty_queues(mp, 0)) != NULL) { if(event_is_type(e, EVENT_PLAYQUEUE_JUMP) || event_is_action(e, ACTION_PREV_TRACK) || event_is_action(e, ACTION_NEXT_TRACK) || event_is_action(e, ACTION_STOP)) { mp_flush(mp, 0); break; } event_release(e); } if(e == NULL) e = event_create_type(EVENT_EOF); break; } mb = media_buf_alloc(); mb->mb_data_type = MB_AUDIO; mb->mb_size = sizeof(int16_t) * 2048 * 2; mb->mb_data = malloc(mb->mb_size); mb->mb_size = OSPC_Run(-1, mb->mb_data, mb->mb_size); mb->mb_channels = 2; mb->mb_rate = 32000; mb->mb_time = sample * 1000000LL / mb->mb_rate; sample += 2048; } if((e = mb_enqueue_with_events(mp, mq, mb)) == NULL) { mb = NULL; /* Enqueue succeeded */ continue; } if(event_is_type(e, EVENT_PLAYQUEUE_JUMP)) { mp_flush(mp, 0); break; } else if(event_is_action(e, ACTION_PLAYPAUSE) || event_is_action(e, ACTION_PLAY) || event_is_action(e, ACTION_PAUSE)) { hold = action_update_hold_by_event(hold, e); mp_send_cmd_head(mp, mq, hold ? MB_CTRL_PAUSE : MB_CTRL_PLAY); lost_focus = 0; mp_set_playstatus_by_hold(mp, hold, NULL); } else if(event_is_type(e, EVENT_MP_NO_LONGER_PRIMARY)) { hold = 1; lost_focus = 1; mp_send_cmd_head(mp, mq, MB_CTRL_PAUSE); mp_set_playstatus_by_hold(mp, hold, e->e_payload); } else if(event_is_type(e, EVENT_MP_IS_PRIMARY)) { if(lost_focus) { hold = 0; lost_focus = 0; mp_send_cmd_head(mp, mq, MB_CTRL_PLAY); mp_set_playstatus_by_hold(mp, hold, NULL); } } else if(event_is_type(e, EVENT_INTERNAL_PAUSE)) { hold = 1; lost_focus = 0; mp_send_cmd_head(mp, mq, MB_CTRL_PAUSE); mp_set_playstatus_by_hold(mp, hold, e->e_payload); } else if(event_is_action(e, ACTION_PREV_TRACK) || event_is_action(e, ACTION_NEXT_TRACK) || event_is_action(e, ACTION_STOP)) { mp_flush(mp, 0); break; } event_release(e); } free(buf); return e; }
static gboolean spc_setup (GstSpcDec * spc) { spc_tag_info *info; GstTagList *taglist; guint64 total_duration; if (!spc->buf || !spc_negotiate (spc)) { return FALSE; } info = &(spc->tag_info); spc_tag_get_info (GST_BUFFER_DATA (spc->buf), GST_BUFFER_SIZE (spc->buf), info); taglist = gst_tag_list_new (); if (info->title) gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_TITLE, info->title, NULL); if (info->artist) gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_ARTIST, info->artist, NULL); /* Prefer the name of the official soundtrack over the name of the game (since this is * how track numbers are derived) */ if (info->album) gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_ALBUM, info->album, NULL); else if (info->game) gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_ALBUM, info->game, NULL); if (info->year) { GDate *date = g_date_new_dmy (1, 1, info->year); gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_DATE, date, NULL); g_date_free (date); } if (info->track) { gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_TRACK_NUMBER, info->track, NULL); } if (info->comment) gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_COMMENT, info->comment, NULL); if (info->disc) gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_ALBUM_VOLUME_NUMBER, info->disc, NULL); if (info->publisher) gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_ORGANIZATION, info->publisher, NULL); if (info->dumper) gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_CONTACT, info->dumper, NULL); if (info->emulator) gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_ENCODER, info->emulator == EMU_ZSNES ? "ZSNES" : "Snes9x", NULL); total_duration = (guint64) (gst_spc_duration (spc) + gst_spc_fadeout (spc)); gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_DURATION, total_duration, GST_TAG_GENRE, "Game", GST_TAG_CODEC, "SPC700", NULL); gst_element_found_tags_for_pad (GST_ELEMENT (spc), spc->srcpad, taglist); /* spc_tag_info_free(&info); */ if (OSPC_Init (GST_BUFFER_DATA (spc->buf), GST_BUFFER_SIZE (spc->buf)) != 0) { return FALSE; } gst_pad_push_event (spc->srcpad, gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0)); gst_pad_start_task (spc->srcpad, (GstTaskFunction) spc_play, spc->srcpad); /* We can't unreference this buffer because we might need to re-initialize * the emulator with the original data during a reverse seek * gst_buffer_unref (spc->buf); * spc->buf = NULL; */ spc->initialized = TRUE; spc->seeking = FALSE; spc->seekpoint = 0; spc->byte_pos = 0; return spc->initialized; }
static void spc_play (GstPad * pad) { GstSpcDec *spc = GST_SPC_DEC (gst_pad_get_parent (pad)); GstFlowReturn flow_return; GstBuffer *out; gboolean seeking = spc->seeking; gint64 duration, fade, end, position; if (!seeking) { out = gst_buffer_new_and_alloc (1600 * 4); gst_buffer_set_caps (out, GST_PAD_CAPS (pad)); GST_BUFFER_TIMESTAMP (out) = (gint64) gst_util_uint64_scale ((guint64) spc->byte_pos, GST_SECOND, 32000 * 2 * 2); spc->byte_pos += OSPC_Run (-1, (short *) GST_BUFFER_DATA (out), 1600 * 4); } else { if (spc->seekpoint < spc->byte_pos) { OSPC_Init (GST_BUFFER_DATA (spc->buf), GST_BUFFER_SIZE (spc->buf)); spc->byte_pos = 0; } spc->byte_pos += OSPC_Run (-1, NULL, 1600 * 4); if (spc->byte_pos >= spc->seekpoint) { spc->seeking = FALSE; } out = gst_buffer_new (); gst_buffer_set_caps (out, GST_PAD_CAPS (pad)); } duration = gst_spc_duration (spc); fade = gst_spc_fadeout (spc); end = duration + fade; position = (gint64) gst_util_uint64_scale ((guint64) spc->byte_pos, GST_SECOND, 32000 * 2 * 2); if (position >= duration) { gint16 *data = (gint16 *) GST_BUFFER_DATA (out); guint32 size = GST_BUFFER_SIZE (out) / sizeof (gint16); unsigned int i; gint64 num = (fade - (position - duration)); for (i = 0; i < size; i++) { /* Apply a parabolic volume envelope */ data[i] = (gint16) (data[i] * num / fade * num / fade); } } if ((flow_return = gst_pad_push (spc->srcpad, out)) != GST_FLOW_OK) { GST_DEBUG_OBJECT (spc, "pausing task, reason %s", gst_flow_get_name (flow_return)); gst_pad_pause_task (pad); if (GST_FLOW_IS_FATAL (flow_return) || flow_return == GST_FLOW_NOT_LINKED) { gst_pad_push_event (pad, gst_event_new_eos ()); } } if (position >= end) { gst_pad_pause_task (pad); gst_pad_push_event (pad, gst_event_new_eos ()); } gst_object_unref (spc); return; }
int main(int argc, char *argv[]) { int optionoffset=0,audio_fd,channels=2,rformat,rchannels,format=AFMT_S16_LE,speed=32000,fd; char audio_device[]="/dev/dsp"; char ver[]="0.2"; char c; void *ptr,*buf; off_t size; if((argc<2)) { printf("\n[?] Usage: soap [sound device] SPC_FILE_NAME\n[?] Optional parameters are in brackets.\n[?] SOAP Version %s (2003) Steve B Melvin Jr\n\n",ver); exit(1); } if((argc>2)) { strcpy(audio_device,argv[1]); optionoffset++; } if((audio_fd=open(audio_device, O_WRONLY, 0)) ==-1) { printf("[-] Could not open, %s.\n", audio_device); exit(1); } printf("[+] Successfully opened, %s.\n",audio_device); rformat=format; if(ioctl(audio_fd, SNDCTL_DSP_SETFMT, &format) == -1) { printf("[-] Could not set sound format.\n"); exit(1); } if(format!=rformat) { printf("[-] Could not set sound format.\n"); exit(1); } printf("[+] Successfully set sound format.\n"); rchannels=channels; if(ioctl(audio_fd,SNDCTL_DSP_CHANNELS, &channels) == -1) { printf("[-] Could not set channels.\n"); exit(1); } if(channels!=rchannels) { printf("[-] Could not set channels.\n"); exit(1); } printf("[+] Successfully set channels.\n"); if(ioctl(audio_fd, SNDCTL_DSP_SPEED, &speed)==-1) { printf("[-] Could not set speed.\n"); exit(1); } printf("[+] Using speed, {%iHz}\n",speed); buf=malloc(32000); fd=open(argv[1+optionoffset],O_RDONLY); if(fd<0) { printf("[-] Could not open \'%s\'\n.",argv[1]); exit(1); } size=lseek(fd,0,SEEK_END); lseek(fd,0,SEEK_SET); ptr=malloc(size); read(fd,ptr,size); close(fd); fd=OSPC_Init(ptr,size); free(ptr); fcntl(STDIN_FILENO,F_SETFL,O_NONBLOCK); printf("[+] Playing SPC, press Enter to quit.\n"); while((read(STDIN_FILENO,&c,1))<=0) { size=OSPC_Run(-1,buf,32000); write(audio_fd,buf,size); } printf("\nGoodbye!\n"); return 0; }
void OSPC_Play(char *fname,int release,int vol) { u16 *menu_bg; u16 *dst,*src; int i,j,pollcpt; char str[256]; char *emulator[3]={"Unknown","Zsnes","Snes9x"}; uint8 *scr; OSPC_Init(); if (i=OSPC_Load(fname)) { sprintf(str,"Error at SPC loading, code : %d",i); msgBoxLines(str,60); //gp32_pause(); //GpAppExit(); return; } OSPC_id=OSPC_GetID666(spc_data); OSPC_sound_fd = sceAudioChReserve( -1, 1024, 0 ); OSPC_exit=0; OSPC_volume=vol; OSPC_thread = sceKernelCreateThread( "OSPC Thread", (SceKernelThreadEntry)OSPC_PlayThread, 0x8, 256*1024, 0, 0 ); if (OSPC_thread<0) { msgBoxLines("Cannot create OSPC playback thread",60); } else { //init start time scePowerSetClockFrequency(266,266,133); sceKernelLibcGettimeofday( &OSPC_start_time, 0 ); sceKernelStartThread( OSPC_thread, 0, 0 ); if (release) return; //init bg menu_bg=(u16*)malloc_64(480*272*2); dst=menu_bg; show_background(bg_img_mul,(os9x_lowbat?0x600000:0)); for (i=0;i<272;i++) { src = (u16*)pgGetVramAddr(0,i); memcpy(dst,src,480*2); dst+=480; } //init fx fx_init(); for (;;) { //show bg OSPC_show_bg(menu_bg); //show bg fx fx_main(pgGetVramAddr(0,0)); //batt infos show_batteryinfo(); //music info //draw frame pgDrawFrame(14,14,20+230+5+1,75+1,12|(12<<5)|(12<<10)); pgDrawFrame(13,13,20+230+5+2,75+2,30|(30<<5)|(30<<10)); pgDrawFrame(12,12,20+230+5+3,75+3,12|(12<<5)|(12<<10)); pgFillBoxHalfer(15,15,20+230+5,75); // if (strlen(OSPC_id->gametitle)) sprintf(str,"Game : %s",OSPC_id->gametitle); else sprintf(str,"Game : unknown"); mh_print(20,20,(char*)str,30|(30<<5)|(30<<10)); if (strlen(OSPC_id->songname)) sprintf(str,"Song : %s",OSPC_id->songname); else sprintf(str,"Song : unknown"); mh_print(20,30,(char*)str,30|(30<<5)|(30<<10)); if (strlen(OSPC_id->dumper)) sprintf(str,"Dumper : %s",OSPC_id->dumper); else sprintf(str,"Dumper : unknown"); mh_print(20,40,(char*)str,30|(30<<5)|(30<<10)); if (strlen(OSPC_id->comments)) sprintf(str,"Comments : %s",OSPC_id->comments); else sprintf(str,"Comments : unknown"); mh_print(20,50,(char*)str,30|(30<<5)|(30<<10)); if (strlen(OSPC_id->author)) sprintf(str,"Author : %s",OSPC_id->author); else sprintf(str,"Author : unknown"); mh_print(20,60,(char*)str,30|(30<<5)|(30<<10)); //time infos //draw frame //draw frame pgDrawFrame(14,94,20+65+5+1,116,8|(8<<5)|(16<<10)); pgDrawFrame(13,93,20+65+5+2,117,28|(28<<5)|(31<<10)); pgDrawFrame(12,92,20+65+5+3,118,8|(8<<5)|(16<<10)); pgFillBoxHalfer(15,95,20+65+5,115); sceKernelLibcGettimeofday( &OSPC_cur_time, 0 ); i=(OSPC_cur_time.tv_sec-OSPC_start_time.tv_sec)+(OSPC_cur_time.tv_usec-OSPC_start_time.tv_usec)/1000000; sprintf(str,"%2d%c%.2d / %2d:%.2d",i/60,((i&1)?':':' '),i%60,OSPC_id->playtime/60,OSPC_id->playtime%60); mh_print(20,100,(char*)str,(20)|(31<<5)|(18<<10)); if (get_pad()) break; pgScreenFlip(); } OSPC_exit=1; sceKernelWaitThreadEnd( OSPC_thread, NULL ); sceKernelDeleteThread( OSPC_thread ); OSPC_thread=-1; free(menu_bg); fx_close(); } sceAudioChRelease( OSPC_sound_fd ); OSPC_Stop(); OSPC_Close(); if (OSPC_id) free(OSPC_id); }