mirror of
https://github.com/digarok/gsplus.git
synced 2024-09-27 16:55:48 +00:00
working audio
This commit is contained in:
parent
800a792359
commit
7888c25d40
@ -60,12 +60,17 @@ gsportmac: $(OBJECTS) compile_time.o
|
||||
cp ../GSport.html ../GSportDmg/GSport/GSport.html
|
||||
arch/mac/makedmg.sh .. GSportDmg GSport GSport 7
|
||||
|
||||
# Linux for X builds:
|
||||
# OSX builds
|
||||
gsportosx: $(OBJECTS) compile_time.o
|
||||
$(LD) $(CCOPTS) $(LDOPTS) $(OBJECTS) compile_time.o $(LDFLAGS) -o $(NAME)$(SUFFIX) $(XLIBS) $(EXTRA_LIBS) -lX11
|
||||
echo $(OBJECTS)
|
||||
mv gsportosx ..
|
||||
|
||||
# Linux/OSX XWindows builds
|
||||
gsportx: $(OBJECTS) compile_time.o
|
||||
$(LD) $(CCOPTS) $(LDOPTS) $(OBJECTS) compile_time.o $(LDFLAGS) -o $(NAME)$(SUFFIX) $(XLIBS) $(EXTRA_LIBS) -lX11
|
||||
echo $(OBJECTS)
|
||||
mv gsportx ..
|
||||
cp -f ../config.template ../config.txt
|
||||
|
||||
# Linux framebuffer builds:
|
||||
gsportfb: $(OBJECTS) compile_time.o
|
||||
|
@ -19,9 +19,13 @@
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
|
||||
// @todo: force refresh after screen mode change
|
||||
#include "SDL.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
|
||||
# if !defined(__CYGWIN__) && !defined(__POWERPC__)
|
||||
/* No shared memory on Cygwin */
|
||||
# define X_SHARED_MEM
|
||||
@ -40,13 +44,24 @@
|
||||
# include <X11/extensions/XShm.h>
|
||||
#endif
|
||||
|
||||
int XShmQueryExtension(Display *display);
|
||||
|
||||
#include "defc.h"
|
||||
#include "protos_xdriver.h"
|
||||
|
||||
int XShmQueryExtension(Display *display);
|
||||
#define FONT_NAME_STATUS "8x13"
|
||||
|
||||
#ifdef X_SHARED_MEM
|
||||
int g_use_shmem = 1;
|
||||
#else
|
||||
int g_use_shmem = 0;
|
||||
#endif
|
||||
|
||||
Cursor g_cursor;
|
||||
Pixmap g_cursor_shape;
|
||||
Pixmap g_cursor_mask;
|
||||
XColor g_xcolor_black = { 0, 0x0000, 0x0000, 0x0000, DoRed|DoGreen|DoBlue, 0 };
|
||||
XColor g_xcolor_white = { 0, 0xffff, 0xffff, 0xffff, DoRed|DoGreen|DoBlue, 0 };
|
||||
Display *g_display = 0;
|
||||
Visual *g_vis = 0;
|
||||
Window g_a2_win;
|
||||
@ -66,13 +81,7 @@ int g_has_focus = 0;
|
||||
int g_auto_repeat_on = -1;
|
||||
int g_x_shift_control_state = 0;
|
||||
int kb_shift_control_state = 0;
|
||||
|
||||
|
||||
#ifdef X_SHARED_MEM
|
||||
int g_use_shmem = 1;
|
||||
#else
|
||||
int g_use_shmem = 0;
|
||||
#endif
|
||||
int g_depth_attempt_list[] = { 16, 24, 15, 8 };
|
||||
|
||||
|
||||
|
||||
@ -109,16 +118,6 @@ extern word32 g_palette_8to1624[256];
|
||||
extern word32 g_a2palette_8to1624[256];
|
||||
|
||||
|
||||
Cursor g_cursor;
|
||||
Pixmap g_cursor_shape;
|
||||
Pixmap g_cursor_mask;
|
||||
|
||||
XColor g_xcolor_black = { 0, 0x0000, 0x0000, 0x0000, DoRed|DoGreen|DoBlue, 0 };
|
||||
XColor g_xcolor_white = { 0, 0xffff, 0xffff, 0xffff, DoRed|DoGreen|DoBlue, 0 };
|
||||
|
||||
int g_depth_attempt_list[] = { 16, 24, 15, 8 };
|
||||
|
||||
void DoSdlIcon();
|
||||
|
||||
#define X_EVENT_LIST_ALL_WIN \
|
||||
(ExposureMask | ButtonPressMask | ButtonReleaseMask | \
|
||||
@ -373,6 +372,18 @@ SDL_Renderer *renderer;
|
||||
SDL_Texture *texture;
|
||||
|
||||
|
||||
|
||||
void set_refresh_needed() {
|
||||
g_a2_screen_buffer_changed = -1;
|
||||
g_full_refresh_needed = -1;
|
||||
|
||||
g_border_sides_refresh_needed = 1;
|
||||
g_border_special_refresh_needed = 1;
|
||||
g_status_refresh_needed = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Queries the Screen to see if it's set to Fullscreen or Not
|
||||
/// @return SDL_FALSE if windowed, SDL_TRUE if fullscreen
|
||||
SDL_bool IsFullScreen(SDL_Window *win)
|
||||
@ -508,8 +519,6 @@ sdl_keysym_to_a2code(int keysym, int is_up)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// called by src/sim65816.c
|
||||
void
|
||||
x_dialog_create_gsport_conf(const char *str)
|
||||
@ -1272,11 +1281,9 @@ x_redraw_status_lines()
|
||||
// int aux_info;
|
||||
// };
|
||||
|
||||
|
||||
void sdl_push_kimage(Kimage *kimage_ptr,
|
||||
int destx, int desty, int srcx, int srcy, int width, int height)
|
||||
{
|
||||
|
||||
byte *src_ptr;
|
||||
int pixel_size = 4;
|
||||
src_ptr = kimage_ptr->data_ptr + (srcy * kimage_ptr->width_act + srcx) * pixel_size;
|
||||
@ -1326,7 +1333,7 @@ bool send_event);
|
||||
if(g_use_shmem) {
|
||||
XShmPutImage(g_display, g_a2_win, g_a2_winGC, xim,
|
||||
srcx, srcy, destx, desty, width, height, False);
|
||||
printf("w/h: %d, %d\tsrcx/y: %d, %d\tdestx/y: %d %d\n", width, height, srcx, srcy, destx, desty);
|
||||
// printf("w/h: %d, %d\tsrcx/y: %d, %d\tdestx/y: %d %d\n", width, height, srcx, srcy, destx, desty);
|
||||
// int c= getchar();
|
||||
}
|
||||
#endif
|
||||
|
@ -19,10 +19,12 @@
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include "defc.h"
|
||||
#include "sound.h"
|
||||
#include "SDL.h"
|
||||
|
||||
|
||||
extern int Verbose;
|
||||
|
||||
extern int g_audio_rate;
|
||||
@ -39,11 +41,34 @@ extern int g_audio_enable;
|
||||
extern word32 *g_sound_shm_addr;
|
||||
extern int g_preferred_rate;
|
||||
|
||||
int g_win32snd_buflen = 0x1000;
|
||||
int g_sdlsnd_buflen = 0x1000;
|
||||
word32 *bptr = NULL;
|
||||
int g_sdlsnd_write_idx;
|
||||
int g_sdlsnd_read_idx;
|
||||
|
||||
// just to makeit stand out
|
||||
#ifdef HAVE_SDL
|
||||
static Uint8 *audio_chunk;
|
||||
static Uint8 *audio_pos;
|
||||
static Uint32 audio_len;
|
||||
|
||||
static byte *sdlsnd_buf = 0;
|
||||
SDL_AudioSpec want, have;
|
||||
SDL_AudioDeviceID dev;
|
||||
|
||||
static byte *playbuf = 0;
|
||||
static int g_playbuf_buffered = 0;
|
||||
static SDL_AudioSpec spec;
|
||||
static int snd_buf;
|
||||
static int snd_write; /* write position into playbuf */
|
||||
static /* volatile */ int snd_read = 0;
|
||||
|
||||
static void _snd_callback(void*, Uint8 *stream, int len);
|
||||
static void sound_write_sdl(int real_samps, int size);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
void sdlsnd_init(word32 *shmaddr)
|
||||
{
|
||||
printf("sdlsnd_init\n");
|
||||
@ -51,10 +76,14 @@ void sdlsnd_init(word32 *shmaddr)
|
||||
printf("Cannot initialize SDL audio\n");
|
||||
g_audio_enable = 0;
|
||||
}
|
||||
|
||||
child_sound_loop(-1, -1, shmaddr);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
win32snd_init(word32 *shmaddr)
|
||||
{
|
||||
@ -65,76 +94,67 @@ win32snd_init(word32 *shmaddr)
|
||||
}
|
||||
|
||||
|
||||
// OG Added global to free the dedicated win32 sound memory
|
||||
byte *bptr = NULL;
|
||||
void sdl_send_audio(word32 *ptr, int size, int real_samps) {
|
||||
|
||||
// OG shut win32 sound resources
|
||||
void
|
||||
win32snd_shutdown()
|
||||
{
|
||||
/*
|
||||
//if (g_wave_handle) //////
|
||||
if (false)
|
||||
{
|
||||
MMRESULT res = waveOutReset(g_wave_handle);
|
||||
if (res!=MMSYSERR_NOERROR )
|
||||
printf("waveOutReset Failed");
|
||||
|
||||
res = waveOutClose(g_wave_handle);
|
||||
if (res!=MMSYSERR_NOERROR )
|
||||
printf("waveOutClose Failed");
|
||||
g_wave_handle=NULL;
|
||||
}
|
||||
// OG Free dedicated sound memory
|
||||
if (bptr)
|
||||
{
|
||||
free(bptr);
|
||||
bptr = NULL;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
void CALLBACK
|
||||
handle_wav_snd(HWAVEOUT hwo, UINT uMsg, DWORD dwInstance, DWORD dwParam1,
|
||||
DWORD dwParam2)
|
||||
{
|
||||
LPWAVEHDR lpwavehdr;
|
||||
|
||||
// Only service "buffer done playing messages
|
||||
if(uMsg == WOM_DONE) {
|
||||
lpwavehdr = (LPWAVEHDR)dwParam1;
|
||||
if(lpwavehdr->dwFlags == (WHDR_DONE | WHDR_PREPARED)) {
|
||||
lpwavehdr->dwUser = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
*/
|
||||
void
|
||||
check_wave_error(int res, char *str)
|
||||
{
|
||||
/*
|
||||
TCHAR buf[256];
|
||||
|
||||
if(res == MMSYSERR_NOERROR) {
|
||||
return;
|
||||
}
|
||||
|
||||
waveOutGetErrorText(res, &buf[0], sizeof(buf));
|
||||
printf("%s: %s\n", str, buf);
|
||||
*/
|
||||
exit(1);
|
||||
}
|
||||
void handle_sdl_snd(/* arguments */) {
|
||||
/* code */
|
||||
//printf(" sdl_s_a %d\t 0x%08x ",size, &ptr);
|
||||
int i;
|
||||
for (i=0; i<size; i++) {
|
||||
if (real_samps) {
|
||||
bptr[g_sdlsnd_write_idx++] = ptr[i];
|
||||
} else {
|
||||
bptr[g_sdlsnd_write_idx++] = 0;
|
||||
}
|
||||
if (g_sdlsnd_write_idx>g_sdlsnd_buflen) {
|
||||
g_sdlsnd_write_idx=0;
|
||||
}
|
||||
}
|
||||
g_playbuf_buffered += size;
|
||||
|
||||
}
|
||||
void
|
||||
sdlsnd_shutdown() {
|
||||
//SDL_Delay(5000); // let the audio callback play some sound for 5 seconds.
|
||||
SDL_CloseAudioDevice(dev);
|
||||
printf("sdlsnd_shutdown");
|
||||
|
||||
void handle_sdl_snd(void *userdata, Uint8 *stream, int len) {
|
||||
/* Only play if we have data left */
|
||||
/* if ( g_playbuf_buffered == 0) {
|
||||
return;
|
||||
}
|
||||
*/
|
||||
for(int i = 0; i < len; ++i) {
|
||||
if(g_playbuf_buffered <= 0) {
|
||||
stream[i] = 0;
|
||||
} else {
|
||||
stream[i] = bptr[g_sdlsnd_read_idx++];
|
||||
if(g_sdlsnd_read_idx == g_sdlsnd_buflen)
|
||||
g_sdlsnd_read_idx = 0;
|
||||
g_playbuf_buffered--;
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
|
||||
/* Mix as much data as possible */
|
||||
len = ( len > g_playbuf_buffered ? g_playbuf_buffered : len );
|
||||
//len = ( g_sdlsnd_read_idx+len < g_sdlsnd_buflen ? len : g_sdlsnd_read_idx+len);
|
||||
SDL_memset(stream, 0, len);
|
||||
if (g_sdlsnd_read_idx+len < g_sdlsnd_buflen) {
|
||||
SDL_memcpy (stream, &bptr[g_sdlsnd_read_idx], len);
|
||||
g_sdlsnd_read_idx += len;
|
||||
g_playbuf_buffered -= len;
|
||||
} else {
|
||||
/*
|
||||
int top_len = 0;
|
||||
top_len = g_sdlsnd_buflen - g_sdlsnd_read_idx;
|
||||
SDL_memcpy (stream, &bptr[g_sdlsnd_read_idx], top_len);
|
||||
g_sdlsnd_read_idx = 0;
|
||||
g_playbuf_buffered -= top_len;
|
||||
// SDL_memcpy (stream+top_len, bptr[g_sdlsnd_read_idx], len-top_len);
|
||||
g_sdlsnd_read_idx += len-top_len;
|
||||
g_playbuf_buffered -= len-top_len;
|
||||
*/
|
||||
}
|
||||
|
||||
//SDL_MixAudio(stream, pointer, len, SDL_MIX_MAXVOLUME);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -144,10 +164,10 @@ child_sound_init_sdl()
|
||||
printf("child_sound_init_sdl");
|
||||
|
||||
SDL_memset(&want, 0, sizeof(want)); // or SDL_zero(want)
|
||||
want.freq = 48000;
|
||||
want.format = AUDIO_F32;
|
||||
want.channels = 2;
|
||||
want.samples = 4096;
|
||||
want.freq = g_preferred_rate; // 48000 ?
|
||||
want.format = AUDIO_S16SYS; // AUDIO_F32
|
||||
want.channels = NUM_CHANNELS; //2
|
||||
want.samples = 512; //4096
|
||||
want.callback = handle_sdl_snd; // you wrote this function elsewhere.
|
||||
|
||||
dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, SDL_AUDIO_ALLOW_FORMAT_CHANGE);
|
||||
@ -157,153 +177,39 @@ child_sound_init_sdl()
|
||||
if (have.format != want.format) { // we let this one thing change.
|
||||
printf("We didn't get Float32 audio format.\n");
|
||||
}
|
||||
SDL_PauseAudioDevice(dev, 0); // start audio playing.
|
||||
|
||||
}
|
||||
|
||||
// UNKNOWN?
|
||||
// super experimental unknown
|
||||
|
||||
g_playbuf_buffered = 0; // init buffered state
|
||||
|
||||
int blen;
|
||||
blen = (SOUND_SHM_SAMP_SIZE * SAMPLE_CHAN_SIZE * 2); // *2 unnecessary?
|
||||
g_sdlsnd_buflen = blen;
|
||||
bptr = (byte*)malloc(blen);
|
||||
if(bptr == NULL) {
|
||||
printf("Unabled to allocate sound buffer\n");
|
||||
exit(1);
|
||||
}
|
||||
memset(bptr, 0, SOUND_SHM_SAMP_SIZE*SAMPLE_CHAN_SIZE *2); // zero out the buffer
|
||||
|
||||
g_sdlsnd_write_idx = 0; // initialize
|
||||
g_sdlsnd_read_idx = 0;
|
||||
|
||||
SDL_PauseAudioDevice(dev, 0); // start audio playing.
|
||||
|
||||
g_audio_rate = have.freq;
|
||||
printf("g_audio_rate: %d\n", g_audio_rate);
|
||||
set_audio_rate(g_audio_rate);
|
||||
set_audio_rate(g_audio_rate); // let kegs simulator know the rate
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
child_sound_init_win32()
|
||||
{
|
||||
/*
|
||||
WAVEFORMATEX wavefmt;
|
||||
WAVEOUTCAPS caps;
|
||||
|
||||
// OG Moved as global variable (to rename)
|
||||
// byte *bptr;
|
||||
int bits_per_sample, channels, block_align;
|
||||
int blen;
|
||||
int res;
|
||||
int i;
|
||||
|
||||
memset(&wavefmt, 0, sizeof(WAVEFORMATEX));
|
||||
|
||||
wavefmt.wFormatTag = WAVE_FORMAT_PCM;
|
||||
#ifndef UNDER_CE
|
||||
bits_per_sample = 16;
|
||||
wavefmt.nSamplesPerSec = g_audio_rate;
|
||||
#else
|
||||
bits_per_sample = 16;
|
||||
wavefmt.nSamplesPerSec = 12000;
|
||||
#endif
|
||||
|
||||
channels = 2;
|
||||
wavefmt.wBitsPerSample = bits_per_sample;
|
||||
wavefmt.nChannels = channels;
|
||||
block_align = channels * (bits_per_sample / 8);
|
||||
wavefmt.nBlockAlign = block_align;
|
||||
wavefmt.nAvgBytesPerSec = block_align * g_audio_rate;
|
||||
|
||||
res = waveOutOpen(&g_wave_handle, WAVE_MAPPER, &wavefmt, 0, 0,
|
||||
WAVE_FORMAT_QUERY);
|
||||
|
||||
if(res != MMSYSERR_NOERROR) {
|
||||
printf("Cannot open audio device\n");
|
||||
g_audio_enable = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
res = waveOutOpen(&g_wave_handle, WAVE_MAPPER, &wavefmt,
|
||||
(DWORD)handle_wav_snd, 0, CALLBACK_FUNCTION | WAVE_ALLOWSYNC);
|
||||
|
||||
if(res != MMSYSERR_NOERROR) {
|
||||
printf("Cannot register audio\n");
|
||||
g_audio_enable = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
g_audio_rate = wavefmt.nSamplesPerSec;
|
||||
|
||||
blen = (SOUND_SHM_SAMP_SIZE * 4 * 2) / NUM_WAVE_HEADERS;
|
||||
g_win32snd_buflen = blen;
|
||||
bptr = (byte*)malloc(blen * NUM_WAVE_HEADERS); // OG Added cast
|
||||
if(bptr == NULL) {
|
||||
printf("Unabled to allocate sound buffer\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for(i = 0; i < NUM_WAVE_HEADERS; i++) {
|
||||
memset(&g_wavehdr[i], 0, sizeof(WAVEHDR));
|
||||
g_wavehdr[i].dwUser = FALSE;
|
||||
g_wavehdr[i].lpData = (LPSTR)&(bptr[i*blen]); // OG Added cast
|
||||
g_wavehdr[i].dwBufferLength = blen;
|
||||
g_wavehdr[i].dwFlags = 0;
|
||||
g_wavehdr[i].dwLoops = 0;
|
||||
res = waveOutPrepareHeader(g_wave_handle, &g_wavehdr[i],
|
||||
sizeof(WAVEHDR));
|
||||
check_wave_error(res, "waveOutPrepareHeader");
|
||||
}
|
||||
|
||||
res = waveOutGetDevCaps((UINT)g_wave_handle, &caps, sizeof(caps));
|
||||
check_wave_error(res, "waveOutGetDevCaps");
|
||||
printf("Using %s\n", caps.szPname);
|
||||
printf(" Bits per Sample = %d. Channels = %d\n",
|
||||
wavefmt.wBitsPerSample, wavefmt.nChannels);
|
||||
printf(" Sampling rate = %d, avg_bytes_per_sec = %d\n",
|
||||
(int)wavefmt.nSamplesPerSec, (int)wavefmt.nAvgBytesPerSec);
|
||||
|
||||
set_audio_rate(g_audio_rate);
|
||||
*/
|
||||
}
|
||||
|
||||
void sdl_send_audio(byte *ptr, int size) {
|
||||
/* code */
|
||||
printf(" sdl_send_audio ");
|
||||
}
|
||||
|
||||
void
|
||||
win32_send_audio2(byte *ptr, int size)
|
||||
{
|
||||
/*
|
||||
int found;
|
||||
int res;
|
||||
int i;
|
||||
|
||||
found = 0;
|
||||
for(i = 0; i < NUM_WAVE_HEADERS; i++) {
|
||||
if(g_wavehdr[i].dwUser == FALSE) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found) {
|
||||
// all audio buffers busy, just get out
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(g_wavehdr[i].lpData, ptr, size);
|
||||
g_wavehdr[i].dwBufferLength = size;
|
||||
g_wavehdr[i].dwUser = TRUE;
|
||||
|
||||
res = waveOutWrite(g_wave_handle, &g_wavehdr[i], sizeof(g_wavehdr));
|
||||
check_wave_error(res, "waveOutWrite");
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
win32_send_audio(byte *ptr, int in_size)
|
||||
{
|
||||
int size;
|
||||
int tmpsize;
|
||||
|
||||
size = in_size;
|
||||
while(size > 0) {
|
||||
tmpsize = size;
|
||||
if(size > g_win32snd_buflen) {
|
||||
tmpsize = g_win32snd_buflen;
|
||||
}
|
||||
win32_send_audio2(ptr, tmpsize);
|
||||
ptr += tmpsize;
|
||||
size = size - tmpsize;
|
||||
}
|
||||
|
||||
return in_size;
|
||||
sdlsnd_shutdown() {
|
||||
//SDL_Delay(5000); // let the audio callback play some sound for 5 seconds.
|
||||
SDL_CloseAudioDevice(dev);
|
||||
printf("sdlsnd_shutdown");
|
||||
}
|
||||
|
213
src/sdlsnd_driver2.c
Normal file
213
src/sdlsnd_driver2.c
Normal file
@ -0,0 +1,213 @@
|
||||
#include "SDL.h"
|
||||
#include "defc.h"
|
||||
|
||||
#include "sound.h"
|
||||
#include <assert.h>
|
||||
extern word32 *g_sound_shm_addr;
|
||||
extern int g_sound_shm_pos;
|
||||
extern int g_audio_enable;
|
||||
extern int g_preferred_rate;
|
||||
|
||||
static byte *playbuf = 0;
|
||||
static int g_playbuf_buffered = 0;
|
||||
static SDL_AudioSpec spec;
|
||||
static int snd_buf;
|
||||
static int snd_write; /* write position into playbuf */
|
||||
static /* volatile */ int snd_read = 0;
|
||||
static int g_sound_paused;
|
||||
static int g_zeroes_buffered;
|
||||
static int g_zeroes_seen;
|
||||
|
||||
void sdlsnd_init(word32 *shmaddr)
|
||||
{
|
||||
printf("sdlsnd_init\n");
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
printf("Cannot initialize SDL audio\n");
|
||||
g_audio_enable = 0;
|
||||
} else {
|
||||
printf("SDL AUDIO INITIALIZED\n");
|
||||
}
|
||||
|
||||
child_sound_loop(-1, -1, shmaddr);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
sound_write_sdl(int real_samps, int size)
|
||||
{
|
||||
|
||||
#ifdef HAVE_SDL
|
||||
int shm_read;
|
||||
|
||||
if (real_samps) {
|
||||
shm_read = (g_sound_shm_pos - size + SOUND_SHM_SAMP_SIZE)%SOUND_SHM_SAMP_SIZE;
|
||||
SDL_LockAudio();
|
||||
while(size > 0) {
|
||||
if(g_playbuf_buffered >= snd_buf) {
|
||||
printf("sound_write_sdl failed @%d, %d buffered, %d samples skipped\n",snd_write,g_playbuf_buffered, size);
|
||||
shm_read += size;
|
||||
shm_read %= SOUND_SHM_SAMP_SIZE;
|
||||
size = 0;
|
||||
} else {
|
||||
((word32*)playbuf)[snd_write/SAMPLE_CHAN_SIZE] = g_sound_shm_addr[shm_read];
|
||||
shm_read++;
|
||||
if (shm_read >= SOUND_SHM_SAMP_SIZE)
|
||||
shm_read = 0;
|
||||
snd_write += SAMPLE_CHAN_SIZE;
|
||||
if (snd_write >= snd_buf)
|
||||
snd_write = 0;
|
||||
size--;
|
||||
g_playbuf_buffered += SAMPLE_CHAN_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
assert((snd_buf+snd_write - snd_read)%snd_buf == g_playbuf_buffered%snd_buf);
|
||||
assert(g_sound_shm_pos == shm_read);
|
||||
SDL_UnlockAudio();
|
||||
}
|
||||
if(g_sound_paused && (g_playbuf_buffered > 0)) {
|
||||
printf("Unpausing sound, %d buffered\n",g_playbuf_buffered);
|
||||
g_sound_paused = 0;
|
||||
SDL_PauseAudio(0);
|
||||
}
|
||||
if(!g_sound_paused && (g_playbuf_buffered <= 0)) {
|
||||
printf("Pausing sound\n");
|
||||
g_sound_paused = 1;
|
||||
SDL_PauseAudio(1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_SDL
|
||||
/* Callback for sound */
|
||||
static void _snd_callback(void* userdata, Uint8 *stream, int len)
|
||||
{
|
||||
int i;
|
||||
/* Slurp off the play buffer */
|
||||
assert((snd_buf+snd_write - snd_read)%snd_buf == g_playbuf_buffered%snd_buf);
|
||||
/*printf("slurp %d, %d buffered\n",len, g_playbuf_buffered);*/
|
||||
for(i = 0; i < len; ++i) {
|
||||
if(g_playbuf_buffered <= 0) {
|
||||
stream[i] = 0;
|
||||
} else {
|
||||
stream[i] = playbuf[snd_read++];
|
||||
if(snd_read == snd_buf)
|
||||
snd_read = 0;
|
||||
g_playbuf_buffered--;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
if (g_playbuf_buffered <= 0) {
|
||||
printf("snd_callback: buffer empty, Pausing sound\n");
|
||||
g_sound_paused = 1;
|
||||
SDL_PauseAudio(1);
|
||||
}
|
||||
#endif
|
||||
//printf("end slurp %d, %d buffered\n",len, g_playbuf_buffered);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
long
|
||||
sound_init_device_sdl()
|
||||
{
|
||||
#ifdef HAVE_SDL
|
||||
long rate;
|
||||
SDL_AudioSpec wanted;
|
||||
|
||||
//if(SDL_InitSubSystem(SDL_INIT_AUDIO)) {
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
fprintf(stderr, "sdl: Couldn't init SDL_Audio: %s!\n", SDL_GetError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set the desired format */
|
||||
wanted.freq = g_preferred_rate;
|
||||
wanted.format = AUDIO_S16SYS;
|
||||
wanted.channels = NUM_CHANNELS;
|
||||
wanted.samples = 512;
|
||||
wanted.callback = _snd_callback;
|
||||
wanted.userdata = NULL;
|
||||
|
||||
/* Open audio, and get the real spec */
|
||||
if(SDL_OpenAudio(&wanted, &spec) < 0) {
|
||||
fprintf(stderr, "sdl: Couldn't open audio: %s!\n", SDL_GetError());
|
||||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||
return 0;
|
||||
}
|
||||
/* Check everything */
|
||||
if(spec.channels != wanted.channels) {
|
||||
fprintf(stderr, "sdl: Couldn't get stereo audio format!\n");
|
||||
goto snd_error;
|
||||
}
|
||||
if(spec.format != wanted.format) {
|
||||
fprintf(stderr, "sdl: Couldn't get a supported audio format!\n");
|
||||
fprintf(stderr, "sdl: wanted %X, got %X\n",wanted.format,spec.format);
|
||||
goto snd_error;
|
||||
}
|
||||
if(spec.freq != wanted.freq) {
|
||||
fprintf(stderr, "sdl: wanted rate = %d, got rate = %d\n", wanted.freq, spec.freq);
|
||||
}
|
||||
/* Set things as they really are */
|
||||
rate = spec.freq;
|
||||
|
||||
snd_buf = SOUND_SHM_SAMP_SIZE*SAMPLE_CHAN_SIZE;
|
||||
playbuf = (byte*) malloc(snd_buf);
|
||||
if (!playbuf)
|
||||
goto snd_error;
|
||||
g_playbuf_buffered = 0;
|
||||
|
||||
printf ("Sound shared memory size=%d\n",
|
||||
SOUND_SHM_SAMP_SIZE * SAMPLE_CHAN_SIZE);
|
||||
|
||||
g_sound_shm_addr = malloc(SOUND_SHM_SAMP_SIZE * SAMPLE_CHAN_SIZE);
|
||||
memset(g_sound_shm_addr,0,SOUND_SHM_SAMP_SIZE * SAMPLE_CHAN_SIZE);
|
||||
|
||||
/* It's all good! */
|
||||
g_zeroes_buffered = 0;
|
||||
g_zeroes_seen = 0;
|
||||
/* Let's start playing sound */
|
||||
g_sound_paused = 0;
|
||||
SDL_PauseAudio(0);
|
||||
|
||||
set_audio_rate(rate);
|
||||
return rate;
|
||||
|
||||
snd_error:
|
||||
/* Oops! Something bad happened, cleanup. */
|
||||
SDL_CloseAudio();
|
||||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||
if(playbuf)
|
||||
free((void*)playbuf);
|
||||
playbuf = 0;
|
||||
snd_buf = 0;
|
||||
return 0;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
sound_shutdown_sdl()
|
||||
{
|
||||
#ifdef HAVE_SDL
|
||||
SDL_CloseAudio();
|
||||
if(playbuf)
|
||||
free((void*)playbuf);
|
||||
playbuf = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
sound_shutdown2()
|
||||
{
|
||||
sound_shutdown_sdl();
|
||||
if (g_sound_shm_addr)
|
||||
{
|
||||
free(g_sound_shm_addr);
|
||||
g_sound_shm_addr=NULL;
|
||||
}
|
||||
}
|
20
src/sound.c
20
src/sound.c
@ -64,7 +64,7 @@ word32 doc_reg_e0 = 0xff;
|
||||
|
||||
/* local function prototypes */
|
||||
void doc_write_ctl_reg(int osc, int val, double dsamps);
|
||||
|
||||
void sound_write_sdl(int real_samps, int size);
|
||||
|
||||
int g_audio_rate = 0;
|
||||
double g_daudio_rate = 0.0;
|
||||
@ -456,7 +456,8 @@ sound_shutdown()
|
||||
#elif defined(__OS2__)
|
||||
#elif defined(HAVE_SDL)
|
||||
if((g_audio_enable != 0)) {
|
||||
sdlsnd_shutdown();
|
||||
//sdlsnd_shutdown();
|
||||
sound_shutdown_sdl();
|
||||
}
|
||||
#else
|
||||
if((g_audio_enable != 0) && g_pipe_fd[1] != 0) {
|
||||
@ -629,9 +630,12 @@ send_sound_to_file(word32 *addr, int shm_pos, int num_samps)
|
||||
|
||||
}
|
||||
|
||||
|
||||
// is called with real_samps = 1 to output sound
|
||||
void
|
||||
send_sound(int real_samps, int size)
|
||||
{
|
||||
// real_samps = 1, size = 1602
|
||||
word32 tmp;
|
||||
int ret;
|
||||
|
||||
@ -639,7 +643,9 @@ send_sound(int real_samps, int size)
|
||||
printf("Entered send_sound but audio off!\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
// really does add this crazy high value. i guess it gets taken off / checked later
|
||||
// so if size = 1602 (0x0642) it becomes 0xa2000642
|
||||
// wtf?
|
||||
if(real_samps) {
|
||||
tmp = size + 0xa2000000;
|
||||
} else {
|
||||
@ -647,11 +653,13 @@ send_sound(int real_samps, int size)
|
||||
}
|
||||
DOC_LOG("send_sound", -1, g_last_sound_play_dsamp,
|
||||
(real_samps << 30) + size);
|
||||
|
||||
// Workaround - gcc in cygwin wasn't defining _WIN32
|
||||
#if defined(MAC) || defined(WIN_SOUND) || defined(HAVE_SDL)
|
||||
#if defined(WIN_SOUND) || defined(MAC) && !defined(HAVE_SDL)
|
||||
ret = 0;
|
||||
child_sound_playit(tmp);
|
||||
#elif defined(HAVE_SDL)
|
||||
sound_write_sdl( real_samps, size);
|
||||
//sdl_send_audio(&g_sound_shm_addr[g_sound_shm_pos], size, real_samps);
|
||||
#elif defined(__OS2__)
|
||||
|
||||
#else
|
||||
@ -1041,6 +1049,7 @@ sound_play(double dsamps)
|
||||
if(snd_buf_init) {
|
||||
/* convert sound buf */
|
||||
|
||||
|
||||
for(i = 0; i < num_samps; i++) {
|
||||
val0 = outptr[0];
|
||||
val1 = outptr[1];
|
||||
@ -1082,6 +1091,7 @@ sound_play(double dsamps)
|
||||
sndptr[pos] = (val0 << 16) + (val & 0xffff);
|
||||
# endif
|
||||
#endif
|
||||
// printf("%08x ", sndptr[pos]);
|
||||
pos++;
|
||||
if(pos >= SOUND_SHM_SAMP_SIZE) {
|
||||
pos = 0;
|
||||
|
@ -59,6 +59,8 @@ void win32snd_shutdown();
|
||||
void child_sound_init_win32();
|
||||
int win32_send_audio(byte *ptr, int size);
|
||||
|
||||
void sound_shutdown_sdl();
|
||||
|
||||
|
||||
/* Prototypes for macsnd_driver.c functions */
|
||||
int mac_send_audio(byte *ptr, int in_size);
|
||||
|
@ -27,6 +27,7 @@
|
||||
#endif
|
||||
#ifdef HAVE_SDL
|
||||
# include "SDL.h"
|
||||
long sound_init_device_sdl();
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) || defined(OSS)
|
||||
@ -69,19 +70,18 @@ void child_sound_init_hpdev();
|
||||
void child_sound_initWIN_SOUND();
|
||||
void child_sound_init_mac();
|
||||
void child_sound_init_sdl();
|
||||
long sound_init_device_sdl();
|
||||
|
||||
void
|
||||
reliable_buf_write(word32 *shm_addr, int pos, int size)
|
||||
{
|
||||
printf("bbbbbb");
|
||||
byte *ptr;
|
||||
int ret;
|
||||
|
||||
if(size < 1 || pos < 0 || pos > SOUND_SHM_SAMP_SIZE ||
|
||||
size > SOUND_SHM_SAMP_SIZE ||
|
||||
(pos + size) > SOUND_SHM_SAMP_SIZE) {
|
||||
printf("reliable_buf_write: pos: %04x, size: %04x\n",
|
||||
pos, size);
|
||||
printf("reliable_buf_write: pos: %04x, size: %04x\n", pos, size);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -90,7 +90,8 @@ reliable_buf_write(word32 *shm_addr, int pos, int size)
|
||||
|
||||
while(size > 0) {
|
||||
#if defined(HAVE_SDL)
|
||||
ret = sdl_send_audio();
|
||||
//ret = sdl_send_audio(ptr, size);
|
||||
|
||||
#elif defined(WIN_SOUND)
|
||||
ret = win32_send_audio(ptr, size);
|
||||
#elif defined(MAC) && !defined(HAVE_SDL)
|
||||
@ -126,15 +127,9 @@ reliable_zero_write(int amt)
|
||||
void
|
||||
child_sound_loop(int read_fd, int write_fd, word32 *shm_addr)
|
||||
{
|
||||
printf("child_sound_loop\n" );
|
||||
#ifdef HPUX
|
||||
long status_return;
|
||||
#endif
|
||||
word32 tmp;
|
||||
int ret;
|
||||
|
||||
doc_printf("Child pipe fd: %d\n", read_fd);
|
||||
|
||||
g_audio_rate = g_preferred_rate;
|
||||
|
||||
g_zeroes_buffered = 0;
|
||||
@ -146,7 +141,8 @@ child_sound_loop(int read_fd, int write_fd, word32 *shm_addr)
|
||||
g_childsnd_shm_addr = shm_addr;
|
||||
|
||||
#if defined(HAVE_SDL)
|
||||
child_sound_init_sdl();
|
||||
//child_sound_init_sdl();
|
||||
long rate = sound_init_device_sdl();
|
||||
return;
|
||||
#elif defined(__linux__) || defined(OSS)
|
||||
child_sound_init_linux();
|
||||
@ -160,6 +156,8 @@ child_sound_loop(int read_fd, int write_fd, word32 *shm_addr)
|
||||
return;
|
||||
#endif
|
||||
|
||||
doc_printf("Child pipe fd: %d\n", read_fd);
|
||||
|
||||
tmp = g_audio_rate;
|
||||
ret = write(write_fd, &tmp, 4);
|
||||
if(ret != 4) {
|
||||
@ -191,16 +189,14 @@ child_sound_loop(int read_fd, int write_fd, word32 *shm_addr)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// called by sound.c:send_sound()
|
||||
void
|
||||
child_sound_playit(word32 tmp)
|
||||
{
|
||||
printf("playit ");
|
||||
int size;
|
||||
|
||||
size = tmp & 0xffffff;
|
||||
|
||||
printf("child_sound_playit: %08x\n", tmp);
|
||||
|
||||
printf("SIze: %d ",size);
|
||||
if((tmp >> 24) == 0xa2) {
|
||||
/* play sound here */
|
||||
|
||||
@ -219,6 +215,7 @@ child_sound_playit(word32 tmp)
|
||||
g_zeroes_buffered = 0;
|
||||
g_zeroes_seen = 0;
|
||||
|
||||
// only write up to end of buffer
|
||||
if((size + g_childsnd_pos) > SOUND_SHM_SAMP_SIZE) {
|
||||
reliable_buf_write(g_childsnd_shm_addr, g_childsnd_pos,
|
||||
SOUND_SHM_SAMP_SIZE - g_childsnd_pos);
|
||||
@ -262,15 +259,6 @@ child_sound_playit(word32 tmp)
|
||||
g_childsnd_vbl++;
|
||||
if(g_childsnd_vbl >= 60) {
|
||||
g_childsnd_vbl = 0;
|
||||
#if 0
|
||||
printf("sound bytes written: %06x\n", g_bytes_written);
|
||||
printf("Sample samples[0]: %08x %08x %08x %08x\n",
|
||||
g_childsnd_shm_addr[0], g_childsnd_shm_addr[1],
|
||||
g_childsnd_shm_addr[2], g_childsnd_shm_addr[3]);
|
||||
printf("Sample samples[100]: %08x %08x %08x %08x\n",
|
||||
g_childsnd_shm_addr[100], g_childsnd_shm_addr[101],
|
||||
g_childsnd_shm_addr[102], g_childsnd_shm_addr[103]);
|
||||
#endif
|
||||
g_bytes_written = 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user