Skip to content

Commit

Permalink
FLAC uses big endian
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Nov 16, 2023
1 parent 73a13db commit c5ac6b9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/AudioCodecs/CodecFLAC.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "AudioCodecs/AudioEncoded.h"
#include "AudioTools/Buffers.h"
#include "AudioBasic/Net.h"
#include "flac.h"

#ifndef FLAC_READ_TIMEOUT_MS
Expand Down Expand Up @@ -217,23 +218,23 @@ class FLACDecoder : public StreamingDecoder {
for (int j = 0; j < frame->header.blocksize; j++) {
for (int i = 0; i < actual_info.channels; i++) {
//self->output_buffer[j*actual_info.channels + i] = buffer[i][j]<<8;
result_frame[i] = buffer[i][j]<<8;
result_frame[i] = ntohl(buffer[i][j])<<8;
}
self->p_print->write((uint8_t *)&frame, sizeof(frame));
}
break;
case 16:
for (int j = 0; j < frame->header.blocksize; j++) {
for (int i = 0; i < actual_info.channels; i++) {
result_frame[i] = buffer[i][j];
result_frame[i] = ntohl(buffer[i][j]);
}
self->p_print->write((uint8_t *)&frame, sizeof(frame));
}
break;
case 24:
for (int j = 0; j < frame->header.blocksize; j++) {
for (int i = 0; i < actual_info.channels; i++) {
result_frame[i] = buffer[i][j] >>8;
result_frame[i] = ntohl(buffer[i][j]) >> 8;
}
self->p_print->write((uint8_t *)&frame, sizeof(frame));
}
Expand All @@ -242,7 +243,7 @@ class FLACDecoder : public StreamingDecoder {
for (int j = 0; j < frame->header.blocksize; j++) {
for (int i = 0; i < actual_info.channels; i++) {
//self->output_buffer[j*actual_info.channels+ i] = buffer[i][j]>>16;
result_frame[i] = buffer[i][j] >>16;
result_frame[i] = ntohl(buffer[i][j]) >> 16;
}
self->p_print->write((uint8_t *)&frame, sizeof(frame));
}
Expand Down Expand Up @@ -368,10 +369,15 @@ class FLACEncoder : public AudioEncoder {
data = buffer.data();
break;

case 24:
case 32:
samples = in_size / sizeof(int32_t);
frames = samples / cfg.channels;
data = (int32_t*) in_ptr;
// convert to big endian
for (int j=0;j<samples;j++){
data[j] = htonl(data[j]);
}
break;

default:
Expand Down Expand Up @@ -419,7 +425,7 @@ class FLACEncoder : public AudioEncoder {
void writeBuffer(int16_t * data, size_t samples) {
buffer.resize(samples);
for (int j=0;j<samples;j++){
buffer[j] = data[j];
buffer[j] = htonl(data[j]);
}
}
};
Expand Down

0 comments on commit c5ac6b9

Please sign in to comment.