Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions qoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@ void *qoa_encode(const short *sample_data, qoa_desc *qoa, unsigned int *out_len)
num_slices * 8 * qoa->channels; /* 8 byte slices */

unsigned char *bytes = QOA_MALLOC(encoded_size);
if (!bytes) {
return NULL;
}

for (unsigned int c = 0; c < qoa->channels; c++) {
/* Set the initial LMS weights to {0, 0, -1, 2}. This helps with the
Expand Down Expand Up @@ -658,6 +661,9 @@ short *qoa_decode(const unsigned char *bytes, int size, qoa_desc *qoa) {
/* Calculate the required size of the sample buffer and allocate */
int total_samples = qoa->samples * qoa->channels;
short *sample_data = QOA_MALLOC(total_samples * sizeof(short));
if (!sample_data) {
return NULL;
}

unsigned int sample_index = 0;
unsigned int frame_len;
Expand Down
8 changes: 7 additions & 1 deletion qoaplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ qoaplay_desc *qoaplay_open(const char *path) {
unsigned char header[QOA_MIN_FILESIZE];
int read = fread(header, QOA_MIN_FILESIZE, 1, file);
if (!read) {
fclose(file);
return NULL;
}

qoa_desc qoa;
unsigned int first_frame_pos = qoa_decode_header(header, QOA_MIN_FILESIZE, &qoa);
if (!first_frame_pos) {
fclose(file);
return NULL;
}

Expand All @@ -78,8 +80,12 @@ qoaplay_desc *qoaplay_open(const char *path) {
unsigned int sample_data_size = qoa.channels * QOA_FRAME_LEN * sizeof(short) * 2;

qoaplay_desc *qp = malloc(sizeof(qoaplay_desc) + buffer_size + sample_data_size);
if (!qp) {
fclose(file);
return NULL;
}

memset(qp, 0, sizeof(qoaplay_desc));

qp->first_frame_pos = first_frame_pos;
qp->file = file;
qp->buffer = ((unsigned char *)qp) + sizeof(qoaplay_desc);
Expand Down