samplebrain/brain/src/renderer.h

124 lines
3.3 KiB
C
Raw Normal View History

2015-07-21 10:58:13 -03:00
// Copyright (C) 2015 Foam Kernow
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2015-07-09 17:50:03 -03:00
#include <list>
2022-09-04 07:38:20 -03:00
#include <spiralcore/sample.h>
2015-07-09 17:50:03 -03:00
#include "brain.h"
2016-07-08 07:41:30 -03:00
#include "block_stream.h"
2015-07-09 17:50:03 -03:00
2015-07-11 07:28:35 -03:00
#ifndef SB_RENDERER
#define SB_RENDERER
2015-07-09 17:50:03 -03:00
namespace spiralcore {
2015-09-23 14:35:13 -03:00
class renderer {
public:
renderer(brain &source, brain &target) :
2015-07-11 08:29:51 -03:00
m_source(source),
2016-02-03 13:45:09 -02:00
m_target(target),
m_search_params(0,0,0,100,0)
{ init(source,target); }
enum search_algo {
2015-09-23 14:35:13 -03:00
BASIC = 0,
REV_BASIC,
SYNAPTIC,
SYNAPTIC_SLIDE
};
2015-07-09 17:50:03 -03:00
2015-07-11 08:29:51 -03:00
void init(brain &source, brain &target);
2015-07-27 12:17:49 -03:00
void reset();
2016-07-08 07:41:30 -03:00
// block stream should be NULL if we are reading the target brain instead
void process(u32 nframes, float *buf, const block_stream *bs=NULL);
2015-07-09 17:50:03 -03:00
void set_search_algo(search_algo s) { m_search_algo=s; }
2015-07-11 08:29:51 -03:00
void set_playing(bool s) { m_playing=s; }
void set_volume(float s) { m_volume=s; }
void set_n_mix(float s) { m_n_mix=s; }
void set_target_mix(float s) { m_target_mix=s; }
void set_slide_error(double s) { m_slide_error=s; }
2015-08-06 09:39:14 -03:00
void set_stretch(u32 s) { m_stretch=s; }
2015-09-25 05:14:01 -03:00
void set_autotune(float s) { m_autotune=s; }
2015-07-11 08:29:51 -03:00
search_params *get_params() { return &m_search_params; }
2015-07-11 07:28:35 -03:00
2015-10-16 12:23:51 -03:00
search_algo get_search_algo() { return m_search_algo; }
float get_volume() { return m_volume; }
float get_n_mix() { return m_n_mix; }
float get_target_mix() { return m_target_mix; }
double get_slide_error() { return m_slide_error; }
u32 get_stretch() { return m_stretch; }
float get_autotune() { return m_autotune; }
brain &get_source() { return m_source; }
2015-07-09 17:50:03 -03:00
static bool unit_test();
2015-10-16 12:23:51 -03:00
friend ios &operator||(ios &s, renderer &b);
2015-09-23 14:35:13 -03:00
private:
2015-07-09 17:50:03 -03:00
2016-07-08 07:41:30 -03:00
bool find_render_blocks(const block_source &target, u32 nframes);
void render(const block_source &target, u32 nframes, float *buf);
2015-08-05 18:09:08 -03:00
void clean_up();
2015-07-09 17:50:03 -03:00
// realtime stuff
class render_block {
public:
2015-09-23 14:35:13 -03:00
render_block(u32 index, u32 tgt_index, u32 time) :
m_index(index),
m_tgt_index(tgt_index),
m_time(time),
m_finished(false),
m_position(0) {}
u32 m_index;
u32 m_tgt_index; // original target block
u32 m_time; // in samples
bool m_finished;
float m_position; // in samples
2015-07-09 17:50:03 -03:00
};
brain &m_source;
brain &m_target;
2015-07-11 08:29:51 -03:00
search_params m_search_params;
float m_volume;
bool m_playing;
u32 m_target_index;
2015-08-06 18:21:30 -03:00
u32 m_render_index;
2015-08-06 09:39:14 -03:00
float m_target_time;
2015-07-09 17:50:03 -03:00
u32 m_render_time;
2015-08-05 18:09:08 -03:00
u32 m_stretch;
float m_n_mix;
float m_target_mix;
2015-09-23 14:35:13 -03:00
float m_autotune;
search_algo m_search_algo;
double m_slide_error;
2015-07-27 12:17:49 -03:00
u32 m_last_tgt_shift;
std::list<render_block> m_render_blocks;
2015-09-23 14:35:13 -03:00
};
2015-07-09 17:50:03 -03:00
2015-10-16 12:23:51 -03:00
std::ios &operator||(std::ios &s, renderer &b);
2015-07-09 17:50:03 -03:00
}
2015-07-11 07:28:35 -03:00
2015-10-16 12:23:51 -03:00
2015-07-11 07:28:35 -03:00
#endif