Move class SimpleAudio into the cpp file

This commit is contained in:
Henrik Rydgård 2024-04-10 13:03:19 +02:00
parent 1805910fac
commit 8adca6492c
2 changed files with 48 additions and 61 deletions

View File

@ -16,6 +16,7 @@
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <algorithm>
#include <cmath>
#include "Common/Serialize/SerializeFuncs.h"
#include "Core/Config.h"
@ -32,11 +33,57 @@ extern "C" {
#include "libswresample/swresample.h"
#include "libavutil/samplefmt.h"
#include "libavcodec/avcodec.h"
}
#include "libavutil/version.h"
#include "Core/FFMPEGCompat.h"
}
#endif // USE_FFMPEG
// FFMPEG-based decoder. TODO: Replace with individual codecs.
class SimpleAudio : public AudioDecoder {
public:
SimpleAudio(PSPAudioType audioType, int sampleRateHz = 44100, int channels = 2);
~SimpleAudio();
bool Decode(const uint8_t* inbuf, int inbytes, uint8_t *outbuf, int *outbytes) override;
bool IsOK() const override;
int GetOutSamples() const override {
return outSamples;
}
int GetSourcePos() const override {
return srcPos;
}
// Not save stated, only used by UI. Used for ATRAC3 (non+) files.
void SetExtraData(const uint8_t *data, int size, int wav_bytes_per_packet) override;
void SetChannels(int channels) override;
// These two are only here because of save states.
PSPAudioType GetAudioType() const { return audioType; }
private:
bool OpenCodec(int block_align);
PSPAudioType audioType;
int sample_rate_;
int channels_;
int outSamples; // output samples per frame
int srcPos; // bytes consumed in source during the last decoding
AVFrame *frame_;
#if HAVE_LIBAVCODEC_CONST_AVCODEC // USE_FFMPEG is implied
const
#endif
AVCodec *codec_;
AVCodecContext *codecCtx_;
SwrContext *swrCtx_;
bool codecOpen_;
};
// TODO: This should also be able to create other types of decoders.
AudioDecoder *CreateAudioDecoder(PSPAudioType audioType, int sampleRateHz, int channels) {
return new SimpleAudio(audioType, sampleRateHz, channels);

View File

@ -17,24 +17,9 @@
#pragma once
#include <cmath>
#include "Core/HW/MediaEngine.h"
#include "Core/HLE/sceAudio.h"
struct AVFrame;
struct AVCodec;
struct AVCodecContext;
struct SwrContext;
#ifdef USE_FFMPEG
extern "C" {
#include "libavutil/version.h"
};
#endif
// Wraps FFMPEG for audio decoding in a nice interface.
// Decodes packet by packet - does NOT demux.
@ -70,51 +55,6 @@ private:
uint32_t ctxPtr = 0xFFFFFFFF;
};
// FFMPEG-based decoder
class SimpleAudio : public AudioDecoder {
public:
SimpleAudio(PSPAudioType audioType, int sampleRateHz = 44100, int channels = 2);
~SimpleAudio();
bool Decode(const uint8_t* inbuf, int inbytes, uint8_t *outbuf, int *outbytes) override;
bool IsOK() const override;
int GetOutSamples() const override {
return outSamples;
}
int GetSourcePos() const override {
return srcPos;
}
// Not save stated, only used by UI. Used for ATRAC3 (non+) files.
void SetExtraData(const uint8_t *data, int size, int wav_bytes_per_packet) override;
void SetChannels(int channels) override;
// These two are only here because of save states.
PSPAudioType GetAudioType() const { return audioType; }
private:
bool OpenCodec(int block_align);
PSPAudioType audioType;
int sample_rate_;
int channels_;
int outSamples; // output samples per frame
int srcPos; // bytes consumed in source during the last decoding
AVFrame *frame_;
#if HAVE_LIBAVCODEC_CONST_AVCODEC // USE_FFMPEG is implied
const
#endif
AVCodec *codec_;
AVCodecContext *codecCtx_;
SwrContext *swrCtx_;
bool codecOpen_;
};
void AudioClose(SimpleAudio **ctx);
void AudioClose(AudioDecoder **ctx);
const char *GetCodecName(int codec); // audioType
bool IsValidCodec(PSPAudioType codec);