void CWaveReader::Seek(int sampleNumber) { // Go back by size of smoothing buffer int startAtSampleNumber = sampleNumber - (_smoothingPeriod+1); if (startAtSampleNumber<0) startAtSampleNumber = 0; // Seek to sample SeekRaw(startAtSampleNumber); // Reset and refill the smoothing buffer memset(_smoothingBuffer, 0, _smoothingPeriod * sizeof(int)); _smoothingBufferPos=0; _smoothingBufferTotal=0; while (CurrentPosition() < sampleNumber) { if (!NextSample()) break; } }
void SingleSampler::DoSamples( ShadeOutput* pOut, SamplingCallback* cb, ShadeContext* sc, MASK pMask ) { n = 0; if ( pMask ) copyMask( mask, pMask ); else setMask( mask, ALL_ONES ); float sampleScale; Point2 sample; NextSample( &sample, &sampleScale ); // c.r = c.g = c.b = t.r = t.g = t.b = 0; pOut->Reset(); if ( sampleInMask( sample, mask, sc->globContext->fieldRender ) ) cb->SampleAtOffset( pOut, sample, sampleScale ); else cb->SampleAtOffset( pOut, sample, sampleScale ); }
MAINTYPE main() { char record[10], fname[20] ; int i, ecg[2], delay, recNum ; WFDB_Siginfo s[2] ; WFDB_Anninfo a[2] ; WFDB_Annotation annot ; unsigned char byte ; FILE *newAnn0, *newAnn1 ; long SampleCount = 0, lTemp, DetectionTime ; int beatType, beatMatch ; // Set up path to database directory setwfdb(ECG_DB_PATH) ; // Analyze all 48 MIT/BIH Records. for(recNum = 0; recNum < REC_COUNT; ++recNum) { sprintf(record,"%d",Records[recNum]) ; printf("Record %d\n",Records[recNum]) ; // Open a 2 channel record if(isigopen(record,s,2) < 1) { printf("Couldn't open %s\n",record) ; return ; } ADCZero = s[0].adczero ; ADCUnit = s[0].gain ; InputFileSampleFrequency = sampfreq(record) ; // Setup for output annotations a[0].name = "atest"; a[0].stat = WFDB_WRITE ; if(annopen(record, a, 1) < 0) return ; // Initialize sampling frequency adjustment. NextSample(ecg,2,InputFileSampleFrequency,SAMPLE_RATE,1) ; // Initialize beat detection and classification. ResetBDAC() ; SampleCount = 0 ; // Read data from MIT/BIH file until there is none left. while(NextSample(ecg,2,InputFileSampleFrequency,SAMPLE_RATE,0) >= 0) { ++SampleCount ; // Set baseline to 0 and resolution to 5 mV/lsb (200 units/mV) lTemp = ecg[0]-ADCZero ; lTemp *= 200 ; lTemp /= ADCUnit ; ecg[0] = lTemp ; // Pass sample to beat detection and classification. delay = BeatDetectAndClassify(ecg[0], &beatType, &beatMatch) ; // If a beat was detected, annotate the beat location // and type. if(delay != 0) { DetectionTime = SampleCount - delay ; // Convert sample count to input file sample // rate. DetectionTime *= InputFileSampleFrequency ; DetectionTime /= SAMPLE_RATE ; annot.time = DetectionTime ; annot.anntyp = beatType ; annot.aux = NULL ; putann(0,&annot) ; } } // Reset database after record is done. wfdbquit() ; #if 0 /* This code is obsolete. The annotation files are always written into "<record>.ate" in the current directory. They do not need to be copied in order to be read by bxbep, if the WFDB path includes both the current current directory and the one containing the .atr reference annotation files. */ // Copy "atest.<record>" to "<record>.ate" for future ascess. // (This is necessary for PC files) sprintf(fname,"%s.ate",record) ; newAnn0 = fopen(fname,"rb") ; sprintf(fname,"%s%s.ate",ECG_DB_PATH,record) ; newAnn1 = fopen(fname,"wb") ; // Copy byte image of annotation file in this // directory to a correctly named file in the // database directory. while(fread(&byte,sizeof(char),1,newAnn0) == 1) fwrite(&byte,sizeof(char),1,newAnn1) ; fclose(newAnn0) ; fclose(newAnn1) ; #endif } }