more cleanups
[fceu.git] / drivers / pc / sdl-sound.c
CommitLineData
c62d2810 1/* FCE Ultra - NES/Famicom Emulator
2 *
3 * Copyright notice for this file:
5232c20c 4 * Copyright (C) 2002 Xodnizel
c62d2810 5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <stdio.h>
5232c20c 22#include <string.h>
23#include <stdlib.h>
24#include <sys/time.h>
25#include <pthread.h>
26#include <unistd.h>
15300263 27#include <sys/ioctl.h>
5232c20c 28#include <linux/soundcard.h>
29
c62d2810 30#include "sdl.h"
5232c20c 31#include "minimal.h"
c62d2810 32
5232c20c 33#define GP2X_SOUND 1
c62d2810 34
5232c20c 35extern void pthread_yield(void);
36extern void FCEUI_FrameSkip(int x);
c62d2810 37
5232c20c 38//extern int dosound;
39extern int soundvol;
c62d2810 40
5232c20c 41// always have this call
42INLINE void gp2x_sound_frame(void *blah, void *buff, int samples)
c62d2810 43 {
c62d2810 44}
45
c62d2810 46
c62d2810 47
5232c20c 48
49
50//static int sexy_in_function=0;
51#define NumSexyBufferBuffers 2
52struct timespec gp2x_sleep_ts;
53int firstentry=1;
54//int firstprint=1;
55struct timeval sleeptimer;
56
57
58
59pthread_t gp2x_sexy_sound_thread=0;
60int** SexyBufferBuffers=NULL;
61int SexyBufferBufferCounts[NumSexyBufferBuffers];
62int gp2x_sound_inited=0;
63int gp2x_in_sound_thread=0;
64extern unsigned long gp2x_dev[8];
65
66pthread_cond_t gp2x_sound_cond=PTHREAD_COND_INITIALIZER;
67pthread_mutex_t gp2x_sound_mutex = PTHREAD_MUTEX_INITIALIZER;
68int zzdebug01_entry=0;
69int zzdebug01_wait=0;
15300263 70int hasSound=0;
5232c20c 71extern unsigned long fps;
72extern unsigned long avg_fps;
5232c20c 73extern unsigned long ticks;
74
75int throttlecount=0;
76
77void WriteSound(int32 *Buffer, int Count)
c62d2810 78 {
5232c20c 79 write(gp2x_dev[3], Buffer, Count<<1);
80 pthread_yield();
81 SpeedThrottle();
c62d2810 82 }
5232c20c 83
84void* gp2x_write_sound(void* blah)
c62d2810 85 {
15300263 86 gp2x_in_sound_thread=1;
c62d2810 87 {
5232c20c 88 if (hasSound)
c62d2810 89 {
5232c20c 90 hasSound=0;
c62d2810 91 }
5232c20c 92 else
c62d2810 93 {
c62d2810 94 }
5232c20c 95
c62d2810 96 }
5232c20c 97 gp2x_in_sound_thread=0;
98 return NULL;
c62d2810 99}
100
101void SilenceSound(int n)
102{
5232c20c 103 soundvol=0;
c62d2810 104}
105
5232c20c 106int InitSound(FCEUGI *gi)
c62d2810 107{
5232c20c 108 Settings.sound=22050;
109 FCEUI_Sound(Settings.sound);
110 gp2x_sound_volume(soundvol, soundvol);
111 printf("InitSound() sound_rate: %d\n", Settings.sound);
15300263 112 if(firstentry)
113 {
114 firstentry=0;
5232c20c 115 gp2x_sound_inited=1;
116 }
117 return 1 ;
c62d2810 118}
119
5232c20c 120uint32 GetMaxSound(void)
c62d2810 121{
5232c20c 122 return(4096);
c62d2810 123}
124
5232c20c 125uint32 GetWriteSound(void)
c62d2810 126 {
5232c20c 127 return 1024;
c62d2810 128}
5232c20c 129
130int KillSound(void)
c62d2810 131{
5232c20c 132 FCEUI_Sound(0);
133 gp2x_sound_inited=0;
134
135 return 1;
c62d2810 136}
5232c20c 137
138
139
140