2006-01-09 11:22:36 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 by Nick Lanham
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "autoconf.h"
|
|
|
|
|
|
|
|
#ifdef ROCKBOX_HAS_SIMSOUND /* play sound in sim enabled */
|
|
|
|
|
2006-02-03 15:19:58 +00:00
|
|
|
#include <memory.h>
|
2006-01-09 11:22:36 +00:00
|
|
|
#include <stdlib.h>
|
2006-02-03 15:19:58 +00:00
|
|
|
#include "uisdl.h"
|
2006-01-09 11:22:36 +00:00
|
|
|
#include "sound.h"
|
|
|
|
|
|
|
|
static int audio_len;
|
|
|
|
static char *audio_pos;
|
|
|
|
SDL_sem* sem;
|
|
|
|
|
|
|
|
void mixaudio(void *udata, Uint8 *stream, int len)
|
|
|
|
{
|
|
|
|
(void)udata;
|
|
|
|
|
|
|
|
/* Only play if we have data left */
|
|
|
|
if ( audio_len == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
len = (len > audio_len) ? audio_len : len;
|
|
|
|
memcpy(stream, audio_pos, len);
|
|
|
|
audio_pos += len;
|
|
|
|
audio_len -= len;
|
|
|
|
|
|
|
|
if(audio_len == 0) {
|
|
|
|
if(SDL_SemPost(sem))
|
|
|
|
fprintf(stderr,"Couldn't post: %s",SDL_GetError());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int sim_sound_init(void)
|
|
|
|
{
|
|
|
|
SDL_AudioSpec fmt;
|
|
|
|
|
|
|
|
/* Set 16-bit stereo audio at 44Khz */
|
|
|
|
fmt.freq = 44100;
|
|
|
|
fmt.format = AUDIO_S16SYS;
|
|
|
|
fmt.channels = 2;
|
|
|
|
fmt.samples = 512; /* A good value for games */
|
|
|
|
fmt.callback = mixaudio;
|
|
|
|
fmt.userdata = NULL;
|
|
|
|
|
|
|
|
sem = SDL_CreateSemaphore(0);
|
|
|
|
|
|
|
|
/* Open the audio device and start playing sound! */
|
|
|
|
if(SDL_OpenAudio(&fmt, NULL) < 0) {
|
|
|
|
fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError());
|
|
|
|
return -1;
|
|
|
|
}
|
2006-02-03 15:19:58 +00:00
|
|
|
|
2006-01-09 11:22:36 +00:00
|
|
|
SDL_PauseAudio(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-03 15:19:58 +00:00
|
|
|
int sound_playback_thread(void *p)
|
2006-01-09 11:22:36 +00:00
|
|
|
{
|
|
|
|
int sndret = sim_sound_init();
|
|
|
|
unsigned char *buf;
|
|
|
|
long size;
|
|
|
|
|
2006-01-13 13:38:31 +00:00
|
|
|
(void)p;
|
|
|
|
|
2006-01-09 11:22:36 +00:00
|
|
|
while(sndret)
|
2006-02-03 15:19:58 +00:00
|
|
|
SDL_Delay(100000); /* wait forever, can't play sound! */
|
2006-01-09 11:22:36 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
while(!sound_get_pcm)
|
|
|
|
/* TODO: fix a fine thread-synch mechanism here */
|
2006-02-03 15:19:58 +00:00
|
|
|
SDL_Delay(100);
|
2006-01-09 11:22:36 +00:00
|
|
|
do {
|
|
|
|
sound_get_pcm(&buf, &size);
|
|
|
|
if(!size) {
|
|
|
|
sound_get_pcm = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
audio_pos = buf; // TODO: is this safe?
|
|
|
|
audio_len = size;
|
2006-02-03 15:19:58 +00:00
|
|
|
|
2006-01-09 11:22:36 +00:00
|
|
|
if(SDL_SemWait(sem))
|
|
|
|
fprintf(stderr,"Couldn't wait: %s",SDL_GetError());
|
|
|
|
} while(size);
|
|
|
|
} while(1);
|
2006-02-03 15:19:58 +00:00
|
|
|
|
2006-01-09 11:22:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ROCKBOX_HAS_SIMSOUND */
|
2006-02-03 15:19:58 +00:00
|
|
|
|