50class Sample final :
public AudioFile {
55 void workOutBitMask();
56 Error initialize(int32_t numClusters);
57 void markAsUnloadable();
58 float determinePitch(
bool doingSingleCycle,
float minFreqHz,
float maxFreqHz,
bool doPrimeTest);
59 void workOutMIDINote(
bool doingSingleCycle,
float minFreqHz = 20,
float maxFreqHz = 10000,
bool doPrimeTest =
true);
60 uint32_t getLengthInMSec();
62 bool reversed,
bool mayCreate,
bool* created);
64 int32_t getFirstClusterIndexWithAudioData();
65 int32_t getFirstClusterIndexWithNoAudioData();
66 Error fillPercCache(
TimeStretcher* timeStretcher, int32_t startPosSamples, int32_t endPosSamples,
67 int32_t playDirection, int32_t maxNumSamplesToProcess);
68 void percCacheClusterStolen(
Cluster* cluster);
69 void deletePercCache(
bool beingDestructed =
false);
70 uint8_t* prepareToReadPercCache(int32_t pixellatedPos, int32_t playDirection, int32_t* earliestPixellatedPos,
71 int32_t* latestPixellatedPos);
72 bool getAveragesForCrossfade(int32_t* totals, int32_t startBytePos, int32_t crossfadeLengthSamples,
73 int32_t playDirection, int32_t lengthToAverageEach);
74 void convertDataOnAnyClustersIfNecessary();
75 int32_t getMaxPeakFromZero();
76 int32_t getFoundValueCentrePoint();
77 int32_t getValueSpan();
78 void finalizeAfterLoad(uint32_t fileSize)
override;
81 [[nodiscard]] q31_t convertToNative(
float value)
const {
return q31_from_float(value); }
83 [[nodiscard]] q31_t convertToNative(int32_t value)
const {
84 switch (rawDataFormat) {
85 case RawDataFormat::FLOAT:
86 return q31_from_float(std::bit_cast<float>(value));
88 case RawDataFormat::ENDIANNESS_WRONG_32:
89 return swapEndianness32(value);
91 case RawDataFormat::ENDIANNESS_WRONG_16:
92 return swapEndianness2x16(value);
94 case RawDataFormat::UNSIGNED_8:
95 return value ^ 0x80808080;
97 case RawDataFormat::ENDIANNESS_WRONG_24:
101 case RawDataFormat::NATIVE:
108 String tempFilePathForRecording;
109 uint8_t byteDepth{0};
110 uint32_t sampleRate{44100};
111 uint32_t audioDataStartPosBytes;
112 uint64_t audioDataLengthBytes;
114 bool audioStartDetected;
116 uint64_t lengthInSamples;
119 uint32_t fileLoopStartSamples;
120 uint32_t fileLoopEndSamples;
122 float midiNoteFromFile;
124 RawDataFormat rawDataFormat;
126 bool unloadable{
false};
128 bool unplayable{
false};
129 bool partOfFolderBeingLoaded;
130 bool fileExplicitlySpecifiesSelfAsWaveTable{
false};
139 int32_t minValueFound;
140 int32_t maxValueFound;
144 uint8_t* percCacheMemory[2]{
nullptr,
nullptr};
147 Cluster** percCacheClusters[2]{
nullptr,
nullptr};
148 int32_t numPercCacheClusters{};
150 int32_t beginningOffsetForPitchDetection;
151 bool beginningOffsetForPitchDetectionFound;
153 uint32_t waveTableCycleSize{0};
158 bool mayBeStolen(
void* thingNotToStealFrom =
nullptr)
override;
159 void steal(
char const* errorCode)
override;
162#if ALPHA_OR_BETA_VERSION
163 void numReasonsDecreasedToZero(
char const* errorCode)
override;
167 int32_t investigateFundamentalPitch(int32_t fundamentalIndexProvided, int32_t tableSize, int32_t* heightTable,
168 uint64_t* sumTable,
float* floatIndexTable,
float* getFreq,
169 int32_t numDoublings,
bool doPrimeTest);