bool BlockGenerator::GenerateTrack(WaveTrack *tmp,
                                   const WaveTrack &track,
                                   int ntrack)
{
   bool bGoodResult = true;
   numSamples = track.TimeToLongSamples(GetDuration());
   sampleCount i = 0;
   float *data = new float[tmp->GetMaxBlockSize()];
   sampleCount block = 0;

   while ((i < numSamples) && bGoodResult) {
      block = tmp->GetBestBlockSize(i);
      if (block > (numSamples - i))
         block = numSamples - i;

      GenerateBlock(data, track, block);

      // Add the generated data to the temporary track
      tmp->Append((samplePtr)data, floatSample, block);
      i += block;

      // Update the progress meter
      if (TrackProgress(ntrack, (double)i / numSamples))
         bGoodResult = false;
   }
   delete[] data;
   return bGoodResult;
}
Example #2
0
byte RandomNumberGenerator::GenerateByte()
{
    byte b;
    GenerateBlock(&b, 1);

    return b;
}
Example #3
0
// Get seed and key cipher
RandomNumberGenerator::RandomNumberGenerator()
{
    byte key[32];
    byte junk[256];

    seed_.GenerateSeed(key, sizeof(key));
    cipher_.SetKey(key, sizeof(key));
    GenerateBlock(junk, sizeof(junk));  // rid initial state
}
Example #4
0
void RandomNumberGenerator::GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword length)
{
	FixedSizeSecBlock<byte, 256> buffer;
	while (length)
	{
		size_t len = UnsignedMin(buffer.size(), length);
		GenerateBlock(buffer, len);
		target.ChannelPut(channel, buffer, len);
		length -= len;
	}
}
Example #5
0
word32 RandomNumberGenerator::GenerateWord32(word32 min, word32 max)
{
	const word32 range = max-min;
	const unsigned int maxBits = BitPrecision(range);

	word32 value;

	do
	{
		GenerateBlock((byte *)&value, sizeof(value));
		value = Crop(value, maxBits);
	} while (value > range);

	return value+min;
}
Example #6
0
// **************************************************************************** //
// Fills the given area with perlin noise. Not doing any test for boundaries!
void Fill(int x1, int x2, int y1, int y2, int z1, int z2)
{
	for(int x=x1;x<x2;++x)
		for(int y=y1;y<y2;++y)
			for(int z=z1;z<z2;++z)
				Map.Set(x,y,z, GenerateBlock(x,y,z));
	for(int x=x1;x<x2;++x)
		for(int y=y1;y<y2;++y)
			for(int z=z2;z>z1;--z)
				if(Map.Get(x,y,z)==3)
				{
					Map.Set(x,y,z+1, TestMode?5:GenerateDynamics(x,y));
					break;
				}
}
Example #7
0
void RDSEED::DiscardBytes(size_t n)
{
	// RoundUpToMultipleOf is used because a full word is read, and its cheaper
	//   to discard full words. There's no sense in dealing with tail bytes.
	CRYPTOPP_ASSERT(HasRDSEED());
#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32
	FixedSizeSecBlock<word64, 16> discard;
	n = RoundUpToMultipleOf(n, sizeof(word64));
#else
	FixedSizeSecBlock<word32, 16> discard;
	n = RoundUpToMultipleOf(n, sizeof(word32));
#endif

	size_t count = STDMIN(n, discard.SizeInBytes());
	while (count)
	{
		GenerateBlock(discard.BytePtr(), count);
		n -= count;
		count = STDMIN(n, discard.SizeInBytes());
	}
}
Example #8
0
Void WINAPI DecryptMovie(const PBYTE pbMovieSeed, const PBYTE pbSeed, DWORD dwSeedLength, PBYTE pbBuffer, DWORD dwBufferSize)
{
    static const DWORD dwKeyLength = 0x10000;
    BYTE key[dwKeyLength], pbRC4Table[256], pbRC4Key[256];

    if (dwSeedLength)
    {
        for (unsigned long i = 0; i != 256; i++)
        {
            pbRC4Key[i] = pbMovieSeed[i] ^ pbSeed[i % dwSeedLength];
        }
    }

    InitRC4Table(pbRC4Table, pbRC4Key);
    GenerateBlock(key, sizeof(key), pbRC4Table, sizeof(pbRC4Table));

    for (unsigned long i = 0; i != dwBufferSize; i++)
    {
        pbBuffer[i] ^= key[i % dwKeyLength];
    }
}
Example #9
0
byte NonblockingRng::GenerateByte()
{
	byte b;
	GenerateBlock(&b, 1);
	return b;
}
Example #10
0
/* creates and filles and chunk spezified with its origin
 * adds the chunk to the map
 */
chunk* createChunk(int x, int y, int z)
{
	int Index;
	int i = findVoidEntry();
	Map.pChunkArray[i] = new chunk;
	Map.pChunkArray[i]->x0 = x;
	Map.pChunkArray[i]->y0 = y;
	Map.pChunkArray[i]->z0 = z;
	for(int ix = 0; ix < ChunkLength; ix++)
		for(int iy = 0; iy < ChunkLength; iy++)
			for(int iz = 0; iz < ChunkLength; iz++)
				Map.pChunkArray[i]->block[abs(iz) + abs(ix)*ChunkLength + abs(iy)*ChunkLength*ChunkLength]=GenerateBlock(x+ix,y+iy,z+iz); 
	for(int ix = 0; ix < ChunkLength; ix++)
		for(int iy = 0; iy < ChunkLength; iy++)
			for(int iz = 0; iz < ChunkLength; iz++)
			{
				Index = abs(iz) + abs(ix)*ChunkLength + abs(iy)*ChunkLength*ChunkLength;
				if(!Map.pChunkArray[i]->block[Index] && GetBlock(ix,iy,iz-1)==3)//Map.pChunkArray[i]->block[Index-1])
				{
					Map.pChunkArray[i]->block[Index]=GenerateDynamics(x+ix,y+iy);
					break;
				}
			}
	return Map.pChunkArray[i];
}