2013-10-17 14:00:43 +00:00
|
|
|
// Copyright (c) 2013- PPSSPP Project.
|
|
|
|
|
|
|
|
// 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, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// 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 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2013-10-20 06:41:34 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
2013-10-17 14:00:43 +00:00
|
|
|
#include "base/basictypes.h"
|
2014-03-23 18:45:08 +00:00
|
|
|
#include "Core/HW/MediaEngine.h"
|
Universal Audio Class
Based on my implementation in sceAac https://github.com/hrydgard/ppsspp/pull/5836
I've created a class AuCtx included in My SimpleAudioDec.cpp/.h which aims at providing a standard easy implementation to support all codecs in ffmpeg.
Here, I also completely re-code sceMp3 file with this class to give an example how to use this class, and it has solved all mp3 issues I've observed in the current master.
Tests on different freq and channels mp3 audios as:
Miku custom BGM (48kHz, stereo), Hanayaka Nari Wa ga Ichizoku(32kHz, mono, a little fast but better than before now), downstreet panic (44.1kHz, stereo), and learn jp09(44.1kHz, stero) are just all right.
Especially, I am very glad to see that Miku's Custom BGMs have no repetition issues in first tone any more and no longer stopped in the first second neither. :)
We will come into a new age to fast support new audio formats from now on I hope :P
2014-04-11 20:56:59 +00:00
|
|
|
#include "Core/HLE/sceAudio.h"
|
2014-03-23 18:45:08 +00:00
|
|
|
|
2014-06-22 12:01:23 +00:00
|
|
|
struct AVFrame;
|
|
|
|
struct AVCodec;
|
|
|
|
struct AVCodecContext;
|
|
|
|
struct SwrContext;
|
2013-10-17 14:00:43 +00:00
|
|
|
|
2014-06-22 12:01:23 +00:00
|
|
|
// Wraps FFMPEG for audio decoding in a nice interface.
|
|
|
|
// Decodes packet by packet - does NOT demux.
|
2013-10-18 12:12:10 +00:00
|
|
|
|
2013-10-17 14:00:43 +00:00
|
|
|
// Based on http://ffmpeg.org/doxygen/trunk/doc_2examples_2decoding_encoding_8c-example.html#_a13
|
|
|
|
|
2014-06-22 12:01:23 +00:00
|
|
|
// audioType
|
|
|
|
enum {
|
|
|
|
PSP_CODEC_AT3PLUS = 0x00001000,
|
|
|
|
PSP_CODEC_AT3 = 0x00001001,
|
|
|
|
PSP_CODEC_MP3 = 0x00001002,
|
|
|
|
PSP_CODEC_AAC = 0x00001003,
|
|
|
|
};
|
|
|
|
|
|
|
|
class SimpleAudio {
|
2014-03-23 18:45:08 +00:00
|
|
|
public:
|
2014-06-22 16:33:09 +00:00
|
|
|
SimpleAudio(int audioType, int sample_rate = 44100, int channels = 2);
|
2014-03-23 18:45:08 +00:00
|
|
|
~SimpleAudio();
|
|
|
|
|
|
|
|
bool Decode(void* inbuf, int inbytes, uint8_t *outbuf, int *outbytes);
|
2014-06-22 12:01:23 +00:00
|
|
|
bool IsOK() const;
|
2014-06-22 15:02:04 +00:00
|
|
|
|
|
|
|
int GetOutSamples();
|
|
|
|
int GetSourcePos();
|
2015-01-18 20:59:26 +00:00
|
|
|
int GetAudioCodecID(int audioType); // Get audioCodecId from audioType
|
2014-06-22 12:01:23 +00:00
|
|
|
|
2014-06-22 16:55:14 +00:00
|
|
|
// Not save stated, only used by UI. Used for ATRAC3 (non+) files.
|
|
|
|
void SetExtraData(u8 *data, int size, int wav_bytes_per_packet);
|
|
|
|
|
2014-06-22 12:01:23 +00:00
|
|
|
// These two are only here because of save states.
|
|
|
|
int GetAudioType() const { return audioType; }
|
2014-06-22 15:02:04 +00:00
|
|
|
void SetResampleFrequency(int freq) { wanted_resample_freq = freq; }
|
|
|
|
|
|
|
|
// Just metadata.
|
|
|
|
void SetCtxPtr(u32 ptr) { ctxPtr = ptr; }
|
2014-06-22 12:01:23 +00:00
|
|
|
u32 GetCtxPtr() const { return ctxPtr; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Init();
|
2015-01-18 20:59:26 +00:00
|
|
|
bool OpenCodec(int block_align);
|
2014-03-23 18:45:08 +00:00
|
|
|
|
|
|
|
u32 ctxPtr;
|
|
|
|
int audioType;
|
2014-06-22 16:33:09 +00:00
|
|
|
int sample_rate_;
|
|
|
|
int channels_;
|
2014-04-11 13:09:31 +00:00
|
|
|
int outSamples; // output samples per frame
|
2014-04-11 21:42:07 +00:00
|
|
|
int srcPos; // bytes consumed in source during the last decoding
|
Universal Audio Class
Based on my implementation in sceAac https://github.com/hrydgard/ppsspp/pull/5836
I've created a class AuCtx included in My SimpleAudioDec.cpp/.h which aims at providing a standard easy implementation to support all codecs in ffmpeg.
Here, I also completely re-code sceMp3 file with this class to give an example how to use this class, and it has solved all mp3 issues I've observed in the current master.
Tests on different freq and channels mp3 audios as:
Miku custom BGM (48kHz, stereo), Hanayaka Nari Wa ga Ichizoku(32kHz, mono, a little fast but better than before now), downstreet panic (44.1kHz, stereo), and learn jp09(44.1kHz, stero) are just all right.
Especially, I am very glad to see that Miku's Custom BGMs have no repetition issues in first tone any more and no longer stopped in the first second neither. :)
We will come into a new age to fast support new audio formats from now on I hope :P
2014-04-11 20:56:59 +00:00
|
|
|
int wanted_resample_freq; // wanted resampling rate/frequency
|
2014-03-23 18:45:08 +00:00
|
|
|
|
|
|
|
AVFrame *frame_;
|
|
|
|
AVCodec *codec_;
|
|
|
|
AVCodecContext *codecCtx_;
|
|
|
|
SwrContext *swrCtx_;
|
2014-06-22 16:55:14 +00:00
|
|
|
|
2015-01-18 20:59:26 +00:00
|
|
|
bool codecOpen_;
|
2014-03-23 18:45:08 +00:00
|
|
|
};
|
|
|
|
|
2014-06-22 12:01:23 +00:00
|
|
|
void AudioClose(SimpleAudio **ctx);
|
|
|
|
const char *GetCodecName(int codec); // audioType
|
|
|
|
bool IsValidCodec(int codec);
|
2014-03-23 18:45:08 +00:00
|
|
|
|
2014-06-22 12:01:23 +00:00
|
|
|
class AuCtx {
|
|
|
|
public:
|
|
|
|
AuCtx();
|
|
|
|
~AuCtx();
|
2014-03-23 18:45:08 +00:00
|
|
|
|
2014-06-22 12:01:23 +00:00
|
|
|
u32 AuDecode(u32 pcmAddr);
|
|
|
|
|
|
|
|
u32 AuNotifyAddStreamData(int size);
|
|
|
|
int AuCheckStreamDataNeeded();
|
|
|
|
u32 AuResetPlayPosition();
|
|
|
|
u32 AuResetPlayPositionByFrame(int position);
|
2014-04-11 13:09:31 +00:00
|
|
|
|
2014-06-22 12:01:23 +00:00
|
|
|
u32 AuSetLoopNum(int loop);
|
|
|
|
u32 AuGetLoopNum();
|
2014-04-11 13:09:31 +00:00
|
|
|
|
2014-06-22 12:01:23 +00:00
|
|
|
u32 AuGetInfoToAddStreamData(u32 buff, u32 size, u32 srcPos);
|
|
|
|
u32 AuGetMaxOutputSample() const { return MaxOutputSample; }
|
|
|
|
u32 AuGetSumDecodedSample() const { return SumDecodedSamples; }
|
|
|
|
int AuGetChannelNum() const { return Channels; }
|
|
|
|
int AuGetBitRate() const { return BitRate; }
|
|
|
|
int AuGetSamplingRate() const { return SamplingRate; }
|
|
|
|
int AuGetVersion() const { return Version; }
|
|
|
|
int AuGetFrameNum() const { return FrameNum; }
|
|
|
|
|
|
|
|
void DoState(PointerWrap &p);
|
|
|
|
|
|
|
|
void EatSourceBuff(int amount) {
|
|
|
|
sourcebuff.erase(0, amount);
|
|
|
|
AuBufAvailable -= amount;
|
|
|
|
}
|
|
|
|
// Au source information. Written to from for example sceAacInit so public for now.
|
2014-04-11 13:09:31 +00:00
|
|
|
u64 startPos;
|
|
|
|
u64 endPos;
|
|
|
|
u32 AuBuf;
|
|
|
|
u32 AuBufSize;
|
|
|
|
u32 PCMBuf;
|
|
|
|
u32 PCMBufSize;
|
|
|
|
int freq;
|
|
|
|
int BitRate;
|
|
|
|
int SamplingRate;
|
|
|
|
int Channels;
|
Universal Audio Class
Based on my implementation in sceAac https://github.com/hrydgard/ppsspp/pull/5836
I've created a class AuCtx included in My SimpleAudioDec.cpp/.h which aims at providing a standard easy implementation to support all codecs in ffmpeg.
Here, I also completely re-code sceMp3 file with this class to give an example how to use this class, and it has solved all mp3 issues I've observed in the current master.
Tests on different freq and channels mp3 audios as:
Miku custom BGM (48kHz, stereo), Hanayaka Nari Wa ga Ichizoku(32kHz, mono, a little fast but better than before now), downstreet panic (44.1kHz, stereo), and learn jp09(44.1kHz, stero) are just all right.
Especially, I am very glad to see that Miku's Custom BGMs have no repetition issues in first tone any more and no longer stopped in the first second neither. :)
We will come into a new age to fast support new audio formats from now on I hope :P
2014-04-11 20:56:59 +00:00
|
|
|
int Version;
|
2014-04-11 13:09:31 +00:00
|
|
|
|
2014-06-22 12:01:23 +00:00
|
|
|
// State variables. These should be relatively easy to move into private.
|
2014-04-11 13:09:31 +00:00
|
|
|
u32 SumDecodedSamples;
|
|
|
|
int LoopNum;
|
|
|
|
u32 MaxOutputSample;
|
2014-04-14 09:47:28 +00:00
|
|
|
int FrameNum; // number of decoded frame
|
2014-06-22 12:01:23 +00:00
|
|
|
|
2014-04-11 13:09:31 +00:00
|
|
|
// Au decoder
|
|
|
|
SimpleAudio *decoder;
|
|
|
|
|
|
|
|
// Au type
|
|
|
|
int audioType;
|
|
|
|
|
|
|
|
// buffers informations
|
|
|
|
int AuBufAvailable; // the available buffer of AuBuf to be able to recharge data
|
|
|
|
int readPos; // read position in audio source file
|
2014-04-12 12:54:25 +00:00
|
|
|
int askedReadSize; // the size of data requied to be read from file by the game
|
|
|
|
int realReadSize; // the really read size from file
|
2014-04-11 13:09:31 +00:00
|
|
|
|
2014-06-22 12:01:23 +00:00
|
|
|
private:
|
|
|
|
std::string sourcebuff; // source buffer
|
2014-04-11 13:09:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|