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

Classes

struct  Handler
 
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 WaveChannel &channel, const WaveChannelInterval &clip, const wxRect &rect, const std::shared_ptr< SpectralData > &mpSpectralData, bool selected)
 
void DoNextPeakFrequency (AudacityProject &project, bool up)
 
static CommandHandlerObjectfindCommandHandler (AudacityProject &project)
 
auto SpectralSelectionMenu ()
 

Variables

PopupMenuTable::AttachedItem sAttachment
 
static const AttachedProjectObjects::RegisteredFactory key
 
AttachedItem sAttachment2
 

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

307{
308 if (!isSpectral)
310 if ((selBinCenter >= 0) && (bin0 <= selBinCenter) &&
311 (selBinCenter < bin1))
313 if ((0 == dashCount % 2) &&
314 (((selBinLo >= 0) && (bin0 <= selBinLo) && ( selBinLo < bin1)) ||
315 ((selBinHi >= 0) && (bin0 <= selBinHi) && ( selBinHi < bin1))))
317 if ((selBinLo < 0 || selBinLo < bin1) && (selBinHi < 0 || selBinHi > bin0))
319
321}
@ 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:

◆ DoNextPeakFrequency()

void anonymous_namespace{SpectrumView.cpp}::DoNextPeakFrequency ( AudacityProject project,
bool  up 
)

Definition at line 1096 of file SpectrumView.cpp.

1097{
1098 // This only ever considered the left member of a stereo pair!
1099 // TODO: account for the right hand channel too.
1100 // (How? Average corresponding bin power?)
1101
1102 auto &tracks = TrackList::Get( project );
1103 auto &viewInfo = ViewInfo::Get( project );
1104
1105 // Find the first selected wave track that is in a spectrogram view.
1106 const auto hasSpectrum = [](const WaveTrack *wt){
1107 const auto displays = WaveChannelView::GetFirst(*wt).GetDisplays();
1108 return displays.end() != std::find(
1109 displays.begin(), displays.end(),
1110 WaveChannelSubView::Type{ WaveChannelViewConstants::Spectrum, {} });
1111 };
1112 const auto range = tracks.Selected<const WaveTrack>();
1113 const auto iter = find_if(begin(range), end(range), hasSpectrum);
1114 if (iter != end(range)) {
1115 SpectrumAnalyst analyst;
1116 auto &wt = **iter;
1118 viewInfo, **wt.Channels().first, up);
1120 }
1121}
const auto tracks
const auto project
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
static void SnapCenterOnce(SpectrumAnalyst &analyst, ViewInfo &viewInfo, const WaveChannel &wc, bool up)
Used for finding the peaks, for snapping to peaks.
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
static WaveChannelView & GetFirst(WaveTrack &wt)
Get the view of the first channel.
std::vector< WaveChannelSubView::Type > GetDisplays() const
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101

References ViewInfo::Get(), TrackList::Get(), WaveChannelView::GetDisplays(), WaveChannelView::GetFirst(), project, and tracks.

Referenced by anonymous_namespace{SpectrumView.cpp}::Handler::OnNextHigherPeakFrequency(), and anonymous_namespace{SpectrumView.cpp}::Handler::OnNextLowerPeakFrequency().

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

◆ DrawClipSpectrum()

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

Definition at line 339 of file SpectrumView.cpp.

344{
345 auto &dc = context.dc;
346 const auto artist = TrackArtist::Get(context);
347 bool onBrushTool = artist->onBrushTool;
348 const auto &selectedRegion = *artist->pSelectedRegion;
349 const auto &zoomInfo = *artist->pZoomInfo;
350
351#ifdef PROFILE_WAVEFORM
352 Profiler profiler;
353#endif
354
355 //If clip is "too small" draw a placeholder instead of
356 //attempting to fit the contents into a few pixels
357 if (!WaveChannelView::ClipDetailsVisible(clip, zoomInfo, rect))
358 {
359 auto clipRect = ClipParameters::GetClipRect(clip, zoomInfo, rect);
360 TrackArt::DrawClipFolded(dc, clipRect);
361 return;
362 }
363
364 auto &settings = SpectrogramSettings::Get(channel);
365 const bool autocorrelation = (settings.algorithm == SpectrogramSettings::algPitchEAC);
366
367 enum { DASH_LENGTH = 10 /* pixels */ };
368
369 const ClipParameters params { clip, rect, zoomInfo };
370 const wxRect &hiddenMid = params.hiddenMid;
371 // The "hiddenMid" rect contains the part of the display actually
372 // containing the waveform, as it appears without the fisheye. If it's empty, we're done.
373 if (hiddenMid.width <= 0) {
374 return;
375 }
376
377 const double &t0 = params.t0;
378 const double playStartTime = clip.GetPlayStartTime();
379
380 const auto [ssel0, ssel1] = GetSelectedSampleIndices(selectedRegion, clip,
381 channel.GetTrack().GetSelected());
382 const double &averagePixelsPerSecond = params.averagePixelsPerSecond;
383 const double sampleRate = clip.GetRate();
384 const double stretchRatio = clip.GetStretchRatio();
385 const double &hiddenLeftOffset = params.hiddenLeftOffset;
386 const double &leftOffset = params.leftOffset;
387 const wxRect &mid = params.mid;
388
391 freqLo = selectedRegion.f0();
392 freqHi = selectedRegion.f1();
393
394 const int &colorScheme = settings.colorScheme;
395 const int &range = settings.range;
396 const int &gain = settings.gain;
397
398#ifdef EXPERIMENTAL_FIND_NOTES
399 const bool &fftFindNotes = settings.fftFindNotes;
400 const double &findNotesMinA = settings.findNotesMinA;
401 const int &numberOfMaxima = settings.numberOfMaxima;
402 const bool &findNotesQuantize = settings.findNotesQuantize;
403#endif
404#ifdef EXPERIMENTAL_FFT_Y_GRID
405 const bool &fftYGrid = settings.fftYGrid;
406#endif
407
408 dc.SetPen(*wxTRANSPARENT_PEN);
409
410 // We draw directly to a bit image in memory,
411 // and then paint this directly to our offscreen
412 // bitmap. Note that this could be optimized even
413 // more, but for now this is not bad. -dmazzoni
414 wxImage image((int)mid.width, (int)mid.height);
415 if (!image.IsOk())
416 return;
417#ifdef EXPERIMENTAL_SPECTROGRAM_OVERLAY
418 image.SetAlpha();
419 unsigned char *alpha = image.GetAlpha();
420#endif
421 unsigned char *data = image.GetData();
422
423 const auto half = settings.GetFFTLength() / 2;
424 const double binUnit = sampleRate / (2 * half);
425 const float *freq = 0;
426 const sampleCount *where = 0;
427 bool updated = WaveClipSpectrumCache::Get(clip).GetSpectrogram(
428 clip, freq, settings, where, (size_t)hiddenMid.width, t0,
429 averagePixelsPerSecond);
430 auto nBins = settings.NBins();
431
432 float minFreq, maxFreq;
433 SpectrogramBounds::Get(channel).GetBounds(channel, 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);
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:709
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:68
std::vector< sampleCount > where
Definition: SpectrumCache.h:69
void GetBounds(const WaveChannel &wc, 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)
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:78
WaveTrack & GetTrack()
Definition: WaveTrack.h:840
static bool ClipDetailsVisible(const ClipTimes &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect)
size_t GetChannelIndex() const
Definition: WaveClip.h:99
int GetRate() const override
Definition: WaveClip.cpp:193
double GetPlayStartTime() const override
Definition: WaveClip.cpp:198
double GetStretchRatio() const override
Definition: WaveClip.cpp:218
@ 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
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)
bool GetSpectrogram(const WaveChannelInterval &clip, const float *&spectrogram, SpectrogramSettings &spectrogramSettings, const sampleCount *&where, size_t numPixels, double t0, double pixelsPerSecond)
static WaveClipSpectrumCache & Get(const WaveChannelInterval &clip)

References SpectrogramSettings::algPitchEAC, details::begin(), NumberScale::begin(), ChooseColorSet(), WaveChannelView::ClipDetailsVisible(), AColor::ColorGradientTimeAndFrequencySelected, AColor::ColorGradientUnselected, TrackPanelDrawingContext::dc, TrackArt::DrawClipEdges(), TrackArt::DrawClipFolded(), details::end(), findValue(), SpecCache::freq, WaveClipSpectrumCache::Get(), SpectrogramSettings::Get(), TrackArtist::Get(), SpectrogramBounds::Get(), SpectrogramBounds::GetBounds(), WaveClipChannel::GetChannelIndex(), ClipParameters::GetClipRect(), GetColorGradient(), WaveClipChannel::GetPlayStartTime(), WaveClipChannel::GetRate(), Track::GetSelected(), GetSelectedSampleIndices(), WaveClipSpectrumCache::GetSpectrogram(), WaveClipChannel::GetStretchRatio(), WaveChannel::GetTrack(), 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:

◆ findCommandHandler()

static CommandHandlerObject & anonymous_namespace{SpectrumView.cpp}::findCommandHandler ( AudacityProject project)
static

Definition at line 1171 of file SpectrumView.cpp.

1171 {
1172 return project.AttachedObjects::Get< Handler >( key );
1173};
static const WaveChannelSubViews::RegisteredFactory key

References key, and project.

Referenced by SpectralSelectionMenu().

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

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

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

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

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

Referenced by DrawClipSpectrum().

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

◆ SpectralSelectionMenu()

auto anonymous_namespace{SpectrumView.cpp}::SpectralSelectionMenu ( )

Definition at line 1178 of file SpectrumView.cpp.

1179{
1180 static auto menu = std::shared_ptr{
1182 Menu( wxT("Spectral"), XXO("S&pectral"),
1183 Command( wxT("ToggleSpectralSelection"),
1184 XXO("To&ggle Spectral Selection"), FN(OnToggleSpectralSelection),
1185 TracksExistFlag(), wxT("Q") ),
1186 Command( wxT("NextHigherPeakFrequency"),
1187 XXO("Next &Higher Peak Frequency"), FN(OnNextHigherPeakFrequency),
1188 TracksExistFlag() ),
1189 Command( wxT("NextLowerPeakFrequency"),
1190 XXO("Next &Lower Peak Frequency"), FN(OnNextLowerPeakFrequency),
1191 TracksExistFlag() )
1192 ) ) };
1193 return menu;
1194}
wxT("CloseDown"))
const ReservedCommandFlag & TracksExistFlag()
XXO("&Cut/Copy/Paste Toolbar")
#define FN(X)
constexpr auto Command
Definition: MenuRegistry.h:456
constexpr auto Menu
Items will appear in a main toolbar menu or in a sub-menu.
Definition: MenuRegistry.h:445
static CommandHandlerObject & findCommandHandler(AudacityProject &project)

References MenuRegistry::Command, findCommandHandler(), FN, MenuRegistry::Menu, TracksExistFlag(), wxT(), and XXO().

Here is the call graph for this function:

Variable Documentation

◆ key

const AttachedProjectObjects::RegisteredFactory anonymous_namespace{SpectrumView.cpp}::key
static
Initial value:
{
return std::make_unique< Handler >(); } }
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90

Definition at line 1167 of file SpectrumView.cpp.

◆ sAttachment

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

Definition at line 1009 of file SpectrumView.cpp.

◆ sAttachment2

AttachedItem anonymous_namespace{SpectrumView.cpp}::sAttachment2
Initial value:
Placement{ wxT("Select/Basic"), { OrderingHint::After, wxT("Region") } }
}
std::unique_ptr< detail::IndirectItem< Item > > Indirect(const std::shared_ptr< Item > &ptr)
A convenience function.
Definition: Registry.h:175

Definition at line 1198 of file SpectrumView.cpp.