From f6d2e3fa7e7930af94fd284c30d3c4719fe249c0 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Tue, 14 Apr 2015 21:31:40 +0200 Subject: [PATCH] Added OSS audio backend This adds the OSS audio backend and removes OSS code from core/linux-dist/main.cpp and core/sdl/main.cpp. The OSS backend will be included during compilation if the USE_OSS flag is set. Although OSS code in core/linux-dist/main.cpp depended on the TARGET_PANDORA flag instead of USE_OSS, the latter should work too since it is defined in the Pandora Makefile (lines 7 & 83). --- core/linux-dist/main.cpp | 46 ----------------------- core/oslib/audiobackend_oss.cpp | 54 +++++++++++++++++++++++++++ core/oslib/audiobackend_oss.h | 4 ++ core/oslib/audiostream.cpp | 3 ++ core/sdl/main.cpp | 65 +-------------------------------- 5 files changed, 62 insertions(+), 110 deletions(-) create mode 100644 core/oslib/audiobackend_oss.cpp create mode 100644 core/oslib/audiobackend_oss.h diff --git a/core/linux-dist/main.cpp b/core/linux-dist/main.cpp index 5c89c66da..dd70731d5 100755 --- a/core/linux-dist/main.cpp +++ b/core/linux-dist/main.cpp @@ -110,9 +110,6 @@ void emit_WriteCodeCache(); static int JoyFD = -1; // Joystick file descriptor static int kbfd = -1; -#ifdef TARGET_PANDORA -static int audio_fd = -1; -#endif #define MAP_SIZE 32 @@ -755,7 +752,6 @@ void clean_exit(int sig_num) { // close files if (JoyFD>=0) close(JoyFD); if (kbfd>=0) close(kbfd); - if(audio_fd>=0) close(audio_fd); // Close EGL context ??? if (sig_num!=0) @@ -781,26 +777,6 @@ void clean_exit(int sig_num) { } } -void init_sound() -{ - if((audio_fd=open("/dev/dsp",O_WRONLY))<0) { - printf("Couldn't open /dev/dsp.\n"); - } - else - { - printf("sound enabled, dsp openned for write\n"); - int tmp=44100; - int err_ret; - err_ret=ioctl(audio_fd,SNDCTL_DSP_SPEED,&tmp); - printf("set Frequency to %i, return %i (rate=%i)\n", 44100, err_ret, tmp); - int channels=2; - err_ret=ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &channels); - printf("set dsp to stereo (%i => %i)\n", channels, err_ret); - int format=AFMT_S16_LE; - err_ret=ioctl(audio_fd, SNDCTL_DSP_SETFMT, &format); - printf("set dsp to %s audio (%i/%i => %i)\n", "16bits signed" ,AFMT_S16_LE, format, err_ret); - } -} #endif int main(int argc, wchar* argv[]) @@ -812,11 +788,6 @@ int main(int argc, wchar* argv[]) #ifdef TARGET_PANDORA signal(SIGSEGV, clean_exit); signal(SIGKILL, clean_exit); - - init_sound(); -#else - void os_InitAudio(); - os_InitAudio(); #endif #if defined(USES_HOMEDIR) && HOST_OS != OS_DARWIN @@ -873,23 +844,6 @@ int main(int argc, wchar* argv[]) return 0; } -#if 0 -u32 alsa_Push(void* frame, u32 samples, bool wait); -u32 PushAudio(void* frame, u32 samples, bool wait) -{ - #ifndef TARGET_PANDORA - int audio_fd = -1; - #endif - - if (audio_fd > 0) { - write(audio_fd, frame, samples*4); - } else { - return alsa_Push(frame, samples, wait); - } - - return 1; -} -#endif #endif int get_mic_data(u8* buffer) { return 0; } diff --git a/core/oslib/audiobackend_oss.cpp b/core/oslib/audiobackend_oss.cpp new file mode 100644 index 000000000..b0fce32c9 --- /dev/null +++ b/core/oslib/audiobackend_oss.cpp @@ -0,0 +1,54 @@ +#include "oslib/audiobackend_oss.h" +#ifdef USE_OSS +#include +#include +#include +#include + +static int oss_audio_fd = -1; + +static void oss_init() +{ + oss_audio_fd = open("/dev/dsp", O_WRONLY); + if (oss_audio_fd < 0) + { + printf("Couldn't open /dev/dsp.\n"); + } + else + { + printf("sound enabled, dsp openned for write\n"); + int tmp=44100; + int err_ret; + err_ret=ioctl(oss_audio_fd,SNDCTL_DSP_SPEED,&tmp); + printf("set Frequency to %i, return %i (rate=%i)\n", 44100, err_ret, tmp); + int channels=2; + err_ret=ioctl(oss_audio_fd, SNDCTL_DSP_CHANNELS, &channels); + printf("set dsp to stereo (%i => %i)\n", channels, err_ret); + int format=AFMT_S16_LE; + err_ret=ioctl(oss_audio_fd, SNDCTL_DSP_SETFMT, &format); + printf("set dsp to %s audio (%i/%i => %i)\n", "16bits signed", AFMT_S16_LE, format, err_ret); + } +} + +static u32 oss_push(void* frame, u32 samples, bool wait) +{ + write(oss_audio_fd, frame, samples*4); + return 1; +} + +static void oss_term() { + if(oss_audio_fd >= 0) + { + close(oss_audio_fd); + } +} + +audiobackend_t audiobackend_oss = { + "oss", // Slug + "Open Sound System", // Name + &oss_init, + &oss_push, + &oss_term +}; + +#endif \ No newline at end of file diff --git a/core/oslib/audiobackend_oss.h b/core/oslib/audiobackend_oss.h new file mode 100644 index 000000000..515aa3be9 --- /dev/null +++ b/core/oslib/audiobackend_oss.h @@ -0,0 +1,4 @@ +#pragma once +#include "oslib/audiostream.h" + +extern audiobackend_t audiobackend_oss; \ No newline at end of file diff --git a/core/oslib/audiostream.cpp b/core/oslib/audiostream.cpp index 69fb59b15..de7b3e5ef 100644 --- a/core/oslib/audiostream.cpp +++ b/core/oslib/audiostream.cpp @@ -69,6 +69,9 @@ bool RegisterAudioBackend(audiobackend_t *backend) } void RegisterAllAudioBackends() { + #if USE_OSS + RegisterAudioBackend(&audiobackend_oss); + #endif audiobackends_registered = true; } diff --git a/core/sdl/main.cpp b/core/sdl/main.cpp index 3d9bf97a6..f3257feb7 100755 --- a/core/sdl/main.cpp +++ b/core/sdl/main.cpp @@ -17,11 +17,6 @@ #include #include -#ifdef USE_OSS -#include -#include -#endif - #include #include @@ -103,11 +98,6 @@ static SDL_Joystick *JoySDL = 0; extern bool FrameSkipping; -#ifdef USE_OSS -static int audio_fd = -1; -#endif - - #define MAP_SIZE 32 const u32 JMapBtn_USB[MAP_SIZE] = @@ -426,9 +416,6 @@ void clean_exit(int sig_num) { // close files if (JoySDL) SDL_JoystickClose(JoySDL); - #ifdef USE_OSS - if (audio_fd>=0) close(audio_fd); - #endif // Close EGL context ??? if (sig_num!=0) @@ -437,37 +424,6 @@ void clean_exit(int sig_num) { SDL_Quit(); } -#ifdef USE_OSS -void init_sound() -{ - if((audio_fd=open("/dev/dsp",O_WRONLY))<0) - printf("Couldn't open /dev/dsp.\n"); - else - { - printf("sound enabled, dsp openned for write\n"); - int tmp=44100; - int err_ret; - err_ret=ioctl(audio_fd,SNDCTL_DSP_SPEED,&tmp); - printf("set Frequency to %i, return %i (rate=%i)\n", 44100, err_ret, tmp); - int channels=2; - err_ret=ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &channels); - printf("set dsp to stereo (%i => %i)\n", channels, err_ret); - int format=AFMT_S16_LE; - err_ret=ioctl(audio_fd, SNDCTL_DSP_SETFMT, &format); - printf("set dsp to %s audio (%i/%i => %i)\n", "16bits signed" ,AFMT_S16_LE, format, err_ret); - int frag=(4<<16)|11; - int f=frag; - err_ret=ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag); - printf("set dsp fragment to %i of %i bytes (0x%x => %i)\n", "16bits signed" ,(f>>16), 1<<(f&0xff), frag, err_ret); - /* - // this doesn't help stutering, and the emu goes too fast after that - err_ret=ioctl(audio_fd, SNDCTL_DSP_NONBLOCK, NULL); - printf("set dsp to non-blocking ( => %i)\n", err_ret); - */ - } -} -#endif - int main(int argc, wchar* argv[]) { //if (argc==2) @@ -501,10 +457,6 @@ int main(int argc, wchar* argv[]) die("error initializing SDL"); SetupInput(); - - #ifdef USE_OSS - init_sound(); - #endif FrameSkipping=false; @@ -513,19 +465,4 @@ int main(int argc, wchar* argv[]) clean_exit(0); return 0; -} - -#if 0 -u32 PushAudio(void* frame, u32 samples, bool wait) -{ -#ifdef USE_OSS -static bool blocking = true; - if (wait!=blocking) { - fcntl(audio_fd, F_SETFD, O_WRONLY | wait?0:O_NONBLOCK); - blocking=wait; - } - write(audio_fd, frame, samples*4); -#endif -return 1; -} -#endif \ No newline at end of file +} \ No newline at end of file