Skip to content

Commit

Permalink
Merge pull request #3 from drowe67/dr-cleanup2
Browse files Browse the repository at this point in the history
Cleanup Part 2
  • Loading branch information
drowe67 authored Jul 19, 2023
2 parents 6588e77 + 4d6c143 commit 06d4c11
Show file tree
Hide file tree
Showing 239 changed files with 91,694 additions and 111,671 deletions.
168 changes: 168 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
SortPriority: 0
- Regex: '^<.*\.h>'
Priority: 1
SortPriority: 0
- Regex: '^<.*'
Priority: 2
SortPriority: 0
- Regex: '.*'
Priority: 3
SortPriority: 0
IncludeIsMainRegex: '([-_](test|unittest))?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: true
IndentGotoLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
CanonicalDelimiter: ''
BasedOnStyle: google
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: Auto
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
...

2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
shell: bash
run: |
sudo apt-get update
sudo apt-get install octave octave-common octave-signal liboctave-dev gnuplot sox p7zip-full python3-numpy valgrind
sudo apt-get install octave octave-common octave-signal liboctave-dev gnuplot sox p7zip-full python3-numpy valgrind clang-format
- name: Create Build Directory
shell: bash
Expand Down
30 changes: 6 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ option(BUILD_SHARED_LIBS
"Build shared library. Set to OFF for static library." ON)
option(UNITTEST "Build unittest binaries." OFF)

# LPCNet needs to be bootstraped because codec2 and freedvlpcnet are
# LPCNet needs to be bootstrapped because codec2 and freedvlpcnet are
# cross dependent.
option(LPCNET "Build codec2 with LPCNet support." OFF)
set(LPCNET_BUILD_DIR FALSE CACHE PATH "Location of lpcnet build tree.")
Expand Down Expand Up @@ -308,6 +308,10 @@ if(UNITTEST)
include(CTest)
enable_testing()

add_test(NAME test_clang_format
COMMAND sh -c "cd ${CMAKE_CURRENT_SOURCE_DIR};
clang-format --dry-run --Werror src/*.c src/*.h unittest/*.c demo/*.c")

add_test(NAME test_freedv_get_hash
COMMAND sh -c "${CMAKE_CURRENT_BINARY_DIR}/unittest/thash")

Expand Down Expand Up @@ -585,14 +589,7 @@ endif()
./ofdm_mod --in /dev/zero --testframes 10 --mode 2020B --ldpc --clip --txbpf |
./ch - - --No -19 |
./ofdm_demod --mode 2020B --testframes --ldpc -v 2 > /dev/null")

# 2020C AWGN test
add_test(NAME test_OFDM_modem_2020C_AWGN
COMMAND sh -c "cd ${CMAKE_CURRENT_BINARY_DIR}/src;
./ofdm_mod --in /dev/zero --testframes 10 --mode 2020C --ldpc --clip --txbpf |
./ch - - --No -21 |
./ofdm_demod --mode 2020C --testframes --ldpc -v 2 > /dev/null")


# -------------------------------------------------------------------------
# OFDM Data modes
# -------------------------------------------------------------------------
Expand Down Expand Up @@ -861,13 +858,6 @@ if(LPCNET)
./freedv_rx 2020B - /dev/null --testframes"
)

add_test(NAME test_freedv_api_2020C_mpd
COMMAND sh -c "cd ${CMAKE_CURRENT_BINARY_DIR}/src;
dd bs=32000 count=60 if=/dev/zero |
./freedv_tx 2020C - - --testframes --clip 1 |
./ch - - --No -32 --mpd --fading_dir ../unittest |
./freedv_rx 2020C - /dev/null --testframes"
)
endif()

add_test(NAME test_freedv_api_2400A
Expand Down Expand Up @@ -1142,14 +1132,6 @@ endif(NOT APPLE)
COMMAND sh -c "./c2enc 700C ${CMAKE_CURRENT_SOURCE_DIR}/raw/hts1a.raw - | ./c2dec 700C - - | sox -t .s16 -r 8000 - hts1a_700C.wav"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src
)
add_test(NAME test_codec2_mode_450
COMMAND sh -c "./c2enc 450 ${CMAKE_CURRENT_SOURCE_DIR}/raw/hts1a.raw - | ./c2dec 450 - - | sox -t .s16 -r 8000 - hts1a_450.wav"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src
)
add_test(NAME test_codec2_mode_450PWB
COMMAND sh -c "./c2enc 450PWB ${CMAKE_CURRENT_SOURCE_DIR}/raw/hts1a.raw - | ./c2dec 450PWB - - | sox -t .s16 -r 16000 - hts1a_450PWB.wav"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src
)

add_test(NAME test_vq_mbest
COMMAND sh -c "./tvq_mbest; \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ CTest is used as a test framework, with support from [GNU Octave](https://www.gn

1. Install GNU Octave and libraries on Ubuntu with:
```
sudo apt install octave octave-common octave-signal liboctave-dev gnuplot python3-numpy sox valgrind
sudo apt install octave octave-common octave-signal liboctave-dev gnuplot python3-numpy sox valgrind clang-format
```
1. To build and run the tests:
```
Expand Down
2 changes: 1 addition & 1 deletion README_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ From the callers point of view, the frame format of each burst is:
| Preamble | payload data | CRC | payload data | CRC | ........... | Postamble |
| frame 1 -----------| frame 2 -----------| ... frame N |
```
In the next layer down, each frame is comprised of several OFDM "modem frames", that contain pilot, unique word, and FEC symbols to handle syncronisation and error correction over the challenging HF channel. The preamble and postamble are used to locate the burst and estimate it's frequency offset. Having both a pre and postamble increases the probability of successful detection of the burst in a fading channel. Here are some single frame bursts on a MPP channel at 5dB SNR:
In the next layer down, each frame is comprised of several OFDM "modem frames", that contain pilot, unique word, and FEC symbols to handle synchronisation and error correction over the challenging HF channel. The preamble and postamble are used to locate the burst and estimate it's frequency offset. Having both a pre and postamble increases the probability of successful detection of the burst in a fading channel. Here are some single frame bursts on a MPP channel at 5dB SNR:
![](doc/pre_post_amble_mpp.png)
Expand Down
84 changes: 42 additions & 42 deletions demo/c2demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
Encodes and decodes a file of raw speech samples using Codec 2.
Demonstrates use of Codec 2 function API.
cd codec2/build_linux
./demo/c2demo ../raw/hts1a.raw his1a_out.raw
aplay -f S16_LE hts1a_out.raw
\*---------------------------------------------------------------------------*/

/*
Expand All @@ -32,46 +32,46 @@

#include <stdio.h>
#include <stdlib.h>

#include "codec2.h"

int main(int argc, char *argv[])
{
struct CODEC2 *codec2;
FILE *fin;
FILE *fout;

if (argc != 3) {
printf("usage: %s InputRawSpeechFile OutputRawSpeechFile\n", argv[0]);
exit(1);
}

if ( (fin = fopen(argv[1],"rb")) == NULL ) {
fprintf(stderr, "Error opening input speech file: %s\n", argv[1]);
exit(1);
}

if ( (fout = fopen(argv[2],"wb")) == NULL ) {
fprintf(stderr, "Error opening output speech file: %s\n", argv[2]);
exit(1);
}

/* Note only one set of Codec 2 states is required for an encoder
and decoder pair. */
codec2 = codec2_create(CODEC2_MODE_1300);
size_t nsam = codec2_samples_per_frame(codec2);
short speech_samples[nsam];
/* Bits from the encoder are packed into bytes */
unsigned char compressed_bytes[codec2_bytes_per_frame(codec2)];

while(fread(speech_samples, sizeof(short), nsam, fin) == nsam) {
codec2_encode(codec2, compressed_bytes, speech_samples);
codec2_decode(codec2, speech_samples, compressed_bytes);
fwrite(speech_samples, sizeof(short), nsam, fout);
}

codec2_destroy(codec2);
fclose(fin);
fclose(fout);

return 0;
int main(int argc, char *argv[]) {
struct CODEC2 *codec2;
FILE *fin;
FILE *fout;

if (argc != 3) {
printf("usage: %s InputRawSpeechFile OutputRawSpeechFile\n", argv[0]);
exit(1);
}

if ((fin = fopen(argv[1], "rb")) == NULL) {
fprintf(stderr, "Error opening input speech file: %s\n", argv[1]);
exit(1);
}

if ((fout = fopen(argv[2], "wb")) == NULL) {
fprintf(stderr, "Error opening output speech file: %s\n", argv[2]);
exit(1);
}

/* Note only one set of Codec 2 states is required for an encoder
and decoder pair. */
codec2 = codec2_create(CODEC2_MODE_1300);
size_t nsam = codec2_samples_per_frame(codec2);
short speech_samples[nsam];
/* Bits from the encoder are packed into bytes */
unsigned char compressed_bytes[codec2_bytes_per_frame(codec2)];

while (fread(speech_samples, sizeof(short), nsam, fin) == nsam) {
codec2_encode(codec2, compressed_bytes, speech_samples);
codec2_decode(codec2, speech_samples, compressed_bytes);
fwrite(speech_samples, sizeof(short), nsam, fout);
}

codec2_destroy(codec2);
fclose(fin);
fclose(fout);

return 0;
}
Loading

0 comments on commit 06d4c11

Please sign in to comment.