1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <ctype.h>
6 #include <errno.h>
7 #include <fcntl.h>
8 #include <sys/ioctl.h>
9 #include <sys/wait.h>
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <sched.h>
13 #include <esd.h>
14 
15 #include "../sexyal.h"
16 #include "../md5.h"
17 #include "../smallc.h"
18 
19 #include "oss.h"
20 
21 /*
22 void SexyALI_ESD_Enumerate(int (*func)(uint8_t *name, char *id, void *udata), void *udata)
23 {
24  struct stat buf;
25  char fn[64];
26  unsigned int n;
27 
28  n=0;
29 
30  do
31  {
32   strcpy(fn,"/dev/dsp");
33   strcat(fn,sal_uinttos(n));
34   if(stat(fn,&buf)!=0) break;
35  } while(func(fn,sal_uinttos(n),udata));
36 }
37 */
38 
RawWrite(SexyAL_device * device,void * data,uint32_t len)39 static uint32_t RawWrite(SexyAL_device *device, void *data, uint32_t len)
40 {
41  ssize_t bytes;
42 
43  bytes = write(*(int *)device->private,data,len);
44  if(bytes <= 0) return(0);                      /* FIXME:  What to do on -1? */
45  return(bytes);
46 }
47 
RawCanWrite(SexyAL_device * device)48 static uint32_t RawCanWrite(SexyAL_device *device)
49 {
50  return(1);
51 }
52 
Pause(SexyAL_device * device,int state)53 static int Pause(SexyAL_device *device, int state)
54 {
55  return(0);
56 }
57 
Clear(SexyAL_device * device)58 static int Clear(SexyAL_device *device)
59 {
60  //ioctl(*(int *)device->private,SNDCTL_DSP_RESET,0);
61  return(1);
62 }
63 
RawClose(SexyAL_device * device)64 static int RawClose(SexyAL_device *device)
65 {
66  if(device)
67  {
68   if(device->private)
69   {
70    esd_close(*(int*)device->private);
71    free(device->private);
72   }
73   free(device);
74   return(1);
75  }
76  return(0);
77 }
78 
SexyALI_ESD_Open(char * id,SexyAL_format * format,SexyAL_buffering * buffering)79 SexyAL_device *SexyALI_ESD_Open(char *id, SexyAL_format *format, SexyAL_buffering *buffering)
80 {
81  SexyAL_device *device;
82  int fd;
83  unsigned int tmpformat;
84 
85  tmpformat = ESD_STREAM | ESD_PLAY;
86 
87  if(format->channels == 2)
88   tmpformat |= ESD_STEREO;
89  else
90   tmpformat |= ESD_MONO;
91 
92  tmpformat |= ESD_BITS16;
93 
94  if((fd = esd_open_sound(id)) < 0) return(0);
95 
96  format->rate = 44100;
97  buffering->latency = esd_get_latency(fd);
98 
99  esd_close(fd);
100 
101  if((fd=esd_play_stream(tmpformat,format->rate,id,"festalon")) < 0) return(0);
102 
103  buffering->fragcount = buffering->fragsize = buffering->ms = 0;
104  buffering->totalsize = ~0;
105 
106  format->byteorder = 0;
107  format->sampformat = SEXYAL_FMT_PCMS16;
108 
109  device=malloc(sizeof(SexyAL_device));
110  memcpy(&device->format,format,sizeof(SexyAL_format));
111  memcpy(&device->buffering,buffering,sizeof(SexyAL_buffering));
112 
113  device->private=malloc(sizeof(int));
114  device->RawCanWrite = RawCanWrite;
115  device->RawWrite = RawWrite;
116  device->RawClose = RawClose;
117  device->Clear = Clear;
118  device->Pause = Pause;
119 
120  *(int*)device->private=fd;
121 
122  return(device);
123 }
124 
125