Ejemplo n.º 1
0
void Stereo_Buffer::mix_stereo( float* out, long count )
{
        Blip_Reader left;
        Blip_Reader right;
        Blip_Reader center;

        left.begin( bufs [1] );
        right.begin( bufs [2] );
        int bass = center.begin( bufs [0] );

        while ( count-- )
        {
                int c = center.read();
                out [0] = (float)(c + left.read()) / 32768;
                out [1] = (float)(c + right.read()) / 32768;
                out += 2;

                center.next( bass );
                left.next( bass );
                right.next( bass );
        }

        center.end( bufs [0] );
        right.end( bufs [2] );
        left.end( bufs [1] );
}
Ejemplo n.º 2
0
long Nes_Buffer::read_samples( blip_sample_t* out, long count )
{
	count = nonlin.make_nonlinear( tnd, count );
	if ( count )
	{
		Blip_Reader lin;
		Blip_Reader nonlin;
		
		int lin_bass = lin.begin( buf );
		int nonlin_bass = nonlin.begin( tnd );
		
		for ( int n = count; n--; )
		{
			int s = lin.read() + nonlin.read();
			lin.next( lin_bass );
			nonlin.next( nonlin_bass );
			*out++ = s;
			
			if ( (BOOST::int16_t) s != s )
				out [-1] = 0x7FFF - (s >> 24);
		}
		
		lin.end( buf );
		nonlin.end( tnd );
		
		buf.remove_samples( count );
		tnd.remove_samples( count );
	}
	
	return count;
}
Ejemplo n.º 3
0
void Stereo_Buffer::mix_stereo( blip_sample_t* out, long count )
{
	Blip_Reader left; 
	Blip_Reader right; 
	Blip_Reader center;
	
	left.begin( bufs [1] );
	right.begin( bufs [2] );
	int bass = center.begin( bufs [0] );
	
	while ( count-- )
	{
		int c = center.read();
		long l = c + left.read();
		long r = c + right.read();
		center.next( bass );
		out [0] = static_cast< blip_sample_t >( l );
		out [1] = static_cast< blip_sample_t >( r );
		out += 2;
		
		if ( (BOOST::int16_t) l != l )
			out [-2] = static_cast< blip_sample_t >( 0x7FFF - (l >> 24) );
		
		left.next( bass );
		right.next( bass );
		
		if ( (BOOST::int16_t) r != r )
			out [-1] = static_cast< blip_sample_t >( 0x7FFF - (r >> 24) );
	}
	
	center.end( bufs [0] );
	right.end( bufs [2] );
	left.end( bufs [1] );
}
Ejemplo n.º 4
0
// Read samples as unsigned 8-bit
long read_samples( Blip_Buffer& buf, unsigned char* out, long out_size )
{
	// Limit number of samples read to those available
	long count = buf.samples_avail();
	if ( count > out_size )
		count = out_size;
	
	// Begin reading samples from Blip_Buffer
	Blip_Reader reader;
	int bass = reader.begin( buf );
	
	for ( long n = count; n--; )
	{
		// Read 16-bit sample and convert to output format
		long s = reader.read();
		reader.next( bass );
		if ( (short) s != s ) // clamp to 16 bits
			s = 0x7fff - (s >> 24);
		
		*out++ = (s >> 8) + 0x80;
	}
	
	// End reading and remove the samples
	reader.end( buf );
	buf.remove_samples( count );
	
	return count;
}
Ejemplo n.º 5
0
void Stereo_Buffer::mix_mono( float* out, long count )
{
        Blip_Reader in;
        int bass = in.begin( bufs [0] );

        while ( count-- )
        {
                int sample = in.read();
                out [0] = (float)(sample) / 32768;
                out [1] = (float)(sample) / 32768;
                out += 2;
                in.next( bass );
        }

        in.end( bufs [0] );
}
Ejemplo n.º 6
0
// Read samples as floating-point, with values staying
// between 'low' and 'high' (defaults to -1.0 to 1.0).
long read_samples( Blip_Buffer& buf, float* out, long out_size,
		float low = -1.0f, float high = 1.0f )
{
	// Limit number of samples read to those available
	long count = buf.samples_avail();
	if ( count > out_size )
		count = out_size;
	
	// Begin reading samples from Blip_Buffer
	Blip_Reader reader;
	int bass = reader.begin( buf );
	
	float factor = (high - low) * 0.5f;
	float offset = low + 1.0f * factor;
	unsigned long const sample_range = 1UL << blip_sample_bits;
	factor *= 1.0f / (sample_range / 2);
	
	for ( long n = count; n--; )
	{
		// Read sample at full resolution and convert to output format
		long s = reader.read_raw();
		reader.next( bass );
		*out++ = s * factor + offset;
		if ( (unsigned long) (s + sample_range / 2) >= sample_range )
		{
			// clamp
			out [-1] = high;
			if ( s < 0 )
				out [-1] = low;
		}
	}
	
	// End reading and remove the samples
	reader.end( buf );
	buf.remove_samples( count );
	
	return count;
}