Exemple #1
0
static inline void YM3812UpdateOne(Chip *which, BE_ST_SndSample_T *stream, int length)
{
	Bit32s buffer[OPL_NUM_OF_SAMPLES * 2];
	int i;

	// length should be at least the max. samplesPerMusicTick
	// in Catacomb 3-D and Keen 4-6, which is param_samplerate / 700.
	// So 512 is sufficient for a sample rate of 358.4 kHz.
	if(length > OPL_NUM_OF_SAMPLES)
		length = OPL_NUM_OF_SAMPLES;

	Chip__GenerateBlock2(which, length, buffer);

	// GenerateBlock2 generates a number of "length" 32-bit mono samples
	// so we only need to convert them to 16-bit mono samples
	for(i = 0; i < length; i++)
	{
		// Scale volume
		Bit32s sample = 2*buffer[i];
		if(sample > 16383) sample = 16383;
		else if(sample < -16384) sample = -16384;
#ifdef MIXER_SAMPLE_FORMAT_FLOAT
		stream[i] = (float)sample/32767.0f;
#elif (defined MIXER_SAMPLE_FORMAT_SINT16)
		stream[i] = sample;
#endif
	}
}
Exemple #2
0
static void FillBuffer(int16_t *buffer, unsigned int nsamples)
{
    unsigned int i;

    // This seems like a reasonable assumption.  mix_buffer is
    // 1 second long, which should always be much longer than the
    // SDL mix buffer.

    assert(nsamples < mixing_freq);

    Chip__GenerateBlock2(&opl_chip, nsamples, mix_buffer);

    // Mix into the destination buffer, doubling up into stereo.

    for (i=0; i<nsamples; ++i)
    {
        buffer[i * 2] = (int16_t) mix_buffer[i];
        buffer[i * 2 + 1] = (int16_t) mix_buffer[i];
    }
}
Exemple #3
0
static void FillBuffer(int16_t *buffer, unsigned int nsamples)
{
	unsigned int i;

	// FIXME???
	//assert(nsamples < opl_sample_rate);

	Chip__GenerateBlock2(&opl_chip, nsamples, mix_buffer);

#ifdef STEREO
	// Mix into the destination buffer, doubling up into stereo.

	for (i = 0; i<nsamples; ++i)
	{
		buffer[i * 2] = (int16_t)mix_buffer[i];
		buffer[i * 2 + 1] = (int16_t)mix_buffer[i];
	}
#else
	for (i = 0; i<nsamples; ++i)
	{
		buffer[i] = (int16_t)mix_buffer[i];
	}
#endif
}
Exemple #4
0
static void FillBuffer(int16_t *buffer, unsigned int nsamples)
{
    unsigned int i;
    int sampval;
    
    // FIXME???
    //assert(nsamples < opl_sample_rate);

    Chip__GenerateBlock2(&opl_chip, nsamples, mix_buffer);

    // Mix into the destination buffer, doubling up into stereo.

    for (i=0; i<nsamples; ++i)
    {
        sampval = mix_buffer[i] * mus_opl_gain / 50;
        // clip
        if (sampval > 32767)
            sampval = 32767;
        else if (sampval < -32768)
            sampval = -32768;
        buffer[i * 2] = (int16_t) sampval;
        buffer[i * 2 + 1] = (int16_t) sampval;
    }
}