Commit 85cb2b6c authored by jhammen's avatar jhammen
Browse files

gain controls at different config levels

parent 028cfb71
......@@ -161,7 +161,6 @@ LV2_Worker_Status Plugin::work(LV2_Worker_Respond_Function respond,
const char *path = mesg.name();
const uint32_t index = mesg.index();
const float ogaindb = mesg.gain(); // outer config gain as set by preset or UI
const float ogain = db2ratio(ogaindb);
std::ifstream ifs;
ifs.open(path);
if (!ifs.is_open()) {
......@@ -205,12 +204,15 @@ LV2_Worker_Status Plugin::work(LV2_Worker_Respond_Function respond,
for (uint16_t i = 0; i < config->instrumentCount; i++) {
config->instruments[i].key(jsonInstrs[i]["key"].asInt());
config->instruments[i].name(jsonInstrs[i]["iname"].asString());
float instgain = jsonInstrs[i].isMember("gain") ? jsonInstrs[i]["gain"].asFloat() : 0.0;
// layers
Json::Value jsonLayers = jsonInstrs[i]["layers"];
uint16_t layerCount = jsonLayers.size();
Layer *layers = new Layer[layerCount];
for (uint16_t l = 0; l < layerCount; l++) {
layers[l].min(jsonLayers[l]["min"].asInt());
float layergain =
jsonLayers[l].isMember("gain") ? jsonLayers[l]["gain"].asFloat() : 0.0;
// samples
Json::Value jsonSamples = jsonLayers[l]["samples"];
uint16_t sampleCount = jsonSamples.size();
......@@ -239,25 +241,21 @@ LV2_Worker_Status Plugin::work(LV2_Worker_Respond_Function respond,
for (uint16_t f = 0; f < fileCount; f++) {
const string &filename = jsamples[f]["file"].asString();
const string path = fullpath(sampleBase, filename);
const float filegain =
jsamples[f].isMember("gain") ? jsamples[f]["gain"].asFloat() : 0.0;
const float gain = db2ratio(ogaindb + instgain + layergain + filegain);
SampleFile *file = filecache[path];
if (!file) {
try {
file = new SampleFile(zip, path, ogain);
file = new SampleFile(zip, path, gain);
filecache[path] = file;
} catch (const std::logic_error &e) {
StringMesg mesg(e.what(), index);
respond(handle, mesg.size(), &mesg);
return LV2_WORKER_ERR_UNKNOWN;
}
} else {
// check gain is same on cached file
if (file->gain() != ogain) {
StringMesg mesg(
"TBD: sample file adjustgain() when cached gain is different",
index);
respond(handle, mesg.size(), &mesg);
return LV2_WORKER_ERR_UNKNOWN;
}
} else if (file->gain() != gain) { // check gain is same on cached file
file->regain(gain);
}
// validate channels
uint16_t filechannels = file->channels();
......
......@@ -111,3 +111,13 @@ SampleFile::SampleFile(zip *zip, const std::string &path, float gain) : mgain(ga
}
delete[] buffer;
}
void SampleFile::regain(float newgain) {
float ratio = newgain / mgain;
for (uint16_t c = 0; c < mchannels; c++) {
for (uint64_t f = 0; f < mframes; f++) {
mdata[c][f] = mdata[c][f] * ratio;
}
}
mgain = newgain;
}
......@@ -62,6 +62,7 @@ class SampleFile {
uint64_t frames() { return mframes; }
uint16_t channels() { return mchannels; }
float gain() { return mgain; }
void regain(float gain);
};
class SampleZipEntry {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment