From 6cb48863cf50042afc8f4854d0d0780baa68aa75 Mon Sep 17 00:00:00 2001 From: Pezz89 Date: Mon, 11 Jul 2016 20:59:54 +0100 Subject: [PATCH] Begun creation of audio database class. Rethought AudioFile class design (removed mode switching approach) --- CMakeLists.txt | 5 ++++- include/AudioDatabase.h | 45 +++++++++++++++++++++++++++++++++++++++++ include/AudioFile.h | 16 +++++++-------- src/AudioDatabase.cpp | 1 + src/AudioFile.cpp | 29 +++++++++++++------------- src/concatenator.cpp | 7 +++++-- 6 files changed, 77 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 81c61c3..1dd458e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ set(Boost_USE_STATIC_RUNTIME OFF) ############################################################################### # Set build flags -set(CMAKE_CXX_FLAGS "-g -Wall ") +set(CMAKE_CXX_FLAGS "-g -Wall") # Set cmake to output executable to the bin directory set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) @@ -56,7 +56,10 @@ add_subdirectory(external) add_executable(concatenator ${CONCATENATOR_SOURCE_FILES} ${CONCATENATOR_HEADER_FILES}) +# Link to external libraries target_link_libraries(concatenator ${Boost_LIBRARIES}) +target_link_libraries(concatenator ${LIBSNDFILE_LIBRARIES}) + # Test build options (this code adapted from: https://github.com/ComicSansMS/GhulbusBase/blob/master/CMakeLists.txt) option(BUILD_TESTS "Determines whether to build tests." ON) if(BUILD_TESTS) diff --git a/include/AudioDatabase.h b/include/AudioDatabase.h index e69de29..10082fb 100644 --- a/include/AudioDatabase.h +++ b/include/AudioDatabase.h @@ -0,0 +1,45 @@ +#include +#include +#include + +using std::string; +using std::cout; +using std::endl; + +class AudioDatabase { + public: + template + AudioDatabase(std::string audio_dir, std::string database_dir, Iter it, Iter end); + private: + std::string database_dir = ""; + std::string audio_dir = ""; +}; + +template +bool in_array(const string &value, const container &array) +{ + cout <<"Test: " << value << endl; + return std::find(array.begin(), array.end(), value) != array.end(); +} + +template +bool check_analyses_valid(Iter iterator, Iter end) +{ + static std::list valid_analyses = {"f0", "RMS"}; + + while(iterator != end) + { + if(!in_array(*iterator, valid_analyses)) { + cout << "Nope!" << endl; + return false; + } + ++iterator; + } + return true; +} + +template +AudioDatabase::AudioDatabase(string audio_dir, string database_dir, Iter it, Iter end) { + cout << "HELLO?!?" << endl; + check_analyses_valid(it, end); +} diff --git a/include/AudioFile.h b/include/AudioFile.h index 1397e02..a2548c1 100644 --- a/include/AudioFile.h +++ b/include/AudioFile.h @@ -3,19 +3,17 @@ class AudioFile { public: - AudioFile(const char * fname, bool open=true); - AudioFile(const char * fname, int format, int channels, int samplerate); - ~AudioFile(); - void swap_mode(std::string m); - bool is_open() { return open; }; - private: - std::string mode; - std::string name; - bool open; + AudioFile(const char * &name, const int &mode=SFM_RDWR, const int &format=0, const int &channels=0, const int &samplerate=0); + int open(const int &mode=SFM_READ, const int &format=0, const int &channels=0, const int &samplerate=0); + protected: SndfileHandle file; + SF_INFO* file_info; + private: + std::string name; }; class AnalysedAudioFile : public AudioFile { public: private: }; + diff --git a/src/AudioDatabase.cpp b/src/AudioDatabase.cpp index e69de29..8b13789 100644 --- a/src/AudioDatabase.cpp +++ b/src/AudioDatabase.cpp @@ -0,0 +1 @@ + diff --git a/src/AudioFile.cpp b/src/AudioFile.cpp index 209db12..e2af864 100644 --- a/src/AudioFile.cpp +++ b/src/AudioFile.cpp @@ -1,22 +1,23 @@ #include "AudioFile.h" #include +#include +#include using namespace std; -AudioFile::AudioFile(const char * fname, bool open) +AudioFile::AudioFile(const char * &name, const int &mode, const int &format, const int &channels, const int &samplerate) { - if(open) { - file = SndfileHandle(fname); + this->name = name; + open(mode, format, channels, samplerate); +} + +int AudioFile::open(const int &mode, const int &format, const int &channels, const int &samplerate) +{ + switch(mode){ + case SFM_READ: file = SndfileHandle(name); + case SFM_WRITE: file = SndfileHandle(name, SFM_WRITE, format, channels, samplerate); + case SFM_RDWR: file = SndfileHandle(name, SFM_RDWR, format, channels, samplerate); } - name = fname; -} - -AudioFile::AudioFile(const char * fname, const int format, const int channels, const int samplerate) -{ - -} - -void AudioFile::swap_mode(string m) -{ - + + return 0; } diff --git a/src/concatenator.cpp b/src/concatenator.cpp index 5cc29b3..09b6e45 100644 --- a/src/concatenator.cpp +++ b/src/concatenator.cpp @@ -1,15 +1,18 @@ #include -#include "Logger.h" +#include "logger.h" #include "ArgumentParser.h" #include "AudioDatabase.h" +#include using namespace std; int main(int argc, char** argv) { Logger log = Logger(); - ArgumentParser argparse = ArgumentParser(); //argparse.parseargs(argc, argv); log.error("My pretty little error!"); + + vector analyses = {"BLARGH"}; + AudioDatabase db = AudioDatabase("./", "./", analyses.begin(), analyses.end()); return 0; }