Re: Re: Zinf Status?
Ed Sweetman <[email protected]> Fri, 25 Oct 2002 13:18:18 -0400
| Newsgroups | gmane.comp.audio.zinf.user |
|---|---|
| Message-ID | <[email protected]> |
Robert Kaye wrote: > On Fri, 2002-10-25 at 07:40, Ken Causey wrote: > >>I've been wondering how active this project is myself. >> >>http://sourceforge.net/project/stats/index.php?report=months&group_id=51494 >> >>is a little disheartening. CVS commits have been steadily dropping >>since June. > > > Then you better start writing some code, QUICK! > hahahaha here's a very early sneak preview of completely untested code that's far from finished. much more is still in my notebook. No more tests until next friday so i should be able to work on it a lot this weekend
input.h
(text/x-chdr, 477 B)
#ifndef __INPUT_H__
#define __INPUT_H__
#include "info.h"
#include "zinfstream.h"
class input {
public:
input(info *inf) : Info(inf) {;}
int openStream(string);
void *readStream(unsigned int) {return zStream.readData();
unsigned int getRead() const {return zStream.getRead();}
int closeStream();
~input() { Info->clearInput(); closeStream() }
private:
info *Info;
zinfStream zStream(Info);
};
#endif
zinfstream.cpp
(text/x-c++src, 2.5 KB)
#include "zinfstream.h"
#include <fstream>
#include <string>
bool zinfStream::setFilestream(std::string n)
{
ifstream dummy;
dummy.open(n.c_str(),ios::in);
if(!dummy) return(false); // Cannot read file
if(inputFile) closeFile(); // called before closeFile()
inputFile = dummy;
streamName = n;
prebufSize = atoi(Info->getPref("preBuffer").c_str());
readbufSize = atoi(Info->getPref("readBuffer").c_str());
preBuf = new char[prebufSize];
readBuf = new char[readbufSize];
prebufLeft = 0;
readbufLeft = 0;
return(true);
}
bool zinfStream::closeFile()
{
Info->clearFileinfo();
inputFile.clear();
inputFile.close();
if(inputFile.fail()) return(false); // Unable to close file
delete [] preBuf;
delete [] readBuf;
streamName = "";
return(true);
}
int zinfStream::fillPrebuf()
{
// if failed then we dont have any data left to read from file
if(!inputFile.fail()){
preBuf = memmove(preBuf, &preBuf[prebufSize - prebufLeft], prebufLeft);// move remaining down
inputFile.read(&preBuf[prebufLeft], prebufSize - prebufLeft); // add data to end of remaining
int size = inputFile.gcount(); // figure out how much data we actually read in
prebufLeft += size; // reflect how much data we actually read in
}
memset(preBuf[prebufLeft],' ',prebufLeft - prebufSize);
}
char *zinfStream::readFData(long int reqSize) const
{
if(reqSize > 0){
if(reqSize > readbufLeft)
reqSize = readbufLeft; // not enough readBuf left to fullfill request
if(prebufLeft < prebufSize)
fillPreBuf(); // prebuf is not full
readBuf = memmove(readBuf,&readBuf[bufRead],readbufLeft-bufRead); // move remaining down
readbufLeft -= bufRead; // reflect amount we last returned
memset(readBuf[readbufSize-bufRead],' ',bufRead);
// if following is false preBuf is empty and readBuf slowly drains away
if(prebufLeft > 0){
if(prebufLeft >= bufRead){
readBuf = memmove(readBuf[readbufSize - bufRead], preBuf, prebufLeft - bufRead);
prebufLeft -= bufRead; // reflect amount we just took from preBuf
readbufLeft += bufRead; // add what we took from preBuf
}
else{
readBuf = memmove(readBuf[readbufSize - bufRead], preBuf, prebufLeft);
prebufLeft =0; // not enough preBuf to replace what we read
readbufLeft += prebufLeft; // only add what was left in preBuf
}
fillPreBuf(); // try and fill preBuf
}
}
readBuf = reqSize; // Amount being read from readBuf is saved
return(readBuf);
}
zinfstream.h
(text/x-chdr, 856 B)
#ifndef __ZINFSTREAM_H__
#define __ZINFSTREAM_H__
#include "info.h"
class zinfStream {
public:
zinfStream(info *inf) : Info(inf), bufread(0), netbuf(NULL), readbuf(NULL),
inputfile(NULL), netstream("") {;}
bool setFilestream(std::string);
bool setNetstream(std::string);
char *readFData(long int) const;
char *readNData();
char *getData(long);
unsigned int getRead() const {return bufread;}
bool closeFile();
bool closeNet();
~zinfStream(){ Info->clearFileinfo(); closeFile();closeNet();}
private:
int fillPrebuf();
info *Info;
ifstream inputFile;
string streamName;
long int prebufLeft;
long int readbufLeft;
long int prebufSize;
long int readbufSize;
long int bufRead;
char *preBuf;
char *readBuf;
};
#endif