// --------------------------------------------------------------------------- // synthesizeNext // --------------------------------------------------------------------------- //! Synthesize next block of samples of the partials. The synthesizer //! will resize the inner buffer as necessary. Previous contents of the buffer //! are overwritten. //! //! \param sample Number of samples to synthesize. //! \return Nothing. //! \post Internal state of synthesizer changes - it is ready to synthesize //! next block of samples starting at 'previous count of samples' + samples. void RealTimeSynthesizer::synthesizeNext( int samples ) noexcept { //TODO: check processedSamples overflow processedSamples += samples;// for performance reason this is computed at the beginning PartialStruct *partial; // prepare buffer for new data if (buffer->capacity() < samples) buffer->reserve(samples); memset(buffer->data(), 0, samples * sizeof(decltype(buffer->data()))); // process partials being processed int size = partialsBeingProcessed.size(); for (int i = 0; i < size; i++) { partial = partialsBeingProcessed.front(); synthesize( *partial, buffer->data(), samples ); if ( partial->state.lastBreakpointIdx < partial->numBreakpoints - 1) partialsBeingProcessed.push( partial ); partialsBeingProcessed.pop(); } // partials to be processed int partialSize = partials.size(); for (; partialIdx < partialSize; partialIdx++) { partial = &(partials[partialIdx]); // setup partial for synthesis partial->state.currentSamp = index_type( (partial->startTime * m_srateHz) + 0.5 ); // cheap rounding if (partial->state.currentSamp > processedSamples) break; partial->state.lastBreakpointIdx = PartialStruct::NoBreakpointProcessed; partial->state.envelope = partial->breakpoints[0].second; partial->state.breakpointFinished = true; // cache the previous frequency (in Hz) so that it can be used to reset the phase when necessary partial->state.prevFrequency = m_osc.frequencyScaling() * partial->breakpoints[1].second._frequency;// 0 is null breakpoint int sampleCount = processedSamples - partial->state.currentSamp; // how much sample to be processed during this call int sampleDelta = samples - sampleCount; // delta when partial should start synthesize( *partial, buffer->data() + sampleDelta, sampleCount ); if ( partial->state.lastBreakpointIdx < partial->numBreakpoints - 1) partialsBeingProcessed.push(partial); } }
void FaceSynthesisManager::run() { synthesizedImgs.clear(); for (int i=0;i<(int)inputImgs.size();i++) { synthesize(inputImgs.at(i)); synthesizedImgs.push_back(synthesizedImg); } emit FSDone(); }
int main(int argc, char **argv) { struct app app; FILE *txtfp; char buff[MAXBUFLEN]; int ret = 0; if (argc == 1) usage(); /* init */ memset(&app, 0, sizeof(app)); app.sampling_rate = 48000; app.fperiod = -1; app.alpha = -1.0; app.beta = -1.0; app.half_tone = -1.0; app.audio_buff_size = 0; app.uv_threshold = -1.0; app.gv_weight_mgc = -1.0; app.gv_weight_lf0 = -1.0; #ifdef HTS_MELP app.gv_weight_lpf = -1.0; #endif /* HTS_MELP */ app.speed = -1.0; parse_arg(&app, argc, argv); txtfp = (app.txtfn != NULL) ? get_fp(app.txtfn, "rt") : stdin; /* initialize and load */ if (setup(&app) < 0) goto out; /* synthesis */ fgets(buff, MAXBUFLEN - 1, txtfp); if (synthesize(&app, buff) < 0) { fprintf(stderr, "failed to synthesize.\n"); ret = 1; } out: /* cleanup */ cleanup(&app); /* free */ if (app.txtfn != NULL) fclose(txtfp); if (app.logfp != NULL) fclose(app.logfp); return ret; }
int main(int argc, char **argv) { stb_synth_adsr adsr = { 0.005,0.05,0.6,0.25 }; stb_synth_adsr attack = { 0.05,0,1,0.25 }; stb_synth_adsr bell = { 0.001, 0.2,0,0 }; stb_synth_waveform triangle = { 0,0.5,0,0 }; stb_synth_waveform square = { 0,0,1,0 }; stb_synth_waveform sq_tri = { 0,0.25,0.5,0 }; stb_synth_waveform saw = { 0,0,0,1 }; stb_synth_waveform saw2 = { 0,1,0.5,1 }; stb_synth_waveform square_pw= { 0.85,0,1,0 }; stb_synth_waveform weird1 = { 0.1f, 0.3f, 0.15f, 1 }; stb_synth_waveform weird2 = { 0.1f, 0.7f, 0.55f, 1 }; stb_mixhigh_init(20000,0.005, 88200*4); stb_mixlow_global_volume(0.5); // 1/8th second into the future so we have time to synthesize start_time = stb_mixhigh_time() + 44100/8; synthesize(8, 4, 84, 0.4f , 0.9, 0.25 , &bell, &sq_tri, &triangle); synthesize(8, 2, 60, 0.20f, -0.4, 0.95 , &attack, &saw, &saw2); synthesize(4, 2, 36, 0.5f , 0.1, 0.25 , &adsr, &square, NULL); synthesize(8, 4, 91, 0.4f , -0.9, 0.10 , &bell, &sq_tri, NULL); synthesize(8, 4, 91, 0.4f , -0.9, 0.10 , &bell, &sq_tri, NULL); synthesize(8, 4, 91, 0.4f , -0.9, 0.10 , &bell, &sq_tri, NULL); synthesize(8, 4, 91, 0.4f , -0.9, 0.10 , &bell, &sq_tri, NULL); synthesize(8, 4, 91, 0.4f , -0.9, 0.10 , &bell, &sq_tri, NULL); synthesize(8, 4, 91, 0.4f , -0.9, 0.10 , &bell, &sq_tri, NULL); while (stb_mixlow_num_active()) { stb_mixhigh_step(5000); Sleep(1); } stb_mixhigh_deinit(); return 0; }
void Bonsai::buildAll() { // generate a unique random seed for the whole thing from the name DBG::info("Generate planet '%s'\n", m_name ); int master_seed = 1; for (const char *ch=m_name; *ch; ch++) { master_seed *= (*ch); } // generate random seeds for each step .. this keeps them // somewhat resistant to changes in the algoritms int pally_seed, param_seed, terrain_seed; srand( master_seed ); pally_seed = rand(); terrain_seed = rand(); param_seed = rand(); // Make the palette m_pally.generate( pally_seed ); // synthesize the height data m_hiteData = new float [ HITE_RES * HITE_RES ]; m_terrainColor = new GLubyte [ HITE_RES * HITE_RES * 3 ]; m_terrainNorm = new GLubyte [ HITE_RES * HITE_RES * 3 ]; // Set up params srand( param_seed ); m_params.offs = randUniform( 0.0, 1000.0 ); m_params.base = (int)randUniform( 0, NUM_BASE ); m_params.base_distAmt = randUniform( 0.0, 0.3 ); m_params.base_scale = randUniform( 0.3, 1.0 ); m_params.baseVeg = (int)randUniform( 0, NUM_BASEVEG ); m_params.baseVeg_hite_repeats = (int)randUniform( 1, 5 ); m_params.baseVeg_hite_repeats *= m_params.baseVeg_hite_repeats; m_params.patchVeg = (int)randUniform( 0, NUM_PATCHVEG ); m_params.patchVeg_scale = randUniform( 1.0, 20.0 ); m_params.patchVeg_nscale = randUniform( 0.01, 8.0 ); m_params.patchVeg_nscale *= m_params.patchVeg_nscale; m_params.patchMixMineral = (randUniform() > 0.5)?1:0; m_params.patchVeg_thresh = randUniform( 0.55, 0.85 ); // Decoration m_params.deco = (int)randUniform( 0, NUM_DECORATION ); m_params.decoLavaScale = randUniform( 1.0, 10.0 ); m_params.decoLavaWidth = randUniform( 0.01, 0.1 ); // ============================================= // build textures Luddite::HTexture htexColor; Luddite::HTexture htexNorms; // check if there is cached image data available htexColor = _checkCachedColorImage( "DIF0", m_terrainColor, HITE_RES); if ( (!htexColor.isNull() ) && (_checkCachedHeight( "HITE", m_hiteData, HITE_RES ) )) { DBG::info( "Land '%s' read cached color and height.\n", m_name ); } else { // Synthesize srand( terrain_seed ); // step for tuning/debugging quicker // step=1 for final quality int step = SYNTH_STEP; for (int j=0; j < HITE_RES; j += step) { // status progress( "Generating", j, HITE_RES ); for (int i=0; i < HITE_RES; i += step ) { float ii = (((float)i / (float)HITE_RES) * 2.0) - 1.0; float jj = (((float)j / (float)HITE_RES) * 2.0) - 1.0; // synthesize a texel size_t ndx = (j*HITE_RES)+i; synthesize( ndx, ii, jj ); for (int sj = 0; sj < step; sj++) { for(int si=0; si < step; si++) { if (si || sj) { size_t ndx2 = ((j+sj)*HITE_RES)+(i+si); m_terrainColor[ndx2 * 3 + 0] = m_terrainColor[ndx * 3 + 0]; m_terrainColor[ndx2 * 3 + 1] = m_terrainColor[ndx * 3 + 1]; m_terrainColor[ndx2 * 3 + 2] = m_terrainColor[ndx * 3 + 2]; m_hiteData[ndx2] = m_hiteData[ndx]; } } } } } // Calculate (fake) ambient occlusion for (int j=0; j < HITE_RES; j += 1) { progress( "AmbOccl", j, HITE_RES ); for (int i=0; i < HITE_RES; i += 1 ) { float ambOccl = 0.0f; int c = 0; size_t ndx = (j*HITE_RES)+i; // TODO: gaussian weight for (int ii=-8; ii < 8; ii += 2) { for (int jj=-8; jj < 8; jj += 2) { int i2 = i+ii; int j2 = j+jj; c += 1; float occl = 0.0; if ((i2 >=0) && (i2 < HITE_RES) && (j2 >=0) && (j2 < HITE_RES) ) { size_t ndx2 = (j2*HITE_RES)+i2; occl = m_hiteData[ndx2] - m_hiteData[ndx]; occl = fstep( 0.0, 0.015, occl ); ambOccl += occl; } } } // avg ambOccl /= c; ambOccl = clamp( 1.0-ambOccl, 0.0, 1.0 ); // darken color image (dbg replace) #if 0 m_terrainColor[ndx * 3 + 0] = (int)(ambOccl * 255); m_terrainColor[ndx * 3 + 1] = (int)(ambOccl * 255); m_terrainColor[ndx * 3 + 2] = (int)(ambOccl * 255); #else m_terrainColor[ndx * 3 + 0] *= ambOccl; m_terrainColor[ndx * 3 + 1] *= ambOccl; m_terrainColor[ndx * 3 + 2] *= ambOccl; #endif } } // Cache the height & color data SDL_WM_SetCaption( "[Cache Height/Color] LD19 Jovoc - Discovery", NULL ); _cacheColorImage( "DIF0", m_terrainColor, HITE_RES ); _cacheHeight( "HITE", m_hiteData, HITE_RES ); } // check if there is cached normal data available htexNorms = _checkCachedColorImage( "NRM", m_terrainNorm, HITE_RES); if ( !htexNorms.isNull() ) { DBG::info( "Land '%s' read cached normals.\n", m_name ); } else { // Shitty calc normals -- ideally this should use the // height samples to not soften it but for now do it this // way cause it's easier/faster for (int j=0; j < HITE_RES-1; j++) { progress( "Calc Normals", j, HITE_RES ); for (int i=0; i < HITE_RES-1; i++ ) { PVRTVec3 nrm; size_t ndx = (j*HITE_RES)+i; float a = m_hiteData[ndx]; float b = m_hiteData[ (j*HITE_RES)+(i+1) ]; float c = m_hiteData[ ((j+1)*HITE_RES)+i ]; //float scl = 5.4; float scl = 50.0f; float dy1 = (b - a) * scl; float dy2 = (c - a) * scl; PVRTVec3 n( dy1, dy2, 1.0 - sqrt( dy1*dy1 + dy2*dy2 ) ); n.normalize(); m_terrainNorm[ndx * 3 + 0] = (int)((n.x * 128.0) + 128.0); m_terrainNorm[ndx * 3 + 1] = (int)((n.y * 128.0) + 128.0); m_terrainNorm[ndx * 3 + 2] = (int)((n.z * 128.0) + 128.0); } } // Cache the normal map SDL_WM_SetCaption( "[Cache Normals] LD19 Jovoc - Discovery", NULL ); _cacheColorImage( "NRM", m_terrainNorm, HITE_RES ); } SDL_WM_SetCaption( "LD19 Jovoc - Discovery [Press TAB to ungrab mouse]", NULL ); // Build texture static int treeId = 0; Luddite::TextureDB *texDB = Luddite::TextureDB::singletonPtr(); if (htexColor.isNull()) { char s[20]; sprintf( s, "treeland%d", treeId++); htexColor = texDB->buildTextureFromData( s, m_terrainColor, 1024, 1024 ); } if (htexNorms.isNull()) { char s[20]; sprintf( s, "treenorms%d", treeId++); htexNorms = texDB->buildTextureFromData( s, m_terrainNorm, 1024, 1024 ); } // Make a land part m_treeLand = new TreeLand( m_hiteData, htexColor, htexNorms ); m_treeLand->build(); }