mirror of
https://gitlab.com/then-try-this/samplebrain.git
synced 2025-07-03 18:53:35 +00:00
Compare commits
3 Commits
developmen
...
production
Author | SHA1 | Date | |
---|---|---|---|
30e290dcbd | |||
032fd7c039 | |||
a8ea957f45 |
@ -33,10 +33,6 @@ Load the demo using "load session" not "load brain" (sessions contain
|
||||
both the target and brain samples). The original samples used to
|
||||
create the demo session [can be found here for
|
||||
testing](https://static.thentrythis.org/samplebrain/samples/).
|
||||
|
||||
# Community
|
||||
|
||||
* https://www.reddit.com/r/samplebrain/
|
||||
|
||||
# Download
|
||||
|
||||
|
@ -113,8 +113,8 @@ void MainWindow::init_from_session(const string &filename) {
|
||||
ifstream ifs(filename.c_str(),ios::binary);
|
||||
if (!ifs) return;
|
||||
|
||||
brain s,t,lt;
|
||||
u32 version=1;
|
||||
brain s,t;
|
||||
u32 version=0;
|
||||
ifs||version;
|
||||
renderer r(s,t);
|
||||
ifs||r;
|
||||
@ -133,14 +133,7 @@ void MainWindow::init_from_session(const string &filename) {
|
||||
ifs||source_window||target_window;
|
||||
// todo: probably don't need to load all the sample data too :/
|
||||
ifs||s;
|
||||
ifs||t; // left
|
||||
ifs||lt; // right
|
||||
|
||||
if (version>0) {
|
||||
ifs||m_stereo;
|
||||
m_Ui.checkBoxStereo->setChecked(m_stereo);
|
||||
}
|
||||
|
||||
ifs||t;
|
||||
|
||||
// brain tweaks
|
||||
search_params * p = r.get_params();
|
||||
@ -166,7 +159,7 @@ void MainWindow::init_from_session(const string &filename) {
|
||||
m_Ui.spinBoxSynapses->setValue(p->m_num_synapses);
|
||||
m_Ui.sliderSlideError->setValue(r.get_slide_error());
|
||||
m_Ui.spinBoxSlideError->setValue(r.get_slide_error());
|
||||
|
||||
|
||||
// target
|
||||
if (t.get_samples().size()>0) {
|
||||
// extract target filename from brain sample
|
||||
@ -205,6 +198,8 @@ void MainWindow::init_from_session(const string &filename) {
|
||||
m_Ui.sliderAutotune->setValue(r.get_autotune()*100);
|
||||
m_Ui.doubleSpinBoxAutotune->setValue(r.get_autotune());
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -393,11 +393,7 @@ private slots:
|
||||
}
|
||||
|
||||
void stereo_mode(bool s) {
|
||||
m_stereo=s;
|
||||
send_audio_osc("/stereo","i",s);
|
||||
// irritating but need to tell process thread about stereo state
|
||||
// just to it can save it to the session file
|
||||
send_process_osc("/stereo","i",s);
|
||||
}
|
||||
|
||||
void net_enable(int id) {
|
||||
@ -471,7 +467,6 @@ private:
|
||||
audio_thread *m_audio_thread;
|
||||
|
||||
string m_audio_port;
|
||||
string m_process_port;
|
||||
string m_process_port;
|
||||
QString m_format_string;
|
||||
bool m_stereo;
|
||||
};
|
||||
|
@ -140,10 +140,6 @@ void process_thread::process() {
|
||||
if (name=="/save_session") {
|
||||
save_session(cmd.get_string(0));
|
||||
}
|
||||
if (name=="/stereo") {
|
||||
// only for session file save
|
||||
m_stereo=cmd.get_int(0);
|
||||
}
|
||||
}
|
||||
#ifdef WIN32
|
||||
Sleep(1);
|
||||
@ -178,7 +174,16 @@ void process_thread::load_session(const std::string &filename) {
|
||||
m_left_target.clear();
|
||||
m_right_target.clear();
|
||||
ifstream ifs(filename.c_str(),ios::binary);
|
||||
stream_session(ifs);
|
||||
u32 version=0;
|
||||
ifs||version;
|
||||
ifs||(*m_left_renderer);
|
||||
ifs||(*m_right_renderer);
|
||||
ifs||m_source_block_size||m_source_overlap;
|
||||
ifs||m_target_block_size||m_target_overlap;
|
||||
ifs||m_window_type||m_target_window_type;
|
||||
ifs||m_source;
|
||||
ifs||m_left_target;
|
||||
ifs||m_right_target;
|
||||
ifs.close();
|
||||
pthread_mutex_unlock(m_brain_mutex);
|
||||
}
|
||||
@ -186,23 +191,16 @@ void process_thread::load_session(const std::string &filename) {
|
||||
void process_thread::save_session(const std::string &filename) {
|
||||
pthread_mutex_lock(m_brain_mutex);
|
||||
ofstream ofs(filename.c_str(),ios::binary);
|
||||
stream_session(ofs);
|
||||
u32 version=0;
|
||||
ofs||version;
|
||||
ofs||(*m_left_renderer);
|
||||
ofs||(*m_right_renderer);
|
||||
ofs||m_source_block_size||m_source_overlap;
|
||||
ofs||m_target_block_size||m_target_overlap;
|
||||
ofs||m_window_type||m_target_window_type;
|
||||
ofs||m_source;
|
||||
ofs||m_left_target;
|
||||
ofs||m_right_target;
|
||||
ofs.close();
|
||||
pthread_mutex_unlock(m_brain_mutex);
|
||||
}
|
||||
|
||||
void process_thread::stream_session(std::ios &fs) {
|
||||
u32 version=1;
|
||||
fs||version;
|
||||
fs||(*m_left_renderer);
|
||||
fs||(*m_right_renderer);
|
||||
fs||m_source_block_size||m_source_overlap;
|
||||
fs||m_target_block_size||m_target_overlap;
|
||||
fs||m_window_type||m_target_window_type;
|
||||
fs||m_source;
|
||||
fs||m_left_target;
|
||||
fs||m_right_target;
|
||||
if (version>0) {
|
||||
fs||m_stereo;
|
||||
}
|
||||
}
|
||||
|
@ -54,16 +54,13 @@ namespace spiralcore {
|
||||
brain m_source, m_left_target, m_right_target;
|
||||
|
||||
private:
|
||||
void stream_session(std::ios &fs);
|
||||
|
||||
OSC_server m_osc;
|
||||
OSC_server m_osc;
|
||||
u32 m_source_block_size;
|
||||
float m_source_overlap;
|
||||
u32 m_target_block_size;
|
||||
float m_target_overlap;
|
||||
window::type m_window_type;
|
||||
window::type m_target_window_type;
|
||||
bool m_stereo;
|
||||
pthread_t *m_thread;
|
||||
|
||||
// only use in mutex obvs...
|
||||
|
@ -60,7 +60,7 @@ void OSC_server::error_handler(int num, const char *msg, const char *path) {
|
||||
}
|
||||
|
||||
int OSC_server::default_handler(const char *path, const char *types, lo_arg **argv,
|
||||
int argc, void *data, void *user_data) {
|
||||
int argc, lo_message data, void *user_data) {
|
||||
OSC_server *server = (OSC_server*)user_data;
|
||||
if (!server) return -1;
|
||||
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
bool ok() { return m_server!=NULL; }
|
||||
|
||||
private:
|
||||
static int default_handler(const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
|
||||
static int default_handler(const char *path, const char *types, lo_arg **argv, int argc, lo_message data, void *user_data);
|
||||
static void error_handler(int num, const char *m, const char *path);
|
||||
|
||||
lo_server_thread m_server;
|
||||
|
@ -51,12 +51,12 @@ void audio_device::connect(const string &output_device_name, const string &clien
|
||||
m_client.attach(output_device_name,clientname,opt);
|
||||
}
|
||||
|
||||
void audio_device::save_sample(const string &filename, unsigned int channels, const sample s) {
|
||||
void audio_device::save_sample(const string &filename, const sample s) {
|
||||
SF_INFO sfinfo;
|
||||
sfinfo.format=SF_FORMAT_WAV | SF_FORMAT_FLOAT;
|
||||
sfinfo.frames=s.get_length();
|
||||
sfinfo.samplerate=m_samplerate;
|
||||
sfinfo.channels=channels;
|
||||
sfinfo.channels=1;
|
||||
sfinfo.sections=1;
|
||||
sfinfo.seekable=0;
|
||||
SNDFILE* f=sf_open(filename.c_str(), SFM_WRITE, &sfinfo);
|
||||
@ -69,7 +69,8 @@ void audio_device::save_sample(const string &filename, unsigned int channels, co
|
||||
void audio_device::start_recording(std::string filename) {
|
||||
m_record_filename=filename;
|
||||
m_recording=true;
|
||||
m_record_buffer.clear();
|
||||
m_record_buffer_left.clear();
|
||||
m_record_buffer_right.clear();
|
||||
m_record_counter=0;
|
||||
}
|
||||
|
||||
@ -80,19 +81,13 @@ void audio_device::stop_recording() {
|
||||
|
||||
void audio_device::maybe_record() {
|
||||
if (m_recording) {
|
||||
sample news(left_out.get_length()*2);
|
||||
for (unsigned int i=0; i<left_out.get_length(); i++) {
|
||||
news[i*2]=left_out[i];
|
||||
news[i*2+1]=right_out[i];
|
||||
}
|
||||
|
||||
m_record_buffer.add(news);
|
||||
m_record_counter++;
|
||||
|
||||
// save "every now and again"
|
||||
if (m_record_counter%10==0) {
|
||||
save_sample(m_record_filename+".wav",2,m_record_buffer);
|
||||
}
|
||||
m_record_buffer_left.add(left_out);
|
||||
m_record_buffer_right.add(right_out);
|
||||
m_record_counter++;
|
||||
if (m_record_counter%10==0) {
|
||||
save_sample(m_record_filename+"-left.wav", m_record_buffer_left);
|
||||
save_sample(m_record_filename+"-right.wav", m_record_buffer_right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,12 +42,13 @@ namespace spiralcore {
|
||||
|
||||
portaudio_client m_client;
|
||||
|
||||
void save_sample(const std::string &filename, unsigned int channels, const sample s);
|
||||
void save_sample(const std::string &filename, const sample s);
|
||||
|
||||
private:
|
||||
bool m_recording;
|
||||
std::string m_record_filename;
|
||||
sample m_record_buffer;
|
||||
sample m_record_buffer_left;
|
||||
sample m_record_buffer_right;
|
||||
u32 m_record_counter;
|
||||
u32 m_samplerate;
|
||||
};
|
||||
|
Reference in New Issue
Block a user