1 //============================================================================= 2 // MuseScore 3 // Music Composition & Notation 4 // 5 // Copyright (C) 2007-2011 Werner Schweer 6 // 7 // This program is free software; you can redistribute it and/or modify 8 // it under the terms of the GNU General Public License version 2 9 // as published by the Free Software Foundation and appearing in 10 // the file LICENCE.GPL 11 //============================================================================= 12 13 #ifndef __AUDIOFILE_H__ 14 #define __AUDIOFILE_H__ 15 16 #include <sndfile.h> 17 18 //--------------------------------------------------------- 19 // AudioFile 20 //--------------------------------------------------------- 21 22 class AudioFile { 23 enum FormatType 24 { 25 s16p, 26 fltp 27 }; 28 SF_INFO info; 29 SNDFILE* sf { nullptr }; 30 SF_INSTRUMENT inst; 31 bool hasInstrument { false }; 32 QByteArray buf; // used during read of Sample 33 int idx { 0 }; 34 FormatType _type { fltp }; 35 36 public: 37 AudioFile(); 38 ~AudioFile(); 39 40 bool open(const QByteArray&); error()41 const char* error() const { return sf_strerror(sf); } 42 sf_count_t readData(short* data, sf_count_t frames); 43 channels()44 int channels() const { return info.channels; } frames()45 sf_count_t frames() const { return info.frames; } samplerate()46 int samplerate() const { return info.samplerate; } 47 getFileLen()48 sf_count_t getFileLen() const { return buf.size(); } tell()49 sf_count_t tell() const { return idx; } 50 sf_count_t read(void* ptr, sf_count_t count); 51 sf_count_t write(const void* ptr, sf_count_t count); 52 sf_count_t seek(sf_count_t offset, int whence); 53 unsigned int loopStart(int v = 0) { return hasInstrument ? inst.loops[v].start : -1; } 54 unsigned int loopEnd(int v = 0) { return hasInstrument ? inst.loops[v].end : -1; } 55 int loopMode(int v = 0) { return hasInstrument ? inst.loops[v].mode : -1; } 56 }; 57 58 #endif 59 60