#include #include #include #include #include #include std::vector data; generator generator() { constexpr unsigned P = 256; constexpr unsigned voice_pitch = 110; double k[P]={0}, d[P]={0}, bp[P+1]={0}; double factor=0, gain=0, frame_length = 0.02, sampling_period = 1. / 96000; unsigned offset=0, count=0, index=0, Num=P; for(;;) { char Buf[4096]; if(!std::fgets(Buf, sizeof Buf, stdin)) break; std::sscanf(Buf, " nCoefficients = %d", &Num); std::sscanf(Buf, "dx = %lf", &frame_length); std::sscanf(Buf, "samplingPeriod = %lf", &sampling_period); assert(Num <= P); if(std::sscanf(Buf, "%*s [%d] = %lf\n", &index, &factor) == 2) { k[index-1] = factor; } if(std::sscanf(Buf, " gain = %lf", &gain) == 1) { unsigned framemax = unsigned(frame_length/sampling_period); for(unsigned frame=0; frame < framemax; ++frame) { double w = count / double(1/sampling_period/voice_pitch); double f = (-0.3 + drand48()*0.6)*0.5 + std::exp2(w) - 1/(1+w); if(++count >= unsigned(1./sampling_period/voice_pitch)) { count=0; } d[offset%P] = f; double sum = f; for(unsigned j=0; jcallback((float*)stream, len/sizeof(float)); }; auto dev = SDL_OpenAudioDevice(nullptr, 0, &spec, &spec, 0); SDL_PauseAudioDevice(dev, 0); } std::size_t pos = 0; void callback(float* target, int num_samples) { for(int n=0; n