diff --git a/src/engine/filePlayer.cpp b/src/engine/filePlayer.cpp index dda2e9066..94e335dc6 100644 --- a/src/engine/filePlayer.cpp +++ b/src/engine/filePlayer.cpp @@ -23,11 +23,63 @@ #define DIV_FPCACHE_BLOCK_SIZE (1U<>DIV_FPCACHE_BLOCK_SHIFT; + size_t lastBlock=firstBlock+DIV_FPCACHE_BLOCKS_FROM_FILL; + if (lastBlock>=numBlocks) lastBlock=numBlocks-1; + + // don't read if we're after end of file + if (firstBlock>lastBlock) return; + + bool needToFill=false; + for (size_t i=firstBlock; i<=lastBlock; i++) { + if (!blocks[i]) { + needToFill=true; + firstBlock=blocks[i]; + break; + } + } + + if (!needToFill) return; + + // check whether we need to seek + sf_count_seek curSeek=sf_seek(sf,0,SEEK_CUR); + if (curSeek==-1) { + // I/O error + fileError=true; + return; + } + + + + // read blocks + for (size_t i=firstBlock; i<=lastBlock; i++) { + if (!blocks[i]) { + blocks[i]=new float[DIV_FPCACHE_BLOCK_SIZE*si.channels]; + memset(blocks[i],0, + } + sf_count_t totalRead=sf_readf_float(sf,blocks[i],DIV_FPCACHE_BLOCK_SIZE); + if (totalRead>DIV_FPCACHE_BLOCK_SHIFT; + blocks=new float*[numBlocks]; + memset(blocks,0,numBlocks*sizeof(void*)); + + playPos=0; + rateAccum=0; + fileError=false; + + // read the entire file if not seekable + if (!si.seekable) { + for (size_t i=0; i