c5cd806a340a618537221d95178e2ef874b25dd0
[fceu.git] / drivers / pc / sdl-sound.c
1 /* FCE Ultra - NES/Famicom Emulator
2  *
3  * Copyright notice for this file:
4  *  Copyright (C) 2002 Xodnizel
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>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <sys/time.h>
25 #include <pthread.h>
26 #include <unistd.h>
27 #include <sys/ioctl.h> 
28 #include <linux/soundcard.h>
29
30 #include "sdl.h"
31 #include "minimal.h"
32
33 #define GP2X_SOUND 1
34
35 extern INLINE SpeedThrottle(void);
36 extern void pthread_yield(void);
37 extern void FCEUI_FrameSkip(int x);
38
39 //extern int dosound;
40 extern int soundvol;
41
42 // always have this call
43 INLINE void gp2x_sound_frame(void *blah, void *buff, int samples)
44  {
45 }
46
47
48
49
50
51 //static int sexy_in_function=0;
52 #define NumSexyBufferBuffers 2
53 struct timespec gp2x_sleep_ts;
54 int firstentry=1;
55 //int firstprint=1;
56 struct timeval sleeptimer;
57
58
59
60 pthread_t       gp2x_sexy_sound_thread=0;
61 int**  SexyBufferBuffers=NULL;
62 int    SexyBufferBufferCounts[NumSexyBufferBuffers];
63 int  gp2x_sound_inited=0;
64 int gp2x_in_sound_thread=0;
65 extern unsigned long   gp2x_dev[8];
66
67 pthread_cond_t gp2x_sound_cond=PTHREAD_COND_INITIALIZER;
68 pthread_mutex_t gp2x_sound_mutex = PTHREAD_MUTEX_INITIALIZER;
69 int zzdebug01_entry=0;
70 int zzdebug01_wait=0;
71 int hasSound=0; 
72 extern unsigned long fps;
73 extern unsigned long avg_fps;
74 extern unsigned long framesRendered;
75 extern unsigned long ticks;
76
77 int throttlecount=0;
78
79 void WriteSound(int32 *Buffer, int Count)
80   {
81   write(gp2x_dev[3], Buffer, Count<<1);
82   pthread_yield();
83   SpeedThrottle();
84   }
85
86 void* gp2x_write_sound(void* blah)
87   {
88   gp2x_in_sound_thread=1;  
89   {
90     if (hasSound)
91   {
92       hasSound=0;
93   }
94     else
95   {
96   }
97
98  }
99   gp2x_in_sound_thread=0;
100   return NULL;
101 }
102
103 void SilenceSound(int n)
104 {
105   soundvol=0;
106 }
107
108 int InitSound(FCEUGI *gi)
109 {
110   Settings.sound=22050;
111   FCEUI_Sound(Settings.sound);
112   gp2x_sound_volume(soundvol, soundvol);
113   printf("InitSound() sound_rate: %d\n", Settings.sound);
114   if(firstentry) 
115   {   
116       firstentry=0; 
117       gp2x_sound_inited=1;
118   }
119   return 1 ;
120 }
121
122 uint32 GetMaxSound(void)
123 {
124  return(4096);
125 }
126
127 uint32 GetWriteSound(void)
128         {
129  return 1024;
130 }
131
132 int KillSound(void)
133 {
134   FCEUI_Sound(0);
135   gp2x_sound_inited=0;
136
137   return 1;
138 }
139
140
141
142