Skip to content

Commit

Permalink
Add FLAC host test (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
earlephilhower authored Sep 3, 2020
1 parent 1c51669 commit 93a540d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/libflac/bitreader.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ struct FLAC__BitReader {
void *client_data;
};

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
static inline void crc16_update_word_(FLAC__BitReader *br, brword word)
{
unsigned crc = br->read_crc16;
Expand Down Expand Up @@ -149,6 +151,7 @@ static inline void crc16_update_word_(FLAC__BitReader *br, brword word)
#endif
br->crc16_align = 0;
}
#pragma GCC diagnostic pop

static FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
{
Expand Down Expand Up @@ -338,6 +341,8 @@ void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
br->crc16_align = br->consumed_bits;
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
{
FLAC__ASSERT(0 != br);
Expand All @@ -353,6 +358,7 @@ FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
}
return br->read_crc16;
}
#pragma GCC diagnostic pop

inline FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
{
Expand Down
4 changes: 3 additions & 1 deletion src/libflac/crc.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)

return crc;
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
{
unsigned crc = 0;
Expand All @@ -146,3 +147,4 @@ unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)

return crc;
}
#pragma GCC diagnostic pop
3 changes: 3 additions & 0 deletions src/libflac/stream_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -2021,6 +2021,8 @@ FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
return true;
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
{
uint32_t channel;
Expand Down Expand Up @@ -2167,6 +2169,7 @@ FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FL
decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
return true;
}
#pragma GCC diagnostic pop

FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
{
Expand Down
16 changes: 14 additions & 2 deletions tests/host/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,17 @@ libopus=../../src/libopus/opus_decoder.c ../../src/libopus/opus_projection_decod

opusfile=../../src/opusfile/opusfile.c ../../src/opusfile/stream.c ../../src/opusfile/internal.c ../../src/opusfile/info.c

libflac=../../src/libflac/md5.c ../../src/libflac/window.c ../../src/libflac/memory.c ../../src/libflac/cpu.c \
../../src/libflac/fixed.c ../../src/libflac/format.c ../../src/libflac/lpc.c ../../src/libflac/crc.c \
../../src/libflac/bitreader.c ../../src/libflac/bitmath.c ../../src/libflac/stream_decoder.c ../../src/libflac/float.c


CCOPTS=-g -Wunused-parameter -Wall -m32 -include Arduino.h
CPPOPTS=-g -Wunused-parameter -Wall -std=c++11 -m32 -include Arduino.h

.phony: all

all: mp3 aac wav midi opus
all: mp3 aac wav midi opus flac

mp3: FORCE
rm -f *.o
Expand All @@ -94,6 +99,13 @@ aac: FORCE
rm -f *.o
echo valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all ./aac

flac: FORCE
rm -f *.o
gcc $(CCOPTS) -DUSE_DEFAULT_STDLIB -c $(libflac) -I ../../src/ -I ../../src/libflac -I.
g++ $(CPPOPTS) -o flac flac.cpp Serial.cpp *.o ../../src/AudioFileSourceSTDIO.cpp ../../src/AudioOutputSTDIO.cpp ../../src/AudioFileSourceID3.cpp ../../src/AudioGeneratorFLAC.cpp ../../src/AudioLogger.cpp -I ../../src/ -I.
rm -f *.o
echo valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all ./flac

wav: FORCE
rm -f *.o
g++ $(CPPOPTS) -o wav wav.cpp Serial.cpp ../../src/AudioFileSourceSTDIO.cpp ../../src/AudioOutputSTDIO.cpp ../../src/AudioGeneratorWAV.cpp ../../src/AudioLogger.cpp -I ../../src/ -I.
Expand All @@ -116,6 +128,6 @@ opus: FORCE
echo valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all ./opus

clean:
rm -f mp3 aac wav midi opus *.o
rm -f mp3 aac wav midi opus flac *.o

FORCE:
24 changes: 24 additions & 0 deletions tests/host/flac.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <Arduino.h>
#include "AudioFileSourceSTDIO.h"
#include "AudioOutputSTDIO.h"
#include "AudioGeneratorFLAC.h"

#define AAC "gs-16b-2c-44100hz.flac"

int main(int argc, char **argv)
{
(void) argc;
(void) argv;
AudioFileSourceSTDIO *in = new AudioFileSourceSTDIO(AAC);
AudioOutputSTDIO *out = new AudioOutputSTDIO();
out->SetFilename("out.flac.wav");
AudioGeneratorFLAC *flac = new AudioGeneratorFLAC();

flac->begin(in, out);
while (flac->loop()) { /*noop*/ }
flac->stop();

delete flac;
delete out;
delete in;
}
Binary file added tests/host/gs-16b-2c-44100hz.flac
Binary file not shown.

0 comments on commit 93a540d

Please sign in to comment.