Changeset 425

Show
Ignore:
Timestamp:
08/17/06 21:32:49 (5 years ago)
Author:
radekk
Message:

rounding problems resolved.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sweep/branches/display-cache/src/display-cache.c

    r424 r425  
    4242//#define DEBUG_VERBOSE 
    4343//#define DEBUG_VERY_VERBOSE 
     44//#define DEBUG_CUST 
    4445//#define DEBUG_VERBOSE_CUST 
    4546//#define DEBUG_VERY_VERBOSE_CUST 
     
    8283 
    8384#ifdef DEBUG_VERBOSE 
    84         g_print("display_cache_right_realloc: l1:%i l2:%i len:%i\n",l1, l2, len); 
    85 #endif 
    86 //XXX i have to add MARGIN to arrays size in case of avoiding sweep crash 
    87 //XXX it should be checked whats is wrong 
    88 #define MARGIN  10000 
    89         tmp = g_malloc0(l1 * sizeof(sw_audio_t) + MARGIN); 
     85        g_print("display_cache_right_realloc(%p): l1:%i l2:%i len:%i\n", dc, l1, l2, len); 
     86#endif 
     87         
     88        tmp = g_malloc0(l1 * sizeof(sw_audio_t)); 
    9089        g_memmove(tmp, dc->min, l2 * sizeof(sw_audio_t)); 
    9190        g_free(dc->min); 
    9291        dc->min = tmp; 
    9392 
    94         tmp = g_malloc0(l1 * sizeof(sw_audio_t) + MARGIN); 
     93        tmp = g_malloc0(l1 * sizeof(sw_audio_t)); 
    9594        g_memmove(tmp, dc->max, l2 * sizeof(sw_audio_t)); 
    9695        g_free(dc->max); 
    9796        dc->max = tmp; 
    9897 
    99         tmp = g_malloc0(l1 * sizeof(sw_audio_t) + MARGIN); 
     98        tmp = g_malloc0(l1 * sizeof(sw_audio_t)); 
    10099        g_memmove(tmp, dc->rms, l2 * sizeof(sw_audio_t)); 
    101100        g_free(dc->rms); 
    102101        dc->rms = tmp; 
    103102 
    104         tmpb = g_malloc0(l1 * sizeof(gboolean) + MARGIN); 
     103        tmpb = g_malloc0(l1 * sizeof(gboolean)); 
    105104        g_memmove(tmpb, dc->points, l2 * sizeof(gboolean)); 
    106105        g_free(dc->points); 
     
    108107 
    109108        dc->len += len; 
    110  
    111109} 
    112110 
     
    122120#endif 
    123121 
    124         // dst, src, len 
    125122        tmp = g_malloc0((l1 + l2) * sizeof(sw_audio_t)); 
    126123        g_memmove(tmp + l1, dc->min, l2 * sizeof(sw_audio_t)); 
     
    144141 
    145142        dc->len += len; 
    146  
    147143} 
    148144 
     
    278274                        g_mutex_lock (sample->sounddata->data_mutex); 
    279275                         
    280                         x0 = n * dc->fpp; 
    281                         x1 = x0 + dc->fpp
     276                        x0 = n * 1.0 * dc->fpp; 
     277                        x1 = x0 + dc->fpp + 0.5
    282278 
    283279                        for (i = start + x0; i < start + x1; i += step)  
     
    289285                                if (d > maxd) { maxd = d; } 
    290286                                if (d < mind) { mind = d; } 
    291 //                              avgd += d * d; 
    292287                                avgd += d; 
    293288                                numd++; 
     
    297292                        g_mutex_unlock (sample->sounddata->data_mutex); 
    298293    
    299 //                      avgd = sqrt( avgd / numd); 
    300294                        avgd /= numd; 
    301295 
    302296#ifdef DEBUG_VERBOSE 
    303                         g_print("display_cache_prepare_minmax: n:%i channel:%i offset:%i min:%f max:%f rms:%f\n", n, channel, n * dc->channels + channel, mind, maxd, avgd); 
    304 #endif 
     297                        g_print("display_cache_prepare_minmax(%p): n:%i channel:%i offset:%i min:%f max:%f rms:%f\n",  
     298                                        dc, n, channel, (n + offset) * dc->channels + channel, mind, maxd, avgd); 
     299#endif 
     300 
    305301                        dc->min[(n + offset) * dc->channels + channel] = mind; 
    306302                        dc->max[(n + offset) * dc->channels + channel] = maxd; 
     
    347343                        dc->max[off] = dc->min[off]; 
    348344                        dc->rms[off] = 0; 
    349                         if (x ==  ceil(p / fpp)) 
     345                        if (x ==  ceil(p / fpp + 0.5)) 
    350346                        { 
    351347                                p++; 
     
    375371        gint offset; 
    376372 
    377 #ifdef DEBUG 
    378         g_print("DisplayCache: PREPARE: %p sample:%p length:%i start:%i end:%i\n",dc, sample, length, start, end);  
     373#ifdef DEBUG_VERBOSE 
     374        g_print("display_cache_prepare(%p): sample:%p length:%i start:%i end:%i\n",dc, sample, length, start, end);  
    379375#endif 
    380376 
     
    388384        fpp = (end - start) * 1.0 / length; 
    389385 
    390 #ifdef DEBUG 
     386#ifdef DEBUG_VERBOSE 
    391387        g_print("DisplayCache: fpp:%f\n",fpp); 
    392388        g_print("DisplayCache: dc->fpp:%f\n",dc->fpp); 
     
    433429                // and cache is valid 
    434430 
    435 #ifdef DEBUG 
     431#ifdef DEBUG_CUST 
    436432                g_print("DisplayCache: HIT\n"); 
    437433#endif 
    438434 
    439435                // compute prepared view offset 
    440                 dc->psoff = (start - dc->start) * 1.0 / dc->fpp; 
     436                dc->psoff = (start - dc->start) / dc->fpp; 
    441437                dc->peoff = dc->psoff + length; 
    442438 
     
    452448        } else { 
    453449 
    454 #ifdef DEBUG 
     450#ifdef DEBUG_CUST 
    455451                g_print("DisplayCache: MISS\n"); 
    456452#endif 
     
    462458                // and alocate new cache 
    463459 
    464 #ifdef DEBUG 
     460#ifdef DEBUG_CUST 
    465461                g_print("DisplayCache: MAJOR CHANGE\n"); 
    466462#endif 
     
    468464                        dc->fpp = fpp; 
    469465                        dc->start = start; 
     466                        dc->end = end; 
    470467                        cstart = start; 
    471468                        dc->psoff = 0; 
    472                         dc->end = end
     469                        dc->peoff = length
    473470                        cend = end; 
    474                         dc->peoff = length; 
    475471                        clength = length; 
    476472                        dc->channels = sample->sounddata->format->channels; 
    477473                        offset = 0; 
    478474 
    479                         display_cache_realloc(dc, length); 
     475                        display_cache_realloc(dc, clength); 
    480476 
    481477                } else 
     
    486482                        // TODO: make valid parameters for sinc interpolation 
    487483 
    488 #ifdef DEBUG 
     484#ifdef DEBUG_CUST 
    489485                g_print("DisplayCache: EXPAND CACHE RIGHT\n"); 
    490486#endif 
     
    492488                        dc->psoff = (start - dc->start) * 1.0 / dc->fpp; 
    493489                        dc->peoff = dc->psoff + length; 
    494                         if (dc->fpp > 1) 
    495                         { 
    496                                 cstart = dc->end; 
    497                                 clength = (end - dc->end) * 1.0 / dc->fpp; 
    498                                 offset = dc->end * 1.0 / dc->fpp; 
    499                         } else { 
     490                        cstart = dc->end; 
     491                        clength = (end - dc->end) * 1.0 / dc->fpp + 1.0; 
     492                        offset = dc->end * 1.0 / dc->fpp; 
     493                        cend = end; 
     494                        dc->end = end; 
     495                         
     496                        display_cache_right_realloc(dc, clength); 
     497                         
     498                        if (dc->fpp < 1){ 
    500499                                cstart = start; 
    501500                                clength = length; 
    502501                                offset = start * 1.0 / dc->fpp; 
    503502                        } 
    504                         cend = end; 
    505                         dc->end = end; 
    506                          
    507                         display_cache_right_realloc(dc, clength); 
    508503 
    509504                } else 
     
    514509                        // TODO: make valid parameters for sinc interpolation 
    515510 
    516 #ifdef DEBUG 
     511#ifdef DEBUG_CUST 
    517512                g_print("DisplayCache: EXPAND CACHE LEFT\n"); 
    518513#endif 
     
    520515                        dc->psoff = 0; 
    521516                        dc->peoff = dc->psoff + length; 
    522                         if (dc->fpp > 1) 
    523                         { 
    524                                 cend = dc->start; 
    525                                 clength = (dc->start - start) * 1.0 / dc->fpp; 
    526                                 offset = 0; 
    527                         } else { 
     517                        cend = dc->start; 
     518                        clength = (dc->start - start) * 1.0 / dc->fpp + 1.0; 
     519                        offset = 0; 
     520                        cstart = start; 
     521                        dc->start = start; 
     522 
     523                        display_cache_left_realloc(dc, clength); 
     524 
     525                        if (dc->fpp < 1){ 
    528526                                cend = end; 
    529527                                clength = length; 
    530                                 offset = 0; 
    531528                        } 
    532                         cstart = start; 
    533                         dc->start = start; 
    534  
    535                         display_cache_left_realloc(dc, clength); 
    536529 
    537530                } else { 
    538531                        // we have only dirty cache 
    539532                        // or jump out of present cache 
     533 
     534#ifdef DEBUG_CUST 
     535                g_print("DisplayCache: DIRTY/MISS CACHE\n"); 
     536#endif 
    540537 
    541538                        dc->start = start; 
     
    622619        g_return_if_fail(points);        
    623620 
    624 #ifdef DEBUG 
    625         g_print("DisplayCacheMinMax: length:%i\n",length); 
    626         g_print("DisplayCacheMinMax: dc->start:%i\n",dc->start); 
    627         g_print("DisplayCacheMinMax: dc->psoff:%i\n",dc->psoff); 
    628         g_print("DisplayCacheMinMax: dc->peoff:%i\n",dc->peoff); 
    629         g_print("DisplayCacheMinMax: dc->fpp:%f\n",dc->fpp); 
    630         g_print("DisplayCacheMinMax: offset:%i\n",offset); 
    631         g_print("DisplayCacheMinMax: dc->len:%i\n",dc->len); 
    632 #endif 
    633  
    634621        if ( offset + length > dc->peoff ) 
    635622        { 
     
    665652        g_return_if_fail(points);        
    666653 
    667 #ifdef DEBUG 
    668         g_print("DisplayCacheMinMaxRms: length:%i\n",length); 
    669         g_print("DisplayCacheMinMaxRms: dc->start:%i\n",dc->start); 
    670         g_print("DisplayCacheMinMaxRms: dc->psoff:%i\n",dc->psoff); 
    671         g_print("DisplayCacheMinMaxRms: dc->peoff:%i\n",dc->peoff); 
    672         g_print("DisplayCacheMinMaxRms: dc->fpp:%f\n",dc->fpp); 
    673         g_print("DisplayCacheMinMaxRms: offset:%i\n",offset); 
    674         g_print("DisplayCacheMinMaxRms: dc->len:%i\n",dc->len); 
    675 #endif 
    676  
    677654        if ( offset + length > dc->peoff ) 
    678655        { 
     
    687664 
    688665        off = (dc->psoff + offset) * dc->channels; 
     666#ifdef DEBUG 
     667        g_print("DisplayCacheMinMaxRms(%p): off:%i length:%i\n",dc,off,length); 
     668#endif 
    689669        *min = dc->min + off; 
    690670        *max = dc->max + off; 
  • sweep/branches/display-cache/src/display-cache.h

    r424 r425  
    4343struct _DisplayCache 
    4444{ 
    45         gfloat        fpp;                                                    // frames per pixel (display resolution) 
     45        gdouble       fpp;                                                    // frames per pixel (display resolution) 
    4646        sw_framecount_t start;          // first cached sample (in frames) 
    4747        sw_framecount_t end;                    // last cached sample (in frames) 
  • sweep/branches/display-cache/src/sample-display.c

    r424 r425  
    576576                             int h) 
    577577{ 
     578#ifdef DOUBLE_BUFFER 
    578579  GdkWindow * window; 
    579580  GdkVisual * visual; 
     581#endif 
    580582  sw_framecount_t len, vlen, vlendelta; 
    581583 
     
    635637  s->height = h; 
    636638 
     639#ifdef DOUBLE_BUFFER 
    637640  if(s->backing_pixmap) { 
    638641    g_object_unref(s->backing_pixmap); 
     
    643646  s->backing_pixmap = gdk_pixmap_new (GTK_WIDGET(s)->window,   
    644647                                      w, h, visual->depth); 
     648#endif 
    645649} 
    646650 
     
    893897#else 
    894898 
    895         display_cache_get_minmaxrms(s->displaycache, &min, &max, &rms, &points, x, width); 
     899#define IND_POINTS_COEF         0.5 
     900        gint x0, index; 
     901         
     902        x0 = x; 
     903        index = channel; 
     904 
     905        if (x > 0){ 
     906                x0--;  
     907                index   += sample->sounddata->format->channels; 
     908        } 
     909 
     910        display_cache_get_minmaxrms(s->displaycache, &min, &max, &rms, &points, x0, width); 
    896911 
    897912        prevmaxd = max[channel]; 
    898913        prevmind = min[channel]; 
    899         gint index = channel; 
    900914 
    901915  while(width > 0) { 
     
    927941                  x, YPOS(mind)); 
    928942 
    929                 if (s->displaycache->fpp < 0.25 && points[index]) 
     943                if (s->displaycache->fpp < IND_POINTS_COEF && points[index]) 
    930944                        gdk_draw_rectangle(win, gc, 
    931945                                        TRUE, 
  • sweep/branches/display-cache/src/sweep_sounddata.c

    r304 r425  
    120120#endif 
    121121    sounddata_clear_selection (sounddata); 
     122    g_mutex_free(sounddata->data_mutex); 
    122123    g_free (sounddata); 
    123     g_mutex_free(sounddata->data_mutex); 
    124124  } 
    125125}