Nugget
Loading...
Searching...
No Matches
spu.hh
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2024 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27#pragma once
28
29#include <EASTL/functional.h>
30
31#include "psyqo/fixed-point.hh"
32#include "psyqo/kernel.hh"
33
34namespace psyqo {
35
36class SPU {
37 public:
44 static constexpr uint32_t SOUND_RAM_SIZE = 512 * 1024;
45
53 static constexpr size_t ADPCM_BLOCK_SIZE = 16;
54
61 static constexpr size_t MAX_DMA_BLOCK_SIZE = 16 * sizeof(uint32_t);
62
69 static void initialize();
70
78 void initAsync();
79
85 static void silenceChannels(uint32_t channelMask);
86
101 static void dmaWrite(uint32_t spuAddress, const void* ramAddress, size_t dataSize, size_t blockSize = 0);
102
120 void dmaWrite(uint32_t spuAddress, const void* ramAddress, size_t dataSize, eastl::function<void()>&& callback,
122
124 FixedPoint<12, uint16_t> sampleRate;
127 };
128
138 static void playADPCM(uint8_t channelId, uint32_t spuRamAddress, const ChannelPlaybackConfig& config, bool hardCut);
140
141 static constexpr uint32_t NO_FREE_CHANNEL = 0xffffffff;
142 static constexpr uint32_t BASE_SAMPLE_RATE = 44100;
143 static constexpr uint16_t BASE_ALLOC_ADDR = 0x1010;
144
145 private:
146 eastl::function<void()> m_dmaCallback = nullptr;
147 unsigned m_dmaEventSlot = 0;
148 bool m_transferPending = false;
149 bool m_fromISR = false;
150 bool m_initialized = false;
151};
152
153} // namespace psyqo
Definition spu.hh:36
static void dmaWrite(uint32_t spuAddress, const void *ramAddress, size_t dataSize, size_t blockSize=0)
Synchronously uploads data to the SPU's sound RAM.
Definition spu.cpp:85
static constexpr uint32_t SOUND_RAM_SIZE
The size of the SPU's sound RAM, in bytes.
Definition spu.hh:44
static void initialize()
Resets the SPU to a known, silent state.
Definition spu.cpp:127
static constexpr size_t MAX_DMA_BLOCK_SIZE
The largest DMA block size the SPU will accept, in bytes.
Definition spu.hh:61
static uint32_t getNextFreeChannel()
Definition spu.cpp:214
static constexpr uint32_t NO_FREE_CHANNEL
Definition spu.hh:141
static constexpr uint16_t BASE_ALLOC_ADDR
Definition spu.hh:143
static constexpr uint32_t BASE_SAMPLE_RATE
Definition spu.hh:142
void initAsync()
Enables asynchronous DMA transfers for this SPU object.
Definition spu.cpp:158
static void playADPCM(uint8_t channelId, uint32_t spuRamAddress, const ChannelPlaybackConfig &config, bool hardCut)
Starts playing an ADPCM sample on the given channel.
Definition spu.cpp:187
static void silenceChannels(uint32_t channelMask)
Silences the given channels.
Definition spu.cpp:108
static constexpr size_t ADPCM_BLOCK_SIZE
The size of a single ADPCM block, in bytes.
Definition spu.hh:53
DmaCallback
Definition kernel.hh:38
@ FROM_MAIN_LOOP
Definition kernel.hh:40
Definition lua.hh:38
uint16_t volumeRight
Definition spu.hh:125
uint32_t adsr
Definition spu.hh:126
FixedPoint< 12, uint16_t > sampleRate
Definition spu.hh:124
uint16_t volumeLeft
Definition spu.hh:125
void void(ptr, size)
void uint32_t(classId, spec)