Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better audio playback code #642

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/PICA/pica_vertex.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
#include "PICA/float_types.hpp"
#include <array>

#include "PICA/float_types.hpp"

namespace PICA {
// A representation of the output vertex as it comes out of the vertex shader, with padding and all
struct Vertex {
Expand Down
8 changes: 4 additions & 4 deletions include/audio/dsp_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include "helpers.hpp"
#include "logger.hpp"
#include "scheduler.hpp"
#include "ring_buffer.hpp"
#include "scheduler.hpp"

// The DSP core must have access to the DSP service to be able to trigger interrupts properly
class DSPService;
Expand All @@ -24,7 +24,8 @@ namespace Audio {
static constexpr u64 lleSlice = 16384;

class DSPCore {
using Samples = Common::RingBuffer<s16, 1024>;
// 0x2000 stereo (= 2 channel) samples
using Samples = Common::RingBuffer<s16, 0x2000 * 2>;

protected:
Memory& mem;
Expand All @@ -38,8 +39,7 @@ namespace Audio {

public:
enum class Type { Null, Teakra, HLE };
DSPCore(Memory& mem, Scheduler& scheduler, DSPService& dspService)
: mem(mem), scheduler(scheduler), dspService(dspService) {}
DSPCore(Memory& mem, Scheduler& scheduler, DSPService& dspService) : mem(mem), scheduler(scheduler), dspService(dspService) {}
virtual ~DSPCore() {}

virtual void reset() = 0;
Expand Down
5 changes: 4 additions & 1 deletion include/audio/miniaudio_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
#include <string>
#include <vector>

#include "helpers.hpp"
#include "miniaudio.h"
#include "ring_buffer.hpp"

class MiniAudioDevice {
using Samples = Common::RingBuffer<ma_int16, 1024>;
using Samples = Common::RingBuffer<ma_int16, 0x2000 * 2>;
static constexpr ma_uint32 sampleRate = 32768; // 3DS sample rate
static constexpr ma_uint32 channelCount = 2; // Audio output is stereo

Expand All @@ -20,6 +21,8 @@ class MiniAudioDevice {
bool initialized = false;
bool running = false;

// Store the last stereo sample we output. We play this when underruning to avoid pops.
std::array<s16, 2> lastStereoSample;
std::vector<std::string> audioDevices;

public:
Expand Down
2 changes: 1 addition & 1 deletion include/audio/null_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Audio {
std::array<u8, Memory::DSP_RAM_SIZE> dspRam;

void resetAudioPipe();
bool loaded = false; // Have we loaded a component?
bool loaded = false; // Have we loaded a component?

public:
NullDSP(Memory& mem, Scheduler& scheduler, DSPService& dspService) : DSPCore(mem, scheduler, dspService) {}
Expand Down
2 changes: 1 addition & 1 deletion include/renderdoc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace Renderdoc {
}

~InstantScope() { Renderdoc::endCapture(); }

InstantScope(const InstantScope&) = delete;
InstantScope& operator=(const InstantScope&) = delete;

Expand Down
268 changes: 134 additions & 134 deletions include/services/region_codes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enum class Regions : u32 {
Australia = 3,
China = 4,
Korea = 5,
Taiwan = 6
Taiwan = 6,
};

// Used for the language field in the NAND user data
Expand Down Expand Up @@ -42,137 +42,137 @@ enum class LanguageCodes : u32 {
};

enum class CountryCodes : u32 {
JP = 1,
AI = 8,
AG = 9,
AR = 10,
AW = 11,
BS = 12,
BB = 13,
BZ = 14,
BO = 15,
BR = 16,
VG = 17,
CA = 18,
KY = 19,
CL = 20,
CO = 21,
CR = 22,
DM = 23,
DO = 24,
EC = 25,
SV = 26,
GF = 27,
GD = 28,
GP = 29,
GT = 30,
GY = 31,
HT = 32,
HN = 33,
JM = 34,
MQ = 35,
MX = 36,
MS = 37,
AN = 38,
NI = 39,
PA = 40,
PY = 41,
PE = 42,
KN = 43,
LC = 44,
VC = 45,
SR = 46,
TT = 47,
TC = 48,
US = 49,
UY = 50,
VI = 51,
VE = 52,
AL = 64,
AU = 65,
AT = 66,
BE = 67,
BA = 68,
BW = 69,
BG = 70,
HR = 71,
CY = 72,
CZ = 73,
DK = 74,
EE = 75,
FI = 76,
FR = 77,
DE = 78,
GR = 79,
HU = 80,
IS = 81,
IE = 82,
IT = 83,
LV = 84,
LS = 85,
LI = 86,
LT = 87,
LU = 88,
MK = 89,
MT = 90,
ME = 91,
MZ = 92,
NA = 93,
NL = 94,
NZ = 95,
NO = 96,
PL = 97,
PT = 98,
RO = 99,
RU = 100,
RS = 101,
SK = 102,
SI = 103,
ZA = 104,
ES = 105,
SZ = 106,
SE = 107,
CH = 108,
TR = 109,
GB = 110,
ZM = 111,
ZW = 112,
AZ = 113,
MR = 114,
ML = 115,
NE = 116,
TD = 117,
SD = 118,
ER = 119,
DJ = 120,
SO = 121,
AD = 122,
GI = 123,
GG = 124,
IM = 125,
JE = 126,
MC = 127,
TW = 128,
KR = 136,
HK = 144,
MO = 145,
ID = 152,
SG = 153,
TH = 154,
PH = 155,
MY = 156,
CN = 160,
AE = 168,
IND = 169, // We can't use the 2-letter country code for India because the Windows SDK does #define IN...
EG = 170,
OM = 171,
QA = 172,
KW = 173,
SA = 174,
SY = 175,
BH = 176,
JO = 177,
SM = 184,
VA = 185,
BM = 186,
JP = 1,
AI = 8,
AG = 9,
AR = 10,
AW = 11,
BS = 12,
BB = 13,
BZ = 14,
BO = 15,
BR = 16,
VG = 17,
CA = 18,
KY = 19,
CL = 20,
CO = 21,
CR = 22,
DM = 23,
DO = 24,
EC = 25,
SV = 26,
GF = 27,
GD = 28,
GP = 29,
GT = 30,
GY = 31,
HT = 32,
HN = 33,
JM = 34,
MQ = 35,
MX = 36,
MS = 37,
AN = 38,
NI = 39,
PA = 40,
PY = 41,
PE = 42,
KN = 43,
LC = 44,
VC = 45,
SR = 46,
TT = 47,
TC = 48,
US = 49,
UY = 50,
VI = 51,
VE = 52,
AL = 64,
AU = 65,
AT = 66,
BE = 67,
BA = 68,
BW = 69,
BG = 70,
HR = 71,
CY = 72,
CZ = 73,
DK = 74,
EE = 75,
FI = 76,
FR = 77,
DE = 78,
GR = 79,
HU = 80,
IS = 81,
IE = 82,
IT = 83,
LV = 84,
LS = 85,
LI = 86,
LT = 87,
LU = 88,
MK = 89,
MT = 90,
ME = 91,
MZ = 92,
NA = 93,
NL = 94,
NZ = 95,
NO = 96,
PL = 97,
PT = 98,
RO = 99,
RU = 100,
RS = 101,
SK = 102,
SI = 103,
ZA = 104,
ES = 105,
SZ = 106,
SE = 107,
CH = 108,
TR = 109,
GB = 110,
ZM = 111,
ZW = 112,
AZ = 113,
MR = 114,
ML = 115,
NE = 116,
TD = 117,
SD = 118,
ER = 119,
DJ = 120,
SO = 121,
AD = 122,
GI = 123,
GG = 124,
IM = 125,
JE = 126,
MC = 127,
TW = 128,
KR = 136,
HK = 144,
MO = 145,
ID = 152,
SG = 153,
TH = 154,
PH = 155,
MY = 156,
CN = 160,
AE = 168,
IND = 169, // We can't use the 2-letter country code for India because the Windows SDK does #define IN...
EG = 170,
OM = 171,
QA = 172,
KW = 173,
SA = 174,
SY = 175,
BH = 176,
JO = 177,
SM = 184,
VA = 185,
BM = 186,
};
Loading
Loading