|
|
| version 1.11, 2008/03/18 15:40:20 | version 1.12, 2008/04/02 13:03:34 |
|---|---|
| Line 69 MIDIMOD vermouth_module = NULL; | Line 69 MIDIMOD vermouth_module = NULL; |
| /* | /* |
| * driver | * driver |
| */ | */ |
| int audio_fd = -1; | static struct { |
| snddrv_t snddrv; | BOOL (*drvinit)(UINT rate, UINT samples); |
| BOOL (*drvterm)(void); | |
| void (*drvlock)(void); | |
| void (*drvunlock)(void); | |
| void (*sndplay)(void); | |
| void (*sndstop)(void); | |
| void *(*pcmload)(UINT num, const char *path); | |
| void (*pcmdestroy)(void *chanp, UINT num); | |
| void (*pcmplay)(void *chanp, UINT num, BOOL loop); | |
| void (*pcmstop)(void *chanp, UINT num); | |
| void (*pcmvolume)(void *chanp, UINT num, int volume); | |
| } snddrv; | |
| static int audio_fd = -1; | |
| static BOOL opened = FALSE; | static BOOL opened = FALSE; |
| static UINT mute = 0; | |
| static UINT opna_frame; | static UINT opna_frame; |
| static BOOL nosound_setup(void); | static BOOL nosound_setup(void); |
| static BOOL sdlaudio_setup(void); | |
| static void PARTSCALL (*fnmix)(SINT16* dst, const SINT32* src, UINT size); | static void PARTSCALL (*fnmix)(SINT16* dst, const SINT32* src, UINT size); |
| Line 97 static void soundmng_pcmdestroy(void); | Line 110 static void soundmng_pcmdestroy(void); |
| /* | /* |
| * buffer | * buffer |
| */ | */ |
| int sound_nextbuf; | #ifndef NSOUNDBUFFER |
| char *sound_event; | #define NSOUNDBUFFER 2 |
| char *sound_buffer[NSOUNDBUFFER]; | #endif |
| static char *sound_buffer[NSOUNDBUFFER]; | |
| static int sound_nextbuf; | |
| static char *sound_event; | |
| static BOOL buffer_init(void); | static BOOL buffer_init(void); |
| static void buffer_destroy(void); | static void buffer_destroy(void); |
| static void buffer_clear(void); | static void buffer_clear(void); |
| UINT | static UINT |
| calc_blocksize(UINT size) | calc_blocksize(UINT size) |
| { | { |
| UINT s = size; | UINT s = size; |
| Line 117 calc_blocksize(UINT size) | Line 133 calc_blocksize(UINT size) |
| return s; | return s; |
| } | } |
| UINT | |
| calc_fragment(UINT size) | |
| { | |
| UINT f; | |
| for (f = 0; size > (UINT)(1 << f); f++) | |
| continue; | |
| return f; | |
| } | |
| static void | static void |
| snddrv_setup(void) | snddrv_setup(void) |
| { | { |
| Line 135 snddrv_setup(void) | Line 141 snddrv_setup(void) |
| switch (np2oscfg.snddrv) { | switch (np2oscfg.snddrv) { |
| #if defined(USE_SDLAUDIO) || defined(USE_SDLMIXER) | #if defined(USE_SDLAUDIO) || defined(USE_SDLMIXER) |
| case SNDDRV_SDL: | case SNDDRV_SDL: |
| #if defined(USE_SDLMIXER) | |
| sdlmixer_setup(); | |
| #else | |
| sdlaudio_setup(); | sdlaudio_setup(); |
| #endif | |
| return; | return; |
| #endif | #endif |
| } | } |
| } else { | } else { |
| #if defined(USE_SDLMIXER) | #if defined(USE_SDLAUDIO) || defined(USE_SDLMIXER) |
| if (sdlmixer_setup() == SUCCESS) { | |
| np2oscfg.snddrv = SNDDRV_SDL; | |
| sysmng_update(SYS_UPDATEOSCFG); | |
| return; | |
| } else | |
| #endif | |
| #if defined(USE_SDLAUDIO) | |
| if (sdlaudio_setup() == SUCCESS) { | if (sdlaudio_setup() == SUCCESS) { |
| np2oscfg.snddrv = SNDDRV_SDL; | np2oscfg.snddrv = SNDDRV_SDL; |
| sysmng_update(SYS_UPDATEOSCFG); | sysmng_update(SYS_UPDATEOSCFG); |
| Line 170 snddrv_setup(void) | Line 165 snddrv_setup(void) |
| sysmng_update(SYS_UPDATEOSCFG); | sysmng_update(SYS_UPDATEOSCFG); |
| } | } |
| static void | |
| sounddrv_lock(void) | |
| { | |
| (*snddrv.drvlock)(); | |
| } | |
| static void | |
| sounddrv_unlock(void) | |
| { | |
| (*snddrv.drvunlock)(); | |
| } | |
| UINT | UINT |
| soundmng_create(UINT rate, UINT bufmsec) | soundmng_create(UINT rate, UINT bufmsec) |
| { | { |
| Line 192 soundmng_create(UINT rate, UINT bufmsec) | Line 201 soundmng_create(UINT rate, UINT bufmsec) |
| if ((*snddrv.drvinit)(rate, samples) != SUCCESS) { | if ((*snddrv.drvinit)(rate, samples) != SUCCESS) { |
| audio_fd = -1; | audio_fd = -1; |
| nosound_setup(); | |
| np2oscfg.snddrv = SNDDRV_NODRV; | np2oscfg.snddrv = SNDDRV_NODRV; |
| sysmng_update(SYS_UPDATEOSCFG); | sysmng_update(SYS_UPDATEOSCFG); |
| return 0; | return 0; |
| Line 215 void | Line 225 void |
| soundmng_reset(void) | soundmng_reset(void) |
| { | { |
| sounddrv_lock(); | |
| sound_nextbuf = 0; | sound_nextbuf = 0; |
| sound_event = NULL; | sound_event = NULL; |
| sounddrv_unlock(); | |
| buffer_clear(); | buffer_clear(); |
| } | } |
| Line 235 soundmng_destroy(void) | Line 247 soundmng_destroy(void) |
| } | } |
| (*snddrv.sndstop)(); | (*snddrv.sndstop)(); |
| (*snddrv.drvterm)(); | (*snddrv.drvterm)(); |
| buffer_destroy(); | |
| nosound_setup(); | |
| audio_fd = -1; | audio_fd = -1; |
| opened = FALSE; | opened = FALSE; |
| } | } |
| Line 246 void | Line 256 void |
| soundmng_play(void) | soundmng_play(void) |
| { | { |
| if (!mute) { | (*snddrv.sndplay)(); |
| (*snddrv.sndplay)(); | |
| } | |
| } | } |
| void | void |
| soundmng_stop(void) | soundmng_stop(void) |
| { | { |
| if (!mute) { | (*snddrv.sndstop)(); |
| (*snddrv.sndstop)(); | |
| } | |
| } | } |
| BOOL | BOOL |
| Line 276 soundmng_deinitialize(void) | Line 282 soundmng_deinitialize(void) |
| soundmng_pcmdestroy(); | soundmng_pcmdestroy(); |
| soundmng_destroy(); | soundmng_destroy(); |
| buffer_destroy(); | |
| } | } |
| void | void |
| Line 285 soundmng_sync(void) | Line 292 soundmng_sync(void) |
| SINT16 *q; | SINT16 *q; |
| if (opened) { | if (opened) { |
| sounddrv_lock(); | |
| if (sound_event) { | if (sound_event) { |
| pcm = sound_pcmlock(); | pcm = sound_pcmlock(); |
| q = (SINT16 *)sound_event; | q = (SINT16 *)sound_event; |
| Line 292 soundmng_sync(void) | Line 300 soundmng_sync(void) |
| (*fnmix)(q, pcm, opna_frame); | (*fnmix)(q, pcm, opna_frame); |
| sound_pcmunlock(pcm); | sound_pcmunlock(pcm); |
| } | } |
| sounddrv_unlock(); | |
| } | } |
| } | } |
| Line 405 buffer_init(void) | Line 414 buffer_init(void) |
| { | { |
| int i; | int i; |
| sounddrv_lock(); | |
| for (i = 0; i < NSOUNDBUFFER; i++) { | for (i = 0; i < NSOUNDBUFFER; i++) { |
| if (sound_buffer[i]) { | if (sound_buffer[i]) { |
| _MFREE(sound_buffer[i]); | _MFREE(sound_buffer[i]); |
| Line 412 buffer_init(void) | Line 422 buffer_init(void) |
| sound_buffer[i] = (char *)_MALLOC(opna_frame, "sound buffer"); | sound_buffer[i] = (char *)_MALLOC(opna_frame, "sound buffer"); |
| if (sound_buffer[i] == NULL) { | if (sound_buffer[i] == NULL) { |
| fprintf(stderr, "buffer_init: can't alloc memory\n"); | fprintf(stderr, "buffer_init: can't alloc memory\n"); |
| sounddrv_unlock(); | |
| return FAILURE; | return FAILURE; |
| } | } |
| } | } |
| sounddrv_unlock(); | |
| return SUCCESS; | return SUCCESS; |
| } | } |
| Line 423 buffer_clear(void) | Line 435 buffer_clear(void) |
| { | { |
| int i; | int i; |
| sounddrv_lock(); | |
| for (i = 0; i < NSOUNDBUFFER; i++) { | for (i = 0; i < NSOUNDBUFFER; i++) { |
| if (sound_buffer[i]) { | if (sound_buffer[i]) { |
| memset(sound_buffer[i], 0, opna_frame); | memset(sound_buffer[i], 0, opna_frame); |
| } | } |
| } | } |
| sounddrv_unlock(); | |
| } | } |
| static void | static void |
| Line 435 buffer_destroy(void) | Line 449 buffer_destroy(void) |
| { | { |
| int i; | int i; |
| sounddrv_lock(); | |
| for (i = 0; i < NSOUNDBUFFER; i++) { | for (i = 0; i < NSOUNDBUFFER; i++) { |
| if (sound_buffer[i]) { | if (sound_buffer[i]) { |
| _MFREE(sound_buffer[i]); | _MFREE(sound_buffer[i]); |
| sound_buffer[i] = NULL; | sound_buffer[i] = NULL; |
| } | } |
| } | } |
| sounddrv_unlock(); | |
| } | } |
| /* | /* |
| Line 464 nosound_drvterm(void) | Line 480 nosound_drvterm(void) |
| } | } |
| static void | static void |
| nosound_drvlock(void) | |
| { | |
| /* Nothing to do */ | |
| } | |
| static void | |
| nosound_drvunlock(void) | |
| { | |
| /* Nothing to do */ | |
| } | |
| static void | |
| nosound_sndplay(void) | nosound_sndplay(void) |
| { | { |
| Line 477 nosound_sndstop(void) | Line 507 nosound_sndstop(void) |
| /* Nothing to do */ | /* Nothing to do */ |
| } | } |
| void * | static void * |
| nosound_pcmload(UINT num, const char *path) | nosound_pcmload(UINT num, const char *path) |
| { | { |
| Line 487 nosound_pcmload(UINT num, const char *pa | Line 517 nosound_pcmload(UINT num, const char *pa |
| return NULL; | return NULL; |
| } | } |
| void | static void |
| nosound_pcmdestroy(void *chanp, UINT num) | nosound_pcmdestroy(void *chanp, UINT num) |
| { | { |
| Line 497 nosound_pcmdestroy(void *chanp, UINT num | Line 527 nosound_pcmdestroy(void *chanp, UINT num |
| /* Nothing to do */ | /* Nothing to do */ |
| } | } |
| void | static void |
| nosound_pcmplay(void *chanp, UINT num, BOOL loop) | nosound_pcmplay(void *chanp, UINT num, BOOL loop) |
| { | { |
| Line 508 nosound_pcmplay(void *chanp, UINT num, B | Line 538 nosound_pcmplay(void *chanp, UINT num, B |
| /* Nothing to do */ | /* Nothing to do */ |
| } | } |
| void | static void |
| nosound_pcmstop(void *chanp, UINT num) | nosound_pcmstop(void *chanp, UINT num) |
| { | { |
| Line 518 nosound_pcmstop(void *chanp, UINT num) | Line 548 nosound_pcmstop(void *chanp, UINT num) |
| /* Nothing to do */ | /* Nothing to do */ |
| } | } |
| void | static void |
| nosound_pcmvolume(void *chanp, UINT num, int volume) | nosound_pcmvolume(void *chanp, UINT num, int volume) |
| { | { |
| Line 535 nosound_setup(void) | Line 565 nosound_setup(void) |
| snddrv.drvinit = nosound_drvinit; | snddrv.drvinit = nosound_drvinit; |
| snddrv.drvterm = nosound_drvterm; | snddrv.drvterm = nosound_drvterm; |
| snddrv.drvlock = nosound_drvlock; | |
| snddrv.drvunlock = nosound_drvunlock; | |
| snddrv.sndplay = nosound_sndplay; | snddrv.sndplay = nosound_sndplay; |
| snddrv.sndstop = nosound_sndstop; | snddrv.sndstop = nosound_sndstop; |
| snddrv.pcmload = nosound_pcmload; | snddrv.pcmload = nosound_pcmload; |
| Line 752 saturation_s16mmx(SINT16 *dst, const SIN | Line 784 saturation_s16mmx(SINT16 *dst, const SIN |
| #include <SDL.h> | #include <SDL.h> |
| static void sdlaudio_lock(void); | |
| static void sdlaudio_unlock(void); | |
| static void sdlaudio_play(void); | |
| static void sdlaudio_stop(void); | |
| static void sdlaudio_callback(void *, unsigned char *, int); | static void sdlaudio_callback(void *, unsigned char *, int); |
| #if defined(USE_SDLAUDIO) | #if !defined(USE_SDLMIXER) |
| static BOOL | static BOOL |
| sdlaudio_init(UINT rate, UINT samples) | sdlaudio_init(UINT rate, UINT samples) |
| Line 769 sdlaudio_init(UINT rate, UINT samples) | Line 805 sdlaudio_init(UINT rate, UINT samples) |
| fmt.callback = sdlaudio_callback; | fmt.callback = sdlaudio_callback; |
| fmt.userdata = (void *)(samples * 2 * sizeof(SINT16)); | fmt.userdata = (void *)(samples * 2 * sizeof(SINT16)); |
| rv = SDL_Init(SDL_INIT_AUDIO); | rv = SDL_InitSubSystem(SDL_INIT_AUDIO); |
| if (rv < 0) { | if (rv < 0) { |
| fprintf(stderr, "sdlaudio_init: SDL_Init\n"); | fprintf(stderr, "sdlaudio_init: SDL_InitSubSystem\n"); |
| return FAILURE; | return FAILURE; |
| } | } |
| audio_fd = SDL_OpenAudio(&fmt, NULL); | audio_fd = SDL_OpenAudio(&fmt, NULL); |
| if (audio_fd < 0) { | if (audio_fd < 0) { |
| fprintf(stderr, "sdlaudio_init: SDL_OpenAudio\n"); | fprintf(stderr, "sdlaudio_init: SDL_OpenAudio\n"); |
| SDL_Quit(); | SDL_QuitSubSystem(SDL_INIT_AUDIO); |
| return FAILURE; | return FAILURE; |
| } | } |
| Line 789 static BOOL | Line 825 static BOOL |
| sdlaudio_term(void) | sdlaudio_term(void) |
| { | { |
| SDL_PauseAudio(1); | |
| SDL_CloseAudio(); | SDL_CloseAudio(); |
| SDL_Quit(); | |
| return SUCCESS; | return SUCCESS; |
| } | } |
| static void | static BOOL |
| sdlaudio_play(void) | |
| { | |
| SDL_PauseAudio(0); | |
| } | |
| static void | |
| sdlaudio_stop(void) | |
| { | |
| SDL_PauseAudio(1); | |
| } | |
| BOOL | |
| sdlaudio_setup(void) | sdlaudio_setup(void) |
| { | { |
| snddrv.drvinit = sdlaudio_init; | snddrv.drvinit = sdlaudio_init; |
| snddrv.drvterm = sdlaudio_term; | snddrv.drvterm = sdlaudio_term; |
| snddrv.drvlock = sdlaudio_lock; | |
| snddrv.drvunlock = sdlaudio_unlock; | |
| snddrv.sndplay = sdlaudio_play; | snddrv.sndplay = sdlaudio_play; |
| snddrv.sndstop = sdlaudio_stop; | snddrv.sndstop = sdlaudio_stop; |
| snddrv.pcmload = nosound_pcmload; | snddrv.pcmload = nosound_pcmload; |
| Line 826 sdlaudio_setup(void) | Line 850 sdlaudio_setup(void) |
| return SUCCESS; | return SUCCESS; |
| } | } |
| #endif /* USE_SDLAUDIO */ | #else /* USE_SDLMIXER */ |
| #if defined(USE_SDLMIXER) | |
| #include <SDL_mixer.h> | #include <SDL_mixer.h> |
| Line 837 sdlmixer_init(UINT rate, UINT samples) | Line 859 sdlmixer_init(UINT rate, UINT samples) |
| { | { |
| int rv; | int rv; |
| rv = SDL_Init(SDL_INIT_AUDIO); | rv = SDL_InitSubSystem(SDL_INIT_AUDIO); |
| if (rv < 0) { | if (rv < 0) { |
| fprintf(stderr, "SDL_Init(): %s\n", SDL_GetError()); | fprintf(stderr, "sdlmixer_init: SDL_InitSubSystem(): %s\n", |
| SDL_GetError()); | |
| goto failure; | goto failure; |
| } | } |
| rv = Mix_OpenAudio(rate, AUDIO_S16SYS, 2, samples); | rv = Mix_OpenAudio(rate, AUDIO_S16SYS, 2, samples); |
| if (rv < 0) { | if (rv < 0) { |
| fprintf(stderr, "Mix_OpenAudio(): %s\n", Mix_GetError()); | fprintf(stderr, "sdlmixer_init: Mix_OpenAudio(): %s\n", |
| Mix_GetError()); | |
| goto failure1; | goto failure1; |
| } | } |
| SDL_PauseAudio(1); | |
| rv = Mix_AllocateChannels(SOUND_MAXPCM); | rv = Mix_AllocateChannels(SOUND_MAXPCM); |
| if (rv < 0) { | if (rv < 0) { |
| fprintf(stderr, "Mix_AllocateChannels(): %s\n", Mix_GetError()); | fprintf(stderr, "sdlmixer_init: Mix_AllocateChannels(): %s\n", |
| goto failure2; | Mix_GetError()); |
| goto failure1; | |
| } | } |
| Mix_HookMusic(sdlaudio_callback, (void*)(samples * 2 * sizeof(SINT16))); | Mix_HookMusic(sdlaudio_callback, (void*)(samples * 2 * sizeof(SINT16))); |
| return SUCCESS; | return SUCCESS; |
| failure2: | |
| Mix_CloseAudio(); | |
| failure1: | failure1: |
| SDL_Quit(); | Mix_CloseAudio(); |
| failure: | failure: |
| return FAILURE; | return FAILURE; |
| } | } |
| Line 872 static BOOL | Line 894 static BOOL |
| sdlmixer_term(void) | sdlmixer_term(void) |
| { | { |
| SDL_PauseAudio(1); | |
| Mix_CloseAudio(); | Mix_CloseAudio(); |
| SDL_Quit(); | |
| return SUCCESS; | return SUCCESS; |
| } | } |
| static void | |
| sdlmixer_play(void) | |
| { | |
| SDL_PauseAudio(0); | |
| } | |
| static void | |
| sdlmixer_stop(void) | |
| { | |
| SDL_PauseAudio(1); | |
| } | |
| static void * | static void * |
| sdlmixer_pcmload(UINT num, const char *path) | sdlmixer_pcmload(UINT num, const char *path) |
| { | { |
| Line 938 sdlmixer_pcmvolume(void *chanp, UINT num | Line 946 sdlmixer_pcmvolume(void *chanp, UINT num |
| Mix_Volume(num, (MIX_MAX_VOLUME * volume) / 100); | Mix_Volume(num, (MIX_MAX_VOLUME * volume) / 100); |
| } | } |
| BOOL | static BOOL |
| sdlmixer_setup(void) | sdlaudio_setup(void) |
| { | { |
| snddrv.drvinit = sdlmixer_init; | snddrv.drvinit = sdlmixer_init; |
| snddrv.drvterm = sdlmixer_term; | snddrv.drvterm = sdlmixer_term; |
| snddrv.sndplay = sdlmixer_play; | snddrv.drvlock = sdlaudio_lock; |
| snddrv.sndstop = sdlmixer_stop; | snddrv.drvunlock = sdlaudio_unlock; |
| snddrv.sndplay = sdlaudio_play; | |
| snddrv.sndstop = sdlaudio_stop; | |
| snddrv.pcmload = sdlmixer_pcmload; | snddrv.pcmload = sdlmixer_pcmload; |
| snddrv.pcmdestroy = sdlmixer_pcmdestroy; | snddrv.pcmdestroy = sdlmixer_pcmdestroy; |
| snddrv.pcmplay = sdlmixer_pcmplay; | snddrv.pcmplay = sdlmixer_pcmplay; |
| Line 955 sdlmixer_setup(void) | Line 965 sdlmixer_setup(void) |
| return SUCCESS; | return SUCCESS; |
| } | } |
| #endif /* USE_SDLMIXER */ | #endif /* !USE_SDLMIXER */ |
| static void | |
| sdlaudio_lock(void) | |
| { | |
| SDL_LockAudio(); | |
| } | |
| static void | |
| sdlaudio_unlock(void) | |
| { | |
| SDL_UnlockAudio(); | |
| } | |
| static void | |
| sdlaudio_play(void) | |
| { | |
| SDL_PauseAudio(0); | |
| } | |
| static void | |
| sdlaudio_stop(void) | |
| { | |
| SDL_PauseAudio(1); | |
| } | |
| static void | static void |
| sdlaudio_callback(void *userdata, unsigned char *stream, int len) | sdlaudio_callback(void *userdata, unsigned char *stream, int len) |