Skip to content

Commit 9f2611d

Browse files
fixed csound round
1 parent 1dfd680 commit 9f2611d

File tree

4 files changed

+74
-6
lines changed

4 files changed

+74
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ The resulting binaries will all be located in `bin` directory. On Windows, `lua_
160160
This must be considered when packaging the library to be embedded or used by another application.
161161

162162
# TODO
163+
* ISSUE : Still bugs when segments size is 1/3 or /6 (etc) in Csound. Probably due to the use of floor instead of round. // Probably fixed
163164
* Improve hc_resize to resize curve without creating new one (temp memory)
164165
* Documentation on hc_resize, and hc_cubic_spline_curve
165166
* Propagate resize to Lua, Faust and C++ api

csound_opcode/csound_hypercurve.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ class cs_rt_hypercurve
8787
void process_init() {it = samples.begin(); }
8888
void process_one(std::shared_ptr<segment> seg)
8989
{
90-
seg->process(it, std::floor(seg->fractional_size * _definition));
90+
//
91+
seg->process(it, std::round(seg->fractional_size * _definition));
9192
}
9293

9394
double *get_samples() {return samples.data();}
@@ -693,10 +694,12 @@ struct cs_gen : public csnd::Plugin<1, 67>, public cs_rt_hypercurve
693694
{
694695
csound->plugin_deinit(this);
695696
table = allocate_gen(csound->get_csound(), inargs[0], inargs[1]);
697+
std::cout << "gen allocated with result : " << table.res << std::endl;
696698
if(table.res != 0) {
697699
return table.res;
698700
}
699701

702+
700703
_initialize(inargs[1], inargs[2], table.t_ptr);
701704
check_total_size();
702705
process_init();
@@ -743,6 +746,7 @@ struct cs_gen : public csnd::Plugin<1, 67>, public cs_rt_hypercurve
743746

744747
int deinit()
745748
{
749+
std::cout << "hypercurve deallocation for gen number : " << table.fno << std::endl;
746750
csound->get_csound()->FTDelete(csound->get_csound(), table.fno);
747751
curve_map.erase(table.fno);
748752
return OK;
@@ -759,7 +763,10 @@ struct cs_concat : public csnd::Plugin<1, 66>, public cs_rt_hypercurve
759763
size_t total_size = count_total_size();
760764
size_t size = (inargs[1] == 0) ? total_size : inargs[1];
761765
table = allocate_gen(csound->get_csound(), inargs[0], size);
762-
766+
std::cout << "gen allocated with result : " << table.res << std::endl;
767+
if(table.res != 0) {
768+
return table.res;
769+
}
763770

764771
t = get_gen(csound->get_csound(), inargs[2]);
765772
_initialize(size, *t.t_ptr, table.t_ptr);
@@ -841,6 +848,7 @@ struct cs_concat : public csnd::Plugin<1, 66>, public cs_rt_hypercurve
841848

842849
int deinit()
843850
{
851+
std::cout << "hypercurve deallocation for gen number : " << table.fno << std::endl;
844852
csound->get_csound()->FTDelete(csound->get_csound(), table.fno);
845853
curve_map.erase(table.fno);
846854
return OK;

faust_lib/faust_hypercurve_lib/hypercurve_faust.h

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ class mouth_curve : public curve_base
12311231

12321232
constexpr static const double a = 1.0;
12331233
};
1234-
using kiss_curve = mouse_curve;
1234+
using kiss_curve = mouth_curve;
12351235

12361236
// See https://mathcurve.com/courbes2d/bicorne/bicorne.shtml
12371237
class bicorn_curve : public curve_base
@@ -1912,6 +1912,62 @@ class curve
19121912
process();
19131913
}
19141914

1915+
// Concatenate constructor
1916+
// If definition is 0, it will be the sum of all curves
1917+
curve(size_t definition_, std::vector<curve*> to_concat)
1918+
{
1919+
double total_size = 0;
1920+
for(auto & it : to_concat)
1921+
total_size += it->definition;
1922+
if(definition_ == 0)
1923+
{
1924+
definition = total_size;
1925+
} else {
1926+
definition = definition_;
1927+
}
1928+
1929+
y_start = to_concat[0]->y_start;
1930+
samples.resize(definition);
1931+
1932+
if(definition_ == 0) {
1933+
// Full size, copy all samples
1934+
size_t index = 0;
1935+
for(auto &it : to_concat)
1936+
{
1937+
for(size_t i = 0; i < it->definition; ++i)
1938+
{
1939+
samples[index] = it->samples[i];
1940+
index++;
1941+
}
1942+
}
1943+
} else {
1944+
// Interpolate
1945+
double incr = double(total_size) / double(definition);
1946+
int passed = 0;
1947+
size_t current = 0;
1948+
for(size_t i = 0; i < definition; ++i)
1949+
{
1950+
double index = i * incr;
1951+
double cindex = index - passed;
1952+
if(cindex >= to_concat[current]->definition)
1953+
{
1954+
passed += to_concat[current]->definition;
1955+
current++;
1956+
}
1957+
if(cindex == 0)
1958+
{
1959+
samples[i] = to_concat[current]->samples[0];
1960+
} else {
1961+
int f = floor(cindex);
1962+
int c = f + 1;
1963+
double relative_x = relative_position(f, c, cindex);
1964+
samples[i] = linear_interpolation(to_concat[current]->samples[f], to_concat[current]->samples[c], relative_x );
1965+
}
1966+
1967+
}
1968+
}
1969+
}
1970+
19151971
curve() {}
19161972
virtual ~curve() {}
19171973

@@ -2112,6 +2168,9 @@ class curve
21122168
memory_vector<double> samples;
21132169
};
21142170

2171+
inline curve concatenate(size_t new_size, std::vector<curve*> to_concat) {return curve(new_size, to_concat);}
2172+
inline curve concat(size_t new_size, std::vector<curve*> to_concat) {return curve(new_size, to_concat);}
2173+
21152174
}
21162175
#endif // CORE_H
21172176

@@ -2401,7 +2460,7 @@ const char *get_curve_base_name (const curve_base_index b)
24012460
case polynomial_i: return "polynomial";
24022461
case user_defined_i: return "user_defined";
24032462
case typed_i: return "typed";
2404-
case mouse_i: return "mouse";
2463+
case mouth_i: return "mouse";
24052464
case bicorn_i: return "bicorn";
24062465
case lagrange_polynomial_i: return "lagrange_polynomial";
24072466
default: return "";
@@ -2499,7 +2558,7 @@ std::pair<std::vector<double>, std::vector<control_point>> random_args_generator
24992558
return {{}, cps};
25002559
};
25012560
case typed_i: return {{random<double>(-10, 10)}, {}};
2502-
case mouse_i: return {{},{}};
2561+
case mouth_i: return {{},{}};
25032562
case bicorn_i: return {{(double)random<int>(-1, 1)}, {}};
25042563

25052564
default: return {{},{}};

src/curve_lib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ class conchal_curve : public curve_base
385385
//////////////////////////////////////////////////
386386
// Tightrope walker cure
387387
// https://mathcurve.com/courbes2d.gb/danseur/danseur.shtml
388-
// The more a is sperior to b, the more is is "straight"
388+
// The more a is superior to b, the more is is "straight"
389389
// abs(b) is the curve x max point
390390
// Also a must not be too close to b (undefined behavior) : a = 1.01 b = 1 is ok. a = 1.0001 is not.
391391
//////////////////////////////////////////////////

0 commit comments

Comments
 (0)