CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/HW/SimpleAudioDec.h
Views: 1401
// Copyright (c) 2013- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include "Core/HW/MediaEngine.h"20#include "Core/HLE/sceAudio.h"2122// Decodes packet by packet - does NOT demux.2324// audioType25enum PSPAudioType {26PSP_CODEC_AT3PLUS = 0x00001000,27PSP_CODEC_AT3 = 0x00001001,28PSP_CODEC_MP3 = 0x00001002,29PSP_CODEC_AAC = 0x00001003,30};3132class AudioDecoder {33public:34virtual ~AudioDecoder() {}3536virtual PSPAudioType GetAudioType() const = 0;3738// inbytesConsumed can include skipping metadata.39// outSamples is in stereo samples. So you have to multiply by 4 for 16-bit stereo audio to get bytes.40// For Atrac3, if *outSamples != 0, it'll cap the number of samples to output. In this case, its value can only shrink.41// TODO: Implement that in the other decoders too, if needed.42virtual bool Decode(const uint8_t *inbuf, int inbytes, int *inbytesConsumed, int outputChannels, int16_t *outbuf, int *outSamples) = 0;43virtual bool IsOK() const = 0;4445virtual void SetChannels(int channels) = 0;46virtual void FlushBuffers() {}4748// Just metadata.49void SetCtxPtr(uint32_t ptr) { ctxPtr = ptr; }50uint32_t GetCtxPtr() const { return ctxPtr; }5152private:53uint32_t ctxPtr = 0xFFFFFFFF;54};5556void AudioClose(AudioDecoder **ctx);57const char *GetCodecName(int codec); // audioType58bool IsValidCodec(PSPAudioType codec);59AudioDecoder *CreateAudioDecoder(PSPAudioType audioType, int sampleRateHz = 44100, int channels = 2, size_t blockAlign = 0, const uint8_t *extraData = nullptr, size_t extraDataSize = 0);6061class AuCtx {62public:63AuCtx();64~AuCtx();6566u32 AuDecode(u32 pcmAddr);6768u32 AuNotifyAddStreamData(int size);69int AuCheckStreamDataNeeded();70int AuStreamBytesNeeded();71int AuStreamWorkareaSize();72u32 AuResetPlayPosition();73u32 AuResetPlayPositionByFrame(int position);74u32 AuGetInfoToAddStreamData(u32 bufPtr, u32 sizePtr, u32 srcPosPtr);7576void SetReadPos(int pos) { readPos = pos; }77int ReadPos() { return readPos; }7879void DoState(PointerWrap &p);8081void EatSourceBuff(int amount) {82if (amount > (int)sourcebuff.size()) {83amount = (int)sourcebuff.size();84}85if (amount > 0)86sourcebuff.erase(sourcebuff.begin(), sourcebuff.begin() + amount);87AuBufAvailable -= amount;88}89// Au source information. Written to from for example sceAacInit so public for now.90u64 startPos = 0;91u64 endPos = 0;92u32 AuBuf = 0;93u32 AuBufSize = 0;94u32 PCMBuf = 0;95u32 PCMBufSize = 0;9697int freq = -1; // used by AAC only?98int BitRate = 0;99int SamplingRate = -1;100int Channels = 0;101int Version = -1;102103// State variables. These should be relatively easy to move into private.104u32 SumDecodedSamples = 0;105int LoopNum = -1;106u32 MaxOutputSample = 0;107int FrameNum = 0;108109// Au decoder110AudioDecoder *decoder = nullptr;111112private:113size_t FindNextMp3Sync();114115std::vector<u8> sourcebuff; // source buffer116117// buffers informations118int AuBufAvailable = 0; // the available buffer of AuBuf to be able to recharge data119int readPos = 0; // read position in audio source file120int askedReadSize = 0; // the size of data requied to be read from file by the game121int nextOutputHalf = 0;122};123124125126127128129