Skip to content

Commit

Permalink
Ship input.wav in flac format and convert it to wav when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
brummer10 committed Oct 11, 2023
1 parent d3bc412 commit 99691e2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion plugins/NeuralRecord/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ ifeq ($(BUILD_LV2),true)
@mkdir -p -m755 $(USER_LV2_DIR)/$(NAME).lv2 && \
install -m755 $(TARGET_DIR)/$(NAME).lv2/*$(LIB_EXT) $(USER_LV2_DIR)/$(NAME).lv2 && \
install -m644 $(TARGET_DIR)/$(NAME).lv2/*.ttl $(USER_LV2_DIR)/$(NAME).lv2 && \
cp -r $(TARGET_DIR)/$(NAME).lv2/resources $(DESTDIR)$(LV2_DIR)/$(NAME).lv2
cp -r $(TARGET_DIR)/$(NAME).lv2/resources $(USER_LV2_DIR)/$(NAME).lv2
endif
ifeq ($(BUILD_JACK),true)
ifeq ($(HAVE_JACK),true)
Expand Down
23 changes: 19 additions & 4 deletions plugins/NeuralRecord/profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,17 +283,32 @@ inline std::string Profil::get_ifilename() {
struct stat sb;
char * path = strdup(get_profile_library_path().data());
std::string iname = dirname(path);
iname += PATH_SEPARATOR "resources" PATH_SEPARATOR "input.wav";
iname += PATH_SEPARATOR "resources" PATH_SEPARATOR "input.flac";
std::string oname = get_path() + "input.wav";
if (stat (oname.c_str(), &sb) != 0 && stat (iname.c_str(), &sb) == 0) {
std::ifstream src(iname.c_str(), std::ios::binary);
std::ofstream dest(oname.c_str(), std::ios::binary);
dest << src.rdbuf();
convert_to_wave(iname, oname);
}
free(path);
return oname;
}

inline void Profil::convert_to_wave(std::string fname, std::string oname) {
if (tape1) { delete[] tape1; tape1 = 0; }
int lsize = load_from_wave(fname); // load flac file
SF_INFO sfinfo ;
sfinfo.channels = channel;
sfinfo.samplerate = fSamplingFreq;
sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_24;

SNDFILE * sf = sf_open(oname.c_str(), SFM_WRITE, &sfinfo);
if (sf) {
save_to_wave(sf, tape1, lsize);
sf_close(sf);
}
if (tape1) { delete[] tape1; tape1 = 0; }
}


// load wav file into buffer
inline int Profil::load_from_wave(std::string fname) {
SF_INFO sfinfo;
Expand Down
1 change: 1 addition & 0 deletions plugins/NeuralRecord/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class Profil {
void normalize();
static void *run_thread(void* p);
inline int load_from_wave(std::string fname);
inline void convert_to_wave(std::string fname, std::string oname);
inline std::string get_path();
inline std::string get_ffilename();
inline std::string get_ifilename();
Expand Down
Binary file added plugins/NeuralRecord/resources/input.flac
Binary file not shown.
Binary file removed plugins/NeuralRecord/resources/input.wav
Binary file not shown.

0 comments on commit 99691e2

Please sign in to comment.