aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/SPU.cpp11
-rw-r--r--src/SPU.h2
-rw-r--r--src/libui_sdl/main.cpp65
-rw-r--r--src/version.h2
4 files changed, 62 insertions, 18 deletions
diff --git a/src/SPU.cpp b/src/SPU.cpp
index a0d8dc8..7f70e65 100644
--- a/src/SPU.cpp
+++ b/src/SPU.cpp
@@ -684,19 +684,26 @@ void Mix(u32 samples)
}
-void ReadOutput(s16* data, int samples)
+int ReadOutput(s16* data, int samples)
{
+ if (OutputReadOffset == OutputWriteOffset)
+ return 0;
+
for (int i = 0; i < samples; i++)
{
*data++ = OutputBuffer[OutputReadOffset];
*data++ = OutputBuffer[OutputReadOffset + 1];
- if (OutputReadOffset != OutputWriteOffset)
+ //if (OutputReadOffset != OutputWriteOffset)
{
OutputReadOffset += 2;
OutputReadOffset &= ((2*OutputBufferSize)-1);
}
+ if (OutputReadOffset == OutputWriteOffset)
+ return i+1;
}
+
+ return samples;
}
diff --git a/src/SPU.h b/src/SPU.h
index cc0127a..85c27ee 100644
--- a/src/SPU.h
+++ b/src/SPU.h
@@ -31,7 +31,7 @@ void SetBias(u16 bias);
void Mix(u32 samples);
-void ReadOutput(s16* data, int samples);
+int ReadOutput(s16* data, int samples);
u8 Read8(u32 addr);
u16 Read16(u32 addr);
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp
index 841aa9c..61742b5 100644
--- a/src/libui_sdl/main.cpp
+++ b/src/libui_sdl/main.cpp
@@ -96,7 +96,46 @@ void UpdateWindowTitle(void* data)
void AudioCallback(void* data, Uint8* stream, int len)
{
- SPU::ReadOutput((s16*)stream, len>>2);
+ // resampling:
+ // buffer length is 1024 samples
+ // which is 710 samples at the original sample rate
+
+ //SPU::ReadOutput((s16*)stream, len>>2);
+ s16 buf_in[710*2];
+ s16* buf_out = (s16*)stream;
+
+ int num_in = SPU::ReadOutput(buf_in, 710);
+ int num_out = 1024;
+
+ int margin = 6;
+ if (num_in < 710-margin)
+ {
+ int last = num_in-1;
+ if (last < 0) last = 0;
+
+ for (int i = num_in; i < 710-margin; i++)
+ ((u32*)buf_in)[i] = ((u32*)buf_in)[last];
+
+ num_in = 710-margin;
+ }
+
+ float res_incr = num_in / (float)num_out;
+ float res_timer = 0;
+ int res_pos = 0;
+
+ for (int i = 0; i < 1024; i++)
+ {
+ // TODO: interp!!
+ buf_out[i*2 ] = buf_in[res_pos*2 ];
+ buf_out[i*2+1] = buf_in[res_pos*2+1];
+
+ res_timer += res_incr;
+ while (res_timer >= 1.0)
+ {
+ res_timer -= 1.0;
+ res_pos++;
+ }
+ }
}
int EmuThreadFunc(void* burp)
@@ -111,15 +150,9 @@ int EmuThreadFunc(void* burp)
ScreenDrawInited = false;
Touching = false;
- // DS:
- // 547.060546875 samples per frame
- // 32823.6328125 samples per second
- //
- // 48000 samples per second:
- // 800 samples per frame
SDL_AudioSpec whatIwant, whatIget;
memset(&whatIwant, 0, sizeof(SDL_AudioSpec));
- whatIwant.freq = 32824; // 32823.6328125
+ whatIwant.freq = 47340;
whatIwant.format = AUDIO_S16LSB;
whatIwant.channels = 2;
whatIwant.samples = 1024;
@@ -1112,11 +1145,6 @@ int main(int argc, char** argv)
uiMenuItemOnClicked(menuitem, OnSetScreenFiltering, NULL);
uiMenuItemSetChecked(menuitem, Config::ScreenFilter==1);
- uiMenuItemSetChecked(MenuItem_ScreenRot[ScreenRotation], 1);
- uiMenuItemSetChecked(MenuItem_ScreenGap[ScreenGap], 1);
- uiMenuItemSetChecked(MenuItem_ScreenLayout[ScreenLayout], 1);
- uiMenuItemSetChecked(MenuItem_ScreenSizing[ScreenSizing], 1);
-
int w = Config::WindowWidth;
int h = Config::WindowHeight;
@@ -1156,11 +1184,20 @@ int main(int argc, char** argv)
#define SANITIZE(var, min, max) if ((var < min) || (var > max)) var = 0;
SANITIZE(ScreenRotation, 0, 3);
- SANITIZE(ScreenGap, 0, 5);
SANITIZE(ScreenLayout, 0, 2);
SANITIZE(ScreenSizing, 0, 3);
#undef SANITIZE
+ uiMenuItemSetChecked(MenuItem_ScreenRot[ScreenRotation], 1);
+ uiMenuItemSetChecked(MenuItem_ScreenLayout[ScreenLayout], 1);
+ uiMenuItemSetChecked(MenuItem_ScreenSizing[ScreenSizing], 1);
+
+ for (int i = 0; i < 6; i++)
+ {
+ if (ScreenGap == kScreenGap[i])
+ uiMenuItemSetChecked(MenuItem_ScreenGap[i], 1);
+ }
+
OnSetScreenRotation(MenuItem_ScreenRot[ScreenRotation], MainWindow, (void*)&kScreenRot[ScreenRotation]);
EmuRunning = 2;
diff --git a/src/version.h b/src/version.h
index deaf3f3..9e2d867 100644
--- a/src/version.h
+++ b/src/version.h
@@ -19,7 +19,7 @@
#ifndef VERSION_H
#define VERSION_H
-#define MELONDS_VERSION "0.6"
+#define MELONDS_VERSION "0.6b"
#define MELONDS_URL "http://melonds.kuribo64.net/"