Exemplo n.º 1
0
 void Compact()
 {
    Transition *ptr = mX.begin();
    Transition *end = mX.end();
    
    if (ptr == end) return;
    
    std::sort(ptr, end);
    Transition *dest = ptr;
    ptr++;
    
    for(; ptr < end; ptr++)
    {
       if (dest->x == ptr->x)
       {
          dest->val += ptr->val;
       }
       else
       {
          ++dest;
          if (dest != ptr)
             *dest = *ptr;
       }
    }
    
    mX.resize(dest - mX.begin() + 1);
    
 }
Exemplo n.º 2
0
		bool loadOggSample(OggVorbis_File &oggFile, QuickVec<unsigned char> &outBuffer, int *channels, int *bitsPerSample, int* outSampleRate)
		{
			// 0 for Little-Endian, 1 for Big-Endian
			#ifdef HXCPP_BIG_ENDIAN
			#define BUFFER_READ_TYPE 1
			#else
			#define BUFFER_READ_TYPE 0
			#endif
			
			int bitStream;
			long bytes = 1;
			int totalBytes = 0;
			
			#define BUFFER_SIZE 32768
			
			//Get the file information
			//vorbis data
			vorbis_info *pInfo = ov_info(&oggFile, -1);            
			//Make sure this is a valid file
			if (pInfo == NULL)
			{
				LOG_SOUND("FAILED TO READ OGG SOUND INFO, IS THIS EVEN AN OGG FILE?\n");
				return false;
			}
			
			//The number of channels
			*channels = pInfo->channels;
			//default to 16? todo 
			*bitsPerSample = 16;
			//Return the same rate as well
			*outSampleRate = pInfo->rate;
			
			// Seem to need four times the read PCM total
			outBuffer.resize(ov_pcm_total(&oggFile, -1)*4);
			
			while (bytes > 0)
			{
				if (outBuffer.size() < totalBytes + BUFFER_SIZE)
				{
					outBuffer.resize(totalBytes + BUFFER_SIZE);
				}
				// Read up to a buffer's worth of decoded sound data
				bytes = ov_read(&oggFile, (char*)outBuffer.begin() + totalBytes, BUFFER_SIZE, BUFFER_READ_TYPE, 2, 1, &bitStream);
				totalBytes += bytes;
			}
			
			outBuffer.resize(totalBytes);
			ov_clear(&oggFile);
			
			#undef BUFFER_SIZE
			#undef BUFFER_READ_TYPE
			
			return true;
		}