int checkhang() { long ptr[4]; first_init=0; buffptr(ptr); #ifdef DEBUG fprintf(stderr,"first_buf=%lx ptr[0]=%lx\n",first_buf,ptr[0]); #endif if(ptr[0]-first_buf < 512) { #ifdef DEBUG fprintf(stderr,"init failed, trying again!\n"); fprintf(stderr,"first_buf=%lx ptr[0]=%lx\n",first_buf,ptr[0]); #endif Fseek(o_filepos,fd,0); filepos = o_filepos; init_replay(); return 1; } return 0; }
long calc_time() { long ptr[4]; if(buf_init) buffptr(ptr); else ptr[0]=(long)buffer_mem; return (bufferpos+ptr[0]-(long)buffer_mem)/(mp2info.bitrate/8); }
//wrapper to deal with advance sprintf formating options with automatic length finding //can't take strings by reference because of "va_start", so overload it with char * std::string fmt::FormatV(const char *fmt, va_list args) { size_t length = 256; std::string str; for (;;) { std::vector<char> buffptr(length); size_t printlen = vsnprintf(buffptr.data(), length, fmt, args); if (printlen < length) { str = std::string(buffptr.data(), printlen); break; } length *= 2; } return str; }
int replay_sample(FILE *fp, long f_size) { long f_left; SndBufPtr pointer; f_left = f_size; init_sound_system(); load_dsample(sound, fp, &f_left, sizeof(sound)/2); printf("\rPlayback sound\n"); buffoper(0x3); load_dsample(sound+sizeof(sound)/2, fp, &f_left, sizeof(sound)/2); buffptr(&pointer); while(pointer.play < sound+sizeof(sound)/2) buffptr(&pointer); while (f_left > 0) { buffptr(&pointer); while(pointer.play < sound+sizeof(sound)/2) buffptr(&pointer); printf("\r%lds ", (f_size-f_left)/(4*options.frequency)); fflush(stdout); load_dsample(sound, fp, &f_left, sizeof(sound)/2); buffptr(&pointer); while(pointer.play > sound+sizeof(sound)/2) buffptr(&pointer); printf("\r%lds ", (f_size-f_left)/(4*options.frequency)); fflush(stdout); load_dsample(sound+sizeof(sound)/2, fp, &f_left, sizeof(sound)/2); if (!f_left) { fseek(fp, 0, 0); f_left = filelength(fp); } } buffptr(&pointer); while(pointer.play < sound+sizeof(sound)/2 && !Bconstat(2)) buffptr(&pointer); load_dsample(sound, fp, &f_left, sizeof(sound)/2); buffoper(0x0); exit_sound_system(); return(0); }