49class Sample final :
public AudioFile {
54 void workOutBitMask();
55 Error initialize(int32_t numClusters);
56 void markAsUnloadable();
57 float determinePitch(
bool doingSingleCycle,
float minFreqHz,
float maxFreqHz,
bool doPrimeTest);
58 void workOutMIDINote(
bool doingSingleCycle,
float minFreqHz = 20,
float maxFreqHz = 10000,
bool doPrimeTest =
true);
59 uint32_t getLengthInMSec();
61 bool reversed,
bool mayCreate,
bool* created);
63 int32_t getFirstClusterIndexWithAudioData();
64 int32_t getFirstClusterIndexWithNoAudioData();
65 Error fillPercCache(
TimeStretcher* timeStretcher, int32_t startPosSamples, int32_t endPosSamples,
66 int32_t playDirection, int32_t maxNumSamplesToProcess);
67 void percCacheClusterStolen(
Cluster* cluster);
68 void deletePercCache(
bool beingDestructed =
false);
69 uint8_t* prepareToReadPercCache(int32_t pixellatedPos, int32_t playDirection, int32_t* earliestPixellatedPos,
70 int32_t* latestPixellatedPos);
71 bool getAveragesForCrossfade(int32_t* totals, int32_t startBytePos, int32_t crossfadeLengthSamples,
72 int32_t playDirection, int32_t lengthToAverageEach);
73 void convertDataOnAnyClustersIfNecessary();
74 int32_t getMaxPeakFromZero();
75 int32_t getFoundValueCentrePoint();
76 int32_t getValueSpan();
77 void finalizeAfterLoad(uint32_t fileSize)
override;
80 [[nodiscard]] q31_t convertToNative(
float value)
const {
return q31_from_float(value); }
82 [[nodiscard]] q31_t convertToNative(int32_t value)
const {
83 switch (rawDataFormat) {
84 case RawDataFormat::FLOAT:
85 return q31_from_float(std::bit_cast<float>(value));
87 case RawDataFormat::ENDIANNESS_WRONG_32:
88 return swapEndianness32(value);
90 case RawDataFormat::ENDIANNESS_WRONG_16:
91 return swapEndianness2x16(value);
93 case RawDataFormat::UNSIGNED_8:
94 return value ^ 0x80808080;
96 case RawDataFormat::ENDIANNESS_WRONG_24:
100 case RawDataFormat::NATIVE:
107 String tempFilePathForRecording;
108 uint8_t byteDepth{0};
109 uint32_t sampleRate{44100};
110 uint32_t audioDataStartPosBytes;
111 uint64_t audioDataLengthBytes;
113 bool audioStartDetected;
115 uint64_t lengthInSamples;
118 uint32_t fileLoopStartSamples;
119 uint32_t fileLoopEndSamples;
121 float midiNoteFromFile;
123 RawDataFormat rawDataFormat;
125 bool unloadable{
false};
127 bool unplayable{
false};
128 bool partOfFolderBeingLoaded;
129 bool fileExplicitlySpecifiesSelfAsWaveTable{
false};
138 int32_t minValueFound;
139 int32_t maxValueFound;
143 uint8_t* percCacheMemory[2]{
nullptr,
nullptr};
146 Cluster** percCacheClusters[2]{
nullptr,
nullptr};
147 int32_t numPercCacheClusters{};
149 int32_t beginningOffsetForPitchDetection;
150 bool beginningOffsetForPitchDetectionFound;
152 uint32_t waveTableCycleSize{0};
154 std::vector<SampleCluster> clusters;
157 bool mayBeStolen(
void* thingNotToStealFrom =
nullptr)
override;
158 void steal(
char const* errorCode)
override;
161#if ALPHA_OR_BETA_VERSION
162 void numReasonsDecreasedToZero(
char const* errorCode)
override;
166 int32_t investigateFundamentalPitch(int32_t fundamentalIndexProvided, int32_t tableSize, int32_t* heightTable,
167 uint64_t* sumTable,
float* floatIndexTable,
float* getFreq,
168 int32_t numDoublings,
bool doPrimeTest);