int _tmain(int argc, _TCHAR* argv[]) { waveform = 0; freq = 32.65f; pulseWidth = 0; cutoff = 65; resonance = 30; generate_samples(carrier); waveform = 0; freq = 5000.f; pulseWidth = 100; cutoff = 50; resonance = 0; generate_samples(modulator); for(int t = 0; t < MAX_SAMPLES; t++) { // carrier[t] = carrier[t] * modulator[t] >> 14; } FILE *file; file = fopen("Output.raw", "wb"); if (file == NULL) { // std::cout << "File cannot be opened\n"; return 1; } fwrite(carrier, 2, MAX_SAMPLES, file); fclose(file); }
void SampleGeneratorBase::generate_samples( const size_t sample_count, SampleAccumulationBuffer& buffer, IAbortSwitch& abort_switch) { assert(sample_count > 0); clear_keep_memory(m_samples); m_samples.reserve(sample_count); size_t stored_sample_count = 0; while (stored_sample_count < sample_count) { stored_sample_count += generate_samples(m_sequence_index, m_samples); ++m_sequence_index; if (++m_current_batch_size == SampleBatchSize) { m_current_batch_size = 0; m_sequence_index += m_stride; if (abort_switch.is_aborted()) break; } } if (stored_sample_count > 0) buffer.store_samples(stored_sample_count, &m_samples[0]); }
void mage_hts_engine_impl::do_synthesize() { setup(); int time=0; int dur=0; for(label_sequence::iterator label_iter=input->lbegin();label_iter!=input->lend();++label_iter) { label_iter->set_time(time); generate_parameters(*label_iter); dur=mage->getDuration()*MAGE::defaultFrameRate; label_iter->set_duration(dur); time+=dur; generate_samples(*label_iter); if(output->is_stopped()) return; } }
PureRandom::PureRandom(const int num) : Sampler(num) { generate_samples(); }
int main(int argc, char **argv) { key_data key; int inc = 10; int num_trials = 1; // Initialize the microblaze platform... init_platform(); // Set up the attack incremement if (inc > 0) { inc = 1 << inc; } printf("\nStudy increment: %d", inc); // Display the algorithm. printf("\nUsing algorithm \"%s\"", alg_name()); printf("\nAttacking key \"%s\"", argv[1]); // Display the number of trials... if (num_trials != 1) { printf("\nNumber of trials: %d", num_trials); } /* else if (out_file) printf("\nOutputting to file: %s", out_file); else if (in_file) printf("\nReading from file: %s", in_file); */ #ifdef NONE_AES printf("\nAttacking NONE_AES_CORE implementation"); #elif defined(SMALL_AES) printf("\nAttacking SMALL_AES_CORE implementation"); #else printf("\nAttacking traditional AES_CORE implementation"); #endif #ifdef DECRYPT_MODE printf("\nDECRYPT MODE"); #else printf("\nENCRYPT MODE"); #endif cache_evict_init(); int * results = malloc(num_trials * sizeof(int)); timing_pair * buffer = malloc(BUF_SIZE * sizeof(timing_pair)); timing_data * data = malloc(sizeof(timing_data)); if (data == 0x0) { printf("Data couldn't allocate.\n"); return; } if (buffer == 0x0) { printf("Buffer couldn't allocate.\n"); return; } FILE * in; //if (!USE_RANDOM_KEY) { printf("Initializing random key...\n"); re_key(&key, argv[1]); } fflush(stdout); /* if (out_file) { output_timings(out_file, buffer, inc, &key); return 1; } if (in_file) { char open_type = 'r'; in = fopen(in_file, &open_type); if (in == NULL) { printf("\nCould not open file: %s", in_file); return -1; } } */ int round, i; for (round = 1; round <= num_trials; round++) { printf("\nBeginning Attack #%d\n", round); init_data(data); //if (USE_RANDOM_KEY) // reseed with a random key re_key(&key, "/dev/random"); long long num_studies = 0; double clip_time = 0; int success = 0; long long max = MAX_STUDY; while (num_studies < max && !success) { printf("num_studies = %d\n", num_studies); int offset = num_studies % BUF_SIZE; if (inc > BUF_SIZE) { int read = 0; int num_read = BUF_SIZE; while (read < inc) { //printf("read = %d\n", read); generate_samples(buffer, &key); printf("buffer address %x:\n", buffer); printf("data address = %x\n", data); clip_time = calculate_clip_time(buffer, num_read); for (i = 0; i < BUF_SIZE && read < inc; i++) { //printf("i = %d\n", i); if (buffer[offset + i].time < clip_time) record_timing(data, &buffer[offset + i]); read++; } } } else { printf("inc <= BUF_SIZE\n"); if (offset == 0) { int num_read = BUF_SIZE; //if (!in_file) generate_samples(buffer, &key); printf("generate_samples done\n"); /*else { num_read = fread(buffer, sizeof(timing_pair), BUF_SIZE, in); if (num_read < BUF_SIZE) max = num_studies + num_read; printf("\nRead in %d samples ", num_read); }*/ clip_time = calculate_clip_time(buffer, num_read); printf("clip_time done\n"); } for (i = 0; i < inc; i++) printf("i (inc) = %d\n", i); if (buffer[offset + i].time < clip_time) record_timing(data, &buffer[offset + i]); } num_studies += inc; printf("\nchecking data!\n"); if (check_data(data, &key)) { printf( "\nKey recovered after studying %lld samples (< 2^%d)\n", num_studies, bound(num_studies)); success = 1; } else printf("\nNo success after studying %d samples", num_studies); } if (!success) printf("Attack failed after %d encryptions", num_studies); else { int j = round - 1; while (j > 0 && results[j - 1] > num_studies) { results[j] = results[j - 1]; j--; } results[j] = num_studies; printf("\nResults: "); int total = 0; for (j = 0; j < round; j++) { printf(" %d ", results[j]); total += results[j]; } printf("\nMin: %d", results[0]); printf("\nMax: %d", results[round - 1]); printf("\nMed: %d", results[round / 2]); printf("\nMean: %.2f", ((double) total) / round); } } // Clean up and terminate... cleanup_platform(); }
Regular::Regular(const int num) : Sampler(num) { generate_samples(); }
Regular::Regular(const Regular& u) : Sampler(u) { generate_samples(); }
//copy constructor Hammersley::Hammersley(const Hammersley& h) : Sampler(h) { generate_samples(); }
MultiJittered::MultiJittered(const int num_samples, const int m) : Sampler(num_samples, m) { generate_samples(); }
NRooks::NRooks(const NRooks& nr) : Sampler(nr) { generate_samples(); }
MultiJittered::MultiJittered(unsigned long num_samples): Sampler(num_samples) { generate_samples(); }
MultiJittered::MultiJittered(unsigned long num_samples, const int m): Sampler(num_samples, m) { generate_samples(); }
const SampleBundle2D& Hammersley2D::get_next() { if ( samples_.empty() ) generate_samples(); return samples_; }
PureRandom::PureRandom(const PureRandom& r) : Sampler(r) { generate_samples(); }
const SampleBundle2D& NRooks2D::get_next() { samples_.clear(); generate_samples(); return samples_; }
NRooks::NRooks(const int num_samples, const int m) : Sampler(num_samples, m) { generate_samples(); }
Jittered::Jittered(const Jittered& js) : Sampler(js) { generate_samples(); }
MultiJittered::MultiJittered(const int num_samples) : Sampler(num_samples) { // count = 0; // jump = 0; generate_samples(); }
Jittered::Jittered(const int num_samples) : Sampler(num_samples) { generate_samples(); }
MultiJittered::MultiJittered(const MultiJittered& mjs) : Sampler(mjs) { generate_samples(); }
//constructor Hammersley::Hammersley(const int num) : Sampler(num) { generate_samples(); }