1 //----------------------------------------------------------------------------- 2 // Copyright (c) 2015-2018 Marcelo Fernandez 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a copy 5 // of this software and associated documentation files (the "Software"), to 6 // deal in the Software without restriction, including without limitation the 7 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 // sell copies of the Software, and to permit persons to whom the Software is 9 // furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 // IN THE SOFTWARE. 21 //----------------------------------------------------------------------------- 22 23 #ifndef __OAMLAUDIOFILE_H__ 24 #define __OAMLAUDIOFILE_H__ 25 26 #ifdef __HAVE_SOXR 27 #include <soxr.h> 28 #endif 29 30 class ByteBuffer; 31 32 class oamlAudioFile { 33 private: 34 oamlBase *base; 35 bool verbose; 36 oamlFileCallbacks *fcbs; 37 38 #ifdef __HAVE_SOXR 39 soxr_t soxr; 40 #endif 41 42 ByteBuffer buffer; 43 audioFile *handle; 44 std::string filename; 45 std::string layer; 46 int randomChance; 47 float gain; 48 49 int format; 50 unsigned int bytesPerSample; 51 unsigned int samplesPerSec; 52 unsigned int totalSamples; 53 unsigned int channelCount; 54 unsigned int samplesToEnd; 55 56 int fileFormat; 57 unsigned int fileBytesPerSample; 58 59 bool chance; 60 bool lastChance; 61 62 oamlRC OpenFile(); 63 64 int Read(); 65 int Read32(unsigned int pos); 66 67 public: 68 oamlAudioFile(std::string _filename, oamlBase *_base, oamlFileCallbacks *cbs, bool _verbose); 69 ~oamlAudioFile(); 70 SetFilename(std::string _filename)71 void SetFilename(std::string _filename) { filename = _filename; } SetLayer(std::string _layer)72 void SetLayer(std::string _layer) { layer = _layer; } SetRandomChance(int _randomChance)73 void SetRandomChance(int _randomChance) { randomChance = _randomChance; } SetGain(float _gain)74 void SetGain(float _gain) { gain = _gain; } 75 GetFilename()76 std::string GetFilename() const { return filename; } GetFilenameStr()77 const char *GetFilenameStr() const { return filename.c_str(); } GetLayer()78 std::string GetLayer() const { return layer; } GetRandomChance()79 int GetRandomChance() { return randomChance; } GetGain()80 float GetGain() { return gain; } 81 82 oamlRC Open(); 83 oamlRC Load(); 84 int LoadProgress(); 85 float ReadFloat(unsigned int pos, bool isTail = false); 86 GetChannels()87 unsigned int GetChannels() const { return channelCount; } GetTotalSamples()88 unsigned int GetTotalSamples() const { return totalSamples; } GetSamplesPerSec()89 unsigned int GetSamplesPerSec() const { return samplesPerSec; } SetSamplesToEnd(unsigned int samples)90 void SetSamplesToEnd(unsigned int samples) { samplesToEnd = samples; } 91 92 void FreeMemory(); 93 }; 94 95 #endif 96