Exemple #1
0
	result WavStream::loadFileToMem(File *aFile)
	{
		delete[] mFilename;
		delete mMemFile;
		mStreamFile = 0;
		mMemFile = 0;
		mFilename = 0;
		mSampleCount = 0;

		MemoryFile *mf = new MemoryFile();
		int res = mf->openFileToMem(aFile);
		if (res != SO_NO_ERROR)
		{
			delete mf;
			return res;
		}

		res = parse(mf);

		if (res != SO_NO_ERROR)
		{
			delete mf;
			return res;
		}

		mMemFile = mf;

		return res;
	}
//-------------------------------------------------------------------------
bool ReadChunkData(const IwRIFFChunkHeader& header, MemoryFile &memfp, std::vector<short>&data, int samplebits)
{
	size_t len = data.size();

	if(samplebits == 16)
	{
		data.resize(len+header.length/2);
		if(memfp.Read(&data[len], header.length) != header.length)
		{
			return false;
		}
	}
	else
	{
		std::vector<char>bit8data(header.length);
		if(memfp.Read(&bit8data[0], header.length) != header.length)
		{
			return false;
		}

		data.resize(len+header.length);
		for(int i=0; i<header.length; i++)
		{
			data[len+i] = bit8data[i]*256;
		}
	}
	return true;
}
Exemple #3
0
	result WavStream::loadMem(unsigned char *aData, unsigned int aDataLen, bool aCopy, bool aTakeOwnership)
	{
		delete[] mFilename;
		delete mMemFile;
		mStreamFile = 0;
		mMemFile = 0;
		mFilename = 0;
		mSampleCount = 0;

		if (aData == NULL || aDataLen == 0)
			return INVALID_PARAMETER;

		MemoryFile *mf = new MemoryFile();
		int res = mf->openMem(aData, aDataLen, aCopy, aTakeOwnership);
		if (res != SO_NO_ERROR)
		{
			delete mf;
			return res;
		}

		res = parse(mf);

		if (res != SO_NO_ERROR)
		{
			delete mf;
			return res;
		}

		mMemFile = mf;

		return 0;
	}
/*---------------------------------------------------------------------*//**
	バッファから作成
**//*---------------------------------------------------------------------*/
bool Wave::create(const char* fbuf, int size, u16 cflag)
{
	MemoryFile* file = new MemoryFile(fbuf, size);
	if(!file->isOpened())	{	return false;	}

	return createFromFile(file, cflag);
}
Exemple #5
0
	result Sfxr::loadParamsMem(unsigned char *aMem, unsigned int aLength, bool aCopy, bool aTakeOwnership)
	{
		MemoryFile mf;
		int res = mf.openMem(aMem, aLength, aCopy, aTakeOwnership);
		if (res != SO_NO_ERROR)
			return res;
		return loadParamsFile(&mf);
	}
Exemple #6
0
	result Wav::loadMem(unsigned char *aMem, unsigned int aLength, bool aCopy, bool aTakeOwnership)
	{
		if (aMem == NULL || aLength == 0)
			return INVALID_PARAMETER;

		MemoryFile dr;
        dr.openMem(aMem, aLength, aCopy, aTakeOwnership);
		return testAndLoadFile(&dr);
	}
//
// Reads data from the input file
//
static
void pngReadFunc(png_struct * pngPtr, png_byte * data, png_size_t bytes)
{
	MemoryFile * file = (MemoryFile *)pngPtr->io_ptr;
	Q_ASSERT(file);

	int64 result = file->read((char *)data, bytes);
	if (unlikely(result != (int64)bytes))
		png_error(pngPtr, "I/O error");
}
Exemple #8
0
	WavStreamInstance::WavStreamInstance(WavStream *aParent)
	{
		mParent = aParent;
		mOffset = 0;
		mOgg = 0;
		mFile = 0;
		if (aParent->mMemFile)
		{
			MemoryFile *mf = new MemoryFile();
			mFile = mf;
			mf->openMem(aParent->mMemFile->getMemPtr(), aParent->mMemFile->length(), false, false);
		}
		else
		if (aParent->mFilename)
		{
			DiskFile *df = new DiskFile;
			mFile = df;
			df->open(aParent->mFilename);
		}
		else
		if (aParent->mStreamFile)
		{
			mFile = aParent->mStreamFile;
			mFile->seek(0); // stb_vorbis assumes file offset to be at start of ogg
		}
		else
		{
			return;
		}
		
		if (mFile)
		{
			if (mParent->mOgg)
			{
				int e;

				mOgg = stb_vorbis_open_file((Soloud_Filehack *)mFile, 0, &e, 0);

				if (!mOgg)
				{
					if (mFile != mParent->mStreamFile)
						delete mFile;
					mFile = 0;
				}
				mOggFrameSize = 0;
				mOggFrameOffset = 0;
				mOggOutputs = 0;
			}
			else
			{		
				mFile->seek(aParent->mDataOffset);
			}
		}
	}
Exemple #9
0
	result Wav::loadogg(File *aReader)
	{
		aReader->seek(0);
		MemoryFile memoryFile;
		memoryFile.openFileToMem(aReader);

		int e = 0;
		stb_vorbis *vorbis = 0;
		vorbis = stb_vorbis_open_memory(memoryFile.getMemPtr(), memoryFile.length(), &e, 0);

		if (0 == vorbis)
		{
			return FILE_LOAD_FAILED;
		}

        stb_vorbis_info info = stb_vorbis_get_info(vorbis);
		mBaseSamplerate = (float)info.sample_rate;
        int samples = stb_vorbis_stream_length_in_samples(vorbis);

		int readchannels = 1;
		if (info.channels > 1)
		{
			readchannels = 2;
			mChannels = 2;
		}
		mData = new float[samples * readchannels];
		mSampleCount = samples;
		samples = 0;
		while(1)
		{
			float **outputs;
            int n = stb_vorbis_get_frame_float(vorbis, NULL, &outputs);
			if (n == 0)
            {
				break;
            }
			if (readchannels == 1)
			{
				memcpy(mData + samples, outputs[0],sizeof(float) * n);
			}
			else
			{
				memcpy(mData + samples, outputs[0],sizeof(float) * n);
				memcpy(mData + samples + mSampleCount, outputs[1],sizeof(float) * n);
			}
			samples += n;
		}
        stb_vorbis_close(vorbis);

		return 0;
	}
Exemple #10
0
	result Wav::loadFile(File *aFile)
	{
		if (!aFile)
			return INVALID_PARAMETER;
		stop();

		MemoryFile mr;
		result res = mr.openFileToMem(aFile);

		if (res != SO_NO_ERROR)
		{
			return res;
		}
		return testAndLoadFile(&mr);
	}
bool ReadChunkFormat(const IwRIFFChunkHeader& header, MemoryFile &memfp, int &herz, int &samplebits, int &channels)
{
	IwWAVEFormatChunkADPCM format;

	// Read data from file
	if ((header.length < sizeof(IwWAVEFormatChunk))	|| (memfp.Read(&format, sizeof(IwWAVEFormatChunkADPCM)) != sizeof(IwWAVEFormatChunkADPCM)))
	{
		assert(0);
		return false;
	}

	assert(format.channels==1 && format.bitsPerSample==16 && format.samplesPerSec==22050);
	if((format.channels!=1&&format.channels!=2) || format.formatTag!=WAVE_FORMAT_PCM)
	{
		return false;
	}

	if(format.bitsPerSample != 16 && format.bitsPerSample!=8)
	{
		return false;
	}

	samplebits = format.bitsPerSample;
	herz = format.samplesPerSec;
	channels = format.channels;
	return true;
}
//-------------------------------------------------------------------------
bool ReadChunkFact(const IwRIFFChunkHeader& header, MemoryFile &memfp, int &sampleCount)
{
	if (memfp.Read(&sampleCount, sizeof(int)) != sizeof(int))
	{
		return false;
	}

	return true;
}
//
// Constructor
//
PNGReader::PNGReader(const QString & ext, MemoryFile & file)
	: ImageFormatReaderHelper(file)
{
	if (file.size() < 8)
		return;

	byte buf[8];
	if (!tryReadFile(buf, sizeof(buf)))
		return;

	if (png_check_sig((png_bytep)buf, sizeof(buf)))
		m_IsValid = true;
}
IFile * AnsiFileSystem::CreateFile(const char8 * filename, uint32	attributes)
{
	// find file in attached archives

	for (List<ResourceArchiveItem>::iterator ai = resourceArchiveList.begin();
		ai != resourceArchiveList.end(); ++ai)
	{
		ResourceArchiveItem & item = *ai;
			
		String filenamecpp = filename;

		String::size_type pos = filenamecpp.find(item.attachPath);
		if (pos == 0)
		{
			String relfilename = filenamecpp.substr(item.attachPath.length());
			uint32 size = item.archive->LoadResource(relfilename, 0);
			if ( size == -1 )
			{
				return 0;
			}
			MemoryFile * file = new MemoryFile(size, attributes);
			if (file)
			{
				item.archive->LoadResource(relfilename, file->GetPointer());
				return file;
			}
			SafeRelease(file);
			return 0;
		}
	}

	AnsiFile * file = new AnsiFile();
	if (file->Create(filename, attributes))return file;
	SafeRelease(file);
	return 0;
}
Exemple #15
0
void do_loadxmltobinary(FILE * f, File * outf, BoxcacheData * bd)
{
    TiXmlDocument doc;
    TiXmlNode *pChild;

    if (!doc.LoadFile(f))
	{
        return;
	}

    for (pChild = doc.FirstChild(); pChild != 0; pChild = pChild->NextSibling())
    {
        if (pChild->Type() == TiXmlNode::ELEMENT)
        {
            if (stricmp(pChild->Value(), "Atanua") == 0)
            {
				outf->writeint(0x02617441); // 'Ata' + 2
	
				int chipcount = 0;
                ((TiXmlElement*)pChild)->QueryIntAttribute("ChipCount", &chipcount);
				outf->writeint(chipcount);
	
				int wirecount = 0;   
                ((TiXmlElement*)pChild)->QueryIntAttribute("WireCount", &wirecount);
				outf->writeint(wirecount);

				int scale = 24;
                ((TiXmlElement*)pChild)->QueryIntAttribute("scale", &scale);

                TiXmlNode *part;
                for (part = pChild->FirstChild(); part != 0; part = part->NextSibling())
                {
                    if (part->Type() == TiXmlNode::ELEMENT)
                    {
                        if (stricmp(part->Value(), "Chip")==0)
                        {
                            // we now have the chip id string, but we need to find
                            // the copy which is always in memory so that we get a
                            // sane pointer to it for gChipName.
                            const char *chipname = NULL;
                            const char *temp = ((TiXmlElement*)part)->Attribute("Name");
                            if (temp)
                            {
								// boxes are... special.
								int i = strlen(temp);
								if (i > 7 && stricmp(temp+i-7,".atanua") == 0)
								{
									chipname = mystrdup(temp);
									FILE * f = openfileinsamedir(temp);
									if (!f)
									{
                                        char temp[1024];
                                        sprintf(temp,"Boxed atanua file '%s' not found.\nTry to continue loading?\n\n(it will show up as box with no pins)", chipname);
                                        if (okcancel(temp) == 0)
                                        {
											delete[] chipname;
                                            build_nets();
                                            return;
                                        }
									}
									else
									{
										fclose(f);
									}
								}
								else
                                if (stricmp(temp, "Connection Pin") == 0)
                                {
									// Connection pin is a special case, as you can't create it
									// in a "normal" way
                                    chipname = "Connection Pin";
                                }
                                else
                                {
                                    int j, k;
                                    for (k = 0; chipname == NULL && k < 5; k++)
                                    {
                                        for (j = 0; chipname == NULL && j < (signed)gAvailableChip[k].size(); j++)
                                        {
                                            if (gAvailableChip[k][j])
                                            {
                                                if (stricmp(temp, gAvailableChip[k][j]) == 0)
                                                {
                                                    chipname = gAvailableChip[k][j];
                                                }
                                            }
                                        }
                                    }
                                }
                                
                                if (chipname != NULL)
                                {
                                    int x, y, key, angle;
                                    x = y = key = angle = 0;                                    
                                    ((TiXmlElement*)part)->QueryIntAttribute("xpos", &x);
                                    ((TiXmlElement*)part)->QueryIntAttribute("ypos", &y);
                                    ((TiXmlElement*)part)->QueryIntAttribute("key", &key);
                                    ((TiXmlElement*)part)->QueryIntAttribute("rot", &angle);
                                    int AngleIn90DegreeSteps = angle;
                                    float X = (float)x / (1 << scale);
                                    float Y = (float)y / (1 << scale);

									int len = strlen(chipname);
									outf->writeword(len);
									outf->writechars(chipname, len);
									outf->writeint((int)floor((1 << 16) * X));
									outf->writeint((int)floor((1 << 16) * Y));
									outf->writeint(AngleIn90DegreeSteps);
									outf->writeint(0);

                                    TiXmlNode *text;
                                    for (text = part->FirstChild(); text != 0; text = text->NextSibling())
                                    {
                                        if (text->Type() == TiXmlNode::TEXT)
                                        {
                                            const char *v = text->Value();
                                            int wholebyte = 0;
                                            int data = 0;
											MemoryFile mf;
                                            while (*v)
                                            {
                                                if (*v >= '0' && *v <= '9')
                                                {
                                                    data <<= 4;
                                                    data |= *v - '0';
                                                    wholebyte++;
                                                }
                                                else
                                                if (*v >= 'A' && *v <= 'F')
                                                {
                                                    data <<= 4;
                                                    data |= *v - 'A' + 10;
                                                    wholebyte++;
                                                }
                                                else
                                                if (*v >= 'a' && *v <= 'f')
                                                {
                                                    data <<= 4;
                                                    data |= *v - 'a' + 10;
                                                    wholebyte++;
                                                }
                                                // ignore other values, including whitespace
                                                if (wholebyte == 2)
                                                {
													mf.writebyte(data);
                                                    data = 0;
                                                    wholebyte = 0;
                                                }
                                                v++;
                                            }

											if (stricmp(chipname, "External Pin") == 0)
											{
												if (bd)
												{
													mf.seek(0);
													mf.readint();
													int l = mf.readint();
													char *temp = new char[l+1];
													memset(temp,0,l+1);
													mf.readchars(temp, l);
													bd->mTooltips.push_back(temp);
												}
											}
											
											int i;
											for (i = 0; i < (signed)mf.mData.size(); i++)
												outf->writebyte(mf.mData[i]);											

                                            if (wholebyte != 0)
                                            {
                                                char temp[1024];
                                                sprintf(temp,"Decoding chip-specific data while loading '%s' failed.\nTry to continue loading?", chipname);
                                                if (okcancel(temp) == 0)
                                                {
                                                    return;
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    char mtemp[1024];
                                    sprintf(mtemp,"Chip called '%s' requested by savefile but it is\n"
                                                  "not supported by this version, or a plugin is missing.\n"
                                                  "\n"
                                                  "Try to continue loading?", temp);
                                    if (okcancel(mtemp) == 0)
                                    {
                                        build_nets();
                                        return;
                                    }
                                }
                            }
                        }
                        if (stricmp(part->Value(), "Wire")==0)
                        {
                            int chip1, pin1, chip2, pin2;
                            ((TiXmlElement*)part)->QueryIntAttribute("chip1", &chip1);
                            ((TiXmlElement*)part)->QueryIntAttribute("chip2", &chip2);
                            ((TiXmlElement*)part)->QueryIntAttribute("pad1", &pin1);
                            ((TiXmlElement*)part)->QueryIntAttribute("pad2", &pin2);
							
							outf->writeint((chip1<<16) | pin1);
							outf->writeint((chip2<<16) | pin2);
							outf->writeint(0);
						}
                    }
                }
            }
        }
    }	
}
Exemple #16
0
//
// tries to open a file from the given framenumber and reads the content into the vector of particles
//
void loadParticles( std::string fileName, std::vector<Particle> &particles )
{

	// if the file is a zip file, then we assume that the zip contains the pcl file among other things
	if( util::getExtension( fileName ) == ".zip" )
	{
		// unzip the pcl file into the memory

		std::string title = dk::util::PathInfo::getTitle( fileName );

		// open the zipfile
		HZIP zip = OpenZip( util::toWString( fileName ).c_str(), 0 );

		// set base directory for unzipping operations
		SetUnzipBaseDir( zip, _T("\\") );

		// zip entry for the pcl file
		ZIPENTRY ze;
		int entryIndex = -1;

		// look for the pcl file
		FindZipItem( zip, util::toWString( std::string( title ) + ".pcl" ).c_str(), false, &entryIndex, &ze );

		if( entryIndex == -1 )
		{
			printf( "error : zip file doesnt contain %s\n", util::setExtension( fileName, ".pcl" ).c_str() );
			// stop everything
			return;
		}

		// prepare memory
		MemoryFile file;

		file.resize( ze.unc_size );

		// we have found the particles -> unpack them into memory
		UnzipItem( zip, entryIndex, file.getMemory(), file.size() );

		CloseZip( zip );

		// now read the particles
		int particleCount = 0;

		file.read((char *) &particleCount, sizeof(int) );
		printf( "number of particles: %i\n", particleCount );

		// prepare vector
		particles.resize( particleCount );

		// now read in (kinda rough)
		for( int i=0; i<particleCount; ++i )
		{
			float pos[3];
			file.read((char *) pos, sizeof(float) * 3 );

			particles[i].position.x = pos[0];
			particles[i].position.y = pos[1];
			particles[i].position.z = pos[2];
		}
	}else
	{
		// open file from disk
		std::ifstream in( fileName.c_str(), std::ios::in | std::ios::binary );

		if( !in )
			return;

		int particleCount = 0;

		in.read((char *) &particleCount, sizeof(int) );
		printf( "number of particles: %i\n", particleCount );


		// prepare vector
		particles.resize( particleCount );

		// now read in (kinda rough)
		for( int i=0; i<particleCount; ++i )
		{
			float pos[3];
			in.read((char *) pos, sizeof(float) * 3 );

			particles[i].position.x = pos[0];
			particles[i].position.y = pos[1];
			particles[i].position.z = pos[2];
		}

		in.close();
	}
}