Audacity 3.2.0
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
NyquistEffect::NyxContext Struct Reference
Collaboration diagram for NyquistEffect::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 {}
 
std::shared_ptr< TrackListmOutputTracks
 
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 667 of file Nyquist.cpp.

Member Typedef Documentation

◆ Buffer

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

Definition at line 691 of file Nyquist.cpp.

◆ ProgressReport

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

Definition at line 668 of file Nyquist.cpp.

Constructor & Destructor Documentation

◆ NyxContext()

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

Definition at line 670 of file Nyquist.cpp.

671 : mProgressReport{ move(progressReport) }
672 , mScale{ scale }
673 , mProgressTot{ progressTot }
674 {}
const double mProgressTot
Definition: Nyquist.cpp:704
const ProgressReport mProgressReport
Definition: Nyquist.cpp:702

Member Function Documentation

◆ GetCallback()

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

Definition at line 2565 of file Nyquist.cpp.

2567{
2568 if (mCurBuffer[ch]) {
2569 if ((mCurStart + start) < mCurBufferStart[ch] ||
2570 (mCurStart + start) + len >
2571 mCurBufferStart[ch] + mCurBufferLen[ch]) {
2572 mCurBuffer[ch].reset();
2573 }
2574 }
2575
2576 if (!mCurBuffer[ch]) {
2577 mCurBufferStart[ch] = (mCurStart + start);
2579
2580 if (mCurBufferLen[ch] < (size_t) len)
2581 mCurBufferLen[ch] = mCurTrack[ch]->GetIdealBlockSize();
2582
2585
2586 // C++20
2587 // mCurBuffer[ch] = std::make_unique_for_overwrite(mCurBufferLen[ch]);
2588 mCurBuffer[ch] = Buffer{ safenew float[ mCurBufferLen[ch] ] };
2589 try {
2590 mCurTrack[ch]->GetFloats( mCurBuffer[ch].get(),
2592 }
2593 catch ( ... ) {
2594 // Save the exception object for re-throw when out of the library
2595 mpException = std::current_exception();
2596 return -1;
2597 }
2598 }
2599
2600 // We have guaranteed above that this is nonnegative and bounded by
2601 // mCurBufferLen[ch]:
2602 auto offset = (mCurStart + start - mCurBufferStart[ch]).as_size_t();
2603 const void *src = &mCurBuffer[ch][offset];
2604 std::memcpy(buffer, src, len * sizeof(float));
2605
2606 if (ch == 0) {
2607 double progress = mScale * ((start + len) / mCurLen.as_double());
2608 if (progress > mProgressIn)
2609 mProgressIn = progress;
2611 return -1;
2612 }
2613
2614 return 0;
2615}
#define safenew
Definition: MemoryX.h:9
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:159
size_t GetBestBlockSize(sampleCount t) const
A hint for sizing of well aligned fetches.
Definition: WaveTrack.h:1244
double as_double() const
Definition: SampleCount.h:46
std::exception_ptr mpException
Definition: Nyquist.cpp:706
WaveChannel * mCurTrack[2]
Definition: Nyquist.cpp:686
std::unique_ptr< float[]> Buffer
Definition: Nyquist.cpp:691
Buffer mCurBuffer[2]
used only in GetCallback
Definition: Nyquist.cpp:692
sampleCount mCurBufferStart[2]
Definition: Nyquist.cpp:693

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 NyquistEffect::NyxContext::PutCallback ( float *  buffer,
int  channel,
int64_t  start,
int64_t  len,
int64_t  totlen 
)

Definition at line 2624 of file Nyquist.cpp.

2626{
2627 // Don't let C++ exceptions propagate through the Nyquist library
2628 return GuardedCall<int>( [&] {
2629 if (channel == 0) {
2630 double progress = mScale * ((float)(start + len) / totlen);
2631 if (progress > mProgressOut)
2632 mProgressOut = progress;
2634 return -1;
2635 }
2636
2637 auto iChannel =
2638 (*mOutputTracks->Any<WaveTrack>().begin())->Channels().begin();
2639 std::advance(iChannel, channel);
2640 const auto pChannel = *iChannel;
2641 pChannel->Append((samplePtr)buffer, floatSample, len);
2642
2643 return 0; // success
2644 }, MakeSimpleGuard(-1)); // translate all exceptions into failure
2645}
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
A Track that contains audio waveform data.
Definition: WaveTrack.h:227
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150
std::shared_ptr< TrackList > mOutputTracks
Definition: Nyquist.cpp:697

References PackedArray::begin(), 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 NyquistEffect::NyxContext::StaticGetCallback ( float *  buffer,
int  channel,
int64_t  start,
int64_t  len,
int64_t  totlen,
void *  userdata 
)
static

Definition at line 2558 of file Nyquist.cpp.

2560{
2561 auto This = static_cast<NyxContext*>(userdata);
2562 return This->GetCallback(buffer, channel, start, len, totlen);
2563}
NyxContext(ProgressReport progressReport, double scale, double progressTot)
Definition: Nyquist.cpp:670

References GetCallback().

Referenced by NyquistEffect::ProcessOne().

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

◆ StaticPutCallback()

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

Definition at line 2617 of file Nyquist.cpp.

2619{
2620 auto This = static_cast<NyxContext*>(userdata);
2621 return This->PutCallback(buffer, channel, start, len, totlen);
2622}

References PutCallback().

Referenced by NyquistEffect::ProcessOne().

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

Member Data Documentation

◆ mCurBuffer

Buffer NyquistEffect::NyxContext::mCurBuffer[2]

used only in GetCallback

Definition at line 692 of file Nyquist.cpp.

◆ mCurBufferLen

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

Definition at line 694 of file Nyquist.cpp.

◆ mCurBufferStart

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

Definition at line 693 of file Nyquist.cpp.

◆ mCurChannelGroup

WaveTrack* NyquistEffect::NyxContext::mCurChannelGroup {}

Definition at line 685 of file Nyquist.cpp.

Referenced by NyquistEffect::ProcessOne().

◆ mCurLen

sampleCount NyquistEffect::NyxContext::mCurLen {}

Definition at line 695 of file Nyquist.cpp.

Referenced by NyquistEffect::ProcessOne().

◆ mCurNumChannels

unsigned NyquistEffect::NyxContext::mCurNumChannels {}

Not used in the callbacks.

Definition at line 689 of file Nyquist.cpp.

Referenced by NyquistEffect::ProcessOne().

◆ mCurStart

sampleCount NyquistEffect::NyxContext::mCurStart {}

Definition at line 687 of file Nyquist.cpp.

◆ mCurTrack

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

Definition at line 686 of file Nyquist.cpp.

Referenced by NyquistEffect::ProcessOne().

◆ mOutputTracks

std::shared_ptr<TrackList> NyquistEffect::NyxContext::mOutputTracks

Definition at line 697 of file Nyquist.cpp.

Referenced by NyquistEffect::ProcessOne().

◆ mpException

std::exception_ptr NyquistEffect::NyxContext::mpException {}

Definition at line 706 of file Nyquist.cpp.

Referenced by NyquistEffect::ProcessOne().

◆ mProgressIn

double NyquistEffect::NyxContext::mProgressIn {}

Definition at line 699 of file Nyquist.cpp.

◆ mProgressOut

double NyquistEffect::NyxContext::mProgressOut {}

Definition at line 700 of file Nyquist.cpp.

◆ mProgressReport

const ProgressReport NyquistEffect::NyxContext::mProgressReport

Definition at line 702 of file Nyquist.cpp.

◆ mProgressTot

const double NyquistEffect::NyxContext::mProgressTot

Definition at line 704 of file Nyquist.cpp.

◆ mScale

const double NyquistEffect::NyxContext::mScale

Definition at line 703 of file Nyquist.cpp.


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