Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

SID_sun.i

Go to the documentation of this file.
00001 /*
00002  *  SID_sun.i - 6581 emulation, SUN specific stuff
00003  *
00004  *  Marc Chabanas
00005  * 
00006  *  The SID emulation will slow down the entire emulator to 100% after
00007  *  it is selected. It is not compatible with the SID filters so these
00008  *  have to be disabled if you don't want to see the performance becoming
00009  *  as low as 20%.
00010  */
00011 
00012 extern "C" {
00013         #include <sys/audioio.h>
00014         #include <unistd.h>
00015         #include "VIC.h"
00016 }
00017 
00018 #define FRAGSIZE (SAMPLE_FREQ/CALC_FREQ)  // samples in a fragment
00019 #define MAXBUFFERED (3*FRAGSIZE) // allow ourself a little buffering
00020 
00021 /*
00022  *  Initialization
00023  */
00024 
00025 void DigitalRenderer::init_sound(void)
00026 {
00027  struct audio_info info;
00028 
00029  ready = false;
00030         
00031  if ((fd = open("/dev/audio", O_WRONLY|O_NDELAY, 0)) < 0) 
00032    {
00033     fprintf(stderr, "SID_sun : unable to open /dev/audio.\n");
00034     return;
00035    }
00036         
00037  AUDIO_INITINFO(&info);
00038  info.play.sample_rate = SAMPLE_FREQ;
00039  info.play.channels = 1;
00040  info.play.precision = 16;
00041  info.play.encoding = AUDIO_ENCODING_LINEAR;
00042  info.play.port = AUDIO_SPEAKER;
00043  if (ioctl(fd, AUDIO_SETINFO, &info)) 
00044    {
00045     fprintf(stderr,
00046             "SID_sun : unable to select 16 bits/%d khz linear encoding.\n",
00047             SAMPLE_FREQ);
00048     return;
00049    } 
00050  else 
00051    {
00052     fprintf(stderr,"SID_sun : selecting 16 bits/%d khz linear encoding.\n",
00053             SAMPLE_FREQ);
00054    }
00055 
00056  sound_calc_buf = new int16[FRAGSIZE];
00057  sent_samples = 0;
00058  delta_samples = 0;
00059 
00060  ready = true;
00061  return;
00062 }
00063 
00064 
00065 /*
00066  *  Destructor
00067  */
00068 
00069 DigitalRenderer::~DigitalRenderer()
00070 {
00071  fprintf(stderr,"SID_sun : leaving audio mode.\n");
00072  if (fd > 0) 
00073    {
00074     if (ready) 
00075       ioctl(fd, AUDIO_DRAIN);
00076     close(fd);
00077    }
00078 }
00079 
00080 
00081 /*
00082  *  Pause sound output
00083  */
00084 
00085 void DigitalRenderer::Pause(void)
00086 {
00087 }
00088 
00089 
00090 /*
00091  * Resume sound output
00092  */
00093 
00094 void DigitalRenderer::Resume(void)
00095 {
00096 }
00097 
00098 /*
00099  *  Fill buffer, sample volume (for sampled voice)
00100  */
00101 
00102 void DigitalRenderer::EmulateLine(void)
00103 {
00104  static int divisor = 0;
00105  static int to_output = 0;
00106 
00107  static unsigned int sleeping;
00108 
00109  int ret;
00110 
00111  sample_buf[sample_in_ptr] = volume;
00112  sample_in_ptr = (sample_in_ptr + 1) % SAMPLE_BUF_SIZE;
00113 
00114  /*
00115   * Now see how many samples have to be added for this line
00116   */
00117 
00118  divisor += SAMPLE_FREQ;
00119  while (divisor >= 0)
00120     divisor -= TOTAL_RASTERS*SCREEN_FREQ, to_output++;
00121 
00122  if (to_output >= FRAGSIZE) /* got enough to send */
00123    {
00124     calc_buffer(sound_calc_buf, FRAGSIZE*2);
00125 
00126     ret = write (fd,sound_calc_buf, FRAGSIZE*2);
00127     if (ret != FRAGSIZE*2) /* should not happen */
00128       {
00129        fprintf(stderr,"SID_sun : write to audio device failed. Exit.\n");
00130        exit(-1);
00131       } 
00132 
00133     sent_samples+=FRAGSIZE;
00134     to_output=0;
00135 
00136     if (ioctl(fd, AUDIO_GETINFO, &status)) 
00137       {
00138        fprintf(stderr,"SID_sun : get audio status failed. Exit.\n");
00139        exit(-1);
00140       }
00141     while ((delta_samples = (sent_samples - status.play.samples)) > MAXBUFFERED)
00142       {
00143        sleeping = ((1000000*(delta_samples-MAXBUFFERED))/SAMPLE_FREQ);
00144        usleep(sleeping);
00145 
00146        if (ioctl(fd, AUDIO_GETINFO, &status))
00147          {
00148           fprintf(stderr,"SID_sun : get audio status failed. Exit.\n");
00149           exit(-1);
00150          }
00151       }
00152    }
00153 }

Generated on Tue Feb 8 04:08:12 2005 for E32frodo by doxygen 1.3.3