diff --git a/gtk/src/gtk_sound_driver.h b/common/audio/s9x_sound_driver.hpp similarity index 89% rename from gtk/src/gtk_sound_driver.h rename to common/audio/s9x_sound_driver.hpp index 52ea042e..90a82b1b 100644 --- a/gtk/src/gtk_sound_driver.h +++ b/common/audio/s9x_sound_driver.hpp @@ -4,8 +4,8 @@ For further information, consult the LICENSE file in the root directory. \*****************************************************************************/ -#ifndef __S9X_SOUND_DRIVER_H -#define __S9X_SOUND_DRIVER_H +#ifndef __S9X_SOUND_DRIVER_HPP +#define __S9X_SOUND_DRIVER_HPP #include #include @@ -26,4 +26,4 @@ class S9xSoundDriver virtual void stop() = 0; }; -#endif /* __GTK_SOUND_DRIVER_H */ +#endif /* __S9X_SOUND_DRIVER_HPP */ diff --git a/gtk/src/gtk_sound_driver_alsa.cpp b/common/audio/s9x_sound_driver_alsa.cpp similarity index 99% rename from gtk/src/gtk_sound_driver_alsa.cpp rename to common/audio/s9x_sound_driver_alsa.cpp index 275f2535..8f7f51b6 100644 --- a/gtk/src/gtk_sound_driver_alsa.cpp +++ b/common/audio/s9x_sound_driver_alsa.cpp @@ -4,7 +4,7 @@ For further information, consult the LICENSE file in the root directory. \*****************************************************************************/ -#include "gtk_sound_driver_alsa.h" +#include "s9x_sound_driver_alsa.hpp" #include #include diff --git a/gtk/src/gtk_sound_driver_alsa.h b/common/audio/s9x_sound_driver_alsa.hpp similarity index 84% rename from gtk/src/gtk_sound_driver_alsa.h rename to common/audio/s9x_sound_driver_alsa.hpp index 53d9aadb..ed94aae8 100644 --- a/gtk/src/gtk_sound_driver_alsa.h +++ b/common/audio/s9x_sound_driver_alsa.hpp @@ -4,11 +4,10 @@ For further information, consult the LICENSE file in the root directory. \*****************************************************************************/ -#ifndef __GTK_SOUND_DRIVER_ALSA_H -#define __GTK_SOUND_DRIVER_ALSA_H +#ifndef __S9X_SOUND_DRIVER_ALSA_HPP +#define __S9X_SOUND_DRIVER_ALSA_HPP -#include "gtk_sound.h" -#include "gtk_sound_driver.h" +#include "s9x_sound_driver.hpp" #include "alsa/asoundlib.h" class S9xAlsaSoundDriver : public S9xSoundDriver @@ -29,4 +28,4 @@ class S9xAlsaSoundDriver : public S9xSoundDriver int output_buffer_size_bytes; }; -#endif /* __GTK_SOUND_DRIVER_ALSA_H */ +#endif /* __S9X_SOUND_DRIVER_ALSA_HPP */ diff --git a/gtk/src/gtk_sound_driver_oss.cpp b/common/audio/s9x_sound_driver_oss.cpp similarity index 92% rename from gtk/src/gtk_sound_driver_oss.cpp rename to common/audio/s9x_sound_driver_oss.cpp index 41494aae..9d9c3c3e 100644 --- a/gtk/src/gtk_sound_driver_oss.cpp +++ b/common/audio/s9x_sound_driver_oss.cpp @@ -4,13 +4,29 @@ For further information, consult the LICENSE file in the root directory. \*****************************************************************************/ -#include "gtk_sound_driver_oss.h" +#include "s9x_sound_driver_oss.hpp" #include #include #include #include #include +#include + +static inline int log2(int num) +{ + int power; + + if (num < 1) + return 0; + + for (power = 0; num > 1; power++) + { + num >>= 1; + } + + return power; +} S9xOSSSoundDriver::S9xOSSSoundDriver() { @@ -106,7 +122,7 @@ bool S9xOSSSoundDriver::open_device(int playback_rate, int buffer_size_ms) /* OSS requires a power-of-two buffer size, first 16 bits are the number * of fragments to generate, second 16 are the respective power-of-two. */ - temp = (4 << 16) | (S9xSoundBase2log(output_buffer_size_bytes / 4)); + temp = (4 << 16) | (log2(output_buffer_size_bytes / 4)); if (ioctl(filedes, SNDCTL_DSP_SETFRAGMENT, &temp) < 0) goto close_fail; diff --git a/gtk/src/gtk_sound_driver_oss.h b/common/audio/s9x_sound_driver_oss.hpp similarity index 84% rename from gtk/src/gtk_sound_driver_oss.h rename to common/audio/s9x_sound_driver_oss.hpp index 6fd10b77..4d7aa99f 100644 --- a/gtk/src/gtk_sound_driver_oss.h +++ b/common/audio/s9x_sound_driver_oss.hpp @@ -4,11 +4,10 @@ For further information, consult the LICENSE file in the root directory. \*****************************************************************************/ -#ifndef __GTK_SOUND_DRIVER_OSS_H -#define __GTK_SOUND_DRIVER_OSS_H +#ifndef __S9X_SOUND_DRIVER_OSS_HPP +#define __S9X_SOUND_DRIVER_OSS_HPP -#include "gtk_sound.h" -#include "gtk_sound_driver.h" +#include "s9x_sound_driver.hpp" class S9xOSSSoundDriver : public S9xSoundDriver { @@ -28,4 +27,4 @@ class S9xOSSSoundDriver : public S9xSoundDriver int output_buffer_size_bytes; }; -#endif /* __GTK_SOUND_DRIVER_OSS_H */ +#endif /* __S9X_SOUND_DRIVER_OSS_HPP */ diff --git a/gtk/src/gtk_sound_driver_portaudio.cpp b/common/audio/s9x_sound_driver_portaudio.cpp similarity index 97% rename from gtk/src/gtk_sound_driver_portaudio.cpp rename to common/audio/s9x_sound_driver_portaudio.cpp index dc513345..ecadbb14 100644 --- a/gtk/src/gtk_sound_driver_portaudio.cpp +++ b/common/audio/s9x_sound_driver_portaudio.cpp @@ -4,8 +4,11 @@ For further information, consult the LICENSE file in the root directory. \*****************************************************************************/ -#include "gtk_sound_driver_portaudio.h" +#include "s9x_sound_driver_portaudio.hpp" #include +#include +#include +#include S9xPortAudioSoundDriver::S9xPortAudioSoundDriver() { diff --git a/gtk/src/gtk_sound_driver_portaudio.h b/common/audio/s9x_sound_driver_portaudio.hpp similarity index 84% rename from gtk/src/gtk_sound_driver_portaudio.h rename to common/audio/s9x_sound_driver_portaudio.hpp index f3eea923..516b6ca9 100644 --- a/gtk/src/gtk_sound_driver_portaudio.h +++ b/common/audio/s9x_sound_driver_portaudio.hpp @@ -4,14 +4,13 @@ For further information, consult the LICENSE file in the root directory. \*****************************************************************************/ -#ifndef __GTK_SOUND_DRIVER_PORTAUDIO_H -#define __GTK_SOUND_DRIVER_PORTAUDIO_H +#ifndef __S9X_SOUND_DRIVER_PORTAUDIO_HPP +#define __S9X_SOUND_DRIVER_PORTAUDIO_HPP #include #include -#include "gtk_sound.h" -#include "gtk_sound_driver.h" +#include "s9x_sound_driver.hpp" class S9xPortAudioSoundDriver : public S9xSoundDriver { @@ -32,4 +31,4 @@ class S9xPortAudioSoundDriver : public S9xSoundDriver int output_buffer_size; }; -#endif /* __GTK_SOUND_DRIVER_PORTAUDIO_H */ +#endif /* __S9X_SOUND_DRIVER_PORTAUDIO_HPP */ diff --git a/gtk/src/gtk_sound_driver_pulse.cpp b/common/audio/s9x_sound_driver_pulse.cpp similarity index 98% rename from gtk/src/gtk_sound_driver_pulse.cpp rename to common/audio/s9x_sound_driver_pulse.cpp index e7eab8b5..120db531 100644 --- a/gtk/src/gtk_sound_driver_pulse.cpp +++ b/common/audio/s9x_sound_driver_pulse.cpp @@ -4,9 +4,10 @@ For further information, consult the LICENSE file in the root directory. \*****************************************************************************/ -#include "gtk_sound_driver_pulse.h" +#include "s9x_sound_driver_pulse.hpp" #include +#include #include #include #include diff --git a/gtk/src/gtk_sound_driver_pulse.h b/common/audio/s9x_sound_driver_pulse.hpp similarity index 85% rename from gtk/src/gtk_sound_driver_pulse.h rename to common/audio/s9x_sound_driver_pulse.hpp index 06e5b177..e4bdae46 100644 --- a/gtk/src/gtk_sound_driver_pulse.h +++ b/common/audio/s9x_sound_driver_pulse.hpp @@ -4,11 +4,10 @@ For further information, consult the LICENSE file in the root directory. \*****************************************************************************/ -#ifndef __GTK_SOUND_DRIVER_PULSE_H -#define __GTK_SOUND_DRIVER_PULSE_H +#ifndef __S9X_SOUND_DRIVER_PULSE_HPP +#define __S9X_SOUND_DRIVER_PULSE_HPP -#include "gtk_sound.h" -#include "gtk_sound_driver.h" +#include "s9x_sound_driver.hpp" #include "pulse/pulseaudio.h" class S9xPulseSoundDriver : public S9xSoundDriver @@ -35,4 +34,4 @@ class S9xPulseSoundDriver : public S9xSoundDriver int buffer_size; }; -#endif /* __GTK_SOUND_DRIVER_PULSE_H */ +#endif /* __S9X_SOUND_DRIVER_PULSE_HPP */ diff --git a/gtk/src/gtk_sound_driver_sdl.cpp b/common/audio/s9x_sound_driver_sdl.cpp similarity index 98% rename from gtk/src/gtk_sound_driver_sdl.cpp rename to common/audio/s9x_sound_driver_sdl.cpp index 22e52e7e..e5f8baa4 100644 --- a/gtk/src/gtk_sound_driver_sdl.cpp +++ b/common/audio/s9x_sound_driver_sdl.cpp @@ -4,7 +4,7 @@ For further information, consult the LICENSE file in the root directory. \*****************************************************************************/ -#include "gtk_sound_driver_sdl.h" +#include "s9x_sound_driver_sdl.hpp" #include "SDL_audio.h" void S9xSDLSoundDriver::write_samples(int16_t *data, int samples) diff --git a/gtk/src/gtk_sound_driver_sdl.h b/common/audio/s9x_sound_driver_sdl.hpp similarity index 87% rename from gtk/src/gtk_sound_driver_sdl.h rename to common/audio/s9x_sound_driver_sdl.hpp index 61890e0c..53426b45 100644 --- a/gtk/src/gtk_sound_driver_sdl.h +++ b/common/audio/s9x_sound_driver_sdl.hpp @@ -4,16 +4,15 @@ For further information, consult the LICENSE file in the root directory. \*****************************************************************************/ -#ifndef __GTK_SOUND_DRIVER_SDL_H -#define __GTK_SOUND_DRIVER_SDL_H +#ifndef __S9X_SOUND_DRIVER_SDL_HPP +#define __S9X_SOUND_DRIVER_SDL_HPP #include "SDL.h" // SDL.h may include altivec.h which redefines vector and bool #undef vector #undef bool -#include "gtk_sound.h" -#include "gtk_sound_driver.h" +#include "s9x_sound_driver.hpp" #include "../../apu/resampler.h" #include @@ -41,4 +40,4 @@ class S9xSDLSoundDriver : public S9xSoundDriver int16_t temp[512]; }; -#endif /* __GTK_SOUND_DRIVER_SDL_H */ +#endif /* __S9X_SOUND_DRIVER_SDL_HPP */ diff --git a/gtk/CMakeLists.txt b/gtk/CMakeLists.txt index fb0906bf..ce428bec 100644 --- a/gtk/CMakeLists.txt +++ b/gtk/CMakeLists.txt @@ -175,7 +175,7 @@ endif() if(USE_PULSEAUDIO) pkg_check_modules(PULSEAUDIO REQUIRED libpulse) list(APPEND DEFINES "USE_PULSEAUDIO") - list(APPEND SOURCES src/gtk_sound_driver_pulse.cpp) + list(APPEND SOURCES ../common/audio/s9x_sound_driver_pulse.cpp) list(APPEND ARGS ${PULSEAUDIO_CFLAGS}) list(APPEND LIBS ${PULSEAUDIO_LIBRARIES}) endif() @@ -183,7 +183,7 @@ endif() if(USE_PORTAUDIO) pkg_check_modules(PORTAUDIO REQUIRED portaudio-2.0) list(APPEND DEFINES "USE_PORTAUDIO") - list(APPEND SOURCES src/gtk_sound_driver_portaudio.cpp) + list(APPEND SOURCES ../common/audio/s9x_sound_driver_portaudio.cpp) list(APPEND ARGS ${PORTAUDIO_CFLAGS}) list(APPEND LIBS ${PORTAUDIO_LIBRARIES}) endif() @@ -191,7 +191,7 @@ endif() if(USE_ALSA) pkg_check_modules(ALSA REQUIRED alsa) list(APPEND DEFINES "USE_ALSA") - list(APPEND SOURCES src/gtk_sound_driver_alsa.cpp) + list(APPEND SOURCES ../common/audio/s9x_sound_driver_alsa.cpp) list(APPEND ARGS ${ALSA_CFLAGS}) list(APPEND LIBS ${ALSA_LIBRARIES}) endif() @@ -199,7 +199,7 @@ endif() if(USE_OSS) CHECK_INCLUDE_FILE("sys/soundcard.h" OSS) if(OSS) - list(APPEND SOURCES src/gtk_sound_driver_oss.cpp) + list(APPEND SOURCES ../common/audio/s9x_sound_driver_oss.cpp) list(APPEND DEFINES "USE_OSS") endif() endif() @@ -238,7 +238,7 @@ if(DANGEROUS_HACKS) endif() list(APPEND SOURCES - src/gtk_sound_driver.h + ../common/audio/s9x_sound_driver.hpp ../filter/2xsai.cpp ../filter/2xsai.h ../filter/epx.cpp @@ -279,8 +279,8 @@ list(APPEND SOURCES ../filter/snes_ntsc_impl.h ../filter/snes_ntsc.c src/gtk_compat.h - src/gtk_sound_driver_sdl.h - src/gtk_sound_driver_sdl.cpp + ../common/audio/s9x_sound_driver_sdl.hpp + ../common/audio/s9x_sound_driver_sdl.cpp ../fxinst.cpp ../fxemu.cpp ../fxdbg.cpp diff --git a/gtk/src/gtk_sound.cpp b/gtk/src/gtk_sound.cpp index 1fbaaf50..157027d7 100644 --- a/gtk/src/gtk_sound.cpp +++ b/gtk/src/gtk_sound.cpp @@ -9,22 +9,22 @@ #include "gtk_s9x.h" #include "gtk_sound.h" -#include "gtk_sound_driver.h" +#include "common/audio/s9x_sound_driver.hpp" #include "snes9x.h" #include "apu/apu.h" #ifdef USE_PORTAUDIO -#include "gtk_sound_driver_portaudio.h" +#include "common/audio/s9x_sound_driver_portaudio.hpp" #endif #ifdef USE_OSS -#include "gtk_sound_driver_oss.h" +#include "common/audio/s9x_sound_driver_oss.hpp" #endif -#include "gtk_sound_driver_sdl.h" +#include "common/audio/s9x_sound_driver_sdl.hpp" #ifdef USE_ALSA -#include "gtk_sound_driver_alsa.h" +#include "common/audio/s9x_sound_driver_alsa.hpp" #endif #ifdef USE_PULSEAUDIO -#include "gtk_sound_driver_pulse.h" +#include "common/audio/s9x_sound_driver_pulse.hpp" #endif static int playback_rates[8] =