Пример #1
0
int gaudio_WavSeek(g_id id, long int offset, int whence)
{
    GGWavHandle *handle = (GGWavHandle*)id;

    if (whence == SEEK_SET)
    {
        offset = handle->dataPos + offset * handle->sampleSize;
    }
    else if (whence == SEEK_CUR)
    {
        offset = g_ftell(handle->fis) + offset * handle->sampleSize;
    }
    else if (whence == SEEK_END)
    {
        offset = handle->dataPos + handle->dataSize - offset * handle->sampleSize;
    }
    else
    {
        return -1;
    }

    offset = std::max(offset, (long int)handle->dataPos);

    g_fseek(handle->fis, offset, SEEK_SET);

    return (g_ftell(handle->fis) - handle->dataPos) / handle->sampleSize;
}
Пример #2
0
static off_t mpg123lseek(void* fd, off_t offset, int whence)
{
	G_FILE* file = (G_FILE*)fd;

	if (g_fseek(file, offset, whence) == 0)
		return g_ftell(file);

	return (off_t)-1;
}
Пример #3
0
void ApplicationManager::loadProperties()
{
	G_FILE* fis = g_fopen("properties.bin", "rb");

	g_fseek(fis, 0, SEEK_END);
	int len = g_ftell(fis);
	g_fseek(fis, 0, SEEK_SET);

	std::vector<char> buf(len);
	g_fread(&buf[0], 1, len, fis);
	g_fclose(fis);

	ByteBuffer buffer(&buf[0], buf.size());

	buffer >> properties_.scaleMode;
	buffer >> properties_.logicalWidth;
	buffer >> properties_.logicalHeight;
	
	int scaleCount;
	buffer >> scaleCount;
	properties_.imageScales.resize(scaleCount);
	for (int i = 0; i < scaleCount; ++i)
	{
		buffer >> properties_.imageScales[i].first;
		buffer >> properties_.imageScales[i].second;
	}
	
	buffer >> properties_.orientation;
	buffer >> properties_.fps;
	buffer >> properties_.retinaDisplay;
	buffer >> properties_.autorotation;
	buffer >> properties_.mouseToTouch;
	buffer >> properties_.touchToMouse;
	buffer >> properties_.mouseTouchOrder;

	
	application_->setResolution(width_, height_);
	application_->setOrientation((Orientation)properties_.orientation);
	updateHardwareOrientation();
	application_->getApplication()->setDeviceOrientation(deviceOrientation_);
	application_->setLogicalDimensions(properties_.logicalWidth, properties_.logicalHeight);
	application_->setLogicalScaleMode((LogicalScaleMode)properties_.scaleMode);
	application_->setImageScales(properties_.imageScales);

	g_setFps(properties_.fps);
	
	ginput_setMouseToTouchEnabled(properties_.mouseToTouch);
	ginput_setTouchToMouseEnabled(properties_.touchToMouse);
	ginput_setMouseTouchOrder(properties_.mouseTouchOrder);
}
Пример #4
0
void *ShaderProgram::LoadShaderFile(const char *fname, const char *ext, long *len) {
	char name[256];
	sprintf(name, "%s.%s", fname,ext);
	G_FILE *f = g_fopen(name, "r");
	if (f) {
		g_fseek(f, 0, SEEK_END);
		long sz = g_ftell(f);
		if (len)
			*len = sz;
		void *fdata = malloc(sz+1);
		((char *)fdata)[sz]=0; //NUL TERMINATE
		g_fseek(f, 0, SEEK_SET);
		g_fread(fdata, 1, sz, f);
		g_fclose(f);
		return fdata;
	}
	return NULL;
}
Пример #5
0
void TTFont::constructor(const char *filename, float size, bool smoothing)
{
	face_ = NULL;

	G_FILE* fis = g_fopen(filename, "rb");
	if (fis == NULL)
	{
		throw GiderosException(GStatus(6000, filename));		// Error #6000: %s: No such file or directory.
		return;
	}

	memset(&stream_, 0, sizeof(stream_));

	g_fseek(fis, 0, SEEK_END);
	stream_.size = g_ftell(fis);
	g_fseek(fis, 0, SEEK_SET);
	stream_.descriptor.pointer = fis;
	stream_.read = read;
	stream_.close = close;

	FT_Open_Args args;
	memset(&args, 0, sizeof(args));
	args.flags = FT_OPEN_STREAM;
	args.stream = &stream_;

	if (FT_Open_Face(FT_Library_Singleton::instance(), &args, 0, &face_))
		throw GiderosException(GStatus(6012, filename));		// Error #6012: %s: Error while reading font file.

    float scalex = application_->getLogicalScaleX();
    float scaley = application_->getLogicalScaleY();

	const int RESOLUTION = 72;
	if (FT_Set_Char_Size(face_, 0L, (int)floor(size * 64 + 0.5f), (int)floor(RESOLUTION * scalex + 0.5f), (int)floor(RESOLUTION * scaley + 0.5f)))
	{
		FT_Done_Face(face_);
		face_ = NULL;
        throw GiderosException(GStatus(6017, filename));		// Error #6017: Invalid font size.
	}

	ascender_ = face_->size->metrics.ascender >> 6;
	height_ = face_->size->metrics.height >> 6;

    smoothing_ = smoothing;
}
Пример #6
0
g_id gaudio_WavOpen(const char *fileName, int *numChannels, int *sampleRate, int *bitsPerSample, int *numSamples, gaudio_Error *error)
{
    G_FILE *fis = g_fopen(fileName, "rb");
    if (fis == NULL)
    {
        if (error)
            *error = GAUDIO_CANNOT_OPEN_FILE;
        return 0;
    }

    GGWaveHeader header;
    if (g_fread(&header, sizeof(GGWaveHeader), 1, fis) != 1)
    {
        g_fclose(fis);
        if (error)
            *error = GAUDIO_UNRECOGNIZED_FORMAT;
        return 0;
    }

    if (header.chunkID != 0x46464952/*RIFF*/ || header.format != 0x45564157/*WAVE*/)
    {
        g_fclose(fis);
        if (error)
            *error = GAUDIO_UNRECOGNIZED_FORMAT;
        return 0;
    }

    // read "fmt " chunk
    GGFmtChunk format = {0};
    while (true)
    {
        GGChunkHeader chunk;
        if (g_fread(&chunk, sizeof(GGChunkHeader), 1, fis) != 1)
            break;

        if (chunk.chunkId == 0x20746D66/*fmt */)
        {
            if (g_fread(&format, sizeof(GGFmtChunk), 1, fis) != 1)
            {
                if (error)
                    *error = GAUDIO_ERROR_WHILE_READING;
                g_fclose(fis);
                return 0;
            }

            break;
        }

        g_fseek(fis, chunk.chunkSize, SEEK_CUR);
    }

    g_fseek(fis, sizeof(GGWaveHeader), SEEK_SET);

    // read "data" chunk
    unsigned int dataSize = 0;
    unsigned int dataPos = 0;
    while (true)
    {
        GGChunkHeader chunk;
        if (g_fread(&chunk, sizeof(GGChunkHeader), 1, fis) != 1)
            break;

        if (chunk.chunkId == 0x61746164/*data */)
        {
            dataPos = g_ftell(fis);
            dataSize = chunk.chunkSize;
            break;
        }

        g_fseek(fis, chunk.chunkSize, SEEK_CUR);
    }

    // data chunk is missing or zero sized
    if (dataPos == 0 || dataSize == 0)
    {
        if (error)
            *error = GAUDIO_UNRECOGNIZED_FORMAT;
        g_fclose(fis);
        return 0;
    }

    // only support PCM
    if (format.audioFormat != 1)
    {
        if (error)
            *error = GAUDIO_UNSUPPORTED_FORMAT;
        g_fclose(fis);
        return 0;
    }

    // only support 8 and 16 bits per sample
    if (format.bitsPerSample != 8 && format.bitsPerSample != 16)
    {
        if (error)
            *error = GAUDIO_UNSUPPORTED_FORMAT;
        g_fclose(fis);
        return 0;
    }

    g_fseek(fis, dataPos, SEEK_SET);

    // some writers put a bad blockAlign and/or byteRate value => recalculate them.
    format.blockAlign = (format.bitsPerSample / 8) * format.numChannels;
    format.byteRate = format.blockAlign * format.sampleRate;

    if (numChannels)
        *numChannels = format.numChannels;
    if (sampleRate)
        *sampleRate = format.sampleRate;
    if (bitsPerSample)
        *bitsPerSample = format.bitsPerSample;
    if (numSamples)
        *numSamples = dataSize / format.blockAlign;
    if (error)
        *error = GAUDIO_NO_ERROR;

    GGWavHandle *handle = new GGWavHandle();
    handle->fis = fis;
    handle->sampleSize = format.blockAlign;
    handle->dataPos = dataPos;
    handle->dataSize = dataSize;

    return (g_id)handle;
}
Пример #7
0
long int gaudio_WavTell(g_id id)
{
    GGWavHandle *handle = (GGWavHandle*)id;
    return (g_ftell(handle->fis) - handle->dataPos) / handle->sampleSize;
}