Skip to content
Snippets Groups Projects
Commit 9c0bf391 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Use mixer add and name

parent f8f64014
No related branches found
No related tags found
1 merge request!319Audio mixer GUI and more vectorisation
......@@ -21,9 +21,8 @@ namespace audio {
template <typename T, int CHAN, int FRAME, int SIZE>
class FixedMixer : public ftl::audio::Buffer<T> {
public:
FixedMixer() : Buffer<T>(CHAN, FRAME, 44100), write_position_(0), read_position_(0) { resize(1); }
explicit FixedMixer(int tracks) : Buffer<T>(CHAN, FRAME, 44100), write_position_(0), read_position_(0) { resize(tracks); }
FixedMixer(int tracks, int rate) : Buffer<T>(CHAN, FRAME, rate), write_position_(0), read_position_(0) { resize(tracks); }
FixedMixer() : Buffer<T>(CHAN, FRAME, 44100) { }
explicit FixedMixer(int rate) : Buffer<T>(CHAN, FRAME, rate) { }
inline int maxFrames() const { return SIZE; }
......@@ -72,14 +71,19 @@ class FixedMixer : public ftl::audio::Buffer<T> {
inline void setGain(int track, float g) { tracks_.at(track).setGain(g); }
inline float gain(int track) const { return tracks_.at(track).gain(); }
void resize(int tracks);
//void resize(int tracks);
int add(const std::string &name);
const std::string &name(int track) const { return names_.at(track); }
private:
int track_num_=0;
int write_position_;
int read_position_;
int write_position_=0;
int read_position_=0;
alignas(32) T data_[SIZE][CHAN*FRAME];
std::vector<ftl::audio::FixedBuffer<T,CHAN,FRAME,SIZE>> tracks_;
std::vector<std::string> names_;
};
// ==== Implementations ========================================================
......@@ -133,7 +137,7 @@ void FixedMixer<T,CHAN,FRAME,SIZE>::read(std::vector<T> &out, int count) {
}
}
template <typename T, int CHAN, int FRAME, int SIZE>
/*template <typename T, int CHAN, int FRAME, int SIZE>
void FixedMixer<T,CHAN,FRAME,SIZE>::resize(int t) {
if (track_num_ == t) return;
......@@ -143,6 +147,14 @@ void FixedMixer<T,CHAN,FRAME,SIZE>::resize(int t) {
auto &tr = tracks_.emplace_back();
tr.setWritePosition(write_position_);
}
}*/
template <typename T, int CHAN, int FRAME, int SIZE>
int FixedMixer<T,CHAN,FRAME,SIZE>::add(const std::string &name) {
names_.push_back(name);
auto &tr = tracks_.emplace_back();
tr.setWritePosition(write_position_);
return track_num_++;
}
// ==== Common forms ===========================================================
......
......@@ -5,7 +5,10 @@ using ftl::audio::StereoMixerF;
TEST_CASE("Audio Mixer Stereo Float", "") {
SECTION("Add two in sync tracks") {
StereoMixerF<100> mixer(2);
StereoMixerF<100> mixer;
mixer.add("Track1");
mixer.add("Track2");
// Three 960 sample stereo frames
std::vector<float> in1(960*2*3);
......@@ -36,7 +39,10 @@ TEST_CASE("Audio Mixer Stereo Float", "") {
}
SECTION("Add two out of sync tracks") {
StereoMixerF<100> mixer(2);
StereoMixerF<100> mixer;
mixer.add("Track1");
mixer.add("Track2");
// Three 960 sample stereo frames
std::vector<float> in1(960*2*3);
......@@ -89,7 +95,9 @@ TEST_CASE("Audio Mixer Stereo Float", "") {
TEST_CASE("Audio Mixer Stereo Float Dynamic Tracks", "") {
SECTION("Add one track after write") {
StereoMixerF<100> mixer(1);
StereoMixerF<100> mixer;
mixer.add("Track1");
// Three 960 sample stereo frames
std::vector<float> in1(960*2*3);
......@@ -104,7 +112,7 @@ TEST_CASE("Audio Mixer Stereo Float Dynamic Tracks", "") {
std::vector<float> in2(960*2*3);
for (int i=0; i<960*2*3; ++i) in2[i] = float(i)+2.0f;
mixer.resize(2);
mixer.add("Track2");
mixer.write(0, in1);
mixer.write(1, in2);
mixer.mix();
......
......@@ -387,8 +387,9 @@ bool OpenVRRender::retrieve(ftl::data::Frame &frame_out) {
if (f.hasChannel(Channel::AudioStereo)) {
// Map a mixer track to this frame
auto &mixmap = mixmap_[f.id().id];
if (mixmap.track == -1) mixmap.track = tracks_++;
mixer_.resize(tracks_);
if (mixmap.track == -1) {
mixmap.track = mixer_.add(f.name());
}
// Do mix but must not mix same frame multiple times
if (mixmap.last_timestamp != f.timestamp()) {
......
......@@ -61,7 +61,6 @@ class OpenVRRender : public ftl::render::BaseSourceImpl {
int track=-1;
};
int tracks_=0;
std::unordered_map<uint32_t, AudioMixerMapping> mixmap_;
bool initVR();
......
......@@ -163,8 +163,9 @@ bool ScreenRender::retrieve(ftl::data::Frame &frame_out) {
if (f.hasChannel(Channel::AudioStereo)) {
// Map a mixer track to this frame
auto &mixmap = mixmap_[f.id().id];
if (mixmap.track == -1) mixmap.track = tracks_++;
mixer_.resize(tracks_);
if (mixmap.track == -1) {
mixmap.track = mixer_.add(f.name());
}
// Do mix but must not mix same frame multiple times
if (mixmap.last_timestamp != f.timestamp()) {
......
......@@ -41,7 +41,6 @@ class ScreenRender : public ftl::render::BaseSourceImpl {
int track=-1;
};
int tracks_=0;
std::unordered_map<uint32_t, AudioMixerMapping> mixmap_;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment