Skip to content

Commit 57b9a71

Browse files
committed
ndsp sound
1 parent 80bbfa5 commit 57b9a71

20 files changed

+1749
-84
lines changed

Debug/prboom.log

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Build started 4/18/2015 11:28:10 AM.
1+
Build started 12/31/2015 8:20:03 PM.
22
1>Project "C:\devl\prboom3ds\prboom.vcxproj" on node 2 (Build target(s)).
33
1>Build:
44
make -r 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):/\1(\2):/

arm11/source/3ds_mix.c

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if 0
12
#include "ds_mix.h"
23
#include "doomstat.h"
34
#include "sounds.h"
@@ -8,6 +9,21 @@
89
#include "w_wad.h"
910
#include <3ds.h>
1011

12+
#define USE_CSND
13+
14+
#ifndef USE_CSND
15+
void* ndspMix_init(int channel, int speed, int channels);
16+
void ndsp_update(void *pmix, short *pAudioData, int count);
17+
int ndspMix_pos(void *pmix);
18+
void ndspMix_exit(void *pmix);
19+
void ndspMix_clear(void *pmix);
20+
void *_ndspMixer = 0;
21+
22+
u64 g_sound_time;
23+
u64 g_paint_time;
24+
#endif
25+
26+
1127
extern int snd_card;
1228
extern boolean nosfxparm;
1329

@@ -62,7 +78,6 @@ portable_samplepair_t paintbuffer[PAINTBUFFER_SIZE];
6278
static int snd_scaletable[32][256];
6379
int audio_initialized = 0;
6480

65-
#if 1
6681

6782
static u64 sound_start;
6883
#define TICKS_PER_SEC 268123480.0
@@ -78,8 +93,8 @@ void mix_start() {
7893
memset(c_snd_Buffer_right, 0, SND_SAMPLES);
7994
//c_snd_Buffer_left[4] = c_snd_Buffer_left[5] = 0x7f; // force a pop for debugging
8095
//c_snd_Buffer_right[4] = c_snd_Buffer_right[5] = 0x7f; // force a pop for debugging
81-
GSPGPU_FlushDataCache(NULL, c_snd_Buffer_left, SND_SAMPLES);
82-
GSPGPU_FlushDataCache(NULL, c_snd_Buffer_right, SND_SAMPLES);
96+
GSPGPU_FlushDataCache(c_snd_Buffer_left, SND_SAMPLES);
97+
GSPGPU_FlushDataCache(c_snd_Buffer_right, SND_SAMPLES);
8398
}
8499

85100

@@ -109,6 +124,8 @@ void MIX_init() {
109124
u8 playing = 0;
110125

111126
MIX_InitScaletable();
127+
128+
#ifdef USE_CSND
112129

113130
snd_Samples = SND_SAMPLES;
114131
snd_Speed = 11025;
@@ -136,15 +153,29 @@ void MIX_init() {
136153
csndExecCmds(true);
137154

138155
sound_start = svcGetSystemTick();
156+
#else
157+
_ndspMixer = ndspMix_init(1, 32768, 2);
158+
g_sound_time = g_paint_time = ndspMix_pos();
159+
#endif
139160
}
140161

141162
void MIX_exit() {
163+
#ifdef USE_CSND
142164
CSND_SetPlayState(0x8, 0);
143165
CSND_SetPlayState(0x9, 0);
166+
#else
167+
ndspMixer_exit(_ndspMixer);
168+
#endif
144169
}
145170

146171
void MIX_TransferPaintBuffer(int endtime)
147172
{
173+
#ifndef USE_CSND
174+
int count = endtime - paintedtime;
175+
176+
m_hw->update((int *)paintbuffer, count);
177+
178+
#else
148179
int out_idx;
149180
int count, count1, count2, pos;
150181
int out_mask;
@@ -185,7 +216,7 @@ void MIX_TransferPaintBuffer(int endtime)
185216

186217
out_idx = (out_idx + 1) & out_mask;
187218
}
188-
219+
#endif
189220
}
190221

191222
void MIX_PaintChannelFrom8(channel_t *ch, byte *sfx, int count)
@@ -354,8 +385,8 @@ void MIX_Update_(void)
354385
//printf("mixing %d %d %d\n", soundtime, paintedtime, endtime);
355386
MIX_PaintChannels(endtime);
356387
//DC_FlushRange(c_snd_Buffer, SND_SAMPLES * 2);
357-
GSPGPU_FlushDataCache(NULL, c_snd_Buffer_left, SND_SAMPLES);
358-
GSPGPU_FlushDataCache(NULL, c_snd_Buffer_right, SND_SAMPLES);
388+
GSPGPU_FlushDataCache(c_snd_Buffer_left, SND_SAMPLES);
389+
GSPGPU_FlushDataCache(c_snd_Buffer_right, SND_SAMPLES);
359390
}
360391

361392
extern int snd_SfxVolume;
@@ -751,7 +782,6 @@ void S_StartSoundAtVolume(void *origin_p, int sfx_id, int volume)
751782

752783
I_StartSound(sfx, cnum, volume, sep, pitch, priority);
753784
}
754-
#endif
755785

756786
void S_StartSound(void *origin, int sound_id) {
757787
S_StartSoundAtVolume(origin, sound_id, snd_SfxVolume);
@@ -777,3 +807,4 @@ void S_Stop(void)
777807
//so it should not make any noise while the level loads
778808
mix_start();
779809
}
810+
#endif

arm11/source/3ds_sound.c

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -204,29 +204,7 @@ void S_Init(int sfxVolume, int musicVolume) {
204204
//return;
205205

206206
if (csndInit() == 0) {
207-
#if 1
208-
printf("csndInit ok!\ncsndChannels: %08x\n", csndChannels);
209-
#else
210-
Result ret = 0;
211-
Handle csndHandle;
212-
u32 __channels=0;
213-
printf("csndInit ok!\ncsndChannels: %08x\n", csndChannels);
214-
ret = srvGetServiceHandle(&csndHandle, "csnd:SND");
215-
if (ret != 0) {
216-
printf("handle failed\n");
217-
}
218-
ret = CSND_ReleaseSoundChannels(csndHandle);
219-
if (ret != 0) {
220-
printf("CSND_ReleaseSoundChannels failed\n");
221-
}
222-
ret = CSND_AcquireSoundChannels(csndHandle, &__channels);
223-
if (ret != 0) {
224-
printf("CSND_AcquireSoundChannels failed\n");
225-
}
226-
printf("channels: %08x\n", __channels);
227-
gfxFlushBuffers();
228-
while (1);
229-
#endif
207+
printf("csndInit ok!\n");
230208
audio_initialized = 1;
231209
}
232210
else {
@@ -251,7 +229,6 @@ void S_Exit() {
251229
mus_exit();
252230
//flush csnd command buffers
253231
csndExecCmds(true);
254-
ret = csndExit();
255-
printf("csndExit %d\n", ret);
232+
csndExit();
256233
//svcSleepThread(5000000000LL);
257234
}

arm11/source/MixerHardware.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#pragma once
2-
2+
#include <3ds/types.h>
33
class MixerHardware {
44
public:
55
MixerHardware();
66
virtual ~MixerHardware();
77
virtual void flush() = 0;
88
virtual void update(int *pAudioData, int count) = 0;
99
virtual void update(short *pAudioData, int count) = 0;
10-
virtual int samplepos() = 0;
10+
virtual u64 samplepos() = 0;
1111
};
1212

1313
inline MixerHardware::MixerHardware() {

arm11/source/Mixer_3ds.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void MixerHardware3DS::init() {
88
m_bufferSize = 4096;
99

1010
m_soundBuffer = (byte *)linearAlloc(m_bufferSize);
11-
m_soundBufferPHY = osConvertVirtToPhys((u32)m_soundBuffer);
11+
m_soundBufferPHY = osConvertVirtToPhys(m_soundBuffer);
1212
m_bufferPos = 0;
1313
m_soundPos = 0;
1414
m_lastPos = 0;
@@ -31,7 +31,7 @@ void MixerHardware3DS::init() {
3131

3232
void MixerHardware3DS::clear() {
3333
memset(m_soundBuffer, 0, m_bufferSize);
34-
GSPGPU_FlushDataCache(NULL, m_soundBuffer, m_bufferSize);
34+
GSPGPU_FlushDataCache(m_soundBuffer, m_bufferSize);
3535
}
3636

3737
void MixerHardware3DS::shutdown() {
@@ -49,7 +49,7 @@ byte* MixerHardware3DS::buffer() {
4949
#define TICKS_PER_SEC 268123480.0
5050
#define TICKS_PER_SEC_LL 268111856LL
5151

52-
int MixerHardware3DS::samplepos() {
52+
u64 MixerHardware3DS::samplepos() {
5353
u64 delta = (svcGetSystemTick() - m_start);
5454
u64 samples = delta * m_speed / TICKS_PER_SEC_LL;
5555

@@ -87,10 +87,10 @@ void MixerHardware3DS::update(short *pAudioData, int count)
8787
outp[pos] = val>>8;
8888
pos = (pos + 1) & mask;
8989
}
90-
GSPGPU_FlushDataCache(NULL, m_soundBuffer, m_bufferSize);
90+
GSPGPU_FlushDataCache(m_soundBuffer, m_bufferSize);
9191
}
9292

93-
93+
#if 0
9494
MixerHardware3DS g_mixer(32728, 2);
9595

9696
extern "C" void mixer_update(short *pAudioData, int count) {
@@ -113,7 +113,4 @@ extern "C" void mixer_clear() {
113113
g_mixer.clear();
114114
}
115115

116-
extern "C" byte* mixer_buffer() {
117-
return g_mixer.buffer();
118-
}
119-
116+
#endif

arm11/source/Mixer_3ds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class MixerHardware3DS : public MixerHardware {
1515
void flush();
1616
void update(int *pAudioData, int count);
1717
void update(short *pAudioData, int count);
18-
int samplepos();
18+
u64 samplepos();
1919
void clear();
2020
byte *buffer();
2121
private:

0 commit comments

Comments
 (0)