Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/HLE/AtracCtx.h
3186 views
1
// Copyright (c) 2012- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#pragma once
19
20
#include <vector>
21
22
#include "Common/CommonTypes.h"
23
#include "Common/Swap.h"
24
25
#include "Core/MemMap.h"
26
#include "Core/HLE/AtracBase.h"
27
#include "Core/Util/AtracTrack.h"
28
29
class Atrac : public AtracBase {
30
public:
31
Atrac(int atracID, int codecType = 0) : atracID_(atracID) {
32
if (codecType) {
33
track_.codecType = codecType;
34
}
35
}
36
~Atrac();
37
38
uint32_t CurBufferAddress(int adjust = 0) const {
39
u32 off = track_.FileOffsetBySample(currentSample_ + adjust);
40
if (off < first_.size && ignoreDataBuf_) {
41
return first_.addr + off;
42
}
43
// If it's in dataBug, it's not in PSP memory.
44
return 0;
45
}
46
47
u8 *BufferStart();
48
49
AtracStatus BufferState() const override {
50
return bufferState_;
51
}
52
53
void DoState(PointerWrap &p) override;
54
55
int GetNextDecodePosition(int *pos) const override;
56
int RemainingFrames() const override;
57
58
int CodecType() const override {
59
return track_.codecType;
60
}
61
bool HasSecondBuffer() const override {
62
return second_.size != 0;
63
}
64
int Channels() const override {
65
return track_.channels;
66
}
67
int LoopNum() const override {
68
return loopNum_;
69
}
70
int LoopStatus() const override {
71
// This doesn't match tests.
72
if (track_.loopinfo.size() > 0)
73
return 1;
74
else
75
return 0;
76
}
77
int Bitrate() const override {
78
return track_.Bitrate();
79
}
80
int BytesPerFrame() const override {
81
return track_.BytesPerFrame();
82
}
83
int SamplesPerFrame() const override {
84
return track_.SamplesPerFrame();
85
}
86
87
// This should be rare.
88
Track &GetTrackMut() {
89
return track_;
90
}
91
92
int SetLoopNum(int loopNum) override;
93
94
// Ask where in memory new data should be written.
95
void GetStreamDataInfo(u32 *writePtr, u32 *writableBytes, u32 *readOffset) override;
96
// Notify the player that the user has written some new data.
97
int AddStreamData(u32 bytesToAdd) override;
98
int ResetPlayPosition(int sample, int bytesWrittenFirstBuf, int bytesWrittenSecondBuf, bool *delay) override;
99
int GetBufferInfoForResetting(AtracResetBufferInfo *bufferInfo, int sample, bool *delay) override; // NOTE: Not const! This can cause SkipFrames! (although only in the AtracCtx2)
100
int SetData(const Track &track, u32 buffer, u32 readSize, u32 bufferSize, u32 fileSize, int outputChannels, bool isAA3) override;
101
int GetSecondBufferInfo(u32 *fileOffset, u32 *desiredSize) const override;
102
int SetSecondBuffer(u32 secondBuffer, u32 secondBufferSize) override;
103
u32 DecodeData(u8 *outbuf, u32 outbufPtr, int *SamplesNum, int *finish, int *remains) override;
104
int DecodeLowLevel(const u8 *srcData, int *bytesConsumed, s16 *dstData, int *bytesWritten) override;
105
106
void CheckForSas() override;
107
int EnqueueForSas(u32 address, u32 ptr) override;
108
void DecodeForSas(s16 *dstData, int *bytesWritten, int *finish) override;
109
110
// Returns how many samples the next DecodeData will write.
111
u32 GetNextSamples() override;
112
void InitLowLevel(const Atrac3LowLevelParams &params, int codecType) override;
113
114
int GetSoundSample(int *endSample, int *loopStartSample, int *loopEndSample) const override;
115
116
void NotifyGetContextAddress() override;
117
void UpdateContextFromPSPMem() override;
118
void WriteContextToPSPMem();
119
120
int GetContextVersion() const override { return 1; }
121
122
private:
123
void UpdateBufferState();
124
void ResetData();
125
void SeekToSample(int sample);
126
void ForceSeekToSample(int sample);
127
u32 StreamBufferEnd() const {
128
// The buffer is always aligned to a frame in size, not counting an optional header.
129
// The header will only initially exist after the data is first set.
130
u32 framesAfterHeader = (bufferMaxSize_ - bufferHeaderSize_) / track_.bytesPerFrame;
131
return framesAfterHeader * track_.bytesPerFrame + bufferHeaderSize_;
132
}
133
void ConsumeFrame();
134
void CalculateStreamInfo(u32 *readOffset);
135
136
Track track_{};
137
138
InputBuffer first_{};
139
InputBuffer second_{}; // only addr, size, fileoffset are used (incomplete)
140
141
u8 *dataBuf_ = nullptr;
142
// Indicates that the dataBuf_ array should not be used.
143
bool ignoreDataBuf_ = false;
144
145
int currentSample_ = 0;
146
u32 decodePos_ = 0;
147
u32 bufferMaxSize_ = 0;
148
int loopNum_ = 0;
149
150
// Used to track streaming.
151
u32 bufferPos_ = 0;
152
u32 bufferValidBytes_ = 0;
153
u32 bufferHeaderSize_ = 0;
154
155
int atracID_ = -1;
156
AtracStatus bufferState_ = ATRAC_STATUS_NO_DATA;
157
};
158
159