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)
 
std::pair< sampleCount, sampleCountGetSelectedSampleIndices (const SelectedRegion &selectedRegion, const WaveChannelInterval &clip, bool trackIsSelected)
 
void DrawClipSpectrum (TrackPanelDrawingContext &context, const WaveTrack &track, const WaveChannelInterval &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 302 of file SpectrumView.cpp.

304{
305 if (!isSpectral)
307 if ((selBinCenter >= 0) && (bin0 <= selBinCenter) &&
308 (selBinCenter < bin1))
310 if ((0 == dashCount % 2) &&
311 (((selBinLo >= 0) && (bin0 <= selBinLo) && ( selBinLo < bin1)) ||
312 ((selBinHi >= 0) && (bin0 <= selBinHi) && ( selBinHi < bin1))))
314 if ((selBinLo < 0 || selBinLo < bin1) && (selBinHi < 0 || selBinHi > bin0))
316
318}
@ 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,
const WaveTrack track,
const WaveChannelInterval clip,
const wxRect &  rect,
const std::shared_ptr< SpectralData > &  mpSpectralData,
bool  selected 
)

Definition at line 336 of file SpectrumView.cpp.

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

References SpectrogramSettings::algPitchEAC, PackedArray::begin(), NumberScale::begin(), ChooseColorSet(), WaveChannelView::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(), WaveChannelInterval::GetChannelIndex(), WaveChannelInterval::GetClip(), ClipParameters::GetClipRect(), GetColorGradient(), WaveChannelInterval::GetPlayStartTime(), WaveChannelInterval::GetRate(), Track::GetSelected(), GetSelectedSampleIndices(), WaveClipSpectrumCache::GetSpectrogram(), WaveChannelInterval::GetStretchRatio(), AColor::gradient_inited, SpecCache::Grow(), ZoomInfo::HIDDEN, lrintf, min(), params, SpecCache::Populate(), NumberScale::PositionToValue(), AColor::PreComputeGradient(), anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, settings(), staffpad::audio::simd::sqrt(), 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 242 of file SpectrumView.cpp.

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

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:

◆ GetSelectedSampleIndices()

std::pair< sampleCount, sampleCount > anonymous_namespace{SpectrumView.cpp}::GetSelectedSampleIndices ( const SelectedRegion selectedRegion,
const WaveChannelInterval clip,
bool  trackIsSelected 
)

Definition at line 320 of file SpectrumView.cpp.

323{
324 if (!trackIsSelected)
325 return { 0, 0 };
326 const double t0 = selectedRegion.t0(); // left selection bound
327 const double t1 = selectedRegion.t1(); // right selection bound
328 const auto startTime = clip.GetPlayStartTime();
329 const auto s0 = std::max(sampleCount(0), clip.TimeToSamples(t0 - startTime));
330 auto s1 = std::clamp(
331 clip.TimeToSamples(t1 - startTime), sampleCount { 0 },
332 clip.GetVisibleSampleCount());
333 return { s0, s1 };
334}
double t1() const
double t0() const
sampleCount GetVisibleSampleCount() const override
Definition: WaveTrack.cpp:103
sampleCount TimeToSamples(double time) const override
Definition: WaveTrack.cpp:123

References WaveChannelInterval::GetPlayStartTime(), WaveChannelInterval::GetVisibleSampleCount(), SelectedRegion::t0(), SelectedRegion::t1(), and WaveChannelInterval::TimeToSamples().

Referenced by DrawClipSpectrum().

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 1016 of file SpectrumView.cpp.