bool DsdiffFileReader::readChunk_DIIN(dsf2flac_uint64 chunkStart)
{
	// read the header so that we are certain we are in the correct place.
	dsf2flac_int8 ident[5];
	ident[4]='\0';
	dsf2flac_uint64 chunkSz;
	if (!readChunkHeader(ident,chunkStart,&chunkSz))
		return false;
	// check the ident
	if ( !checkIdent(ident,const_cast<dsf2flac_int8*>("DIIN")) ) {
		errorMsg = "dsdiffFileReader::readChunk_DIIN:chunk ident error";
		return false;
	}
	// read all sub chunks in the FRM8 chunk
	dsf2flac_uint64 subChunkStart = file.tellg();
	dsf2flac_uint64 subChunkSz;
	bool emidRead = false;
	while (subChunkStart < chunkStart + chunkSz) {
		// read the header
		if (!readChunkHeader(ident,subChunkStart,&subChunkSz))
			return false;
		// see if we know how to read this chunk
		if ( !emidRead && checkIdent(ident,const_cast<dsf2flac_int8*>("EMID")) ) {
			emidRead = readChunk_EMID(subChunkStart);
		} else if ( checkIdent(ident,const_cast<dsf2flac_int8*>("MARK")) ) {
			readChunk_MARK(subChunkStart);
		} else
			printf("WARNING: unknown chunk type: %s\n",ident);
		// move to the next chunk
		subChunkStart = subChunkStart + subChunkSz;
	}
	return true;
}
Beispiel #2
0
bool FliPlayer::decodeFrame() {
    FrameTypeChunkHeader frameHeader;
    ChunkHeader cHeader = readChunkHeader(fli_data_);
    do {
        switch (cHeader.type) {
        case 4:
            setPalette(fli_data_ + 6);
            g_System.setPalette8b3(palette_);
            break;
        case 7:
            decodeDeltaFLC(fli_data_ + 6);
            break;
        case 15:
            decodeByteRun(fli_data_ + 6);
            break;
        case FRAME_TYPE:
            frameHeader = readFrameTypeChunkHeader(cHeader, fli_data_);
            fli_info_.numFrames--;
            //printf("Frames Remaining: %d\n", fli_info_.numFrames);
            break;
        default:
            break;
        }

        if (cHeader.type != FRAME_TYPE)
            fli_data_ += cHeader.size;

        cHeader = readChunkHeader(fli_data_);

    } while (isValidChunk(cHeader.type) && cHeader.type != FRAME_TYPE);

    return isValidChunk(cHeader.type);

}
bool DsdiffFileReader::readChunk_CMPR(dsf2flac_uint64 chunkStart)
{
	// read the header so that we are certain we are in the correct place.
	dsf2flac_int8 ident[5];
	ident[4]='\0';
	if (!readChunkHeader(ident,chunkStart))
		return false;
	// check the ident
	if ( !checkIdent(ident,const_cast<dsf2flac_int8*>("CMPR")) ) {
		errorMsg = "dsdiffFileReader::readChunk_CMPR:chunk ident error";
		return false;
	}
	// type of compression
	compressionType[4] = '\0';
	if (file.read_int8(compressionType,4)) {
		errorMsg = "dsdiffFileReader::readChunk_CMPR:file read error";
		return false;
	}
	// read length of next entry
	dsf2flac_uint8 n;
	if (file.read_uint8(&n,1)) {
		errorMsg = "dsdiffFileReader::readChunk_CMPR:file read error";
		return false;
	}
	compressionName = new dsf2flac_int8[n+1];
	compressionName[n] = '\0';
	if (file.read_int8(compressionName,n)) {
		errorMsg = "dsdiffFileReader::readChunk_CMPR:file read error";
		return false;
	}
	return true;
}
bool DsdiffFileReader::readChunk_CHNL(dsf2flac_uint64 chunkStart)
{
	// read the header so that we are certain we are in the correct place.
	dsf2flac_int8 ident[5];
	ident[4]='\0';
	if (!readChunkHeader(ident,chunkStart))
		return false;
	// check the ident
	if ( !checkIdent(ident,const_cast<dsf2flac_int8*>("CHNL")) ) {
		errorMsg = "dsdiffFileReader::readChunk_CHNL:chunk ident error";
		return false;
	}
	// read number of channels
	if (file.read_uint16_rev(&chanNum,1)) {
		errorMsg = "dsdiffFileReader::readChunk_CHNL:file read error";
		return false;
	}
	// read channel identifiers
	chanIdents = new dsf2flac_int8*[chanNum];
	for (dsf2flac_uint16 i=0; i<chanNum; i++) {
		chanIdents[i] = new dsf2flac_int8[5];
		if (file.read_int8(chanIdents[i],4)) {
			errorMsg = "dsdiffFileReader::readChunk_CHNL:file read error";
			return false;
		};
		chanIdents[i][4] = '\0';
	}
	return true;
}
bool DsdiffFileReader::readChunk_ABSS(dsf2flac_uint64 chunkStart)
{
	// read the header so that we are certain we are in the correct place.
	dsf2flac_int8 ident[5];
	ident[4]='\0';
	if (!readChunkHeader(ident,chunkStart))
		return false;
	// check the ident
	if ( !checkIdent(ident,const_cast<dsf2flac_int8*>("ABSS")) ) {
		errorMsg = "dsdiffFileReader::readChunk_ABSS:chunk ident error";
		return false;
	}
	// hours
	if (file.read_uint16_rev(&ast.hours,1)) {
		errorMsg = "dsdiffFileReader::readChunk_ABSS:file read error";
		return false;
	}
	// mins
	if (file.read_uint8(&ast.minutes,1)) {
		errorMsg = "dsdiffFileReader::readChunk_ABSS:file read error";
		return false;
	}
	// secs
	if (file.read_uint8(&ast.seconds,1)) {
		errorMsg = "dsdiffFileReader::readChunk_ABSS:file read error";
		return false;
	}
	// samples
	if (file.read_uint32_rev(&ast.samples,1)) {
		errorMsg = "dsdiffFileReader::readChunk_ABSS:file read error";
		return false;
	}
	return true;
}
Beispiel #6
0
void Model3DS::parseMain()
{
	cout << "parseMain" << endl;
	DWord length = currentChunk.length;
	DWord n = cfg3ds::chunkHeaderSize;
	
	while (n < length)
	{
		readChunkHeader();
		n += currentChunk.length;
		switch (currentChunk.id)
		{
			case chunks::EDIT:
				parseEdit();
				break;
				
			case chunks::KEYFRAMER:
				parseKeyframer();
				break;
			
			default:
				skipChunk();
		}
	}
}
Beispiel #7
0
RecorderEvent PlaybackFile::getNextEvent() {
	assert(_mode == kRead);
	if (isEventsBufferEmpty()) {
		PlaybackFile::ChunkHeader header;
		header.id = kFormatIdTag;
		while (header.id != kEventTag) {
			if (!readChunkHeader(header) || _readStream->eos()) {
				break;
			}
			switch (header.id) {
			case kEventTag:
				readEventsToBuffer(header.len);
				break;
			case kScreenShotTag:
				_readStream->seek(-4, SEEK_CUR);
				header.len = _readStream->readUint32BE();
				_readStream->skip(header.len-8);
				break;
			case kMD5Tag:
				checkRecordedMD5();
				break;
			default:
				_readStream->skip(header.len);
				break;
			}
		}
	}
	RecorderEvent result;
	readEvent(result);
	return result;
}
bool DsdiffFileReader::readChunk_DSTI(dsf2flac_uint64 chunkStart)
{
	// read the header so that we are certain we are in the correct place.
	dsf2flac_int8 ident[5];
	ident[4]='\0';
	dsf2flac_uint64 chunkSz;
	if (!readChunkHeader(ident,chunkStart,&chunkSz))
		return false;
	// check the ident
	if ( !checkIdent(ident,const_cast<dsf2flac_int8*>("DSTI")) ) {
		errorMsg = "dsdiffFileReader::readChunk_DSTI:chunk ident error";
		return false;
	}
	dsf2flac_uint64 n = (chunkSz - 12)/(32+64);
	for (dsf2flac_uint64 i=0; i<n; i++) {
		DSTFrameIndex in;
		if (file.read_uint64_rev(&in.offset,1)) {
			errorMsg = "dsdiffFileReader::readChunk_DSTI:file read error";
			return false;
		}
		if (file.read_uint32_rev(&in.length,1)) {
			errorMsg = "dsdiffFileReader::readChunk_DSTI:file read error";
			return false;
		}
		dstFrameIndices.push_back(in);
	}
	return true;
}
Beispiel #9
0
void Model3DS::parseObject()
{
	cout << "parseObject" << endl;
	DWord length = currentChunk.length;
	
	Object *object = new Object(textures, currentSelectName++);
	
	DWord n = cfg3ds::chunkHeaderSize;
	n += readString(object->name);
	cout << "\tname: " << object->name << endl;
	
	while (n < length)
	{
		readChunkHeader();
		n += currentChunk.length;
		switch (currentChunk.id)
		{
			case chunks::OBJECT_MESH:
				parseMesh(object);
				break;
			
			default:
				skipChunk();
		}
	}
	
	for (int i=0; i<object->numVertices; ++i)
		object->normals[i].normalize();
	
	objects.push_back(object);
}
Beispiel #10
0
void Model3DS::parseTexmap(Material *material)
{
	cout << "parseTexmap" << endl;
	DWord length = currentChunk.length;
	DWord n = cfg3ds::chunkHeaderSize;
	
	while (n < length)
	{
		readChunkHeader();
		n += currentChunk.length;
		switch (currentChunk.id)
		{
			case chunks::TEXMAP_FILE:
			{
				readString(material->texmapFile);
				cout << material->texmapFile << endl;
				
				material->textureRef = numTextures++;
				
				break;
			}
			
			default:
				skipChunk();
		}
	}
}
void
OgreMeshReader::readGeometryVertexBuffer(UInt32              vertCount,
                                         VertexElementStore &vertexElements,
                                         BufferVertexMap    &bufferMap      )
{
    OSG_OGRE_LOG(("OgreMeshReader::readGeometryVertexBuffer\n"));

    UInt16 bindIdx  = readUInt16(_is);
#ifndef OSG_OGRE_SILENT
    UInt16 vertSize = 
#endif
        readUInt16(_is);

    OSG_OGRE_LOG(("OgreMeshReader::readGeometryVertexBuffer: "
                  "bindIdx '%d' vertSize '%d'\n", bindIdx, vertSize));

    readChunkHeader(_is);

    if(_header.chunkId == CHUNK_GEOMETRY_VERTEX_BUFFER_DATA)
    {
        readGeometryVertexBufferData(vertCount,      bindIdx,
                                     vertexElements, bufferMap);
    }
    else
    {
        skip(_is, -_chunkHeaderSize);
    }
}
void
OgreMeshReader::readSubMeshNameTable(SubMeshStore &subMeshInfo)
{
    OSG_OGRE_LOG(("OgreMeshReader::readSubMeshNameTable\n"));

    bool stop = false;

    while(_is)
    {
        readChunkHeader(_is);

        switch(_header.chunkId)
        {
        case CHUNK_SUBMESH_NAME_TABLE_ELEMENT:
            readSubMeshNameTableElement(subMeshInfo);
            break;

        default:
            OSG_OGRE_LOG(("OgreMeshReader::readSubMeshNameTable: Unknown chunkId '0x%x'\n",
                          _header.chunkId));
            stop = true;
            break;
        }

        if(stop == true)
        {
            skip(_is, -_chunkHeaderSize);
            break;
        }
    }
}
Beispiel #13
0
void Model3DS::parseColor(Color &color)
{
	cout << "parseColor" << endl;
	DWord length = currentChunk.length;
	DWord n = cfg3ds::chunkHeaderSize; 
	
	while (n < length)
	{
		readChunkHeader();
		n += currentChunk.length;
		switch (currentChunk.id)
		{
			case chunks::COLOR_FLOAT:
			case chunks::COLOR_FLOATG:
				fread(&color, sizeof(float), 3, fp);
				break;
			
			case chunks::COLOR_BYTE:
			case chunks::COLOR_BYTEG:
				Byte r, g, b;
				read(r);
				read(g);
				read(b);
				
				color.r = r/255.0;
				color.g = g/255.0;
				color.b = b/255.0;
				break;
			
			default:
				skipChunk();
		}
	}
}
void
OgreMeshReader::readGeometryVertexDeclaration(VertexElementStore &vertexElements,
                                              BufferVertexMap    &bufferMap      )
{
    OSG_OGRE_LOG(("OgreMeshReader::readGeometryVertexDeclaration\n"));

    bool stop = false;

    while(_is)
    {
        readChunkHeader(_is);

        switch(_header.chunkId)
        {
        case CHUNK_GEOMETRY_VERTEX_ELEMENT:
            readGeometryVertexElement(vertexElements, bufferMap);
            break;

        default:
            OSG_OGRE_LOG(("OgreMeshReader::readGeometryVertexDeclaration: Unknown chunkId '0x%x'\n",
                          _header.chunkId));
            stop = true;
            break;
        }

        if(stop == true)
        {
            skip(_is, -_chunkHeaderSize);
            break;
        }
    }
}
bool DsdiffFileReader::readHeaders()
{
	// look for the FRM8 chunk (probably at the start of the data).
	dsf2flac_int8 ident[5];
	ident[4]='\0';
	dsf2flac_uint64 chunkStart;
	dsf2flac_uint64 chunkSz;
	bool frm8read = false;
	bool frm8valid = false;
	// assum first chunk is at the start of the file.
	chunkStart = 0;
	// stop once one frm8 chunk is read
	while (!frm8read) {
		// read the chunk header
		if (!readChunkHeader(ident,chunkStart,&chunkSz))
			return false;
		// did we find a FRM8 chunk??
		if ( checkIdent(ident,const_cast<dsf2flac_int8*>("FRM8")) ) {
			frm8valid = readChunk_FRM8(chunkStart);
			frm8read = true;
		}
		// otherwise, move to the next chunk
		chunkStart +=chunkSz;
	}
	return frm8valid;
}
Beispiel #16
0
bool PlaybackFile::processSettingsRecord() {
	ChunkHeader keyChunk;
	if (!readChunkHeader(keyChunk) || (keyChunk.id != kSettingsRecordKeyTag)) {
		warning("Invalid format of settings section");
		return false;
	}
	String key = readString(keyChunk.len);
	ChunkHeader valueChunk;
	if (!readChunkHeader(valueChunk) || (valueChunk.id != kSettingsRecordValueTag)) {
		warning("Invalid format of settings section");
		return false;
	}
	String value = readString(valueChunk.len);
	_header.settingsRecords[key] = value;
	return true;
}
// ---------------------------------------------------------------------------
//	readContainer
// ---------------------------------------------------------------------------
//
static void
readContainer( std::istream & s )
{
	ContainerCk ck;		
	try 
	{
		//	read chunk header:
		readChunkHeader( s, ck.header );
		if( ck.header.id != ContainerId )
			Throw( FileIOException, "Found no Container chunk." );
		
		//	read FORM type
		BigEndian::read( s, 1, sizeof(ID), (char *)&ck.formType );		
	}
	catch( FileIOException & ex ) 
	{
		ex.append( "Failed to read badly-formatted Lemur file (bad Container chunk)." );
		throw;
	}

	//	make sure its really a Dr. Lemur file:
	if ( ck.formType != LEMR_ID ) 
	{
		Throw( ImportException, "File is not formatted correctly for Lemur 5 import." );
	}
}
bool DsdiffFileReader::readChunk_FRTE(dsf2flac_uint64 chunkStart)
{
	// read the header so that we are certain we are in the correct place.
	dsf2flac_int8 ident[5];
	ident[4]='\0';
	dsf2flac_uint64 chunkSz;
	if (!readChunkHeader(ident,chunkStart,&chunkSz))
		return false;
	// check the ident
	if ( !checkIdent(ident,const_cast<dsf2flac_int8*>("FRTE")) ) {
		errorMsg = "dsdiffFileReader::readChunk_FRTE:chunk ident error";
		return false;
	}
	if (file.read_uint32_rev(&dstInfo.numFrames,1)) {
		errorMsg = "dsdiffFileReader::readChunk_FRTE:file read error";
		return false;
	}
	if (file.read_uint16_rev(&dstInfo.frameRate,1)) {
		errorMsg = "dsdiffFileReader::readChunk_FRTE:file read error";
		return false;
	}
	dstInfo.frameSizeInSamplesPerChan = getSamplingFreq()/dstInfo.frameRate;
	dstInfo.frameSizeInBytesPerChan = dstInfo.frameSizeInSamplesPerChan/samplesPerChar;
	return true;
}
bool DsdiffFileReader::readChunk_DSTF(dsf2flac_uint64 chunkStart)
{
	// read the header so that we are certain we are in the correct place.
	dsf2flac_int8 ident[5];
	ident[4]='\0';
	dsf2flac_uint64 chunkLen;
	if (!readChunkHeader(ident,chunkStart,&chunkLen))
		return false;
	// check the ident
	if ( !checkIdent(ident,const_cast<dsf2flac_int8*>("DSTF")) ) {
		errorMsg = "dsdiffFileReader::readChunk_DSTF:chunk ident error";
		return false;
	}
	dsf2flac_uint64 dst_framesize = chunkLen-12;
	dsf2flac_uint8* dst_data = new dsf2flac_uint8[dst_framesize];
	if (file.read_uint8_rev(dst_data,dst_framesize)) {
		errorMsg = "dsdiffFileReader::readChunk_DSTF:file read error";
		return false;
	}
	
	if (DST_FramDSTDecode(dst_data, sampleBuffer,dst_framesize, dstInfo.numFrames, &dstEbunch))
		return false;
	
	return true;
}
Beispiel #20
0
void Model3DS::parseMesh(Object *object)
{
	cout << "parseMesh" << endl;
	DWord length = currentChunk.length;
	DWord n = cfg3ds::chunkHeaderSize;
	
	while (n < length)
	{
		readChunkHeader();
		n += currentChunk.length;
		switch (currentChunk.id)
		{
			case chunks::MESH_VERTICES:
				read(object->numVertices);
				object->vertices = new Vertex[object->numVertices];
				object->normals = new Vector[object->numVertices];
				memset(object->normals, 0, sizeof(Vector)*object->numVertices);
				
				for (int i=0; i<object->numVertices; ++i) {
					read(object->vertices[i].x);
					read(object->vertices[i].y);
					read(object->vertices[i].z);
				}
				break;
				
			case chunks::MESH_FACES:
				parseFaces(object);
				break;
				
			case chunks::MESH_MAPCOORDS:
				Word numEntries;
				read(numEntries);
				
				object->mapCoords = new MapCoord[numEntries];
				
				for (int i=0; i<numEntries; ++i) {
					read(object->mapCoords[i].u);
					read(object->mapCoords[i].v);
				}
				
				break;
				
			case chunks::MESH_LOCALCOORDS:
				read(object->u);
				read(object->v);
				read(object->w);
				read(object->origin);
				
				object->u.normalize();
				object->v.normalize();
				object->w.normalize();
				
				break;
				
			default:
				skipChunk();
		}
	}
}
Beispiel #21
0
bool PlaybackFile::parseHeader() {
	PlaybackFileHeader result;
	ChunkHeader nextChunk;
	_playbackParseState = kFileStateCheckFormat;
	if (!readChunkHeader(nextChunk)) {
		_playbackParseState = kFileStateError;
		return false;
	}
	while ((_playbackParseState != kFileStateDone) && (_playbackParseState != kFileStateError)) {
		if (processChunk(nextChunk)) {
			if (!readChunkHeader(nextChunk)) {
				warning("Error in header parsing");
				_playbackParseState = kFileStateError;
			}
		}
	}
	return _playbackParseState == kFileStateDone;
}
Beispiel #22
0
void Model3DS::parse()
{
	readChunkHeader();
	
	if (currentChunk.id == chunks::MAIN)
		parseMain();
	else
		exit(1);
}
bool DsdiffFileReader::readChunk_DST(dsf2flac_uint64 chunkStart)
{
	// read the header so that we are certain we are in the correct place.
	dsf2flac_int8 ident[5];
	ident[4]='\0';
	dsf2flac_uint64 chunkSz;
	if (!readChunkHeader(ident,chunkStart,&chunkSz))
		return false;
	// check the ident
	if ( !checkIdent(ident,const_cast<dsf2flac_int8*>("DST ")) ) {
		errorMsg = "dsdiffFileReader::readChunk_DST:chunk ident error";
		return false;
	}
	// record the end of the chunk
	dstChunkEnd = chunkStart + chunkSz -1;
	// read all sub chunks in the DST chunk
	dsf2flac_uint64 subChunkStart = file.tellg();
	dsf2flac_uint64 subChunkSz;
	bool found_frte = false;
	bool found_dstf = false;
	//
	while (!(found_frte && found_dstf) && subChunkStart < chunkStart + chunkSz) {
		// read the header
		if (!readChunkHeader(ident,subChunkStart,&subChunkSz))
			return false;
		// see if we know how to read this chunk
		if ( !found_frte && checkIdent(ident,const_cast<dsf2flac_int8*>("FRTE")) ) {
			found_frte = readChunk_FRTE(subChunkStart);
		} else if ( !found_dstf && checkIdent(ident,const_cast<dsf2flac_int8*>("DSTF")) ) {
			found_dstf = true;
			sampleDataPointer = subChunkStart;
		} else
			printf("WARNING: unknown chunk type: %s\n",ident);
		// move to the next chunk
		subChunkStart = subChunkStart + subChunkSz;
	}
	if (found_frte) {
		sampleCountPerChan = (dsf2flac_uint64)dstInfo.numFrames * (dsf2flac_uint64)dstInfo.frameSizeInSamplesPerChan;
		sampleBufferLenPerChan = dstInfo.frameSizeInBytesPerChan;
	}
	return found_frte && found_dstf;
}
Beispiel #24
0
bool PlaybackFile::readSaveRecord() {
	ChunkHeader fileNameChunk;
	if (!readChunkHeader(fileNameChunk) || (fileNameChunk.id != kSaveRecordNameTag)) {
		warning("Invalid format of save section");
		return false;
	}
	String fileName = readString(fileNameChunk.len);
	ChunkHeader saveBufferChunk;
	if (!readChunkHeader(saveBufferChunk) || (saveBufferChunk.id != kSaveRecordBufferTag)) {
		warning("Invalid format of save section");
		return false;
	}
	SaveFileBuffer buf;
	buf.size = saveBufferChunk.len;
	buf.buffer = (byte *)malloc(saveBufferChunk.len);
	_readStream->read(buf.buffer, buf.size);
	_header.saveFiles[fileName] = buf;
	debugC(1, kDebugLevelEventRec, "playback:action=\"Load save file\" filename=%s len=%d", fileName.c_str(), buf.size);
	return true;
}
// ---------------------------------------------------------------------------
//	importPartials
// ---------------------------------------------------------------------------
//	Clients should be prepared to catch ImportExceptions.
//
//	THIS WON'T WORK IF CHUNKS ARE IN A DIFFERENT ORDER!!!
//	Fortunately, they never will be, since only the research 
//	version of Lemur ever wrote these files anyway.
//
static void
importPartials( std::istream & s, PartialList & partials, double bweCutoff )
{
	try 
	{
		//	the Container chunk must be first, read it:
		readContainer( s );
		
		//	read other chunks:
		bool foundParams = false, foundTracks = false;
		while ( ! foundParams || ! foundTracks )
		{
			//	read a chunk header, if it isn't the one we want, skip over it.
			CkHeader h;
			readChunkHeader( s, h );
			
			if ( h.id == AnalysisParamsID )
			{
				readParamsChunk( s );
				foundParams = true;
			}
			else if ( h.id == TrackDataID )
			{
				if (! foundParams) 	//	 I hope this doesn't happen
				{
					Throw( ImportException, 
							"Mia culpa! I am not smart enough to read the Track data before the Analysis Parameters data." );
				}							
				//	read Partials:
				for ( long counter = readTracksChunk( s ); counter > 0; --counter ) 
				{
					getPartial(s, partials, bweCutoff);
				}
				foundTracks = true;
			}
			else
			{
				s.ignore( h.size );
			}
		}

	}
	catch ( Exception & ex ) 
	{
		if ( s.eof() )
		{
			ex.append("Reached end of file before finding both a Tracks chunk and a Parameters chunk.");
		}
		ex.append( "Import failed." );
		Throw( ImportException, ex.str() );
	}

}
Beispiel #26
0
HTTP_RESULT HttpTcpConnection::chunkedRecv(char * buffer, size_t & bufsiz)
{
    HTTP_RESULT res = HTTP_OK;
    // Read the chunked header
    // <size in hex> <chunk ext>\r\n
    //<data... upto size>\r\n
    // 0\r\n
    // \r\n
    unsigned int totalrecv = 0;
    int n;

    do {

        n = readChunkHeader();
        if (n < 0)
            return HTTP_RECV_ERROR;

        if (n == 0) // terminate chunk
        {
            // Read the training \r\n
            bufsiz = totalrecv;

            consumeLine();
            return res;
        }

        // terminate if we don't have enough
        // buffer to hold the data
        if ((totalrecv + n) > bufsiz)
        {
            bufsiz = totalrecv;
            return HTTP_RECV_BUFF_ERROR;
        }

        res = receive(buffer + totalrecv, (size_t &) n);
        if (res != HTTP_OK)
        {
            bufsiz = totalrecv + n;
            return res;
        }

        totalrecv += n;

    }while(totalrecv < bufsiz);

    return res;
}
bool DsdiffFileReader::readChunk_LSCO(dsf2flac_uint64 chunkStart)
{
	// read the header so that we are certain we are in the correct place.
	dsf2flac_int8 ident[5];
	ident[4]='\0';
	if (!readChunkHeader(ident,chunkStart))
		return false;
	// check the ident
	if ( !checkIdent(ident,const_cast<dsf2flac_int8*>("LSCO")) ) {
		errorMsg = "dsdiffFileReader::readChunk_LSCO:chunk ident error";
		return false;
	}
	if (file.read_uint16(&lsConfig,1)) {
		errorMsg = "dsdiffFileReader::readChunk_LSCO:file read error";
		return false;
	}
	return true;
}
bool DsdiffFileReader::readChunk_FS(dsf2flac_uint64 chunkStart)
{
	// read the header so that we are certain we are in the correct place.
	dsf2flac_int8 ident[5];
	ident[4]='\0';
	if (!readChunkHeader(ident,chunkStart))
		return false;
	// check the ident
	if ( !checkIdent(ident,const_cast<dsf2flac_int8*>("FS  ")) ) {
		errorMsg = "dsdiffFileReader::readChunk_FS:chunk ident error";
		return false;
	}
	if (file.read_uint32_rev(&samplingFreq,1)) {
		errorMsg = "dsdiffFileReader::readChunk_FS:File read error";
		return false;
	}
	return true;
}
bool DsdiffFileReader::readChunk_DSD(dsf2flac_uint64 chunkStart)
{
	// read the header so that we are certain we are in the correct place.
	dsf2flac_int8 ident[5];
	ident[4]='\0';
	dsf2flac_uint64 chunkLen;
	if (!readChunkHeader(ident,chunkStart,&chunkLen))
		return false;
	// check the ident
	if ( !checkIdent(ident,const_cast<dsf2flac_int8*>("DSD ")) ) {
		errorMsg = "dsdiffFileReader::readChunk_DSD:chunk ident error";
		return false;
	}
	// we are now at the start of the dsd data, record the position
	sampleDataPointer = file.tellg();
	// chunkLen contains the number of samples
	sampleCountPerChan = (chunkLen - 12)/chanNum*samplesPerChar;
	return true;
}
bool DsdiffFileReader::readChunk_FVER(dsf2flac_uint64 chunkStart)
{
	// read the header so that we are certain we are in the correct place.
	dsf2flac_int8 ident[5];
	ident[4]='\0';
	if (!readChunkHeader(ident,chunkStart))
		return false;
	// check the ident
	if ( !checkIdent(ident,const_cast<dsf2flac_int8*>("FVER")) ) {
		errorMsg = "dsdiffFileReader::readChunk_FVER:chunk ident error";
		return false;
	}
	// read the file version
	if (file.read_uint32_rev(&dsdiffVersion,1)) {
		errorMsg = "dsdiffFileReader::readChunk_FVER:file read error";
		return false;
	};
	return true;
}