void filter_release(Filter filter) { free(filter->as); free(filter->bs); free(filter->xs); free(filter->ys); sampler_free(filter); }
void do_leave_program (void) { sampler_free (); graphics_leave (); inputdevice_close (); DISK_free (); close_sound (); dump_counts (); #ifdef SERIAL_PORT serial_exit (); #endif #ifdef CDTV cdtv_free (); #endif #ifdef A2091 a2091_free (); a3000scsi_free (); #endif #ifdef NCR ncr710_free(); ncr_free(); #endif #ifdef NCR9X ncr9x_free(); #endif #ifdef CD32 akiko_free (); cd32_fmv_free(); #endif if (! no_gui) gui_exit (); #ifdef USE_SDL SDL_Quit (); #endif #ifdef AUTOCONFIG expansion_cleanup (); #endif #ifdef FILESYS filesys_cleanup (); #endif #ifdef BSDSOCKET bsdlib_reset (); #endif gayle_free (); device_func_reset (); #ifdef WITH_LUA uae_lua_free (); #endif savestate_free (); memory_cleanup (); free_shm (); cfgfile_addcfgparam (0); machdep_free (); }
void do_leave_program (void) { #ifdef SAMPLER sampler_free (); #endif graphics_leave (); inputdevice_close (); DISK_free (); close_sound (); dump_counts (); #ifdef SERIAL_PORT serial_exit (); #endif #ifdef CDTV cdtv_free (); #endif #ifdef A2091 a2091_free (); #endif #ifdef NCR ncr_free (); #endif #ifdef CD32 akiko_free (); #endif if (! no_gui) gui_exit (); #ifdef USE_SDL SDL_Quit (); #endif #ifdef AUTOCONFIG expansion_cleanup (); #endif #ifdef FILESYS filesys_cleanup (); #endif #ifdef BSDSOCKET bsdlib_reset (); #endif #ifdef SCSIEMU #ifdef GAYLE gayle_free (); #endif device_func_reset (); #endif savestate_free (); memory_cleanup (); #ifdef NATMEM_OFFSET free_shm (); #endif cfgfile_addcfgparam (0); machdep_free (); }
void sampler_vsync (void) { if (!inited) return; vsynccnt++; if (vsynccnt > 1) { oldcycles = get_cycles (); } if (vsynccnt > 50) { sampler_free (); return; } }
int main(void) { size_t i; #if 1 { sampler s; size_t niter = 10; /* Test the new/free functions for performance and leaks */ for(i = 0; i < niter; i++) { if( (s = sampler_new(nentity, nsamples)) == NULL) abort(); sampler_free(s); } } #endif #define TEST_AGGREGATE #ifdef TEST_AGGREGATE /* Test the aggregate functions. Here's how: * 1) Create 3600 samples, one for each second in an hour. * 2) Aggregate that up to 1 sampler with 60 minutes * 3) Aggregate that up to 1 sampler with 1 hour. * The data will be dummy data to speed things up. */ { sampler secs, minutes, hour; time_t now; size_t eid; long long val; #if 0 now = time(NULL) - 3600; #else // We want more readable time values while testing. now = 0; #endif secs = sampler_new(nentity, 3600); minutes = sampler_new(nentity, 60); hour = sampler_new(nentity, 24); for(i = 0; i < 3600; i++) { /* Add values for this second */ sampler_start_update(secs, now++); for(eid = 0; eid < nentity; eid++) { val = i % 10; sampler_add(secs, eid, val); } sampler_commit(secs); } /* Verify that we have data for all 3600 seconds. */ #if 1 fprintf(stderr, "Secs: Sample count:%zu, nvalue %zu\n", secs->samplecount, secs->nvalue); for(i = 0; i < 3600; i++) { if(secs->entities[0].data[i] == LLONG_MIN) { fprintf(stderr, "WTF?\n"); abort(); } } /* Now we know that we have values for each and every second */ #endif fprintf(stderr, "Aggregating secs->minutes\n"); sampler_aggregate(minutes, secs, 60, 60, SAMPLER_AGG_AVG); #if 1 fprintf(stderr, "Dumping minutes for eid 0\n"); fprintf(stderr, "Minutes: Sample count:%zu, nvalue %zu\n", minutes->samplecount, minutes->nvalue); for(i = sampler_samplecount(minutes) - 3; i < sampler_samplecount(minutes); i++) { if(sampler_get(minutes, 0, i, &val)) fprintf(stderr, "Minute: %zu: Value: %lld\n", i, val); else fprintf(stderr, "Minute: %zu: No value found\n", i); } #endif fprintf(stderr, "Aggregating minutes->hour\n"); sampler_aggregate(hour, minutes, 1, 60, SAMPLER_AGG_AVG); fprintf(stderr, "Dumping hour for eid 0\n"); sleep(1); for(i = 0; i < sampler_samplecount(hour); i++) { if(sampler_get(hour, 0, i, &val)) fprintf(stderr, "Hour: %zu: Value: %lld\n", i, val); else fprintf(stderr, "Hour: %zu: No value found\n", i); } sampler sdup = sampler_dup(secs); sampler_copy(sdup, secs); sampler_free(sdup); sampler_free(hour); sampler_free(secs); sampler_free(minutes); } #endif { pthread_t writerthread, reader1, reader2; int id1 = 1, id2 = 2; sampled_data = sampler_new(nentity, nsamples); /* Start the writer thread */ pthread_create(&writerthread, NULL, writer, NULL); pthread_create(&reader1, NULL, reader, &id1); pthread_create(&reader2, NULL, reader, &id2); fprintf(stderr, "Main thread sleeping\n"); sleep(5); fprintf(stderr, "Main thread shutting down\n"); shutting_down = 1; pthread_join(writerthread, NULL); sampler_free(sampled_data); } return 0; }
void do_leave_program (void) { sampler_free (); graphics_leave (); inputdevice_close (); DISK_free (); close_sound (); dump_counts (); #ifdef PARALLEL_PORT parallel_exit(); #endif #ifdef SERIAL_PORT serial_exit (); #endif #ifdef CDTV cdtv_free(); cdtvcr_free(); #endif #ifdef A2091 a2091_free (); gvp_free (); a3000scsi_free (); #endif soft_scsi_free(); #ifdef NCR ncr_free(); #endif #ifdef NCR9X ncr9x_free(); #endif #ifdef CD32 akiko_free (); cd32_fmv_free(); #endif if (! no_gui) gui_exit (); #ifdef USE_SDL SDL_Quit (); #endif #ifdef AUTOCONFIG expansion_cleanup (); #endif #ifdef WITH_PCI pci_free(); #endif #ifdef WITH_X86 x86_bridge_free(); #endif #ifdef FILESYS filesys_cleanup (); #endif #ifdef BSDSOCKET bsdlib_reset (); #endif gayle_free (); idecontroller_free(); device_func_reset (); #ifdef WITH_LUA uae_lua_free (); #endif #ifdef WITH_PPC uae_ppc_free(); #endif #ifdef WITH_TOCCATA sndboard_free(); #endif gfxboard_free(); #ifdef SAVESTATE savestate_free (); #endif memory_cleanup (); free_shm (); cfgfile_addcfgparam (0); machdep_free (); #ifdef DRIVESOUND driveclick_free(); #endif ethernet_enumerate_free(); }
uae_u8 sampler_getsample (int channel) { #if 0 int cur_pos; static int cap_pos; static float diffsample; #endif static double doffset_offset; HRESULT hr; DWORD t; void *p1, *p2; DWORD len1, len2; evt cycles; int sample, samplecnt; double doffset; int offset; if (!currprefs.sampler_stereo) channel = 0; if (!inited) { DWORD pos; if (!capture_init ()) { capture_free (); return 0; } inited = 1; oldcycles = get_cycles (); oldoffset = -1; doffset_offset = 0; hr = lpDSB2r->GetCurrentPosition (&t, &pos); if (FAILED (hr)) { sampler_free (); return 0; } if (t >= pos) safediff = t - pos; else safediff = recordbufferframes * SAMPLESIZE - pos + t; write_log (_T("SAMPLER: safediff %d %d\n"), safediff, safediff + sampleframes * SAMPLESIZE); safediff += 4 * sampleframes * SAMPLESIZE; #if 0 diffsample = 0; safepos = -recordbufferframes / 10 * SAMPLESIZE; hr = lpDSB2r->GetCurrentPosition (&t, &pos); cap_pos = pos; cap_pos += safepos; if (cap_pos < 0) cap_pos += recordbufferframes * SAMPLESIZE; if (cap_pos >= recordbufferframes * SAMPLESIZE) cap_pos -= recordbufferframes * SAMPLESIZE; if (FAILED (hr)) { sampler_free (); return 0; } #endif } if (clockspersample < 1) return 0; uae_s16 *sbuf = (uae_s16*)samplebuffer; vsynccnt = 0; sample = 0; samplecnt = 0; cycles = (int)get_cycles () - (int)oldcycles; doffset = doffset_offset + cycles / clockspersample; offset = (int)doffset; if (oldoffset < 0 || offset >= sampleframes || offset < 0) { if (offset >= sampleframes) { doffset -= offset; doffset_offset = doffset; } if (oldoffset >= 0 && offset >= sampleframes) { while (oldoffset < sampleframes) { sample += sbuf[oldoffset * SAMPLESIZE / 2 + channel]; oldoffset++; samplecnt++; } } hr = lpDSB2r->GetCurrentPosition (&t, NULL); int pos = t; pos -= safediff; if (pos < 0) pos += recordbufferframes * SAMPLESIZE; hr = lpDSB2r->Lock (pos, sampleframes * SAMPLESIZE, &p1, &len1, &p2, &len2, 0); if (FAILED (hr)) { write_log (_T("SAMPLER: Lock() failed %x\n"), hr); return 0; } memcpy (samplebuffer, p1, len1); if (p2) memcpy (samplebuffer + len1, p2, len2); lpDSB2r->Unlock (p1, len1, p2, len2); #if 0 cap_pos = t; cap_pos += sampleframes * SAMPLESIZE; if (cap_pos < 0) cap_pos += RECORDBUFFER * SAMPLESIZE; if (cap_pos >= RECORDBUFFER * SAMPLESIZE) cap_pos -= RECORDBUFFER * SAMPLESIZE; hr = lpDSB2r->GetCurrentPosition (&t, &pos); cur_pos = pos; if (FAILED (hr)) return 0; cur_pos += safepos; if (cur_pos < 0) cur_pos += RECORDBUFFER * SAMPLESIZE; if (cur_pos >= RECORDBUFFER * SAMPLESIZE) cur_pos -= RECORDBUFFER * SAMPLESIZE; int diff; if (cur_pos >= cap_pos) diff = cur_pos - cap_pos; else diff = RECORDBUFFER * SAMPLESIZE - cap_pos + cur_pos; if (diff > RECORDBUFFER * SAMPLESIZE / 2) diff -= RECORDBUFFER * SAMPLESIZE; diff /= SAMPLESIZE; int diff2 = 100 * diff / (RECORDBUFFER / 2); diffsample = -pow (diff2 < 0 ? -diff2 : diff2, 3.1); if (diff2 < 0) diffsample = -diffsample; write_log (_T("%d\n"), diff); write_log (_T("CAP=%05d CUR=%05d (%-05d) OFF=%05d %f\n"), cap_pos / SAMPLESIZE, cur_pos / SAMPLESIZE, (cap_pos - cur_pos) / SAMPLESIZE, offset, doffset_offset); #endif if (offset < 0) offset = 0; if (offset >= sampleframes) offset -= sampleframes; oldoffset = 0; oldcycles = get_cycles (); } while (oldoffset <= offset) { sample += sbuf[oldoffset * SAMPLESIZE / 2 + channel]; samplecnt++; oldoffset++; } oldoffset = offset; if (samplecnt > 0) sample /= samplecnt; #if 1 /* yes, not 256, without this max recording volume would still be too quiet on my sound cards */ sample /= 128; if (sample < -128) sample = 0; else if (sample > 127) sample = 127; return (uae_u8)(sample - 128); #else return (Uae_u8)((sample / 256) - 128); #endif }