SynthLab SDK
pcmsample.OLD.h
1 #ifndef __wavesample__
2 #define __wavesample__
3 
4 #include "stdint.h"
5 #include <string>
6 #include <iostream>
7 #include <fstream>
8 #include <iomanip>
9 #include <map>
10 
11 namespace SynthLab
12 {
13  // --- windows
14  typedef unsigned int UINT;
15  typedef unsigned long DWORD;
16  typedef unsigned char UCHAR;
17  typedef unsigned char BYTE;
18 
19  // --- wave file parser
20  class PCMSample
21  {
22  public:
23  PCMSample();
24  ~PCMSample();
25 
26  bool loadPCMSample(const char* filePath);
27 
28  UINT numChannels = 0;
29  UINT sampleRate = 0;
30  UINT sampleCount = 0;
31  UINT loopCount = 0;
32  UINT loopStartIndex = 0;
33  UINT loopEndIndex = 0;
34  UINT loopType = 0;
35  UINT unityMIDINote = 0;
36  UINT unityMIDIPitchFraction = 0;
37  UINT smpteFormat = 0;
38  UINT smpteOffset = 0;
39 
40  bool sampleLoaded = false;
41  const float* getSampleBuffer() { return pcmSampleBuffer; }
42  void setPitchless(bool _pitchlessSample) { pitchlessSample = _pitchlessSample; }
43  bool isPitchless() { return pitchlessSample; }
44 
45 
46  protected:
47  // --- the WAV file converted to floats on range of -1.0 --> +1.0
48  float* pcmSampleBuffer = nullptr;
49  bool pitchlessSample = false;
50  };
51 
52  struct convertUpper {
53  void operator()(char& c) { c = toupper((unsigned char)c); }
54  };
55 
56  // --- wave file parser
57  class WaveFolder
58  {
59  public: // Functions
60  //
61  // One Time Initialization
62  // waveFolder is the FULLY qualified file name + additional path info
63  // VALID Examples: audio.wav
64  // //samples//audio.wav
65  WaveFolder(const char* _waveFolderPath, const char* _waveFolderName) {
66  waveFolderPath = _waveFolderPath;
67  waveFolderName = _waveFolderName;
69  }
70  ~WaveFolder() {}
71 
72  // --- get next folder
73  uint32_t parseFolder(PCMSample** sampleSet, bool pitchlessLoops, bool aubioSlices = false);
74  // PCMSample* extractSampleFromFile(std::string filePath);
75 
76  void eraseSubStr(std::string & mainStr, const std::string & toErase)
77  {
78  // Search for the substring in string
79  size_t pos = mainStr.find(toErase);
80  if (pos != std::string::npos)
81  {
82  // If found then erase it from string
83  mainStr.erase(pos, toErase.length());
84  }
85  }
86 
87  void addNextFileToMap(std::string fileFolderPath, std::string fileName, bool aubioSlices, std::map<int, std::string>* wavFilePaths, int& fileCount);
88 
89  protected:
90  const char* waveFolderPath;
91  const char* waveFolderName;
92  void buildNoteTables();
93  std::string noteTableSharps[120];
94  std::string noteTableFlats[120];
95  int32_t findNoteNumberInName(const char* filename, bool shiftUpOctave = true);
96  };
97 
98 } // namespace
99 #endif
uint32_t parseFolder(PCMSample **sampleSet, bool pitchlessLoops, bool aubioSlices=false)
The main function that opens a folder, creates the WAV information map, and then parses the files in ...
Definition: pcmsample.cpp:815
void buildNoteTables()
Sets up the tables for trying to suss out the MIDI note number from a filename that attempts to inclu...
Definition: pcmsample.cpp:666
Definition: analogegcore.cpp:4
void addNextFileToMap(std::string fileFolderPath, std::string fileName, bool aubioSlices, std::map< int, std::string > *wavFilePaths, int &fileCount)
Adds information about a WAV file in the folder to a map that is later used to parse the files in suc...
Definition: pcmsample.cpp:743
bool loadPCMSample(const char *filePath)
Opens a WAV file and extracts the audio guts into a buffer of floats. Anytime later, you can use isSampleLoaded( ) to see if the sample data is valid.
Definition: pcmsample.cpp:29
int32_t findNoteNumberInName(const char *filename, bool shiftUpOctave=true)
figure out MIDI note number from string
Definition: pcmsample.cpp:701
void setPitchless(bool _pitchlessSample)
Definition: pcmsample.h:109
std::string noteTableFlats[120]
table with characters used to decode filenames with flats
Definition: pcmsample.h:230
std::string noteTableSharps[120]
table with characters used to decode filenames with sharps
Definition: pcmsample.h:229