1
0
Fork 0
forked from len0rd/rockbox

First take at PCM playback in the X11 sim on Linux.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7147 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Daniel Stenberg 2005-07-14 21:46:07 +00:00
parent 771ed79f73
commit febb52fc03
6 changed files with 153 additions and 3 deletions

15
tools/configure vendored
View file

@ -12,6 +12,7 @@
CCOPTS="-W -Wall -O -nostdlib -ffreestanding -Wstrict-prototypes"
use_logf="#undef ROCKBOX_HAS_LOGF"
use_simsound="#undef ROCKBOX_HAS_SIMSOUND"
scriptver=`echo '$Revision$' | sed -e 's:\\$::g' -e 's/Revision: //'`
@ -82,7 +83,14 @@ simcc () {
LDOPTS='-L/usr/X11R6/lib -lX11 -lm -lXt -lXmu -lnsl -ldl -lpthread'
if [ "$simver" = "win32" ]; then
crosswincc # setup cross-compiler
fi
else
if test -n "$codecs"; then
if test -f "/usr/include/linux/soundcard.h"; then
# We have a header file so we can build the sound code
use_simsound="#define ROCKBOX_HAS_SIMSOUND 1"
fi # header file present
fi # has codecs
fi # not a cross-compiler
;;
FreeBSD)
@ -691,6 +699,7 @@ fi
sed > autoconf.h \
-e "s,@ENDIAN@,${defendian},g" \
-e "s,^#undef ROCKBOX_HAS_LOGF,$use_logf,g" \
-e "s,@SIMSOUND@,$use_simsound,g" \
<<EOF
/* This header was made by configure */
#ifndef __BUILD_AUTOCONF_H
@ -702,6 +711,10 @@ sed > autoconf.h \
/* Define this if you build rockbox to support the logf logging and display */
#undef ROCKBOX_HAS_LOGF
/* Define this if you have the linux/soundcard.h header and thus can compile
the sound-playing code in the X11 sim */
@SIMSOUND@
#endif /* __BUILD_AUTOCONF_H */
EOF

View file

@ -57,9 +57,10 @@ void pcm_init(void)
{
}
void (*sound_get_pcm)(unsigned char** start, long* size);
void pcm_play_data(void (*get_more)(unsigned char** start, long* size))
{
(void)get_more;
sound_get_pcm = get_more;
}
/* Generic firmware stubs. */
@ -94,7 +95,6 @@ int ata_write_sectors(IF_MV2(int drive,)
FILE* f;
char name[32];
DEBUGF("Writing sector %X\n",start+i);
sprintf(name,"sector%lX.bin",start+i);
f=fopen(name,"w");
if (f) {

View file

@ -9,3 +9,6 @@ screenhack.c
thread.c
uibasic.c
visual.c
#if CONFIG_HWCODEC == MASNONE
sound.c
#endif

95
uisimulator/x11/sound.c Normal file
View file

@ -0,0 +1,95 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 by Daniel Stenberg <daniel@haxx.se>
*
* 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 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/soundcard.h>
#include "sound.h"
int sim_sound_init(void)
{
int fd;
int pcmbits;
int rc;
int channels;
int rate;
fd = open("/dev/dsp", O_WRONLY);
if(-1 == fd)
return 1;
pcmbits = 16;
rc = ioctl(fd, SOUND_PCM_WRITE_BITS, &pcmbits);
rc = ioctl(fd, SOUND_PCM_READ_BITS, &pcmbits);
channels = 2; /* Number of channels, 1=mono */
rc = ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &channels);
rc = ioctl(fd, SOUND_PCM_READ_CHANNELS, &channels);
rate = 44100; /* Yeah. sampling rate */
rc = ioctl(fd, SOUND_PCM_WRITE_RATE, &rate);
rc = ioctl(fd, SOUND_PCM_READ_RATE, &rate);
return fd;
}
void sim_sound_play(int soundfd, char *buffer, long len)
{
write(soundfd, buffer, len);
}
void sound_playback_thread(void)
{
int soundfd = sim_sound_init();
unsigned char *buf;
long size;
while(-1 == soundfd)
sleep(100000); /* wait forever, can't play sound! */
do {
while(!sound_get_pcm)
/* TODO: fix a fine thread-synch mechanism here */
usleep(10000);
do {
sound_get_pcm(&buf, &size);
if(!size) {
sound_get_pcm = NULL;
break;
}
sim_sound_play(soundfd, buf, size);
usleep(10000);
} while(size);
} while(1);
}
#endif /* ROCKBOX_HAS_SIMSOUND */

22
uisimulator/x11/sound.h Normal file
View file

@ -0,0 +1,22 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 by Daniel Stenberg <daniel@haxx.se>
*
* 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.
*
****************************************************************************/
void sound_playback_thread(void);
extern void (*sound_get_pcm)(unsigned char** start, long* size);

View file

@ -17,12 +17,18 @@
*
****************************************************************************/
#include "autoconf.h"
#include <stdio.h>
#include <pthread.h>
#include "kernel.h"
#include <sys/time.h>
#ifdef ROCKBOX_HAS_SIMSOUND
#include "sound.h"
#endif
long current_tick = 0;
extern void button_tick(void);
@ -77,8 +83,19 @@ void init_threads(void)
/* get mutex to only allow one thread running at a time */
pthread_mutex_lock(&mp);
/* start a tick thread */
pthread_create(&tick_tid, NULL, (void *(*)(void *)) update_tick_thread,
NULL);
#ifdef ROCKBOX_HAS_SIMSOUND /* start thread that plays PCM data */
{
pthread_t sound_tid;
pthread_create(&sound_tid, NULL,
(void *(*)(void *)) sound_playback_thread,
NULL);
}
#endif
}
/*
int pthread_create(pthread_t *new_thread_ID,