Skip to content

Improvements for people who want to port the code to another language #63

@mcraiha

Description

@mcraiha

Hi,

I just completed my first port of the QOA to C#, and I noticed couple of things that could be improved in original code, to make the porting process a bit easier.

((v > 0) - (v < 0)) - ((n > 0) - (n < 0))
Many languages do not return 1 or 0 values for comparisons so this part requires some extra unfolding

qoa_uint64_t best_rank = -1;
-1 is not a valid value for unsigned integers in many languages. Maybe ULONG_MAX would be more suitable?

int slice_len = qoa_clamp(QOA_SLICE_LEN, 0, frame_len - sample_index);
int slice_start = sample_index * channels + c;
int slice_end = (sample_index + slice_len) * channels + c;

sample_index, channels, c and slice_len are always 0 or larger (and e.g. sample_index is unsigned), so using int type does not work without casting. Maybe size_t might be more suitable for indexing purposes?

qoa->lms[c].history[i] = ((signed short)(history >> 48));
and
qoa->lms[c].weights[i] = ((signed short)(weights >> 48));
should short be used instead of signed short?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions