Audacity 3.2.0
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
NyquistBase::NyxContext Struct Reference
Collaboration diagram for NyquistBase::NyxContext:
[legend]

Public Types

using ProgressReport = std::function< bool(double)>
 
using Buffer = std::unique_ptr< float[]>
 

Public Member Functions

 NyxContext (ProgressReport progressReport, double scale, double progressTot)
 
int GetCallback (float *buffer, int channel, int64_t start, int64_t len, int64_t totlen)
 
int PutCallback (float *buffer, int channel, int64_t start, int64_t len, int64_t totlen)
 

Static Public Member Functions

static int StaticGetCallback (float *buffer, int channel, int64_t start, int64_t len, int64_t totlen, void *userdata)
 
static int StaticPutCallback (float *buffer, int channel, int64_t start, int64_t len, int64_t totlen, void *userdata)
 

Public Attributes

WaveTrackmCurChannelGroup {}
 
WaveChannelmCurTrack [2] {}
 
sampleCount mCurStart {}
 
unsigned mCurNumChannels {}
 Not used in the callbacks. More...
 
Buffer mCurBuffer [2]
 used only in GetCallback More...
 
sampleCount mCurBufferStart [2] {}
 
size_t mCurBufferLen [2] {}
 
sampleCount mCurLen {}
 
WaveTrack::Holder mOutputTrack
 
double mProgressIn {}
 
double mProgressOut {}
 
const ProgressReport mProgressReport
 
const double mScale
 
const double mProgressTot
 
std::exception_ptr mpException {}
 

Detailed Description

Reads and writes Audacity's track objects, interchanging with Nyquist sound objects (implemented in the library layer written in C)

Definition at line 598 of file NyquistBase.cpp.

Member Typedef Documentation

◆ Buffer

using NyquistBase::NyxContext::Buffer = std::unique_ptr<float[]>

Definition at line 626 of file NyquistBase.cpp.

◆ ProgressReport

using NyquistBase::NyxContext::ProgressReport = std::function<bool(double)>

Definition at line 600 of file NyquistBase.cpp.

Constructor & Destructor Documentation

◆ NyxContext()

NyquistBase::NyxContext::NyxContext ( ProgressReport  progressReport,
double  scale,
double  progressTot 
)
inline

Definition at line 602 of file NyquistBase.cpp.

603 : mProgressReport { move(progressReport) }
604 , mScale { scale }
605 , mProgressTot { progressTot }
606 {
607 }
const ProgressReport mProgressReport

Member Function Documentation

◆ GetCallback()

int NyquistBase::NyxContext::GetCallback ( float *  buffer,
int  channel,
int64_t  start,
int64_t  len,
int64_t  totlen 
)

Definition at line 2616 of file NyquistBase.cpp.

2618{
2619 if (mCurBuffer[ch])
2620 {
2621 if (
2622 (mCurStart + start) < mCurBufferStart[ch] ||
2623 (mCurStart + start) + len > mCurBufferStart[ch] + mCurBufferLen[ch])
2624 {
2625 mCurBuffer[ch].reset();
2626 }
2627 }
2628
2629 if (!mCurBuffer[ch])
2630 {
2631 mCurBufferStart[ch] = (mCurStart + start);
2633
2634 if (mCurBufferLen[ch] < (size_t)len)
2635 mCurBufferLen[ch] = mCurTrack[ch]->GetIdealBlockSize();
2636
2639
2640 // C++20
2641 // mCurBuffer[ch] = std::make_unique_for_overwrite(mCurBufferLen[ch]);
2642 mCurBuffer[ch] = Buffer { safenew float[mCurBufferLen[ch]] };
2643 try
2644 {
2645 mCurTrack[ch]->GetFloats(
2646 mCurBuffer[ch].get(), mCurBufferStart[ch], mCurBufferLen[ch]);
2647 }
2648 catch (...)
2649 {
2650 // Save the exception object for re-throw when out of the library
2651 mpException = std::current_exception();
2652 return -1;
2653 }
2654 }
2655
2656 // We have guaranteed above that this is nonnegative and bounded by
2657 // mCurBufferLen[ch]:
2658 auto offset = (mCurStart + start - mCurBufferStart[ch]).as_size_t();
2659 const void* src = &mCurBuffer[ch][offset];
2660 std::memcpy(buffer, src, len * sizeof(float));
2661
2662 if (ch == 0)
2663 {
2664 double progress = mScale * ((start + len) / mCurLen.as_double());
2665 if (progress > mProgressIn)
2666 mProgressIn = progress;
2668 return -1;
2669 }
2670
2671 return 0;
2672}
#define safenew
Definition: MemoryX.h:10
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
"narrow" overload fetches from the unique channel
Definition: WaveTrack.h:129
size_t GetBestBlockSize(sampleCount t) const
A hint for sizing of well aligned fetches.
Definition: WaveTrack.h:851
double as_double() const
Definition: SampleCount.h:46
Buffer mCurBuffer[2]
used only in GetCallback
sampleCount mCurBufferStart[2]
std::unique_ptr< float[]> Buffer
WaveChannel * mCurTrack[2]
std::exception_ptr mpException

References limitSampleBufferSize(), and safenew.

Referenced by StaticGetCallback().

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

◆ PutCallback()

int NyquistBase::NyxContext::PutCallback ( float *  buffer,
int  channel,
int64_t  start,
int64_t  len,
int64_t  totlen 
)

Definition at line 2682 of file NyquistBase.cpp.

2684{
2685 // Don't let C++ exceptions propagate through the Nyquist library
2686 return GuardedCall<int>(
2687 [&] {
2688 if (channel == 0)
2689 {
2690 double progress = mScale * ((float)(start + len) / totlen);
2691 if (progress > mProgressOut)
2692 mProgressOut = progress;
2694 return -1;
2695 }
2696
2697 auto iChannel = mOutputTrack->Channels().begin();
2698 std::advance(iChannel, channel);
2699 const auto pChannel = *iChannel;
2700 pChannel->Append((samplePtr)buffer, floatSample, len);
2701
2702 return 0; // success
2703 },
2704 MakeSimpleGuard(-1)); // translate all exceptions into failure
2705}
SimpleGuard< R > MakeSimpleGuard(R value) noexcept(noexcept(SimpleGuard< R >{ value }))
Convert a value to a handler function returning that value, suitable for GuardedCall<R>
char * samplePtr
Definition: SampleFormat.h:57
WaveTrack::Holder mOutputTrack

References floatSample, anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, and MakeSimpleGuard().

Referenced by StaticPutCallback().

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

◆ StaticGetCallback()

int NyquistBase::NyxContext::StaticGetCallback ( float *  buffer,
int  channel,
int64_t  start,
int64_t  len,
int64_t  totlen,
void *  userdata 
)
static

Definition at line 2608 of file NyquistBase.cpp.

2611{
2612 auto This = static_cast<NyxContext*>(userdata);
2613 return This->GetCallback(buffer, channel, start, len, totlen);
2614}
NyxContext(ProgressReport progressReport, double scale, double progressTot)

References GetCallback().

Referenced by NyquistBase::ProcessOne().

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

◆ StaticPutCallback()

int NyquistBase::NyxContext::StaticPutCallback ( float *  buffer,
int  channel,
int64_t  start,
int64_t  len,
int64_t  totlen,
void *  userdata 
)
static

Definition at line 2674 of file NyquistBase.cpp.

2677{
2678 auto This = static_cast<NyxContext*>(userdata);
2679 return This->PutCallback(buffer, channel, start, len, totlen);
2680}

References PutCallback().

Referenced by NyquistBase::ProcessOne().

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

Member Data Documentation

◆ mCurBuffer

Buffer NyquistBase::NyxContext::mCurBuffer[2]

used only in GetCallback

Definition at line 627 of file NyquistBase.cpp.

◆ mCurBufferLen

size_t NyquistBase::NyxContext::mCurBufferLen[2] {}

Definition at line 629 of file NyquistBase.cpp.

◆ mCurBufferStart

sampleCount NyquistBase::NyxContext::mCurBufferStart[2] {}

Definition at line 628 of file NyquistBase.cpp.

◆ mCurChannelGroup

WaveTrack* NyquistBase::NyxContext::mCurChannelGroup {}

Definition at line 620 of file NyquistBase.cpp.

Referenced by NyquistBase::ProcessOne().

◆ mCurLen

sampleCount NyquistBase::NyxContext::mCurLen {}

Definition at line 630 of file NyquistBase.cpp.

Referenced by NyquistBase::ProcessOne().

◆ mCurNumChannels

unsigned NyquistBase::NyxContext::mCurNumChannels {}

Not used in the callbacks.

Definition at line 624 of file NyquistBase.cpp.

Referenced by NyquistBase::ProcessOne().

◆ mCurStart

sampleCount NyquistBase::NyxContext::mCurStart {}

Definition at line 622 of file NyquistBase.cpp.

◆ mCurTrack

WaveChannel* NyquistBase::NyxContext::mCurTrack[2] {}

Definition at line 621 of file NyquistBase.cpp.

Referenced by NyquistBase::ProcessOne().

◆ mOutputTrack

WaveTrack::Holder NyquistBase::NyxContext::mOutputTrack

Definition at line 632 of file NyquistBase.cpp.

Referenced by NyquistBase::ProcessOne().

◆ mpException

std::exception_ptr NyquistBase::NyxContext::mpException {}

Definition at line 641 of file NyquistBase.cpp.

Referenced by NyquistBase::ProcessOne().

◆ mProgressIn

double NyquistBase::NyxContext::mProgressIn {}

Definition at line 634 of file NyquistBase.cpp.

◆ mProgressOut

double NyquistBase::NyxContext::mProgressOut {}

Definition at line 635 of file NyquistBase.cpp.

◆ mProgressReport

const ProgressReport NyquistBase::NyxContext::mProgressReport

Definition at line 637 of file NyquistBase.cpp.

◆ mProgressTot

const double NyquistBase::NyxContext::mProgressTot

Definition at line 639 of file NyquistBase.cpp.

◆ mScale

const double NyquistBase::NyxContext::mScale

Definition at line 638 of file NyquistBase.cpp.


The documentation for this struct was generated from the following file: