SWORD VC1_SampleLoad(struct SAMPLOAD* sload,int type)
{
	SAMPLE *s = sload->sample;
	int handle;
	ULONG t, length,loopstart,loopend;

	if(type==MD_HARDWARE) return -1;

	/* Find empty slot to put sample address in */
	for(handle=0;handle<MAXSAMPLEHANDLES;handle++)
		if(!Samples[handle]) break;

	if(handle==MAXSAMPLEHANDLES) {
		_mm_errno = MMERR_OUT_OF_HANDLES;
		return -1;
	}

	length    = s->length;
	loopstart = s->loopstart;
	loopend   = s->loopend;
        
        /* Fix loops */
        if (((loopend-loopstart)>2) && (loopstart > loopend) && (loopstart>length))
        {
            loopstart /= 2;
        }

	SL_SampleSigned(sload);
	SL_Sample8to16(sload);

	if(!(Samples[handle]=(SWORD*)_mm_malloc((length+20)<<1))) {
		_mm_errno = MMERR_SAMPLE_TOO_BIG;
		return -1;
	}

	/* read sample into buffer */
	if (SL_Load(Samples[handle],sload,length))
		return -1;

	/* Unclick sample */
	if(s->flags & SF_LOOP) {
		if(s->flags & SF_BIDI)
			for(t=0;t<16;t++)
				Samples[handle][loopend+t]=Samples[handle][(loopend-t)-1];
		else
			for(t=0;t<16;t++)
				Samples[handle][loopend+t]=Samples[handle][t+loopstart];
	} else
		for(t=0;t<16;t++)
			Samples[handle][t+length]=0;

	return handle;
}
Exemple #2
0
static SWORD NDS_HW_SampleLoad(struct SAMPLOAD* sload, int type)
{
	ASSERT(sload != NULL);

	SAMPLE *s = sload->sample;
	int handle;

	/* Find empty slot to put sample address in */
	for(handle = 0; handle < NDS_HW_MAXSAMPLES; handle++) {
		if(ipc->samples[handle] == 0) {
			break;
		}
	}

	if(handle == MAXSAMPLEHANDLES) {
		_mm_errno = MMERR_OUT_OF_HANDLES;
		return -1;
	}
	
	/* Reality check for loop settings */
	if (s->loopend > s->length)
		s->loopend = s->length;
	if (s->loopstart >= s->loopend)
		s->flags &= ~SF_LOOP;

	/* TODO difference between 8 and 16 bits? */
	SL_SampleSigned(sload);

	ipc->samples[handle] = _mm_malloc(s->length * ((s->flags & SF_16BITS) ? 2 : 1));
	if(ipc->samples[handle] == NULL) {
		_mm_errno = MMERR_SAMPLE_TOO_BIG;
		return -1;
	}

	/* read sample into buffer */
	if (SL_Load(ipc->samples[handle], sload, s->length))
		return -1;

	DC_FlushRange(ipc->samples[handle], s->length * ((s->flags & SF_16BITS) ? 2 : 1));

	return handle;
}
Exemple #3
0
static SWORD sampleLoad(SAMPLOAD *s, int type)
{
	Bank *bankP;
	SamModSamples modSamples;
	SWORD handle;
	SWORD *samples;
int rc;

	for(handle=0; handle<SAM_NUM_BANKS; handle++)
		if(!banks[handle].inUse)
			break;
	if(handle>=SAM_NUM_BANKS) {
		_mm_errno=MMERR_OUT_OF_HANDLES;
		return -1;
	}

	bankP=banks+handle;

	bankP->inUse=1;

	SL_SampleSigned(s);
	SL_Sample8to16(s);

	bankP->length=s->sample->length;
	bankP->loopstart=s->sample->loopstart;
	bankP->loopend=s->sample->loopend ? s->sample->loopend : s->sample->length;
	bankP->flags=s->sample->flags;

	if(!(samples=(SWORD *)MikMod_malloc((bankP->length+NO_LOOP_SAMPLES)<<1))) {
		bankP->inUse=0;
		_mm_errno=MMERR_SAMPLE_TOO_BIG;
		return -1;
	}

	if(SL_Load(samples, s, bankP->length)) {
		MikMod_free(samples);
		bankP->inUse=0;
		_mm_errno=MMERR_SAMPLE_TOO_BIG;
		return -1;
	}

	if(!(bankP->flags & SF_LOOP)) {
		memset(samples+bankP->length, 0, NO_LOOP_SAMPLES);
		bankP->loopstart=bankP->length;
		bankP->length+=NO_LOOP_SAMPLES;
		bankP->loopend=bankP->length-1;
	}

	modSamples.handle=handle;
	modSamples.data=samples;
	modSamples.size=bankP->length;
	if((rc=ioctl(modfd, SAM_IOC_MOD_SAMPLES_LOAD, &modSamples))<0) {
		MikMod_free(samples);
		bankP->inUse=0;
		_mm_errno=MMERR_SAMPLE_TOO_BIG;
		return -1;
	}

	MikMod_free(samples);

	return handle;
}