Audacity 3.2.0
Classes | Functions | Variables
anonymous_namespace{SpectrumView.cpp} Namespace Reference

Classes

struct  SpectrogramSettingsHandler
 

Functions

static float findValue (const float *spectrum, float bin0, float bin1, unsigned nBins, bool autocorrelation, int gain, int range)
 
AColor::ColorGradientChoice ChooseColorSet (float bin0, float bin1, float selBinLo, float selBinCenter, float selBinHi, int dashCount, bool isSpectral)
 
void DrawClipSpectrum (TrackPanelDrawingContext &context, SampleTrackCache &waveTrackCache, const WaveClip *clip, const wxRect &rect, const std::shared_ptr< SpectralData > &mpSpectralData, bool selected)
 

Variables

PopupMenuTable::AttachedItem sAttachment
 

Function Documentation

◆ ChooseColorSet()

AColor::ColorGradientChoice anonymous_namespace{SpectrumView.cpp}::ChooseColorSet ( float  bin0,
float  bin1,
float  selBinLo,
float  selBinCenter,
float  selBinHi,
int  dashCount,
bool  isSpectral 
)
inline

Definition at line 300 of file SpectrumView.cpp.

302{
303 if (!isSpectral)
305 if ((selBinCenter >= 0) && (bin0 <= selBinCenter) &&
306 (selBinCenter < bin1))
308 if ((0 == dashCount % 2) &&
309 (((selBinLo >= 0) && (bin0 <= selBinLo) && ( selBinLo < bin1)) ||
310 ((selBinHi >= 0) && (bin0 <= selBinHi) && ( selBinHi < bin1))))
312 if ((selBinLo < 0 || selBinLo < bin1) && (selBinHi < 0 || selBinHi > bin0))
314
316}
@ ColorGradientTimeAndFrequencySelected
Definition: AColor.h:31
@ ColorGradientEdge
Definition: AColor.h:32
@ ColorGradientTimeSelected
Definition: AColor.h:30

References AColor::ColorGradientEdge, AColor::ColorGradientTimeAndFrequencySelected, and AColor::ColorGradientTimeSelected.

Referenced by DrawClipSpectrum().

Here is the caller graph for this function:

◆ DrawClipSpectrum()

void anonymous_namespace{SpectrumView.cpp}::DrawClipSpectrum ( TrackPanelDrawingContext context,
SampleTrackCache waveTrackCache,
const WaveClip clip,
const wxRect &  rect,
const std::shared_ptr< SpectralData > &  mpSpectralData,
bool  selected 
)

Definition at line 318 of file SpectrumView.cpp.

324{
325 auto &dc = context.dc;
326 const auto artist = TrackArtist::Get( context );
327 bool onBrushTool = artist->onBrushTool;
328 const auto &selectedRegion = *artist->pSelectedRegion;
329 const auto &zoomInfo = *artist->pZoomInfo;
330
331#ifdef PROFILE_WAVEFORM
332 Profiler profiler;
333#endif
334
335 //If clip is "too small" draw a placeholder instead of
336 //attempting to fit the contents into a few pixels
337 if (!WaveTrackView::ClipDetailsVisible(*clip, zoomInfo, rect))
338 {
339 auto clipRect = ClipParameters::GetClipRect(*clip, zoomInfo, rect);
340 TrackArt::DrawClipFolded(dc, clipRect);
341 return;
342 }
343
344 const auto track =
345 dynamic_cast<const WaveTrack*>(waveTrackCache.GetTrack().get());
346 if (!track)
347 // Leave a blank rectangle.
348 // TODO: rewrite GetSpectrumBounds so it is
349 // not a member of WaveTrack, but fetch UI related ClientData
350 // attachments; then this downcast from SampleTrack will not be needed.
351 return;
352
353 auto &settings = SpectrogramSettings::Get(*track);
354 const bool autocorrelation = (settings.algorithm == SpectrogramSettings::algPitchEAC);
355
356 enum { DASH_LENGTH = 10 /* pixels */ };
357
359 true, track, clip, rect, selectedRegion, zoomInfo };
360 const wxRect &hiddenMid = params.hiddenMid;
361 // The "hiddenMid" rect contains the part of the display actually
362 // containing the waveform, as it appears without the fisheye. If it's empty, we're done.
363 if (hiddenMid.width <= 0) {
364 return;
365 }
366
367 const double &t0 = params.t0;
368 const double &tOffset = params.tOffset;
369 const auto &ssel0 = params.ssel0;
370 const auto &ssel1 = params.ssel1;
371 const double &averagePixelsPerSample = params.averagePixelsPerSample;
372 const double &rate = params.rate;
373 const double &hiddenLeftOffset = params.hiddenLeftOffset;
374 const double &leftOffset = params.leftOffset;
375 const wxRect &mid = params.mid;
376
379#ifdef EXPERIMENTAL_SPECTRAL_EDITING
380 freqLo = selectedRegion.f0();
381 freqHi = selectedRegion.f1();
382#endif
383
384 const int &colorScheme = settings.colorScheme;
385 const int &range = settings.range;
386 const int &gain = settings.gain;
387
388#ifdef EXPERIMENTAL_FIND_NOTES
389 const bool &fftFindNotes = settings.fftFindNotes;
390 const double &findNotesMinA = settings.findNotesMinA;
391 const int &numberOfMaxima = settings.numberOfMaxima;
392 const bool &findNotesQuantize = settings.findNotesQuantize;
393#endif
394#ifdef EXPERIMENTAL_FFT_Y_GRID
395 const bool &fftYGrid = settings.fftYGrid;
396#endif
397
398 dc.SetPen(*wxTRANSPARENT_PEN);
399
400 // We draw directly to a bit image in memory,
401 // and then paint this directly to our offscreen
402 // bitmap. Note that this could be optimized even
403 // more, but for now this is not bad. -dmazzoni
404 wxImage image((int)mid.width, (int)mid.height);
405 if (!image.IsOk())
406 return;
407#ifdef EXPERIMENTAL_SPECTROGRAM_OVERLAY
408 image.SetAlpha();
409 unsigned char *alpha = image.GetAlpha();
410#endif
411 unsigned char *data = image.GetData();
412
413 const auto half = settings.GetFFTLength() / 2;
414 const double binUnit = rate / (2 * half);
415 const float *freq = 0;
416 const sampleCount *where = 0;
417 bool updated;
418 {
419 const double pps = averagePixelsPerSample * rate;
420 updated = WaveClipSpectrumCache::Get( *clip ).GetSpectrogram( *clip,
421 waveTrackCache, freq, where,
422 (size_t)hiddenMid.width,
423 t0, pps);
424 }
425 auto nBins = settings.NBins();
426
427 float minFreq, maxFreq;
429 .GetBounds(*track, minFreq, maxFreq);
430
431 const SpectrogramSettings::ScaleType scaleType = settings.scaleType;
432
433 // nearest frequency to each pixel row from number scale, for selecting
434 // the desired fft bin(s) for display on that row
435 float *bins = (float*)alloca(sizeof(*bins)*(hiddenMid.height + 1));
436 {
437 const NumberScale numberScale( settings.GetScale( minFreq, maxFreq ) );
438
439 NumberScale::Iterator it = numberScale.begin(mid.height);
440 float nextBin = std::max( 0.0f, std::min( float(nBins - 1),
441 settings.findBin( *it, binUnit ) ) );
442
443 int yy;
444 for (yy = 0; yy < hiddenMid.height; ++yy) {
445 bins[yy] = nextBin;
446 nextBin = std::max( 0.0f, std::min( float(nBins - 1),
447 settings.findBin( *++it, binUnit ) ) );
448 }
449 bins[yy] = nextBin;
450 }
451
452#ifdef EXPERIMENTAL_FFT_Y_GRID
453 const float
454 log2 = logf(2.0f),
455 scale2 = (lmax - lmin) / log2,
456 lmin2 = lmin / log2;
457
458 ArrayOf<bool> yGrid{size_t(mid.height)};
459 for (int yy = 0; yy < mid.height; ++yy) {
460 float n = (float(yy) / mid.height*scale2 - lmin2) * 12;
461 float n2 = (float(yy + 1) / mid.height*scale2 - lmin2) * 12;
462 float f = float(minFreq) / (fftSkipPoints + 1)*powf(2.0f, n / 12.0f + lmin2);
463 float f2 = float(minFreq) / (fftSkipPoints + 1)*powf(2.0f, n2 / 12.0f + lmin2);
464 n = logf(f / 440) / log2 * 12;
465 n2 = logf(f2 / 440) / log2 * 12;
466 if (floor(n) < floor(n2))
467 yGrid[yy] = true;
468 else
469 yGrid[yy] = false;
470 }
471#endif //EXPERIMENTAL_FFT_Y_GRID
472
473 auto &clipCache = WaveClipSpectrumCache::Get( *clip );
474 if (!updated && clipCache.mSpecPxCache->valid &&
475 ((int)clipCache.mSpecPxCache->len == hiddenMid.height * hiddenMid.width)
476 && scaleType == clipCache.mSpecPxCache->scaleType
477 && gain == clipCache.mSpecPxCache->gain
478 && range == clipCache.mSpecPxCache->range
479 && minFreq == clipCache.mSpecPxCache->minFreq
480 && maxFreq == clipCache.mSpecPxCache->maxFreq
481#ifdef EXPERIMENTAL_FFT_Y_GRID
482 && fftYGrid==fftYGridOld
483#endif //EXPERIMENTAL_FFT_Y_GRID
484#ifdef EXPERIMENTAL_FIND_NOTES
485 && fftFindNotes == artist->fftFindNotesOld
486 && findNotesMinA == artist->findNotesMinAOld
487 && numberOfMaxima == artist->findNotesNOld
488 && findNotesQuantize == artist->findNotesQuantizeOld
489#endif
490 ) {
491 // Wave clip's spectrum cache is up to date,
492 // and so is the spectrum pixel cache
493 }
494 else {
495 // Update the spectrum pixel cache
496 clipCache.mSpecPxCache = std::make_unique<SpecPxCache>(hiddenMid.width * hiddenMid.height);
497 clipCache.mSpecPxCache->valid = true;
498 clipCache.mSpecPxCache->scaleType = scaleType;
499 clipCache.mSpecPxCache->gain = gain;
500 clipCache.mSpecPxCache->range = range;
501 clipCache.mSpecPxCache->minFreq = minFreq;
502 clipCache.mSpecPxCache->maxFreq = maxFreq;
503#ifdef EXPERIMENTAL_FIND_NOTES
504 artist->fftFindNotesOld = fftFindNotes;
505 artist->findNotesMinAOld = findNotesMinA;
506 artist->findNotesNOld = numberOfMaxima;
507 artist->findNotesQuantizeOld = findNotesQuantize;
508#endif
509
510#ifdef EXPERIMENTAL_FIND_NOTES
511 float log2 = logf( 2.0f ),
512 lmin = logf( minFreq ), lmax = logf( maxFreq ), scale = lmax - lmin,
513 lmins = lmin,
514 lmaxs = lmax
515 ;
516#endif //EXPERIMENTAL_FIND_NOTES
517
518#ifdef EXPERIMENTAL_FIND_NOTES
519 int maxima[128];
520 float maxima0[128], maxima1[128];
521 const float
522 f2bin = half / (rate / 2.0f),
523 bin2f = 1.0f / f2bin,
524 minDistance = powf(2.0f, 2.0f / 12.0f),
525 i0 = expf(lmin) / binUnit,
526 i1 = expf(scale + lmin) / binUnit,
527 minColor = 0.0f;
528 const size_t maxTableSize = 1024;
529 ArrayOf<int> indexes{ maxTableSize };
530#endif //EXPERIMENTAL_FIND_NOTES
531
532#ifdef _OPENMP
533#pragma omp parallel for
534#endif
535 for (int xx = 0; xx < hiddenMid.width; ++xx) {
536#ifdef EXPERIMENTAL_FIND_NOTES
537 int maximas = 0;
538 const int x0 = nBins * xx;
539 if (fftFindNotes) {
540 for (int i = maxTableSize - 1; i >= 0; i--)
541 indexes[i] = -1;
542
543 // Build a table of (most) values, put the index in it.
544 for (int i = (int)(i0); i < (int)(i1); i++) {
545 float freqi = freq[x0 + (int)(i)];
546 int value = (int)((freqi + gain + range) / range*(maxTableSize - 1));
547 if (value < 0)
548 value = 0;
549 if (value >= maxTableSize)
550 value = maxTableSize - 1;
551 indexes[value] = i;
552 }
553 // Build from the indices an array of maxima.
554 for (int i = maxTableSize - 1; i >= 0; i--) {
555 int index = indexes[i];
556 if (index >= 0) {
557 float freqi = freq[x0 + index];
558 if (freqi < findNotesMinA)
559 break;
560
561 bool ok = true;
562 for (int m = 0; m < maximas; m++) {
563 // Avoid to store very close maxima.
564 float maxm = maxima[m];
565 if (maxm / index < minDistance && index / maxm < minDistance) {
566 ok = false;
567 break;
568 }
569 }
570 if (ok) {
571 maxima[maximas++] = index;
572 if (maximas >= numberOfMaxima)
573 break;
574 }
575 }
576 }
577
578// The f2pix helper macro converts a frequency into a pixel coordinate.
579#define f2pix(f) (logf(f)-lmins)/(lmaxs-lmins)*hiddenMid.height
580
581 // Possibly quantize the maxima frequencies and create the pixel block limits.
582 for (int i = 0; i < maximas; i++) {
583 int index = maxima[i];
584 float f = float(index)*bin2f;
585 if (findNotesQuantize)
586 {
587 f = expf((int)(log(f / 440) / log2 * 12 - 0.5) / 12.0f*log2) * 440;
588 maxima[i] = f*f2bin;
589 }
590 float f0 = expf((log(f / 440) / log2 * 24 - 1) / 24.0f*log2) * 440;
591 maxima0[i] = f2pix(f0);
592 float f1 = expf((log(f / 440) / log2 * 24 + 1) / 24.0f*log2) * 440;
593 maxima1[i] = f2pix(f1);
594 }
595 }
596
597 int it = 0;
598 bool inMaximum = false;
599#endif //EXPERIMENTAL_FIND_NOTES
600
601 for (int yy = 0; yy < hiddenMid.height; ++yy) {
602 const float bin = bins[yy];
603 const float nextBin = bins[yy+1];
604
606 const float value = findValue
607 (freq + nBins * xx, bin, nextBin, nBins, autocorrelation, gain, range);
608 clipCache.mSpecPxCache->values[xx * hiddenMid.height + yy] = value;
609 }
610 else {
611 float value;
612
613#ifdef EXPERIMENTAL_FIND_NOTES
614 if (fftFindNotes) {
615 if (it < maximas) {
616 float i0 = maxima0[it];
617 if (yy >= i0)
618 inMaximum = true;
619
620 if (inMaximum) {
621 float i1 = maxima1[it];
622 if (yy + 1 <= i1) {
623 value = findValue(freq + x0, bin, nextBin, nBins, autocorrelation, gain, range);
624 if (value < findNotesMinA)
625 value = minColor;
626 }
627 else {
628 it++;
629 inMaximum = false;
630 value = minColor;
631 }
632 }
633 else {
634 value = minColor;
635 }
636 }
637 else
638 value = minColor;
639 }
640 else
641#endif //EXPERIMENTAL_FIND_NOTES
642 {
643 value = findValue
644 (freq + nBins * xx, bin, nextBin, nBins, autocorrelation, gain, range);
645 }
646 clipCache.mSpecPxCache->values[xx * hiddenMid.height + yy] = value;
647 } // logF
648 } // each yy
649 } // each xx
650 } // updating cache
651
652 float selBinLo = settings.findBin( freqLo, binUnit);
653 float selBinHi = settings.findBin( freqHi, binUnit);
654 float selBinCenter = (freqLo < 0 || freqHi < 0)
655 ? -1
656 : settings.findBin( sqrt(freqLo * freqHi), binUnit );
657
658 const bool isSpectral = settings.SpectralSelectionEnabled();
659 const bool hidden = (ZoomInfo::HIDDEN == zoomInfo.GetFisheyeState());
660 const int begin = hidden
661 ? 0
662 : std::max(0, (int)(zoomInfo.GetFisheyeLeftBoundary(-leftOffset)));
663 const int end = hidden
664 ? 0
665 : std::min(mid.width, (int)(zoomInfo.GetFisheyeRightBoundary(-leftOffset)));
666 const size_t numPixels = std::max(0, end - begin);
667
668 SpecCache specCache;
669
670 // need explicit resize since specCache.where[] accessed before Populate()
671 specCache.Grow(numPixels, settings, -1, t0);
672
673 if (numPixels > 0) {
674 for (int ii = begin; ii < end; ++ii) {
675 const double time = zoomInfo.PositionToTime(ii, -leftOffset) - tOffset;
676 specCache.where[ii - begin] = sampleCount(0.5 + rate * time);
677 }
678 specCache.Populate
679 (settings, waveTrackCache,
680 0, 0, numPixels,
681 clip->GetPlaySamplesCount(),
682 tOffset, rate,
683 0 // FIXME: PRL -- make reassignment work with fisheye
684 );
685 }
686
687 // build color gradient tables (not thread safe)
690
691 // left pixel column of the fisheye
692 int fisheyeLeft = zoomInfo.GetFisheyeLeftBoundary(-leftOffset);
693
694 // Bug 2389 - always draw at least one pixel of selection.
695 int selectedX = zoomInfo.TimeToPosition(selectedRegion.t0(), -leftOffset);
696
697#ifdef _OPENMP
698#pragma omp parallel for
699#endif
700
701 const NumberScale numberScale(settings.GetScale(minFreq, maxFreq));
702 int windowSize = mpSpectralData->GetWindowSize();
703 int hopSize = mpSpectralData->GetHopSize();
704 double sr = mpSpectralData->GetSR();
705 auto &dataHistory = mpSpectralData->dataHistory;
706
707 // Lazy way to add all hops and bins required for rendering
708 dataHistory.push_back(mpSpectralData->dataBuffer);
709
710 // Generate combined hops and bins map for rendering
711 std::map<long long, std::set<int>> hopBinMap;
712 for(auto vecIter = dataHistory.begin(); vecIter != dataHistory.end(); ++vecIter){
713 for(const auto &hopMap: *vecIter){
714 for(const auto &binNum: hopMap.second)
715 hopBinMap[hopMap.first].insert(binNum);
716 }
717 }
718
719 // Lambda for converting yy (not mouse coord!) to respective freq. bins
720 auto yyToFreqBin = [&](int yy){
721 const double p = double(yy) / hiddenMid.height;
722 float convertedFreq = numberScale.PositionToValue(p);
723 float convertedFreqBinNum = convertedFreq / (sr / windowSize);
724
725 // By default lrintf will round to nearest by default, rounding to even on tie.
726 // std::round that was used here before rounds halfway cases away from zero.
727 // However, we can probably tolerate rounding issues here, as this will only slightly affect
728 // the visuals.
729 return static_cast<int>(lrintf(convertedFreqBinNum));
730 };
731
732 for (int xx = 0; xx < mid.width; ++xx) {
733 int correctedX = xx + leftOffset - hiddenLeftOffset;
734
735 // in fisheye mode the time scale has changed, so the row values aren't cached
736 // in the loop above, and must be fetched from fft cache
737 float* uncached;
738 if (!zoomInfo.InFisheye(xx, -leftOffset)) {
739 uncached = 0;
740 }
741 else {
742 int specIndex = (xx - fisheyeLeft) * nBins;
743 wxASSERT(specIndex >= 0 && specIndex < (int)specCache.freq.size());
744 uncached = &specCache.freq[specIndex];
745 }
746
747 // zoomInfo must be queried for each column since with fisheye enabled
748 // time between columns is variable
749 auto w0 = sampleCount(0.5 + rate *
750 (zoomInfo.PositionToTime(xx, -leftOffset) - tOffset));
751
752 auto w1 = sampleCount(0.5 + rate *
753 (zoomInfo.PositionToTime(xx+1, -leftOffset) - tOffset));
754
755 bool maybeSelected = ssel0 <= w0 && w1 < ssel1;
756 maybeSelected = maybeSelected || (xx == selectedX);
757
758 // In case the xx matches the hop number, it will be used as iterator for frequency bins
759 std::set<int> *pSelectedBins = nullptr;
760 std::set<int>::iterator freqBinIter;
761 auto advanceFreqBinIter = [&](int nextBinRounded){
762 while (freqBinIter != pSelectedBins->end() &&
763 *freqBinIter < nextBinRounded)
764 ++freqBinIter;
765 };
766
767 bool hitHopNum = false;
768 if (onBrushTool) {
769 int convertedHopNum = (w0.as_long_long() + hopSize / 2) / hopSize;
770 hitHopNum = (hopBinMap.find(convertedHopNum) != hopBinMap.end());
771 if(hitHopNum) {
772 pSelectedBins = &hopBinMap[convertedHopNum];
773 freqBinIter = pSelectedBins->begin();
774 advanceFreqBinIter(yyToFreqBin(0));
775 }
776 }
777
778 for (int yy = 0; yy < hiddenMid.height; ++yy) {
779 if(onBrushTool)
780 maybeSelected = false;
781 const float bin = bins[yy];
782 const float nextBin = bins[yy+1];
783 auto binRounded = yyToFreqBin(yy);
784 auto nextBinRounded = yyToFreqBin(yy + 1);
785
786 if(hitHopNum
787 && freqBinIter != pSelectedBins->end()
788 && binRounded == *freqBinIter)
789 maybeSelected = true;
790
791 if (hitHopNum)
792 advanceFreqBinIter(nextBinRounded);
793
794 // For spectral selection, determine what colour
795 // set to use. We use a darker selection if
796 // in both spectral range and time range.
797
799
800 // If we are in the time selected range, then we may use a different color set.
801 if (maybeSelected) {
802 selected =
803 ChooseColorSet(bin, nextBin, selBinLo, selBinCenter, selBinHi,
804 (xx + leftOffset - hiddenLeftOffset) / DASH_LENGTH, isSpectral);
805 if ( onBrushTool && selected != AColor::ColorGradientUnselected )
806 // use only two sets of colors
808 }
809
810 const float value = uncached
811 ? findValue(uncached, bin, nextBin, nBins, autocorrelation, gain, range)
812 : clipCache.mSpecPxCache->values[correctedX * hiddenMid.height + yy];
813
814 unsigned char rv, gv, bv;
815 GetColorGradient(value, selected, colorScheme, &rv, &gv, &bv);
816
817#ifdef EXPERIMENTAL_FFT_Y_GRID
818 if (fftYGrid && yGrid[yy]) {
819 rv /= 1.1f;
820 gv /= 1.1f;
821 bv /= 1.1f;
822 }
823#endif //EXPERIMENTAL_FFT_Y_GRID
824 int px = ((mid.height - 1 - yy) * mid.width + xx);
825#ifdef EXPERIMENTAL_SPECTROGRAM_OVERLAY
826 // More transparent the closer to zero intensity.
827 alpha[px]= wxMin( 200, (value+0.3) * 500) ;
828#endif
829 px *=3;
830 data[px++] = rv;
831 data[px++] = gv;
832 data[px] = bv;
833 } // each yy
834 } // each xx
835
836 dataHistory.pop_back();
837 wxBitmap converted = wxBitmap(image);
838
839 wxMemoryDC memDC;
840
841 memDC.SelectObject(converted);
842
843 dc.Blit(mid.x, mid.y, mid.width, mid.height, &memDC, 0, 0, wxCOPY, FALSE);
844
845 // Draw clip edges, as also in waveform view, which improves the appearance
846 // of split views
847 {
848 auto clipRect = ClipParameters::GetClipRect(*clip, zoomInfo, rect);
849 TrackArt::DrawClipEdges(dc, clipRect, selected);
850 }
851}
void GetColorGradient(float value, AColor::ColorGradientChoice selected, int colorScheme, unsigned char *__restrict red, unsigned char *__restrict green, unsigned char *__restrict blue)
Definition: AColor.h:151
wxImage(22, 22)
int min(int a, int b)
EffectDistortionSettings params
Definition: Distortion.cpp:77
const wxChar * values
static Settings & settings()
Definition: TrackInfo.cpp:87
ColorGradientChoice
Definition: AColor.h:28
@ ColorGradientUnselected
Definition: AColor.h:29
static void PreComputeGradient()
Definition: AColor.cpp:721
static bool gradient_inited
Definition: AColor.h:135
A simple profiler to measure the average time lengths that a particular task/function takes....
Definition: Profiler.h:40
const std::shared_ptr< const SampleTrack > & GetTrack() const
static const int UndefinedFrequency
void Populate(const SpectrogramSettings &settings, SampleTrackCache &waveTrackCache, int copyBegin, int copyEnd, size_t numPixels, sampleCount numSamples, double offset, double rate, double pixelsPerSecond)
void Grow(size_t len_, SpectrogramSettings &settings, double pixelsPerSecond, double start_)
std::vector< float > freq
Definition: SpectrumCache.h:77
std::vector< sampleCount > where
Definition: SpectrumCache.h:78
void GetBounds(const WaveTrack &wt, float &min, float &max) const
static SpectrogramBounds & Get(WaveTrack &track)
Get either the global default settings, or the track's own if previously created.
static SpectrogramSettings & Get(const WaveTrack &track)
Mutative access to attachment even if the track argument is const.
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:69
sampleCount GetPlaySamplesCount() const
Definition: WaveClip.cpp:910
A Track that contains audio waveform data.
Definition: WaveTrack.h:51
static bool ClipDetailsVisible(const WaveClip &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect)
@ HIDDEN
Definition: ZoomInfo.h:149
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
#define lrintf(flt)
Definition: float_cast.h:170
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150
AUDACITY_DLL_API void DrawClipFolded(wxDC &dc, const wxRect &rect)
Definition: TrackArt.cpp:293
AUDACITY_DLL_API void DrawClipEdges(wxDC &dc, const wxRect &clipRect, bool selected=false)
Definition: TrackArt.cpp:256
AColor::ColorGradientChoice ChooseColorSet(float bin0, float bin1, float selBinLo, float selBinCenter, float selBinHi, int dashCount, bool isSpectral)
static float findValue(const float *spectrum, float bin0, float bin1, unsigned nBins, bool autocorrelation, int gain, int range)
static wxRect GetClipRect(const WaveClip &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect, bool *outShowSamples=nullptr)
static WaveClipSpectrumCache & Get(const WaveClip &clip)
bool GetSpectrogram(const WaveClip &clip, SampleTrackCache &cache, const float *&spectrogram, const sampleCount *&where, size_t numPixels, double t0, double pixelsPerSecond)

References SpectrogramSettings::algPitchEAC, PackedArray::begin(), NumberScale::begin(), ChooseColorSet(), WaveTrackView::ClipDetailsVisible(), AColor::ColorGradientTimeAndFrequencySelected, AColor::ColorGradientUnselected, TrackPanelDrawingContext::dc, TrackArt::DrawClipEdges(), TrackArt::DrawClipFolded(), PackedArray::end(), findValue(), SpecCache::freq, WaveClipSpectrumCache::Get(), SpectrogramSettings::Get(), TrackArtist::Get(), SpectrogramBounds::Get(), SpectrogramBounds::GetBounds(), ClipParameters::GetClipRect(), GetColorGradient(), WaveClip::GetPlaySamplesCount(), WaveClipSpectrumCache::GetSpectrogram(), SampleTrackCache::GetTrack(), AColor::gradient_inited, SpecCache::Grow(), ZoomInfo::HIDDEN, lrintf, min(), params, SpecCache::Populate(), NumberScale::PositionToValue(), AColor::PreComputeGradient(), settings(), SpectrogramSettings::stLogarithmic, SelectedRegion::UndefinedFrequency, SpecCache::where, and wxImage().

Referenced by SpectrumView::DoDraw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findValue()

static float anonymous_namespace{SpectrumView.cpp}::findValue ( const float *  spectrum,
float  bin0,
float  bin1,
unsigned  nBins,
bool  autocorrelation,
int  gain,
int  range 
)
inlinestatic

Definition at line 240 of file SpectrumView.cpp.

243{
244 float value;
245
246
247#if 0
248 // Averaging method
249 if ((int)(bin1) == (int)(bin0)) {
250 value = spectrum[(int)(bin0)];
251 } else {
252 float binwidth= bin1 - bin0;
253 value = spectrum[(int)(bin0)] * (1.f - bin0 + (int)bin0);
254
255 bin0 = 1 + (int)(bin0);
256 while (bin0 < (int)(bin1)) {
257 value += spectrum[(int)(bin0)];
258 bin0 += 1.0;
259 }
260 // Do not reference past end of freq array.
261 if ((int)(bin1) >= (int)nBins) {
262 bin1 -= 1.0;
263 }
264
265 value += spectrum[(int)(bin1)] * (bin1 - (int)(bin1));
266 value /= binwidth;
267 }
268#else
269 // Maximum method, and no apportionment of any single bins over multiple pixel rows
270 // See Bug971
271 int index, limitIndex;
272 if (autocorrelation) {
273 // bin = 2 * nBins / (nBins - 1 - array_index);
274 // Solve for index
275 index = std::max(0.0f, std::min(float(nBins - 1),
276 (nBins - 1) - (2 * nBins) / (std::max(1.0f, bin0))
277 ));
278 limitIndex = std::max(0.0f, std::min(float(nBins - 1),
279 (nBins - 1) - (2 * nBins) / (std::max(1.0f, bin1))
280 ));
281 }
282 else {
283 index = std::min<int>(nBins - 1, (int)(floor(0.5 + bin0)));
284 limitIndex = std::min<int>(nBins, (int)(floor(0.5 + bin1)));
285 }
286 value = spectrum[index];
287 while (++index < limitIndex)
288 value = std::max(value, spectrum[index]);
289#endif
290 if (!autocorrelation) {
291 // Last step converts dB to a 0.0-1.0 range
292 value = (value + range + gain) / (double)range;
293 }
294 value = std::min(1.0f, std::max(0.0f, value));
295 return value;
296}

References min().

Referenced by DrawClipSpectrum(), and anonymous_namespace{WaveTrackControls.cpp}::initFn().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ sAttachment

PopupMenuTable::AttachedItem anonymous_namespace{SpectrumView.cpp}::sAttachment

Definition at line 1012 of file SpectrumView.cpp.