示例#1
0
文件: readduh.c 项目: kode54/Cog
static DUH_SIGNAL *read_signal(DUH *duh, DUMBFILE *f) {
    DUH_SIGNAL *signal;
    long type;

    signal = malloc(sizeof(*signal));

    if (!signal)
        return NULL;

    type = dumbfile_mgetl(f);
    if (dumbfile_error(f)) {
        free(signal);
        return NULL;
    }

    signal->desc = _dumb_get_sigtype_desc(type);
    if (!signal->desc) {
        free(signal);
        return NULL;
    }

    if (signal->desc->load_sigdata) {
        signal->sigdata = (*signal->desc->load_sigdata)(duh, f);
        if (!signal->sigdata) {
            free(signal);
            return NULL;
        }
    } else
        signal->sigdata = NULL;

    return signal;
}
示例#2
0
文件: readduh.c 项目: kode54/Cog
/* read_duh(): reads a DUH from an already open DUMBFILE, and returns its
 * pointer, or null on error. The file is not closed.
 */
DUH *read_duh(DUMBFILE *f) {
    DUH *duh;
    int i;

    if (dumbfile_mgetl(f) != DUH_SIGNATURE)
        return NULL;

    duh = malloc(sizeof(*duh));
    if (!duh)
        return NULL;

    duh->length = dumbfile_igetl(f);
    if (dumbfile_error(f) || duh->length <= 0) {
        free(duh);
        return NULL;
    }

    duh->n_signals = (int)dumbfile_igetl(f);
    if (dumbfile_error(f) || duh->n_signals <= 0) {
        free(duh);
        return NULL;
    }

    duh->signal = malloc(sizeof(*duh->signal) * duh->n_signals);
    if (!duh->signal) {
        free(duh);
        return NULL;
    }

    for (i = 0; i < duh->n_signals; i++)
        duh->signal[i] = NULL;

    for (i = 0; i < duh->n_signals; i++) {
        if (!(duh->signal[i] = read_signal(duh, f))) {
            unload_duh(duh);
            return NULL;
        }
    }

    return duh;
}
示例#3
0
static IFF_CHUNKED *dumbfile_read_okt(DUMBFILE *f)
{
	IFF_CHUNKED *mod = (IFF_CHUNKED *) malloc(sizeof(*mod));
	if (!mod) return NULL;

	mod->chunk_count = 0;
	mod->chunks = 0;

	for (;;)
	{
		long bytes_read;
		IFF_CHUNK * chunk = ( IFF_CHUNK * ) realloc( mod->chunks, ( mod->chunk_count + 1 ) * sizeof( IFF_CHUNK ) );
		if ( !chunk )
		{
			if ( mod->chunks ) free( mod->chunks );
			free( mod );
			return NULL;
		}
		mod->chunks = chunk;
		chunk += mod->chunk_count;

		bytes_read = dumbfile_mgetl( f );
		if ( bytes_read < 0 ) break;

		chunk->type = bytes_read;
		chunk->size = dumbfile_mgetl( f );

		if ( dumbfile_error( f ) ) break;

		chunk->data = (unsigned char *) malloc( chunk->size );
		if ( !chunk->data )
		{
			free( mod->chunks );
			free( mod );
			return NULL;
		}

		bytes_read = dumbfile_getnc( ( char * ) chunk->data, chunk->size, f );
		if ( bytes_read < (long)chunk->size )
		{
			if ( bytes_read <= 0 ) {
				free( chunk->data );
				break;
			} else {
				chunk->size = bytes_read;
				mod->chunk_count++;
				break;
			}
		}

		mod->chunk_count++;
	}

	if ( !mod->chunk_count ) {
		if ( mod->chunks ) free(mod->chunks);
		free(mod);
		mod = NULL;
	}

	return mod;
}
示例#4
0
文件: reads3m.c 项目: codefoco/dumb
static int it_s3m_read_sample_header(IT_SAMPLE *sample, long *offset,
                                     unsigned char *pack, int cwtv,
                                     DUMBFILE *f) {
    unsigned char type;
    int flags;

    type = dumbfile_getc(f);

    dumbfile_getnc((char *)sample->filename, 12, f);
    sample->filename[12] = 0;

    if (type > 1) {
        /** WARNING: no adlib support */
        dumbfile_skip(f, 3 + 12 + 1 + 1 + 2 + 2 + 2 + 12);
        dumbfile_getnc((char *)sample->name, 28, f);
        sample->name[28] = 0;
        dumbfile_skip(f, 4);
        sample->flags &= ~IT_SAMPLE_EXISTS;
        return dumbfile_error(f);
    }

    *offset = dumbfile_getc(f) << 20;
    *offset += dumbfile_igetw(f) << 4;

    sample->length = dumbfile_igetl(f);
    sample->loop_start = dumbfile_igetl(f);
    sample->loop_end = dumbfile_igetl(f);

    sample->default_volume = dumbfile_getc(f);

    dumbfile_skip(f, 1);

    flags = dumbfile_getc(f);

    if (flags < 0 || (flags != 0 && flags != 4))
        /* Sample is packed apparently (or error reading from file). We don't
         * know how to read packed samples.
         */
        return -1;

    *pack = flags;

    flags = dumbfile_getc(f);

    sample->C5_speed = dumbfile_igetl(f) << 1;

    /* Skip four unused bytes and three internal variables. */
    dumbfile_skip(f, 4 + 2 + 2 + 4);

    dumbfile_getnc((char *)sample->name, 28, f);
    sample->name[28] = 0;

    if (type == 0 || sample->length <= 0) {
        /* Looks like no-existy. Anyway, there's for sure no 'SCRS' ... */
        sample->flags &= ~IT_SAMPLE_EXISTS;
        return dumbfile_error(f);
    }

    if (dumbfile_mgetl(f) != DUMB_ID('S', 'C', 'R', 'S'))
        return -1;

    sample->global_volume = 64;

    sample->flags = IT_SAMPLE_EXISTS;
    if (flags & 1)
        sample->flags |= IT_SAMPLE_LOOP;

    /* The ST3 TECH.DOC is unclear on this, but IMAGO Orpheus is not. Piece of
     * crap. */

    if (flags & 2) {
        sample->flags |= IT_SAMPLE_STEREO;

        if ((cwtv & 0xF000) == 0x2000) {
            sample->length >>= 1;
            sample->loop_start >>= 1;
            sample->loop_end >>= 1;
        }
示例#5
0
文件: riff.c 项目: kode54/Cog
struct riff *riff_parse(DUMBFILE *f, long offset, long size, unsigned proper) {
    unsigned stream_size;
    struct riff *stream;

    if (size < 8)
        return 0;

    if (dumbfile_seek(f, offset, DFS_SEEK_SET))
        return 0;
    if (dumbfile_mgetl(f) != DUMB_ID('R', 'I', 'F', 'F'))
        return 0;

    stream_size = (int)dumbfile_igetl(f);
    if (stream_size + 8 > size)
        return 0;
    if (stream_size < 4)
        return 0;

    stream = (struct riff *)malloc(sizeof(struct riff));
    if (!stream)
        return 0;

    stream->type = (int)dumbfile_mgetl(f);
    stream->chunk_count = 0;
    stream->chunks = 0;

    stream_size -= 4;

    while (stream_size && !dumbfile_error(f)) {
        struct riff_chunk *chunk;
        if (stream_size < 8)
            break;
        stream->chunks = (struct riff_chunk *)realloc(
            stream->chunks,
            (stream->chunk_count + 1) * sizeof(struct riff_chunk));
        if (!stream->chunks)
            break;
        chunk = stream->chunks + stream->chunk_count;
        chunk->type = (int)dumbfile_mgetl(f);
        chunk->size = (int)dumbfile_igetl(f);
        chunk->offset = dumbfile_pos(f);
        stream_size -= 8;
        if (stream_size < chunk->size)
            break;
        if (chunk->type == DUMB_ID('R', 'I', 'F', 'F')) {
            chunk->nested =
                riff_parse(f, chunk->offset - 8, chunk->size + 8, proper);
            if (!chunk->nested)
                break;
        } else {
            chunk->nested = 0;
        }
        dumbfile_seek(f, chunk->offset + chunk->size, DFS_SEEK_SET);
        stream_size -= chunk->size;
        if (proper && (chunk->size & 1)) {
            dumbfile_skip(f, 1);
            --stream_size;
        }
        ++stream->chunk_count;
    }

    if (stream_size) {
        riff_free(stream);
        stream = 0;
    }

    return stream;
}
示例#6
0
文件: reads3m.c 项目: eukos16/NGUNIX
static int it_s3m_read_sample_header(IT_SAMPLE *sample, long *offset, DUMBFILE *f)
{
	unsigned char type;
	int flags;

	type = dumbfile_getc(f);

	if (type > 1) {
		/** WARNING: no adlib support */
	}

	dumbfile_getnc(sample->filename, 13, f);
	sample->filename[13] = 0;

	*offset = dumbfile_igetw(f) << 4;

	sample->length = dumbfile_igetl(f);
	sample->loop_start = dumbfile_igetl(f);
	sample->loop_end = dumbfile_igetl(f);

	sample->default_volume = dumbfile_getc(f);

	dumbfile_skip(f, 1);

	if (dumbfile_getc(f) != 0)
		/* Sample is packed apparently (or error reading from file). We don't
		 * know how to read packed samples.
		 */
		return -1;

	flags = dumbfile_getc(f);

	sample->C5_speed = dumbfile_igetl(f) << 1;

	/* Skip four unused bytes and three internal variables. */
	dumbfile_skip(f, 4+2+2+4);

	dumbfile_getnc(sample->name, 28, f);
	sample->name[28] = 0;

	if (type == 0) {
		/* Looks like no-existy. Anyway, there's for sure no 'SCRS' ... */
		sample->flags &= ~IT_SAMPLE_EXISTS;
		return dumbfile_error(f);
	}

	if (dumbfile_mgetl(f) != DUMB_ID('S','C','R','S'))
		return -1;

	sample->global_volume = 64;

	sample->flags = IT_SAMPLE_EXISTS;
	if (flags & 1) sample->flags |= IT_SAMPLE_LOOP;
	if (flags & 2) sample->flags |= IT_SAMPLE_STEREO;
	if (flags & 4) sample->flags |= IT_SAMPLE_16BIT;

	sample->default_pan = 0; // 0 = don't use, or 160 = centre?

	if (sample->length <= 0)
		sample->flags &= ~IT_SAMPLE_EXISTS;
	else if (sample->flags & IT_SAMPLE_LOOP) {
		if ((unsigned int)sample->loop_end > (unsigned int)sample->length)
			sample->flags &= ~IT_SAMPLE_LOOP;
		else if ((unsigned int)sample->loop_start >= (unsigned int)sample->loop_end)
			sample->flags &= ~IT_SAMPLE_LOOP;
		else
			/* ScreamTracker seems not to save what comes after the loop end
			 * point, but rather to assume it is a duplicate of what comes at
			 * the loop start point. I am not completely sure of this though.
			 * It is easy to evade; simply truncate the sample.
			 */
			sample->length = sample->loop_end;
	}


	//Do we need to set all these?
	sample->vibrato_speed = 0;
	sample->vibrato_depth = 0;
	sample->vibrato_rate = 0;
	sample->vibrato_waveform = IT_VIBRATO_SINE;

	return dumbfile_error(f);
}