Exemplo n.º 1
0
void VcfFile::printVCFHeader(IFILE oFile) {
  for(int i=0; i < getMetaCount(); ++i) {
    ifprintf(oFile,"##%s=%s\n",getMetaKey(i).c_str(), getMetaValue(i, "<na>").c_str());
  }
  ifprintf(oFile,"#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO");
  if ( ( getSampleCount() > 0 ) && ( !bSiteOnly ) ) {
    ifprintf(oFile,"\tFORMAT");
    for(int i=0; i < getSampleCount(); ++i) {
      ifprintf(oFile,"\t%s",vpVcfInds[i]->sIndID.c_str());
    }
  }
  ifprintf(oFile,"\n");
}
Exemplo n.º 2
0
static void mergeElementaryIntervals(
    uint *dstKey,
    uint *dstVal,
    uint *srcKey,
    uint *srcVal,
    uint *limitsA,
    uint *limitsB,
    uint stride,
    uint N,
    uint sortDir
){
    uint lastSegmentElements = N % (2 * stride);
    uint          mergePairs = (lastSegmentElements > stride) ? getSampleCount(N) : (N - lastSegmentElements) / SAMPLE_STRIDE;

    for(uint pos = 0; pos < mergePairs; pos++){
        uint           i = pos & ( (2 * stride) / SAMPLE_STRIDE - 1 );
        uint segmentBase = (pos - i) * SAMPLE_STRIDE;

        const uint lenA = stride;
        const uint lenB = umin(stride, N - segmentBase - stride);
        const uint   nA = stride / SAMPLE_STRIDE;
        const uint   nB = getSampleCount(lenB);
        const uint    n = nA + nB;

        const uint   startPosA = limitsA[pos];
        const uint     endPosA = (i + 1 < n) ? limitsA[pos + 1] : lenA;
        const uint   startPosB = limitsB[pos];
        const uint     endPosB = (i + 1 < n) ? limitsB[pos + 1] : lenB;
        const uint startPosDst = startPosA + startPosB;

        assert( startPosA <= endPosA && endPosA <= lenA);
        assert( startPosB <= endPosB && endPosB <= lenB);
        assert( (endPosA - startPosA) <= SAMPLE_STRIDE);
        assert( (endPosB - startPosB) <= SAMPLE_STRIDE);

        merge(
            dstKey  + segmentBase + startPosDst,
            dstVal  + segmentBase + startPosDst,
            (srcKey + segmentBase +      0) + startPosA,
            (srcVal + segmentBase +      0) + startPosA,
            (srcKey + segmentBase + stride) + startPosB,
            (srcVal + segmentBase + stride) + startPosB,
            endPosA - startPosA,
            endPosB - startPosB,
            sortDir
        );
    }
}
Exemplo n.º 3
0
////////////////////////////////////////////////////////////////////////////////
// Merge step 1: find sample ranks in each segment
////////////////////////////////////////////////////////////////////////////////
static void generateSampleRanks(
    uint *ranksA,
    uint *ranksB,
    uint *srcKey,
    uint stride,
    uint N,
    uint sortDir
){
    uint lastSegmentElements = N % (2 * stride);
    uint         sampleCount = (lastSegmentElements > stride) ? (N + 2 * stride - lastSegmentElements) / (2 * SAMPLE_STRIDE) : (N - lastSegmentElements) / (2 * SAMPLE_STRIDE);

    for(uint pos = 0; pos < sampleCount; pos++){
        const uint           i = pos & ( (stride / SAMPLE_STRIDE) - 1 );
        const uint segmentBase = (pos - i) * (2 * SAMPLE_STRIDE);

        const uint lenA = stride;
        const uint lenB = umin(stride, N - segmentBase - stride);
        const uint   nA = stride / SAMPLE_STRIDE;
        const uint   nB = getSampleCount(lenB);

        if(i < nA){
            ranksA[(segmentBase +      0) / SAMPLE_STRIDE + i] = i * SAMPLE_STRIDE;
            ranksB[(segmentBase +      0) / SAMPLE_STRIDE + i] = binarySearchExclusive(srcKey[segmentBase + i * SAMPLE_STRIDE], srcKey + segmentBase + stride, lenB, sortDir);
        }

        if(i < nB){
            ranksB[(segmentBase + stride) / SAMPLE_STRIDE + i] = i * SAMPLE_STRIDE;
            ranksA[(segmentBase + stride) / SAMPLE_STRIDE + i] = binarySearchInclusive(srcKey[segmentBase + stride + i * SAMPLE_STRIDE], srcKey + segmentBase, lenA, sortDir);
        }
    }
}
Exemplo n.º 4
0
////////////////////////////////////////////////////////////////////////////////
// Merge step 2: merge ranks and indices to derive elementary intervals
////////////////////////////////////////////////////////////////////////////////
static void mergeRanksAndIndices(
    uint *limits,
    uint *ranks,
    uint stride,
    uint N
){
    uint lastSegmentElements = N % (2 * stride);
    uint         sampleCount = (lastSegmentElements > stride) ? (N + 2 * stride - lastSegmentElements) / (2 * SAMPLE_STRIDE) : (N - lastSegmentElements) / (2 * SAMPLE_STRIDE);

    for(uint pos = 0; pos < sampleCount; pos++){
        const uint           i = pos & ( (stride / SAMPLE_STRIDE) - 1 );
        const uint segmentBase = (pos - i) * (2 * SAMPLE_STRIDE);

        const uint lenA = stride;
        const uint lenB = umin(stride, N - segmentBase - stride);
        const uint   nA = stride / SAMPLE_STRIDE;
        const uint   nB = getSampleCount(lenB);

        if(i < nA){
            uint dstPosA = binarySearchExclusive(ranks[(segmentBase + 0) / SAMPLE_STRIDE + i], ranks + (segmentBase + stride) / SAMPLE_STRIDE, nB, 1) + i;
            assert( dstPosA < nA + nB );
            limits[(segmentBase / SAMPLE_STRIDE) + dstPosA] = ranks[(segmentBase + 0) / SAMPLE_STRIDE + i];
        }

        if(i < nB){
            uint dstPosA = binarySearchInclusive(ranks[(segmentBase + stride) / SAMPLE_STRIDE + i], ranks + (segmentBase + 0) / SAMPLE_STRIDE, nA, 1) + i;
            assert( dstPosA < nA + nB );
            limits[(segmentBase / SAMPLE_STRIDE) + dstPosA] = ranks[(segmentBase + stride) / SAMPLE_STRIDE + i];
        }
    }
}
Exemplo n.º 5
0
love::sound::SoundData *RecordingDevice::getData()
{
	if (!isRecording())
		return nullptr;

	int samples = getSampleCount();
	if (samples == 0)
		return nullptr;

	love::sound::SoundData *soundData = soundInstance()->newSoundData(samples, sampleRate, bitDepth, channels);

	alcCaptureSamples(device, soundData->getData(), samples);

	return soundData;
}
Exemplo n.º 6
0
void VcfFile::printBEDHeader(IFILE oBedFile, IFILE oFamFile) {
  for(int i=0; i < getSampleCount(); ++i) {
    if ( vpVcfInds[i]->sFamID.Length() == 0 ) {
      ifprintf(oFamFile,"%s",vpVcfInds[i]->sIndID.c_str());
    }
    else {
      ifprintf(oFamFile,"%s",vpVcfInds[i]->sFamID.c_str());
    }

    ifprintf(oFamFile,"\t%s",vpVcfInds[i]->sIndID.c_str());

    if ( vpVcfInds[i]->sFatID.Length() == 0 ) {
      ifprintf(oFamFile,"\t0");
    }
    else {
      ifprintf(oFamFile,"%s",vpVcfInds[i]->sFatID.c_str());
    }

    if ( vpVcfInds[i]->sMotID.Length() == 0 ) {
      ifprintf(oFamFile,"\t0");
    }
    else {
      ifprintf(oFamFile,"\t%s",vpVcfInds[i]->sMotID.c_str());
    }

    switch( vpVcfInds[i]->gender ) {
    case VcfInd::UNKNOWN:
      ifprintf(oFamFile,"\t0");
      break;
    case VcfInd::MALE:
      ifprintf(oFamFile,"\t1");
      break;
    case VcfInd::FEMALE:
      ifprintf(oFamFile,"\t2");
      break;
    default:
      throw VcfFileException("Unrecognized value for gender");
      break;
    }
    ifprintf(oFamFile,"\t-9\n");
  }

  char magicNumbers[3] = {0x6c,0x1b,0x01};
  oBedFile->ifwrite(magicNumbers, 3);
}
Exemplo n.º 7
0
    Mahalanobis TogersonMetricLearner::learnMetric() {

        dim = getVectorDim();
        sampleCount = getSampleCount();


        int iIdx = selectI();

        mat B = generateB(iIdx);
        mat X = generateX();
        mat Y = generateY(B);
        mat Z = generateZ(X, Y);
        mat A = Z.t() * Z;

        // normalize it for convenience
        A = 1 / A(0, 0) * A;

        return Mahalanobis(A);

    }
Exemplo n.º 8
0
bool SkiaWindow::attachGL()
{
  if (!m_glCtx) {
    try {
      auto ctx = new GLContextSkia<GLContextWGL>(handle());
      m_stencilBits = ctx->getStencilBits();
      m_sampleCount = ctx->getSampleCount();

      m_glCtx.reset(ctx);
      m_grCtx.reset(GrContext::Create(kOpenGL_GrBackend,
                                      (GrBackendContext)m_glCtx->gl()));
    }
    catch (const std::exception& ex) {
      LOG("Cannot create GL context: %s\n", ex.what());
      detachGL();
    }
  }

  if (m_glCtx)
    return true;
  else
    return false;
}
Exemplo n.º 9
0
int WavReader::decodeADPCM(unsigned max_samples)
{
    unsigned sample_count = getSampleCount();
    unsigned samples_per_block = (m_BlockSize - m_Channels * 4) * (m_Channels ^ 3) + 1;

    if (sample_count > max_samples)
        sample_count = max_samples;

    unsigned sample = 0;
    while (sample < sample_count)
    {
        unsigned this_block_adpcm_samples = samples_per_block;
        int this_block_pcm_samples = samples_per_block;

        if (this_block_adpcm_samples > sample_count)
        {
            this_block_adpcm_samples = ((sample_count + 6) & ~7) + 1;
            this_block_pcm_samples = sample_count;
        }

        // Add to out-wav
        size_t ofidx = m_Dest.size();
        m_Dest.resize(m_Dest.size() + this_block_pcm_samples * m_Channels * 2);

        adpcm_decode_block(reinterpret_cast<int16_t*>(&m_Dest[ofidx]), &m_Source[m_SourceOffset], m_BlockSize, m_Channels);
        /*
        if (adpcm_decode_block(reinterpret_cast<int16_t*>(&dest[ofidx]), sourcep, block_size, num_channels) != this_block_adpcm_samples) {
            LogWarn() << "adpcm_decode_block() failed";
            return false;
        }
         */
        m_SourceOffset += m_BlockSize;
        sample += this_block_pcm_samples;
    }

    return sample;
}
Exemplo n.º 10
0
    void InfTheoMetricLearner::computeConstraints() {

        simConstraints.flush();
        disSimConstraints.flush();

        int sampleCount = getSampleCount();

        for(int i = 0; i < sampleCount; ++i) {

            vec x1 = getX1(i);
            vec x2 = getX2(i);

            double dist = getSampleDistance(i);
            if(dist <= simBorder) {
                simConstraints.addConstraint(x1, x2, simBorder);
            } else if(dist >= disSimBorder) {
                disSimConstraints.addConstraint(x1, x2, disSimBorder);
            } else {
                // no additional constraint
            }

        }

    }
Exemplo n.º 11
0
soundDataBuffer* sound_DecodeOggVorbis(struct OggVorbisDecoderState* decoder, size_t bufferSize)
{
	size_t		size = 0;
#ifndef WZ_NOSOUND
	int		result;
#endif

	soundDataBuffer* buffer;

	ASSERT(decoder != NULL, "NULL decoder passed!");

#ifndef WZ_NOSOUND
	if (decoder->allowSeeking)
	{
		unsigned int sampleCount = getSampleCount(decoder);

		unsigned int sizeEstimate = sampleCount * decoder->VorbisInfo->channels * 2;

		if (((bufferSize == 0) || (bufferSize > sizeEstimate)) && (sizeEstimate != 0))
		{
			bufferSize = (sampleCount - getCurrentSample(decoder)) * decoder->VorbisInfo->channels * 2;
		}
	}

	// If we can't seek nor receive any suggested size for our buffer, just quit
	if (bufferSize == 0)
	{
		debug(LOG_ERROR, "can't find a proper buffer size");
		return NULL;
	}
#else
	bufferSize = 0;
#endif

	buffer = malloc(bufferSize + sizeof(soundDataBuffer));
	if (buffer == NULL)
	{
		debug(LOG_ERROR, "couldn't allocate memory (%lu bytes requested)", (unsigned long) bufferSize + sizeof(soundDataBuffer));
		return NULL;
	}

	buffer->data = (char*)(buffer + 1);
	buffer->bufferSize = bufferSize;
	buffer->bitsPerSample = 16;

#ifndef WZ_NOSOUND
	buffer->channelCount = decoder->VorbisInfo->channels;
	buffer->frequency = decoder->VorbisInfo->rate;

	// Decode PCM data into the buffer until there is nothing to decode left
	do
	{
		// Decode
		int section;
		result = ov_read(&decoder->oggVorbis_stream, &buffer->data[size], bufferSize - size, OGG_ENDIAN, 2, 1, &section);

		if (result < 0)
		{
			debug(LOG_ERROR, "error decoding from OggVorbis file; errorcode from ov_read: %d", result);
			free(buffer);
			return NULL;
		}
		else
		{
			size += result;
		}

	} while ((result != 0 && size < bufferSize));
#endif

	buffer->size = size;

	return buffer;
}
Exemplo n.º 12
0
double TSoundTrack::getMinPressure(TSound::Channel chan) const {
  return getMinPressure(0, (TINT32)(getSampleCount() - 1), chan);
}
Exemplo n.º 13
0
void TSoundTrack::getMinMaxPressure(TSound::Channel chan, double &min,
                                    double &max) const {
  getMinMaxPressure(0, (TINT32)(getSampleCount() - 1), chan, min, max);
}
Exemplo n.º 14
0
////////////////////////////////////////////////////////////////////////////////
// Interface function
////////////////////////////////////////////////////////////////////////////////
extern "C" void mergeSortHost(
    uint *dstKey,
    uint *dstVal,
    uint *bufKey,
    uint *bufVal,
    uint *srcKey,
    uint *srcVal,
    uint N,
    uint sortDir
){
    uint *ikey, *ival, *okey, *oval;
    uint stageCount = 0;
    for(uint stride = SHARED_SIZE_LIMIT; stride < N; stride <<= 1, stageCount++);
    if(stageCount & 1){
        ikey = bufKey;
        ival = bufVal;
        okey = dstKey;
        oval = dstVal;
    }else{
        ikey = dstKey;
        ival = dstVal;
        okey = bufKey;
        oval = bufVal;
    }

    printf("Bottom-level sort...\n");
        memcpy(ikey, srcKey, N * sizeof(uint));
        memcpy(ival, srcVal, N * sizeof(uint));
        for(uint pos = 0; pos < N; pos += SHARED_SIZE_LIMIT)
           bubbleSort(ikey + pos, ival + pos, umin(SHARED_SIZE_LIMIT, N - pos), sortDir);

    printf("Merge...\n");
        uint  *ranksA = (uint *)malloc( getSampleCount(N) * sizeof(uint) );
        uint  *ranksB = (uint *)malloc( getSampleCount(N) * sizeof(uint) );
        uint *limitsA = (uint *)malloc( getSampleCount(N) * sizeof(uint) );
        uint *limitsB = (uint *)malloc( getSampleCount(N) * sizeof(uint) );
        memset(ranksA,  0xFF, getSampleCount(N) * sizeof(uint));
        memset(ranksB,  0xFF, getSampleCount(N) * sizeof(uint));
        memset(limitsA, 0xFF, getSampleCount(N) * sizeof(uint));
        memset(limitsB, 0xFF, getSampleCount(N) * sizeof(uint));

        for(uint stride = SHARED_SIZE_LIMIT; stride < N; stride <<= 1){
            uint lastSegmentElements = N % (2 * stride);

            //Find sample ranks and prepare for limiters merge
            generateSampleRanks(ranksA, ranksB, ikey, stride, N, sortDir);

            //Merge ranks and indices
            mergeRanksAndIndices(limitsA, ranksA, stride, N);
            mergeRanksAndIndices(limitsB, ranksB, stride, N);

            //Merge elementary intervals
            mergeElementaryIntervals(okey, oval, ikey, ival, limitsA, limitsB, stride, N, sortDir);

            if( lastSegmentElements <= stride ) {
                //Last merge segment consists of a single array which just needs to be passed through
                memcpy(okey + (N - lastSegmentElements), ikey + (N - lastSegmentElements), lastSegmentElements * sizeof(uint));
                memcpy(oval + (N - lastSegmentElements), ival + (N - lastSegmentElements), lastSegmentElements * sizeof(uint));
            }

            uint *t;
            t = ikey; ikey = okey; okey = t;
            t = ival; ival = oval; oval = t;
        }

        free(limitsB);
        free(limitsA);
        free(ranksB);
        free(ranksA);
}