Skip to content

Commit

Permalink
Fix all warnings according to GCC 13.1 -Wall -Wextra
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpatdiscord committed May 28, 2023
1 parent 7c42bb7 commit 5ea8205
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
46 changes: 24 additions & 22 deletions qoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ unsigned int qoa_encode_frame(const short *sample_data, qoa_desc *qoa, unsigned
), bytes, &p);


for (int c = 0; c < channels; c++) {
for (unsigned c = 0; c < channels; c++) {
/* If the weights have grown too large, reset them to 0. This may happen
with certain high-frequency sounds. This is a last resort and will
introduce quite a bit of noise, but should at least prevent pops/clicks */
Expand All @@ -385,7 +385,7 @@ unsigned int qoa_encode_frame(const short *sample_data, qoa_desc *qoa, unsigned
/* Write the current LMS state */
qoa_uint64_t weights = 0;
qoa_uint64_t history = 0;
for (int i = 0; i < QOA_LMS_LEN; i++) {
for (unsigned i = 0; i < QOA_LMS_LEN; i++) {
history = (history << 16) | (qoa->lms[c].history[i] & 0xffff);
weights = (weights << 16) | (qoa->lms[c].weights[i] & 0xffff);
}
Expand All @@ -395,9 +395,13 @@ unsigned int qoa_encode_frame(const short *sample_data, qoa_desc *qoa, unsigned

/* We encode all samples with the channels interleaved on a slice level.
E.g. for stereo: (ch-0, slice 0), (ch 1, slice 0), (ch 0, slice 1), ...*/
for (int sample_index = 0; sample_index < frame_len; sample_index += QOA_SLICE_LEN) {

for (int c = 0; c < channels; c++) {
qoa_lms_t best_lms;
memset(&best_lms, 0, sizeof(best_lms));

for (unsigned sample_index = 0; sample_index < frame_len; sample_index += QOA_SLICE_LEN) {

for (unsigned c = 0; c < channels; c++) {
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;
Expand All @@ -406,9 +410,8 @@ unsigned int qoa_encode_frame(const short *sample_data, qoa_desc *qoa, unsigned
16 scalefactors, encode all samples for the current slice and
meassure the total squared error. */
qoa_uint64_t best_error = -1;
qoa_uint64_t best_slice;
qoa_lms_t best_lms;
int best_scalefactor;
qoa_uint64_t best_slice = 0;
int best_scalefactor = 0;

for (int sfi = 0; sfi < 16; sfi++) {
/* There is a strong correlation between the scalefactors of
Expand Down Expand Up @@ -488,9 +491,7 @@ void *qoa_encode(const short *sample_data, qoa_desc *qoa, unsigned int *out_len)
num_frames * QOA_LMS_LEN * 4 * qoa->channels + /* 4 * 4 bytes lms state per channel */
num_slices * 8 * qoa->channels; /* 8 byte slices */

unsigned char *bytes = QOA_MALLOC(encoded_size);

for (int c = 0; c < qoa->channels; c++) {
for (unsigned c = 0; c < qoa->channels; c++) {
/* Set the initial LMS weights to {0, 0, -1, 2}. This helps with the
prediction of the first few ms of a file. */
qoa->lms[c].weights[0] = 0;
Expand All @@ -500,11 +501,12 @@ void *qoa_encode(const short *sample_data, qoa_desc *qoa, unsigned int *out_len)

/* Explicitly set the history samples to 0, as we might have some
garbage in there. */
for (int i = 0; i < QOA_LMS_LEN; i++) {
for (unsigned i = 0; i < QOA_LMS_LEN; i++) {
qoa->lms[c].history[i] = 0;
}
}

unsigned char *bytes = QOA_MALLOC(encoded_size);

/* Encode the header and go through all frames */
unsigned int p = qoa_encode_header(qoa, bytes);
Expand All @@ -513,7 +515,7 @@ void *qoa_encode(const short *sample_data, qoa_desc *qoa, unsigned int *out_len)
#endif

int frame_len = QOA_FRAME_LEN;
for (int sample_index = 0; sample_index < qoa->samples; sample_index += frame_len) {
for (unsigned sample_index = 0; sample_index < qoa->samples; sample_index += frame_len) {
frame_len = qoa_clamp(QOA_FRAME_LEN, 0, qoa->samples - sample_index);
const short *frame_samples = sample_data + sample_index * qoa->channels;
unsigned int frame_size = qoa_encode_frame(frame_samples, qoa, frame_len, bytes + p);
Expand Down Expand Up @@ -576,14 +578,14 @@ unsigned int qoa_decode_frame(const unsigned char *bytes, unsigned int size, qoa

/* Read and verify the frame header */
qoa_uint64_t frame_header = qoa_read_u64(bytes, &p);
int channels = (frame_header >> 56) & 0x0000ff;
int samplerate = (frame_header >> 32) & 0xffffff;
int samples = (frame_header >> 16) & 0x00ffff;
int frame_size = (frame_header ) & 0x00ffff;
unsigned channels = (frame_header >> 56) & 0x0000ff;
unsigned samplerate = (frame_header >> 32) & 0xffffff;
unsigned samples = (frame_header >> 16) & 0x00ffff;
unsigned frame_size = (frame_header ) & 0x00ffff;

int data_size = frame_size - 8 - QOA_LMS_LEN * 4 * channels;
int num_slices = data_size / 8;
int max_total_samples = num_slices * QOA_SLICE_LEN;
unsigned data_size = frame_size - 8 - QOA_LMS_LEN * 4 * channels;
unsigned num_slices = data_size / 8;
unsigned max_total_samples = num_slices * QOA_SLICE_LEN;

if (
channels != qoa->channels ||
Expand All @@ -596,7 +598,7 @@ unsigned int qoa_decode_frame(const unsigned char *bytes, unsigned int size, qoa


/* Read the LMS state: 4 x 2 bytes history, 4 x 2 bytes weights per channel */
for (int c = 0; c < channels; c++) {
for (unsigned c = 0; c < channels; c++) {
qoa_uint64_t history = qoa_read_u64(bytes, &p);
qoa_uint64_t weights = qoa_read_u64(bytes, &p);
for (int i = 0; i < QOA_LMS_LEN; i++) {
Expand All @@ -609,8 +611,8 @@ unsigned int qoa_decode_frame(const unsigned char *bytes, unsigned int size, qoa


/* Decode all slices for all channels in this frame */
for (int sample_index = 0; sample_index < samples; sample_index += QOA_SLICE_LEN) {
for (int c = 0; c < channels; c++) {
for (unsigned sample_index = 0; sample_index < samples; sample_index += QOA_SLICE_LEN) {
for (unsigned c = 0; c < channels; c++) {
qoa_uint64_t slice = qoa_read_u64(bytes, &p);

int scalefactor = (slice >> 60) & 0xf;
Expand Down
9 changes: 3 additions & 6 deletions qoaplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ unsigned int qoaplay_decode(qoaplay_desc *qp, float *sample_data, int num_sample
}

/* Normalize to -1..1 floats and write to dest */
for (int c = 0; c < qp->info.channels; c++) {
for (unsigned c = 0; c < qp->info.channels; c++) {
sample_data[dst_index++] = qp->sample_data[src_index++] / 32768.0;
}
qp->sample_data_pos++;
Expand All @@ -150,10 +150,7 @@ int qoaplay_get_frame(qoaplay_desc *qp) {
return qp->sample_pos / QOA_FRAME_LEN;
}

void qoaplay_seek_frame(qoaplay_desc *qp, int frame) {
if (frame < 0) {
frame = 0;
}
void qoaplay_seek_frame(qoaplay_desc *qp, unsigned frame) {
if (frame > qp->info.samples / QOA_FRAME_LEN) {
frame = qp->info.samples / QOA_FRAME_LEN;
}
Expand Down Expand Up @@ -200,7 +197,7 @@ hand over to the platform's audio API. All file IO and decoding is done here. */

static void sokol_audio_cb(float* sample_data, int num_samples, int num_channels, void *user_data) {
qoaplay_desc *qoaplay = (qoaplay_desc *)user_data;
if (num_channels != qoaplay->info.channels) {
if ((unsigned)num_channels != qoaplay->info.channels) {
printf("Audio cb channels %d not equal qoa channels %d\n", num_channels, qoaplay->info.channels);
exit(1);
}
Expand Down

0 comments on commit 5ea8205

Please sign in to comment.