diff --git a/AudioEncode/encoder.cpp b/AudioEncode/encoder.cpp index 0dc02c4f..2e8c2eba 100644 --- a/AudioEncode/encoder.cpp +++ b/AudioEncode/encoder.cpp @@ -19,9 +19,9 @@ #include #include +#include "aencode.h" #include "audio_encode.h" #include "mono.h" -#include "Aencode.h" int32_t aenc_ReadSamp(void *data) { FILE *f = (FILE *)data; diff --git a/lib/Aencode.h b/lib/Aencode.h deleted file mode 100644 index 51f965dd..00000000 --- a/lib/Aencode.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -* 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 . -*/ - -#ifndef AENCODE_H_ -#define AENCODE_H_ - -#include -#include -#include "pstypes.h" - - -typedef int32_t ReadSampleFunction(void *data); -enum AudioError { - ReadSampleEof = 0x80000000, -}; - -int32_t AudioEncode(ReadSampleFunction *read, void *data, unsigned channels, unsigned sample_rate, float volume, - FILE *out, int levels, int samples_per_subband, float comp_ratio); - -#endif diff --git a/lib/win/Adecode.lib b/lib/win/Adecode.lib deleted file mode 100644 index 6ac83448..00000000 Binary files a/lib/win/Adecode.lib and /dev/null differ diff --git a/lib/win/Aencode.lib b/lib/win/Aencode.lib deleted file mode 100644 index 1b936ab1..00000000 Binary files a/lib/win/Aencode.lib and /dev/null differ diff --git a/libacm/CMakeLists.txt b/libacm/CMakeLists.txt index fbd4e513..178d81ca 100644 --- a/libacm/CMakeLists.txt +++ b/libacm/CMakeLists.txt @@ -1,11 +1,17 @@ -set(HEADERS) set(CPPS + adecode.cpp aencode.cpp - adecode.cpp) +) # these are the relevant source files from upstream libacm (https://github.com/markokr/libacm/) set(LIB_SRC decode.c - libacm.h) + libacm.h +) -add_library(libacm STATIC ${HEADERS} ${CPPS} ${LIB_SRC}) +add_library(libacm STATIC ${CPPS} ${LIB_SRC}) +target_include_directories(libacm PUBLIC + $ +) diff --git a/libacm/adecode.cpp b/libacm/adecode.cpp index d8a00240..478ee147 100644 --- a/libacm/adecode.cpp +++ b/libacm/adecode.cpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#include "Adecode.h" - +#include "adecode.h" #include "libacm.h" using namespace AudioDecoder; @@ -49,8 +48,7 @@ public: int AcmReadFunc(void *ptr, int size, int n, void *datasrc) { InternalAudioDecoder *iad = reinterpret_cast(datasrc); - int ret = - iad->m_readerFunction(iad->m_pReaderData, ptr, (uint32_t)size * n); + int ret = iad->m_readerFunction(iad->m_pReaderData, ptr, (uint32_t)size * n); // ret < 0: error, ret == 0: EOF, ret > 0: read ret bytes of data // apparently acm_io_callbacks::read() expects pretty much the same behavior, // except that for > 0 it's not number of bytes but number of items (like in @@ -61,15 +59,14 @@ int AcmReadFunc(void *ptr, int size, int n, void *datasrc) { return ret; } -InternalAudioDecoder::InternalAudioDecoder(ReadDataFunction readerFunction, - void *pReaderData) +InternalAudioDecoder::InternalAudioDecoder(ReadDataFunction readerFunction, void *pReaderData) : m_readerFunction(readerFunction), m_pReaderData(pReaderData) {} // Initialize the decoder bool InternalAudioDecoder::Initialize() { // set the read function, the others are optional - acm_io_callbacks io = { AcmReadFunc }; + acm_io_callbacks io = {AcmReadFunc}; // force_channels 0 means libacm will use number of chans from ACM file header const int force_channels = 0; @@ -127,14 +124,10 @@ uint32_t InternalAudioDecoder::Read(void *pBuffer, uint32_t amount) { // and also returns the number of channels (1 or 2), the sample rate // (e.g. 22050), and the number of samples contained in the compressed file // (in case you want to pre-allocate a buffer to load them all into memory). -IAudioDecoder *AudioDecoder::CreateDecoder(ReadDataFunction readerFunction, - void *pReaderData, - uint32_t &numChannels, - uint32_t &sampleRate, - uint32_t &sampleCount) { +IAudioDecoder *AudioDecoder::CreateDecoder(ReadDataFunction readerFunction, void *pReaderData, uint32_t &numChannels, + uint32_t &sampleRate, uint32_t &sampleCount) { // allocate our decoder - InternalAudioDecoder *pDecoder = - new InternalAudioDecoder(readerFunction, pReaderData); + InternalAudioDecoder *pDecoder = new InternalAudioDecoder(readerFunction, pReaderData); if (pDecoder == nullptr) return nullptr; diff --git a/lib/Adecode.h b/libacm/adecode.h similarity index 63% rename from lib/Adecode.h rename to libacm/adecode.h index 040853b7..0b858cc2 100644 --- a/lib/Adecode.h +++ b/libacm/adecode.h @@ -1,20 +1,20 @@ /* -* 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 . + */ #ifndef AUDIODECODE_H_ #define AUDIODECODE_H_ diff --git a/libacm/aencode.cpp b/libacm/aencode.cpp index 12184581..f1562fcb 100644 --- a/libacm/aencode.cpp +++ b/libacm/aencode.cpp @@ -1,30 +1,31 @@ /* -* 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 "Aencode.h" +#include +#include +#include +#include +#include + +#include "aencode.h" struct BitsEncoder { - FILE *m_outFile; // var50 | offset 0x10 + FILE *m_outFile; // var50 | offset 0x10 uint32_t m_bitData; // var4C | offset 0x14 uint32_t m_bitCount; // var48 | offset 0x18 @@ -61,26 +62,26 @@ struct BitsEncoder { }; struct Encoder { - ReadSampleFunction *m_reader; // var60 | offset 0x00 - void *m_pReaderData; // var5C | offset 0x04 - uint32_t m_sampleCount; // var58 | offset 0x08 - float m_volume; // var54 | offset 0x0C - BitsEncoder m_bits; // var50 - var48 | offset 0x10 - 0x18 + ReadSampleFunction *m_reader; // var60 | offset 0x00 + void *m_pReaderData; // var5C | offset 0x04 + uint32_t m_sampleCount; // var58 | offset 0x08 + float m_volume; // var54 | offset 0x0C + BitsEncoder m_bits; // var50 - var48 | offset 0x10 - 0x18 int8_t m_levels; // var44* | offset 0x1C int8_t m_pad[3]; // 43, 42, 41 int32_t m_numColumns; // var40 | offset 0x20 int32_t m_samples_per_subband; // var3C | offset 0x24 int32_t m_samplesPerBlock; // var38 | offset 0x28 int32_t m_adjustedSamplesTimeNumColumns; // var34 | offset 0x2C - float **m_levelSlots; // var30 | offset 0x30 - float *m_pCurrBlockData; // var2C | offset 0x34 + float **m_levelSlots; // var30 | offset 0x30 + float *m_pCurrBlockData; // var2C | offset 0x34 int32_t m_blockSamplesRemaining; // var28 | offset 0x38 int32_t m_bandWriteEnabled; // var24 | offset 0x3C int32_t m_finishedReading; // var20 | offset 0x40 int32_t m_someVal; // var1C | offset 0x44 - float *m_lo_filter; // var18 | offset 0x48 - float *m_hi_filter; // var14 | offset 0x4C - uint32_t *m_pFormatIdPerColumn; // var10 | offset 0x50 + float *m_lo_filter; // var18 | offset 0x48 + float *m_hi_filter; // var14 | offset 0x4C + uint32_t *m_pFormatIdPerColumn; // var10 | offset 0x50 int32_t m_currBlockBitPower; // var0C | offset 0x54 int32_t m_currBlockBitValue; // var08 | offset 0x58 int32_t m_threshold; // var04 | offset 0x5C @@ -922,7 +923,7 @@ void WriteBands(Encoder &enc) { for (int i = 0; i < enc.m_numColumns; ++i) { const uint32_t formatId = enc.m_pFormatIdPerColumn[i]; enc.m_bits.WriteBits(formatId, 5); -// int32_t currPos = ftell(enc.m_bits.m_outFile); + // int32_t currPos = ftell(enc.m_bits.m_outFile); WriteBand_tbl[formatId](enc, i, formatId); } } @@ -987,7 +988,7 @@ void EncodeFlush(Encoder &enc) { } int32_t AudioEncode(ReadSampleFunction *read, void *data, unsigned channels, unsigned sample_rate, float volume, - FILE *out, int levels, int samples_per_subband, float comp_ratio) { + FILE *out, int levels, int samples_per_subband, float comp_ratio) { Encoder enc; memset(&enc, 0, sizeof(enc)); diff --git a/libacm/aencode.h b/libacm/aencode.h new file mode 100644 index 00000000..75eee056 --- /dev/null +++ b/libacm/aencode.h @@ -0,0 +1,33 @@ +/* + * 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 . + */ + +#ifndef AENCODE_H_ +#define AENCODE_H_ + +#include +#include + +typedef int32_t ReadSampleFunction(void *data); +enum AudioError { + ReadSampleEof = 0x80000000, +}; + +int32_t AudioEncode(ReadSampleFunction *read, void *data, unsigned channels, unsigned sample_rate, float volume, + FILE *out, int levels, int samples_per_subband, float comp_ratio); + +#endif diff --git a/music/CMakeLists.txt b/music/CMakeLists.txt index 29b0aafe..1a19d9b4 100644 --- a/music/CMakeLists.txt +++ b/music/CMakeLists.txt @@ -9,6 +9,7 @@ add_library(music STATIC ${HEADERS} ${CPPS}) target_link_libraries(music cfile ddio + libacm mem misc sndlib diff --git a/music/sequencer.cpp b/music/sequencer.cpp index 6f27b152..3cb1a9d8 100644 --- a/music/sequencer.cpp +++ b/music/sequencer.cpp @@ -142,21 +142,17 @@ * $NoKeywords: $ */ +#include +#include + +#include "ddio.h" +#include "inffile.h" +#include "mem.h" #include "music.h" #include "musiclib.h" -#include "ssl_lib.h" -#include "soundload.h" -#include "textaux.h" #include "pserror.h" -#include "ddio.h" -#include "Macros.h" -#include "inffile.h" #include "streamaudio.h" -#include "mem.h" -#include -#include -// #include "samirlog.h" #define LOGFILE(_s) OutrageMusicSeq::OutrageMusicSeq() { diff --git a/stream_audio/CMakeLists.txt b/stream_audio/CMakeLists.txt index 19e217d2..d0d01604 100644 --- a/stream_audio/CMakeLists.txt +++ b/stream_audio/CMakeLists.txt @@ -6,11 +6,13 @@ set(CPPS add_library(stream_audio STATIC ${HEADERS} ${CPPS}) target_link_libraries(stream_audio PRIVATE ddio - libacm mem misc sndlib ) +target_link_libraries(stream_audio PUBLIC + libacm +) target_include_directories(stream_audio PUBLIC $ +#include + +#include "adecode.h" #include "cfile.h" -#include "mem.h" -#include "Macros.h" #include "ddio.h" -#include -#include -// #include "samirlog.h" +#include "Macros.h" +#include "mem.h" +#include "pserror.h" +#include "streamaudio.h" + #define LOGFILE(_s) // this stream is for everyone (used by the StreamPlay interface) static AudioStream User_audio_stream; diff --git a/stream_audio/streamaudio.h b/stream_audio/streamaudio.h index 3937613b..077ba0aa 100644 --- a/stream_audio/streamaudio.h +++ b/stream_audio/streamaudio.h @@ -138,7 +138,7 @@ #ifndef __STREAMAUDIO_H_ #define __STREAMAUDIO_H_ -#include "Adecode.h" +#include "adecode.h" #include "ssl_lib.h" #include "TaskSystem.h"