Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break out the Atrac3/Atrac3+ decoders from FFMPEG to a separate library #19033

Merged
merged 31 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8d4716c
WIP: Add AT3/AT3plus files, get it to compile (though will fail to li…
hrydgard Apr 10, 2024
c902973
Setup more of the setup
hrydgard Apr 10, 2024
fb90648
Disable FFMPEG temporarily to avoid symbol clashes
hrydgard Apr 10, 2024
8fbc4a3
Ultra-gross hackery, but works! Now, need to pare it down, heavily...
hrydgard Apr 10, 2024
c6c6769
Hook up ATRAC3 too
hrydgard Apr 10, 2024
e94faa4
Start paring things down
hrydgard Apr 10, 2024
ae73669
Remove atomics stuff, a lot more
hrydgard Apr 10, 2024
6803775
Remove option table
hrydgard Apr 10, 2024
34afd58
Delete all kinds of stuff
hrydgard Apr 10, 2024
08d5de9
Remove opt, dict, more
hrydgard Apr 10, 2024
7d680c9
Remove AVPacket, more
hrydgard Apr 10, 2024
d617aec
Simplify away AVFrame from decoding functions, remove buffer pools
hrydgard Apr 10, 2024
202886f
Delete attributes.h/compat.h, more
hrydgard Apr 10, 2024
27e28a5
Remove samplefmt
hrydgard Apr 11, 2024
9c32761
Remove fdsp context
hrydgard Apr 11, 2024
bbb563c
More header cleanup
hrydgard Apr 11, 2024
91df8eb
FFT cleanup
hrydgard Apr 11, 2024
e10b90b
Switch at3_standalone to C++ to avoid namespace clashes
hrydgard Apr 11, 2024
0d30728
Remove context parameter from av_log
hrydgard Apr 11, 2024
ae87aa4
Initial CMake/Android.mk support
hrydgard Apr 11, 2024
8d89a7c
Delete more unused stuff
hrydgard Apr 11, 2024
e871133
Buildfixes
hrydgard Apr 11, 2024
416ba81
Remove the channel_layout stuff
hrydgard Apr 11, 2024
8431194
Stop passing around the AVCodecContext pointer so much
hrydgard Apr 11, 2024
33ba306
Revert "Disable FFMPEG temporarily to avoid symbol clashes"
hrydgard Apr 11, 2024
bf280eb
Remove "SetExtraData" from AudioDecoder, pass in the data at creation…
hrydgard Apr 11, 2024
6ea8efc
Bypass AvCodecContext for atrac3plus, for a simpler API.
hrydgard Apr 11, 2024
b35b351
Finally remove the AVCodecContext
hrydgard Apr 11, 2024
6ee008a
Warning fix, rename some variables to avoid clashes with actual ffmpeg
hrydgard Apr 11, 2024
d4023fb
Buildfixes
hrydgard Apr 11, 2024
58cb2ba
Fix playback of atrac3+ when block align not specified
hrydgard Apr 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2215,6 +2215,9 @@ add_library(${CoreLibName} ${CoreLinkType}
Core/HLE/scePauth.h
Core/HW/SimpleAudioDec.cpp
Core/HW/SimpleAudioDec.h
Core/HW/Atrac3Standalone.cpp
Core/HW/Atrac3Standalone.h
Core/HW/SimpleAudioDec.h
Core/HW/AsyncIOManager.cpp
Core/HW/AsyncIOManager.h
Core/HW/BufferQueue.cpp
Expand Down Expand Up @@ -2363,7 +2366,7 @@ endif()

include_directories(ext/libchdr/include)

target_link_libraries(${CoreLibName} Common native chdr kirk cityhash sfmt19937 xbrz xxhash rcheevos minimp3 ${GlslangLibs}
target_link_libraries(${CoreLibName} Common native chdr kirk cityhash sfmt19937 xbrz xxhash rcheevos minimp3 at3_standalone ${GlslangLibs}
${CoreExtraLibs} ${OPENGL_LIBRARIES} ${X11_LIBRARIES} ${CMAKE_DL_LIBS})

if(NOT HTTPS_NOT_AVAILABLE)
Expand Down
29 changes: 28 additions & 1 deletion Common/Common.vcxproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM">
Expand Down Expand Up @@ -385,6 +385,19 @@
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\ext\at3_standalone\at3_decoders.h" />
<ClInclude Include="..\ext\at3_standalone\atrac.h" />
<ClInclude Include="..\ext\at3_standalone\atrac3data.h" />
<ClInclude Include="..\ext\at3_standalone\atrac3plus.h" />
<ClInclude Include="..\ext\at3_standalone\atrac3plus_data.h" />
<ClInclude Include="..\ext\at3_standalone\compat.h" />
<ClInclude Include="..\ext\at3_standalone\fft.h" />
<ClInclude Include="..\ext\at3_standalone\float_dsp.h" />
<ClInclude Include="..\ext\at3_standalone\get_bits.h" />
<ClInclude Include="..\ext\at3_standalone\intreadwrite.h" />
<ClInclude Include="..\ext\at3_standalone\mathematics.h" />
<ClInclude Include="..\ext\at3_standalone\mem.h" />
<ClInclude Include="..\ext\at3_standalone\sinewin.h" />
<ClInclude Include="..\ext\basis_universal\basisu.h" />
<ClInclude Include="..\ext\basis_universal\basisu_containers.h" />
<ClInclude Include="..\ext\basis_universal\basisu_containers_impl.h" />
Expand Down Expand Up @@ -584,6 +597,18 @@
<ClInclude Include="x64Emitter.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\ext\at3_standalone\atrac.cpp" />
<ClCompile Include="..\ext\at3_standalone\atrac3.cpp" />
<ClCompile Include="..\ext\at3_standalone\atrac3plus.cpp" />
<ClCompile Include="..\ext\at3_standalone\atrac3plusdec.cpp" />
<ClCompile Include="..\ext\at3_standalone\atrac3plusdsp.cpp" />
<ClCompile Include="..\ext\at3_standalone\get_bits.cpp" />
<ClCompile Include="..\ext\at3_standalone\compat.cpp" />
<ClCompile Include="..\ext\at3_standalone\fft.cpp" />
<ClCompile Include="..\ext\at3_standalone\float_dsp.cpp" />
<ClCompile Include="..\ext\at3_standalone\mathematics.cpp" />
<ClCompile Include="..\ext\at3_standalone\mem.cpp" />
<ClCompile Include="..\ext\at3_standalone\sinewin.cpp" />
<ClCompile Include="..\ext\basis_universal\basisu_transcoder.cpp" />
<ClCompile Include="..\ext\libpng17\png.c">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
Expand Down Expand Up @@ -1016,6 +1041,8 @@
<ClCompile Include="x64Emitter.cpp" />
</ItemGroup>
<ItemGroup>
<Text Include="..\ext\at3_standalone\CMakeLists.txt" />
<Text Include="..\ext\at3_standalone\README.txt" />
<Text Include="..\ext\libpng17\CMakeLists.txt" />
</ItemGroup>
<ItemGroup>
Expand Down
84 changes: 84 additions & 0 deletions Common/Common.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,45 @@
<ClInclude Include="..\ext\minimp3\minimp3.h">
<Filter>ext\minimp3</Filter>
</ClInclude>
<ClInclude Include="..\ext\at3_standalone\atrac3data.h">
<Filter>ext\at3_standalone</Filter>
</ClInclude>
<ClInclude Include="..\ext\at3_standalone\atrac3plus.h">
<Filter>ext\at3_standalone</Filter>
</ClInclude>
<ClInclude Include="..\ext\at3_standalone\atrac3plus_data.h">
<Filter>ext\at3_standalone</Filter>
</ClInclude>
<ClInclude Include="..\ext\at3_standalone\atrac.h">
<Filter>ext\at3_standalone</Filter>
</ClInclude>
<ClInclude Include="..\ext\at3_standalone\get_bits.h">
<Filter>ext\at3_standalone</Filter>
</ClInclude>
<ClInclude Include="..\ext\at3_standalone\compat.h">
<Filter>ext\at3_standalone</Filter>
</ClInclude>
<ClInclude Include="..\ext\at3_standalone\fft.h">
<Filter>ext\at3_standalone</Filter>
</ClInclude>
<ClInclude Include="..\ext\at3_standalone\float_dsp.h">
<Filter>ext\at3_standalone</Filter>
</ClInclude>
<ClInclude Include="..\ext\at3_standalone\intreadwrite.h">
<Filter>ext\at3_standalone</Filter>
</ClInclude>
<ClInclude Include="..\ext\at3_standalone\mathematics.h">
<Filter>ext\at3_standalone</Filter>
</ClInclude>
<ClInclude Include="..\ext\at3_standalone\at3_decoders.h">
<Filter>ext\at3_standalone</Filter>
</ClInclude>
<ClInclude Include="..\ext\at3_standalone\mem.h">
<Filter>ext\at3_standalone</Filter>
</ClInclude>
<ClInclude Include="..\ext\at3_standalone\sinewin.h">
<Filter>ext\at3_standalone</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ABI.cpp" />
Expand Down Expand Up @@ -981,6 +1020,42 @@
<ClCompile Include="..\ext\minimp3\minimp3.cpp">
<Filter>ext\minimp3</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\atrac3.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\atrac3plus.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\atrac3plusdec.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\atrac3plusdsp.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\float_dsp.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\mem.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\sinewin.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\atrac.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\mathematics.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\fft.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\get_bits.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
<ClCompile Include="..\ext\at3_standalone\compat.cpp">
<Filter>ext\at3_standalone</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="Crypto">
Expand Down Expand Up @@ -1094,11 +1169,20 @@
<Filter Include="ext\minimp3">
<UniqueIdentifier>{83cd76d0-d1ac-4ed1-9bdc-11fb5a20e5d3}</UniqueIdentifier>
</Filter>
<Filter Include="ext\at3_standalone">
<UniqueIdentifier>{586da66e-922a-4479-9dac-9d608a1b9183}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<Text Include="..\ext\libpng17\CMakeLists.txt">
<Filter>ext\libpng17</Filter>
</Text>
<Text Include="..\ext\at3_standalone\README.txt">
<Filter>ext\at3_standalone</Filter>
</Text>
<Text Include="..\ext\at3_standalone\CMakeLists.txt">
<Filter>ext\at3_standalone</Filter>
</Text>
</ItemGroup>
<ItemGroup>
<None Include="..\ext\basis_universal\basisu_transcoder_tables_astc.inc">
Expand Down
2 changes: 2 additions & 0 deletions Core/Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@
<ClCompile Include="HLE\sceUsbAcc.cpp" />
<ClCompile Include="HLE\sceUsbCam.cpp" />
<ClCompile Include="HLE\sceUsbMic.cpp" />
<ClCompile Include="HW\Atrac3Standalone.cpp" />
<ClCompile Include="HW\BufferQueue.cpp" />
<ClCompile Include="HW\Camera.cpp" />
<ClCompile Include="HW\Display.cpp" />
Expand Down Expand Up @@ -1181,6 +1182,7 @@
<ClInclude Include="HLE\sceUsbAcc.h" />
<ClInclude Include="HLE\sceUsbCam.h" />
<ClInclude Include="HLE\sceUsbMic.h" />
<ClInclude Include="HW\Atrac3Standalone.h" />
<ClInclude Include="HW\Camera.h" />
<ClInclude Include="HW\Display.h" />
<ClInclude Include="Instance.h" />
Expand Down
6 changes: 6 additions & 0 deletions Core/Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,9 @@
<ClCompile Include="Util\MemStick.cpp">
<Filter>Util</Filter>
</ClCompile>
<ClCompile Include="HW\Atrac3Standalone.cpp">
<Filter>HW</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ELF\ElfReader.h">
Expand Down Expand Up @@ -2088,6 +2091,9 @@
<ClInclude Include="Util\MemStick.h">
<Filter>Util</Filter>
</ClInclude>
<ClInclude Include="HW\Atrac3Standalone.h">
<Filter>HW</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\LICENSE.TXT" />
Expand Down
123 changes: 123 additions & 0 deletions Core/HW/Atrac3Standalone.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#include "SimpleAudioDec.h"

#include "ext/at3_standalone/at3_decoders.h"

inline int16_t clamp16(float f) {
if (f >= 1.0f)
return 32767;
else if (f <= -1.0f)
return -32767;
else
return (int)(f * 32767);
}

// Uses our standalone AT3/AT3+ decoder derived from FFMPEG
// Test case for ATRAC3: Mega Man Maverick Hunter X, PSP menu sound
class Atrac3Audio : public AudioDecoder {
public:
Atrac3Audio(PSPAudioType audioType, int channels, size_t blockAlign, const uint8_t *extraData, size_t extraDataSize) : audioType_(audioType) {
blockAlign_ = blockAlign;
if (audioType == PSP_CODEC_AT3PLUS) {
at3pCtx_ = atrac3p_alloc(channels, &blockAlign_);
if (at3pCtx_)
codecOpen_ = true;
} else if (audioType_ == PSP_CODEC_AT3) {
at3Ctx_ = atrac3_alloc(channels, &blockAlign_, extraData, extraDataSize);
if (at3Ctx_)
codecOpen_ = true;
}
for (int i = 0; i < 2; i++) {
buffers_[i] = new float[4096];
}
}
~Atrac3Audio() {
if (at3Ctx_) {
atrac3_free(at3Ctx_);
}
if (at3pCtx_) {
atrac3p_free(at3pCtx_);
}
for (int i = 0; i < 2; i++) {
delete[] buffers_[i];
}
}

bool IsOK() const override {
return codecOpen_;
}

bool Decode(const uint8_t *inbuf, int inbytes, uint8_t *outbuf, int *outbytes) override {
if (!codecOpen_) {
_dbg_assert_(false);
}
if (inbytes != blockAlign_ && blockAlign_ != 0) {
WARN_LOG(ME, "Atrac3Audio::Decode: Unexpected block align %d (expected %d)", inbytes, blockAlign_);
}
blockAlign_ = inbytes;
// We just call the decode function directly without going through the whole packet machinery.
int got_frame = 0;
int result;
int nb_samples = 0;
if (audioType_ == PSP_CODEC_AT3PLUS) {
result = atrac3p_decode_frame(at3pCtx_, buffers_, &nb_samples, &got_frame, inbuf, inbytes);
} else {

result = atrac3_decode_frame(at3Ctx_, buffers_, &nb_samples, &got_frame, inbuf, inbytes);
}
if (result < 0) {
*outbytes = 0;
return false;
}
srcPos_ = result;
outSamples_ = nb_samples;
if (nb_samples > 0) {
*outbytes = nb_samples * 2 * 2;

// Convert frame to outbuf.
for (int channel = 0; channel < 2; channel++) {
int16_t *output = (int16_t *)outbuf;
for (int i = 0; i < nb_samples; i++) {
output[i * 2] = clamp16(buffers_[0][i]);
output[i * 2 + 1] = clamp16(buffers_[1][i]);
}
}
} else {
*outbytes = 0;
}
return true;
}

int GetOutSamples() const override {
return outSamples_;
}
int GetSourcePos() const override {
return srcPos_;
}

void SetChannels(int channels) override {
// Hmm. ignore for now.
}

PSPAudioType GetAudioType() const override { return audioType_; }

private:
ATRAC3PContext *at3pCtx_ = nullptr;
ATRAC3Context *at3Ctx_ = nullptr;

int blockAlign_ = 0;

int outSamples_ = 0;
int srcPos_ = 0;
float *buffers_[2]{};

bool codecOpen_ = false;

PSPAudioType audioType_;
};

AudioDecoder *CreateAtrac3Audio(int channels, size_t blockAlign, const uint8_t *extraData, size_t extraDataSize) {
return new Atrac3Audio(PSP_CODEC_AT3, channels, blockAlign, extraData, extraDataSize);
}
AudioDecoder *CreateAtrac3PlusAudio(int channels, size_t blockAlign) {
return new Atrac3Audio(PSP_CODEC_AT3PLUS, channels, blockAlign, nullptr, 0);
}
6 changes: 6 additions & 0 deletions Core/HW/Atrac3Standalone.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "SimpleAudioDec.h"

AudioDecoder *CreateAtrac3Audio(int channels, size_t blockAlign, const uint8_t *extraData, size_t extraDataSize);
AudioDecoder *CreateAtrac3PlusAudio(int channels, size_t blockAlign);
Loading
Loading