From f1737d2a194527c6613671f55dc9a343a6df0ac6 Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Sat, 27 Jul 2024 22:40:09 +0300 Subject: [PATCH] Isolate AudioEncode submodule Isolate AudioEncode from rest of the project, minor cleanups --- AudioEncode/CMakeLists.txt | 15 ++++++--- {lib => AudioEncode}/audio_encode.h | 13 ++++---- AudioEncode/encoder.cpp | 48 ++++++++++++++--------------- 3 files changed, 41 insertions(+), 35 deletions(-) rename {lib => AudioEncode}/audio_encode.h (79%) diff --git a/AudioEncode/CMakeLists.txt b/AudioEncode/CMakeLists.txt index 8415e67b..3dc428cf 100644 --- a/AudioEncode/CMakeLists.txt +++ b/AudioEncode/CMakeLists.txt @@ -1,6 +1,13 @@ -set(HEADERS) set(CPPS - encoder.cpp) + encoder.cpp +) -add_library(AudioEncode STATIC ${HEADERS} ${CPPS}) -target_link_libraries(AudioEncode libacm) +add_library(AudioEncode STATIC ${CPPS}) +target_link_libraries(AudioEncode PRIVATE + libacm +) +target_include_directories(AudioEncode PUBLIC + $ +) diff --git a/lib/audio_encode.h b/AudioEncode/audio_encode.h similarity index 79% rename from lib/audio_encode.h rename to AudioEncode/audio_encode.h index 0eb44e14..b951ceab 100644 --- a/lib/audio_encode.h +++ b/AudioEncode/audio_encode.h @@ -1,5 +1,5 @@ /* -* Descent 3 +* Descent 3 * Copyright (C) 2024 Parallax Software * * This program is free software: you can redistribute it and/or modify @@ -31,8 +31,8 @@ * $NoKeywords: $ */ -#ifndef __AUDIO_ENCODE_H_ -#define __AUDIO_ENCODE_H_ +#ifndef AUDIO_ENCODE_H_ +#define AUDIO_ENCODE_H_ // input_levels (default 7 or for 2k total) // input_samples (default 16 or for 2k total) @@ -40,8 +40,9 @@ // input_channels (default 1) // input_factor (compression factor) (default 4 for 22K, 8 for 44K) // input_volscale (Volume scaling) (slightly <= 1.0, default ,97) -bool aenc_Compress(char *input_filename, char *output_filename, int *input_levels = nullptr, int *input_samples = nullptr, - int *input_rate = nullptr, int *input_channels = nullptr, float *input_factor = nullptr, - float *input_volscale = nullptr); +bool aenc_Compress(char *input_filename, char *output_filename, const int *input_levels = nullptr, + const int *input_samples = nullptr, const int *input_rate = nullptr, + const int *input_channels = nullptr, const float *input_factor = nullptr, + const float *input_volscale = nullptr); #endif diff --git a/AudioEncode/encoder.cpp b/AudioEncode/encoder.cpp index 8e1fa36c..0dc02c4f 100644 --- a/AudioEncode/encoder.cpp +++ b/AudioEncode/encoder.cpp @@ -1,25 +1,24 @@ /* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ + * Descent 3 + * Copyright (C) 2024 Parallax Software + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include -#include -#include -#include +#include + #include "audio_encode.h" #include "mono.h" #include "Aencode.h" @@ -37,8 +36,9 @@ int32_t aenc_ReadSamp(void *data) { return (b << 8) | a; } -bool aenc_Compress(char *input_filename, char *output_filename, int *input_levels, int *input_samples, int *input_rate, - int *input_channels, float *input_factor, float *input_volscale) { +bool aenc_Compress(char *input_filename, char *output_filename, const int *input_levels, const int *input_samples, + const int *input_rate, const int *input_channels, const float *input_factor, + const float *input_volscale) { FILE *in, *out; int32_t result; @@ -90,7 +90,7 @@ bool aenc_Compress(char *input_filename, char *output_filename, int *input_level factor = *input_factor; // Factor of compression (default 4 for 22K, 8 for 44K) factor_set = 1; - if (factor < 1.0f && factor) + if (factor != 0.0f && factor < 1.0f) factor = 1.0f / factor; if (factor <= 0.0f) { @@ -114,9 +114,7 @@ bool aenc_Compress(char *input_filename, char *output_filename, int *input_level } else if (!levels_set) { unsigned subbands = (2048 / samples_per_subband) >> 1; - for (levels = 0; subbands; subbands >>= 1, ++levels) - { - + for (levels = 0; subbands; subbands >>= 1, ++levels) { } }