Skip to content

Commit a8b0550

Browse files
committed
Sound enhancements
1 parent 00c6c90 commit a8b0550

File tree

7 files changed

+269
-39
lines changed

7 files changed

+269
-39
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ To use mods: place mod folder in the same directory as ctrQuake.3dsx and create
1515
- [ ] Better input handling
1616
- [ ] Networking
1717
- [ ] Hardware rendering
18-
- [ ] Better sound processing
18+
- [x] Better sound processing ( Thanks to Rinnegatamante )
1919

2020
## Credits
2121
Felipe Izzo (MasterFeizz) - Main developer
22-
23-
Rinnegatamante - Brightness fix
22+
Rinnegatamante - Sound enhancements
2423
## Thanks to
2524
Id Software - Source code of Quake
2625

banner.bnr

114 KB
Binary file not shown.

cia.rsf

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
# COPIED FROM RINNEGATAMANTE
2+
BasicInfo:
3+
Title : "ctrQuake"
4+
CompanyCode : "00"
5+
ProductCode : "CTR-P-QUAK"
6+
ContentType : Application
7+
Logo : Nintendo # Nintendo / Licensed / Distributed / iQue / iQueForSystem
8+
9+
TitleInfo:
10+
UniqueId : 0xFF123
11+
Category : Application
12+
13+
CardInfo:
14+
MediaSize : 128MB # 128MB / 256MB / 512MB / 1GB / 2GB / 4GB
15+
MediaType : Card1 # Card1 / Card2
16+
CardDevice : NorFlash # NorFlash(Pick this if you use savedata) / None
17+
18+
19+
Option:
20+
UseOnSD : true # true if App is to be installed to SD
21+
FreeProductCode : true # Removes limitations on ProductCode
22+
MediaFootPadding : false # If true CCI files are created with padding
23+
EnableCrypt : false # Enables encryption for NCCH and CIA
24+
EnableCompress : true # Compresses exefs code
25+
26+
AccessControlInfo:
27+
#UseExtSaveData : true
28+
#ExtSaveDataId: 0xff3ff
29+
#UseExtendedSaveDataAccessControl: true
30+
#AccessibleSaveDataIds: [0x101, 0x202, 0x303, 0x404, 0x505, 0x606]
31+
32+
SystemControlInfo:
33+
SaveDataSize: 128KB
34+
RemasterVersion: 0
35+
StackSize: 0x40000
36+
37+
# DO NOT EDIT BELOW HERE OR PROGRAMS WILL NOT LAUNCH (most likely)
38+
39+
AccessControlInfo:
40+
FileSystemAccess:
41+
- Debug
42+
- DirectSdmc
43+
- DirectSdmcWrite
44+
45+
IdealProcessor : 0
46+
AffinityMask : 1
47+
48+
Priority : 16
49+
50+
MaxCpu : 0x9E # Default
51+
DisableDebug : false
52+
EnableForceDebug : false
53+
CanWriteSharedPage : false
54+
CanUsePrivilegedPriority : false
55+
CanUseNonAlphabetAndNumber : false
56+
PermitMainFunctionArgument : false
57+
CanShareDeviceMemory : false
58+
RunnableOnSleep : false
59+
SpecialMemoryArrange : false
60+
CoreVersion : 2
61+
DescVersion : 2
62+
63+
ReleaseKernelMajor : "02"
64+
ReleaseKernelMinor : "33"
65+
MemoryType : Application
66+
HandleTableSize: 512
67+
68+
SystemModeExt : Legacy # Legacy(Default)/124MB/178MB Legacy:Use Old3DS SystemMode
69+
CpuSpeed : 804MHz # 268MHz(Default)/804MHz
70+
EnableL2Cache : true # false(default)/true
71+
CanAccessCore2 : true
72+
73+
IORegisterMapping:
74+
- 1ff50000-1ff57fff
75+
- 1ff70000-1ff77fff
76+
MemoryMapping:
77+
- 1f000000-1f5fffff:r
78+
SystemCallAccess:
79+
ArbitrateAddress: 34
80+
Break: 60
81+
CancelTimer: 28
82+
ClearEvent: 25
83+
ClearTimer: 29
84+
CloseHandle: 35
85+
ConnectToPort: 45
86+
ControlMemory: 1
87+
CreateAddressArbiter: 33
88+
CreateEvent: 23
89+
CreateMemoryBlock: 30
90+
CreateMutex: 19
91+
CreateSemaphore: 21
92+
CreateThread: 8
93+
CreateTimer: 26
94+
DuplicateHandle: 39
95+
ExitProcess: 3
96+
ExitThread: 9
97+
GetCurrentProcessorNumber: 17
98+
GetHandleInfo: 41
99+
GetProcessId: 53
100+
GetProcessIdOfThread: 54
101+
GetProcessIdealProcessor: 6
102+
GetProcessInfo: 43
103+
GetResourceLimit: 56
104+
GetResourceLimitCurrentValues: 58
105+
GetResourceLimitLimitValues: 57
106+
GetSystemInfo: 42
107+
GetSystemTick: 40
108+
GetThreadContext: 59
109+
GetThreadId: 55
110+
GetThreadIdealProcessor: 15
111+
GetThreadInfo: 44
112+
GetThreadPriority: 11
113+
MapMemoryBlock: 31
114+
OutputDebugString: 61
115+
QueryMemory: 2
116+
ReleaseMutex: 20
117+
ReleaseSemaphore: 22
118+
SendSyncRequest1: 46
119+
SendSyncRequest2: 47
120+
SendSyncRequest3: 48
121+
SendSyncRequest4: 49
122+
SendSyncRequest: 50
123+
SetThreadPriority: 12
124+
SetTimer: 27
125+
SignalEvent: 24
126+
SleepThread: 10
127+
UnmapMemoryBlock: 32
128+
WaitSynchronization1: 36
129+
WaitSynchronizationN: 37
130+
InterruptNumbers:
131+
ServiceAccessControl:
132+
- APT:U
133+
- $hioFIO
134+
- $hostio0
135+
- $hostio1
136+
- ac:u
137+
- boss:U
138+
- cam:u
139+
- cecd:u
140+
- cfg:u
141+
- dlp:FKCL
142+
- dlp:SRVR
143+
- dsp::DSP
144+
- frd:u
145+
- fs:USER
146+
- gsp::Gpu
147+
- hid:USER
148+
- http:C
149+
- mic:u
150+
- ndm:u
151+
- news:s
152+
- nwm::UDS
153+
- ptm:u
154+
- pxi:dev
155+
- soc:U
156+
- gsp::Lcd
157+
- y2r:u
158+
- ldr:ro
159+
- ir:USER
160+
- ir:u
161+
- csnd:SND
162+
- ir:rst
163+
- ns:s
164+
165+
SystemControlInfo:
166+
Dependency:
167+
ac: 0x0004013000002402L
168+
am: 0x0004013000001502L
169+
boss: 0x0004013000003402L
170+
camera: 0x0004013000001602L
171+
cecd: 0x0004013000002602L
172+
cfg: 0x0004013000001702L
173+
codec: 0x0004013000001802L
174+
csnd: 0x0004013000002702L
175+
dlp: 0x0004013000002802L
176+
dsp: 0x0004013000001a02L
177+
friends: 0x0004013000003202L
178+
gpio: 0x0004013000001b02L
179+
gsp: 0x0004013000001c02L
180+
hid: 0x0004013000001d02L
181+
http: 0x0004013000002902L
182+
i2c: 0x0004013000001e02L
183+
ir: 0x0004013000003302L
184+
mcu: 0x0004013000001f02L
185+
mic: 0x0004013000002002L
186+
ndm: 0x0004013000002b02L
187+
news: 0x0004013000003502L
188+
nim: 0x0004013000002c02L
189+
nwm: 0x0004013000002d02L
190+
pdn: 0x0004013000002102L
191+
ps: 0x0004013000003102L
192+
ptm: 0x0004013000002202L
193+
ro: 0x0004013000003702L
194+
socket: 0x0004013000002e02L
195+
spi: 0x0004013000002302L
196+
ssl: 0x0004013000002f02L

icon.bin

13.7 KB
Binary file not shown.

make_cia.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
makerom -f cia -o ctrQuake.cia -elf ctrQuake.elf -rsf cia.rsf -banner banner.bnr -icon icon.bin -exefslogo -target t

source/snd_ctr.c

Lines changed: 70 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,94 @@
11
/*
2-
Copyright (C) 2015 Felipe Izzo
2+
Copyright (C) Rinnegatamante <rinnegatamante@gmail.com>
3+
Copyright (C) 2015 Felipe Izzo <masterfeizz@gmail.com>
34
Copyright (C) 1996-1997 Id Software, Inc.
4-
55
This program is free software; you can redistribute it and/or
66
modify it under the terms of the GNU General Public License
77
as published by the Free Software Foundation; either version 2
88
of the License, or (at your option) any later version.
9-
109
This program is distributed in the hope that it will be useful,
1110
but WITHOUT ANY WARRANTY; without even the implied warranty of
1211
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13-
1412
See the GNU General Public License for more details.
15-
1613
You should have received a copy of the GNU General Public License
1714
along with this program; if not, write to the Free Software
1815
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19-
2016
*/
2117

2218
#include <stdio.h>
2319
#include <3ds.h>
2420
#include "quakedef.h"
2521

2622
#define TICKS_PER_SEC 268111856LL
27-
#define SAMPLE_RATE 32730
28-
#define CSND_BUFSIZE 4096
29-
30-
u8 *csnd_buf;
23+
#define QUAKE_SAMPLERATE 32000
24+
#define CSND_SAMPLERATE 32730
25+
#define CSND_BUFSIZE 16384
26+
#define DSP_BUFSIZE 16384
27+
qboolean isDSP = true;
28+
u32 SAMPLERATE = QUAKE_SAMPLERATE<<1;
29+
u32 *audiobuffer;
30+
ndspWaveBuf* waveBuf;
3131
u64 initial_tick;
3232
int snd_inited;
3333

34+
// createDspBlock: Create a new block for DSP service
35+
void createDspBlock(ndspWaveBuf* waveBuf, u16 bps, u32 size, u8 loop, u32* data){
36+
waveBuf->data_vaddr = (void*)data;
37+
waveBuf->nsamples = size / bps;
38+
waveBuf->looping = loop;
39+
waveBuf->offset = 0;
40+
DSP_FlushDataCache(data, size);
41+
}
42+
3443
qboolean SNDDMA_Init(void)
3544
{
3645
snd_initialized = 0;
37-
38-
if(csndInit() != 0){
39-
Con_Printf("csndInit() failed\n");
40-
return 0;
46+
47+
if(ndspInit() != 0){
48+
Con_Printf("dsp::DSP unavailable, trying with csnd:SND...\n");
49+
isDSP = false;
50+
if(csndInit() != 0){
51+
Con_Printf("csnd:SND unavailable, audio off...\n");
52+
return 0;
53+
}
4154
}
42-
43-
csnd_buf = linearAlloc(CSND_BUFSIZE);
55+
56+
if (isDSP) audiobuffer = linearAlloc(DSP_BUFSIZE);
57+
else audiobuffer = linearAlloc(CSND_BUFSIZE);
4458

4559
/* Fill the audio DMA information block */
4660
shm = &sn;
4761
shm->splitbuffer = 0;
4862
shm->samplebits = 16;
49-
shm->speed = SAMPLE_RATE;
50-
shm->channels = 1;
51-
shm->samples = CSND_BUFSIZE / (shm->samplebits / 8);
63+
if (isDSP){
64+
shm->speed = QUAKE_SAMPLERATE;
65+
shm->channels = 2;
66+
shm->samples = DSP_BUFSIZE<<2;
67+
}else{
68+
shm->speed = QUAKE_SAMPLERATE;
69+
SAMPLERATE = QUAKE_SAMPLERATE;
70+
shm->channels = 1;
71+
shm->samples = CSND_BUFSIZE;
72+
}
5273
shm->samplepos = 0;
5374
shm->submission_chunk = 1;
54-
shm->buffer = csnd_buf;
55-
int ret = csndPlaySound(0x10, SOUND_REPEAT | SOUND_FORMAT_16BIT, SAMPLE_RATE, 0.75f, 0.0f, (u32*)csnd_buf, (u32*)csnd_buf, CSND_BUFSIZE);
56-
if(ret != 0){
57-
Con_Printf("csndPlaySound() failed\n");
58-
return 0;
59-
}
75+
shm->buffer = audiobuffer;
76+
if (isDSP){
77+
ndspSetOutputMode(NDSP_OUTPUT_STEREO);
78+
ndspChnReset(0x08);
79+
ndspChnWaveBufClear(0x08);
80+
ndspChnSetInterp(0x08, NDSP_INTERP_LINEAR);
81+
ndspChnSetRate(0x08, (float)QUAKE_SAMPLERATE);
82+
ndspChnSetFormat(0x08, NDSP_FORMAT_STEREO_PCM16);
83+
waveBuf = (ndspWaveBuf*)calloc(1, sizeof(ndspWaveBuf));
84+
createDspBlock(waveBuf, 2, DSP_BUFSIZE<<2, 1, audiobuffer);
85+
ndspChnWaveBufAdd(0x08, waveBuf);
86+
}else csndPlaySound(0x08, SOUND_LINEAR_INTERP | SOUND_REPEAT | SOUND_FORMAT_16BIT, QUAKE_SAMPLERATE, 1.0f, 1.0f, (u32*)audiobuffer, (u32*)audiobuffer, CSND_BUFSIZE<<1);
87+
6088
initial_tick = svcGetSystemTick();
6189

6290
snd_initialized = 1;
63-
return 1;
91+
return 1;
6492
}
6593

6694
int SNDDMA_GetDMAPos(void)
@@ -69,30 +97,37 @@ int SNDDMA_GetDMAPos(void)
6997
return 0;
7098

7199
u64 delta = (svcGetSystemTick() - initial_tick);
72-
u64 samplepos = delta * (SAMPLE_RATE) / TICKS_PER_SEC;
100+
u64 samplepos = delta * (SAMPLERATE) / TICKS_PER_SEC;
73101
shm->samplepos = samplepos;
74102
return samplepos;
75103
}
76104

77105
void SNDDMA_Shutdown(void)
78106
{
79107
if(snd_initialized){
80-
CSND_SetPlayState(0x10, 0);
81-
csndExecCmds(false);
82-
linearFree(csnd_buf);
83-
csndExit();
108+
if (isDSP){
109+
ndspChnWaveBufClear(0x08);
110+
ndspExit();
111+
free(waveBuf);
112+
}else{
113+
CSND_SetPlayState(0x08, 0);
114+
CSND_UpdateInfo(0);
115+
csndExit();
116+
}
117+
linearFree(audiobuffer);
84118
}
85119
}
86120

87121
/*
88122
==============
89123
SNDDMA_Submit
90-
91124
Send sound to device if buffer isn't really the dma buffer
92125
===============
93126
*/
94127
void SNDDMA_Submit(void)
95128
{
96-
//if(snd_initialized)
97-
//GSPGPU_FlushDataCache(NULL, csnd_buf, csnd_bufsize);
98-
}
129+
if (snd_initialized){
130+
if (isDSP) DSP_FlushDataCache(audiobuffer, DSP_BUFSIZE<<2);
131+
else CSND_FlushDataCache(audiobuffer, CSND_BUFSIZE);
132+
}
133+
}

source/sys_ctr.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ int main (int argc, char **argv)
284284
osSetSpeedupEnable(true);
285285

286286
gfxInit(GSP_RGB565_OES,GSP_RGB565_OES,false);
287-
hidInit();
288287
gfxSetDoubleBuffering(GFX_TOP, false);
289288
gfxSetDoubleBuffering(GFX_BOTTOM, false);
290289
gfxSet3D(false);

0 commit comments

Comments
 (0)