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

311{
312 if (!isSpectral)
314 if ((selBinCenter >= 0) && (bin0 <= selBinCenter) &&
315 (selBinCenter < bin1))
317 if ((0 == dashCount % 2) &&
318 (((selBinLo >= 0) && (bin0 <= selBinLo) && ( selBinLo < bin1)) ||
319 ((selBinHi >= 0) && (bin0 <= selBinHi) && ( selBinHi < bin1))))
321 if ((selBinLo < 0 || selBinLo < bin1) && (selBinHi < 0 || selBinHi > bin0))
323
325}
@ 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 1100 of file SpectrumView.cpp.

1101{
1102 // This only ever considered the left member of a stereo pair!
1103 // TODO: account for the right hand channel too.
1104 // (How? Average corresponding bin power?)
1105
1106 auto &tracks = TrackList::Get( project );
1107 auto &viewInfo = ViewInfo::Get( project );
1108
1109 // Find the first selected wave track that is in a spectrogram view.
1110 const auto hasSpectrum = [](const WaveTrack *wt){
1111 const auto displays = WaveChannelView::GetFirst(*wt).GetDisplays();
1112 return displays.end() != std::find(
1113 displays.begin(), displays.end(),
1114 WaveChannelSubView::Type{ WaveChannelViewConstants::Spectrum, {} });
1115 };
1116 const auto range = tracks.Selected<const WaveTrack>();
1117 const auto iter = find_if(begin(range), end(range), hasSpectrum);
1118 if (iter != end(range)) {
1119 SpectrumAnalyst analyst;
1120 auto &wt = **iter;
1122 viewInfo, **wt.Channels().first, up);
1124 }
1125}
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 343 of file SpectrumView.cpp.

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

1175 {
1176 return project.AttachedObjects::Get< Handler >( key );
1177};
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 249 of file SpectrumView.cpp.

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

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

330{
331 if (!trackIsSelected)
332 return { 0, 0 };
333 const double t0 = selectedRegion.t0(); // left selection bound
334 const double t1 = selectedRegion.t1(); // right selection bound
335 const auto startTime = clip.GetPlayStartTime();
336 const auto s0 = std::max(sampleCount(0), clip.TimeToSamples(t0 - startTime));
337 auto s1 = std::clamp(
338 clip.TimeToSamples(t1 - startTime), sampleCount { 0 },
339 clip.GetVisibleSampleCount());
340 return { s0, s1 };
341}
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 1182 of file SpectrumView.cpp.

1183{
1184 static auto menu = std::shared_ptr{
1186 Menu( wxT("Spectral"), XXO("S&pectral"),
1187 Command( wxT("ToggleSpectralSelection"),
1188 XXO("To&ggle Spectral Selection"), FN(OnToggleSpectralSelection),
1189 TracksExistFlag(), wxT("Q") ),
1190 Command( wxT("NextHigherPeakFrequency"),
1191 XXO("Next &Higher Peak Frequency"), FN(OnNextHigherPeakFrequency),
1192 TracksExistFlag() ),
1193 Command( wxT("NextLowerPeakFrequency"),
1194 XXO("Next &Lower Peak Frequency"), FN(OnNextLowerPeakFrequency),
1195 TracksExistFlag() )
1196 ) ) };
1197 return menu;
1198}
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 1171 of file SpectrumView.cpp.

◆ sAttachment

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

Definition at line 1013 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 1202 of file SpectrumView.cpp.