freesci-develop
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freesci-develop] r1521 - in freesci/trunk: . src src/gfx src/sound


From: jameson
Subject: [freesci-develop] r1521 - in freesci/trunk: . src src/gfx src/sound
Date: Sun, 05 Feb 2006 09:27:07 +0100

Author: jameson
Date: 2006-02-05 09:27:02 +0100 (Sun, 05 Feb 2006)
New Revision: 1521

Modified:
   freesci/trunk/ChangeLog
   freesci/trunk/README
   freesci/trunk/src/gfx/operations.c
   freesci/trunk/src/gfx/resmgr.c
   freesci/trunk/src/main.c
   freesci/trunk/src/sound/pcmout.c
   freesci/trunk/src/sound/pcmout_alsa.c
Log:
* It's now possible to set pcm.alsa.device

  My final pre-freeze commit.

-- Christoph



Modified: freesci/trunk/ChangeLog
===================================================================
--- freesci/trunk/ChangeLog     2006-02-05 06:15:29 UTC (rev 1520)
+++ freesci/trunk/ChangeLog     2006-02-05 08:27:02 UTC (rev 1521)
@@ -1,5 +1,10 @@
 2006-02-05  Christoph Reichenbach  <address@hidden>
 
+       * src/sound/pcmout_alsa.c: ALSA pcmout now has a 'device'
+       parameter (default is still "hw:0,0")
+
+       * src/main.c (main): Added driver option support for pcmout
+       
        * src/sound/midi_device.c: Adlibemu is now the default sound
        device
 

Modified: freesci/trunk/README
===================================================================
--- freesci/trunk/README        2006-02-05 06:15:29 UTC (rev 1520)
+++ freesci/trunk/README        2006-02-05 08:27:02 UTC (rev 1521)
@@ -414,6 +414,14 @@
 pcmout_buffer_size:  Buffer size in frames. Range is from 64 to 8192.
                      Defaults to 1024.
 
+The PCM subsystem uses the prefix 'pcm' for driver-specific options.
+
+2.1.3 ALSA driver
+-----------------
+The ALSA driver (infix 'alsa') has precisely one option:
+- device: ALSA device to play back through (default "hw:0,0").
+
+
 2.2 Config file example:
 ------------------------
 # FreeSCI config file

Modified: freesci/trunk/src/gfx/operations.c
===================================================================
--- freesci/trunk/src/gfx/operations.c  2006-02-05 06:15:29 UTC (rev 1520)
+++ freesci/trunk/src/gfx/operations.c  2006-02-05 08:27:02 UTC (rev 1521)
@@ -1,3 +1,4 @@
+
 /***************************************************************************
  gfx_operations Copyright (C) 2000 Christoph Reichenbach
 
@@ -1647,7 +1648,7 @@
        new_pointer = _gfxr_get_cel(state, nr, &real_loop, &real_cel);
 
 
-       if (!state->mouse_pointer) {
+       if (!state->mouse_pointer || (real_loop == -1)) {
                GFXWARN("Attempt to set invalid pointer #%d\n", nr);
        } else if (real_loop != loop || real_cel != cel) {
                GFXDEBUG("Changed loop/cel from %d/%d to %d/%d in view %d\n",
@@ -1882,7 +1883,10 @@
                GFXWARN("Loop number was corrected from %d to %d in view %d\n", 
loop, real_loop, nr);
        }
 
-       return view->loops[real_loop].cels_nr;
+       if (loop == -1)
+               return 0;
+       else
+               return view->loops[real_loop].cels_nr;
 }
 
 
@@ -1896,7 +1900,10 @@
                return GFX_ERROR;
        }
 
-       return GFX_OK;
+       if (*loop == -1)
+               return GFX_ERROR;
+       else
+               return GFX_OK;
 }
 
 int
@@ -1935,6 +1942,13 @@
                return GFX_ERROR;
        }
 
+       if (loop == -1) {
+               *width = 0;
+               *height = 0;
+               offset-> x = offset->y = 0;
+               return GFX_OK;
+       }
+
        pxm = view->loops[loop].cels[cel];
        *width = pxm->index_xl;
        *height = pxm->index_yl;
@@ -1960,6 +1974,10 @@
                GFXWARN("Attempt to draw loop/cel %d/%d in invalid view %d\n", 
loop, cel, nr);
                return GFX_ERROR;
        }
+
+       if (loop == -1)
+               return GFX_OK;
+
        pxm = view->loops[loop].cels[cel];
 
        old_x = pos.x -= pxm->xoffset;

Modified: freesci/trunk/src/gfx/resmgr.c
===================================================================
--- freesci/trunk/src/gfx/resmgr.c      2006-02-05 06:15:29 UTC (rev 1520)
+++ freesci/trunk/src/gfx/resmgr.c      2006-02-05 08:27:02 UTC (rev 1521)
@@ -553,20 +553,27 @@
                if (*loop >= view->loops_nr)
                        *loop = view->loops_nr - 1;
 
-       loop_data = view->loops + (*loop);
-
-       if (*cel < 0)
+       if (view->loops_nr <= 0) {
+               sciprintf("Warning: view.%x has no loops! This game is probably 
corrupt.\n", nr);
+               *loop = -1;
                *cel = 0;
-       else
-               if (*cel >= loop_data->cels_nr)
-                       *cel = loop_data->cels_nr - 1;
+       } else {
 
-       cel_data = loop_data->cels[*cel];
+               loop_data = view->loops + (*loop);
 
-       if (!cel_data->data) {
-               gfx_get_res_config(state->options, cel_data);
-               gfx_xlate_pixmap(cel_data, state->driver->mode, 
state->options->view_xlate_filter);
-               gfxr_endianness_adjust(cel_data, state->driver->mode);
+               if (*cel < 0)
+                       *cel = 0;
+               else
+                       if (*cel >= loop_data->cels_nr)
+                               *cel = loop_data->cels_nr - 1;
+
+               cel_data = loop_data->cels[*cel];
+
+               if (!cel_data->data) {
+                       gfx_get_res_config(state->options, cel_data);
+                       gfx_xlate_pixmap(cel_data, state->driver->mode, 
state->options->view_xlate_filter);
+                       gfxr_endianness_adjust(cel_data, state->driver->mode);
+               }
        }
 
        return view;

Modified: freesci/trunk/src/main.c
===================================================================
--- freesci/trunk/src/main.c    2006-02-05 06:15:29 UTC (rev 1520)
+++ freesci/trunk/src/main.c    2006-02-05 08:27:02 UTC (rev 1521)
@@ -1194,6 +1194,19 @@
                pcmout_sample_rate = active_conf->pcmout_rate;
                pcmout_stereo = active_conf->pcmout_stereo;
                pcmout_buffer_size = active_conf->pcmout_buffer_size;
+
+               if (pcmout_driver) {
+                       driver_option_t *option = 
get_driver_options(active_conf, FREESCI_DRIVER_SUBSYSTEM_PCM, 
pcmout_driver->name);
+                       while (option) {
+                               if 
((pcmout_driver->set_parameter)(pcmout_driver, option->option, option->value)) {
+                                       fprintf(stderr, "Fatal error occured in 
pcmout driver while processing \"%s = %s\"\n",
+                                               option->option, option->value);
+                                       exit(1);
+                               }
+
+                               option = option->next;
+                       }
+               }
        }
 
        /* Configure the midiout driver */

Modified: freesci/trunk/src/sound/pcmout.c
===================================================================
--- freesci/trunk/src/sound/pcmout.c    2006-02-05 06:15:29 UTC (rev 1520)
+++ freesci/trunk/src/sound/pcmout.c    2006-02-05 08:27:02 UTC (rev 1521)
@@ -125,7 +125,7 @@
 
         while (pcmout_drivers[retval] &&
               strcasecmp(name, pcmout_drivers[retval]->name))
-                retval++;
+               retval++;
 
         return pcmout_drivers[retval];
 }

Modified: freesci/trunk/src/sound/pcmout_alsa.c
===================================================================
--- freesci/trunk/src/sound/pcmout_alsa.c       2006-02-05 06:15:29 UTC (rev 
1520)
+++ freesci/trunk/src/sound/pcmout_alsa.c       2006-02-05 08:27:02 UTC (rev 
1521)
@@ -33,122 +33,172 @@
 
 static snd_output_t *output;
 
-static char *alsa_device = "hw:0,0"; 
+static char *default_device = "hw:0,0";
 
+/*static char *alsa_device = "default"; */
+
 static void *sound_thread (void *arg)
 {
-  int count, err;
+       int count, err;
 
-  while(run) {
-    count = mix_sound(buffer_size);
-    //    printf("XXXX Fill buffer, %04x, count: %d \n", *buffer, count);
-    if ((err = snd_pcm_writei(pcm_handle, buffer, count)) < 0) {
-      snd_pcm_prepare(pcm_handle);
-      printf("ALSA: Write error: %s\n", snd_strerror(err));
-    }
-  }
-  pthread_exit(0);
+       while(run) {
+               count = mix_sound(buffer_size);
+               /*    printf("XXXX Fill buffer, %04x, count: %d \n", *buffer, 
count);*/
+               if ((err = snd_pcm_writei(pcm_handle, buffer, count)) < 0) {
+                       snd_pcm_prepare(pcm_handle);
+                       printf("ALSA: Write error: %s\n", snd_strerror(err));
+               }
+       }
+       pthread_exit(0);
 }
 
-static int pcmout_alsa_open(gint16 *b, guint16 size, guint16 rate, guint8 
stereo) 
+
+static int
+alsa_stop(void)
 {
-  snd_pcm_hw_params_t *hwparams;
-  int channels = (stereo) ? 2 : 1;
-  int periods = 8;
-  int err;
-  snd_pcm_stream_t stream = SND_PCM_STREAM_PLAYBACK;
-  snd_pcm_access_t pcm_access = SND_PCM_ACCESS_RW_INTERLEAVED;
+       int err;
+
+       if ((err = snd_pcm_drop(pcm_handle)) < 0) {
+               printf("ALSA:  Can't stop PCM device\n");
+               return -1;
+       }
+       if ((err = snd_pcm_close(pcm_handle)) < 0) {
+               printf("ALSA:  Can't close PCM device\n");
+               return -1;
+       }
+
+       return 0;
+}
+
+static int
+alsa_try_init(char *alsa_device, int size,
+             int rate, int channels,
+             snd_pcm_hw_params_t *hwparams)
+{
+       int periods = 8;
+       snd_pcm_stream_t stream = SND_PCM_STREAM_PLAYBACK;
+       snd_pcm_access_t pcm_access = SND_PCM_ACCESS_RW_INTERLEAVED;
 #ifdef WORDS_BIGENDIAN
-  snd_pcm_format_t alsa_format = SND_PCM_FORMAT_S16_BE;
+       snd_pcm_format_t alsa_format = SND_PCM_FORMAT_S16_BE;
 #else
-  snd_pcm_format_t alsa_format = SND_PCM_FORMAT_S16_LE;
+       snd_pcm_format_t alsa_format = SND_PCM_FORMAT_S16_LE;
 #endif
+       int err;
 
-  buffer = b;
-  buffer_size = size;
+       output = NULL;
+       pcm_handle = NULL;
 
-  snd_pcm_hw_params_alloca(&hwparams);
+       if ((err = snd_output_stdio_attach(&output, stdout, 0)) < 0) {
+               printf("Output failed:  %s\n", snd_strerror(err));
+               return -1;
+       }
 
-  if ((err = snd_output_stdio_attach(&output, stdout, 0)) < 0) {
-    printf("Output failed:  %s\n", snd_strerror(err));
-    return -1;
-  }
+       if ((err = snd_pcm_open(&pcm_handle, alsa_device, stream, 0)) < 0) {
+               printf("ALSA: Playback open error: %s\n", snd_strerror(err));
+               return -1;
+       }
 
-  if ((err = snd_pcm_open(&pcm_handle, alsa_device, stream, 0)) < 0) {
-    printf("ALSA: Playback open error: %s\n", snd_strerror(err));
-    return -1;
-  }
+       if ((err = snd_pcm_hw_params_any(pcm_handle, hwparams)) < 0) {
+               printf("ALSA: Can not configure this PCM device.\n");
+               return -1;
+       }
 
-  if ((err = snd_pcm_hw_params_any(pcm_handle, hwparams)) < 0) {
-    printf("ALSA: Can not configure this PCM device.\n");
-    return -1;
-  }
+       if ((err = snd_pcm_hw_params_set_access(pcm_handle, hwparams, 
pcm_access)) < 0) {
+               printf("ALSA: Error setting access.\n");
+               return -1;
+       }
 
-  if ((err = snd_pcm_hw_params_set_access(pcm_handle, hwparams, pcm_access)) < 
0) {
-    printf("ALSA: Error setting access.\n");    return -1;
-  }
+       if ((err = snd_pcm_hw_params_set_format(pcm_handle, hwparams, 
alsa_format)) < 0) {
+               printf("ALSA: Error setting format.\n");
+               return -1;
+       }
 
-  if ((err = snd_pcm_hw_params_set_format(pcm_handle, hwparams, alsa_format)) 
< 0) {
-    printf("ALSA: Error setting format.\n");
-    return -1;
-  }
+       if ((err = snd_pcm_hw_params_set_rate(pcm_handle, hwparams, rate, 0)) < 
0) {
+               printf("ALSA: Error setting rate.\n");
+               return -1;
+       }
 
-  if ((err = snd_pcm_hw_params_set_rate(pcm_handle, hwparams, rate, 0)) < 0) {
-    printf("ALSA: Error setting rate.\n");
-    return -1;
-  }
+       if ((err = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, 
channels)) < 0) {
+               printf("ALSA: Error setting channels.\n");
+               return -1;
+       }
 
-  if ((err = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, channels)) < 
0) {
-    printf("ALSA: Error setting channels.\n");
-    return -1;
-  }
+       if ((err = snd_pcm_hw_params_set_periods(pcm_handle, hwparams, periods, 
0)) < 0) {
+               printf("ALSA: Error setting periods.\n");
+               return -1;
+       }
 
-  if ((err = snd_pcm_hw_params_set_periods(pcm_handle, hwparams, periods, 0)) 
< 0) {
-    printf("ALSA: Error setting periods.\n");
-    return -1;
-  }
+       /* buffer size, in frames */
+       if ((err = snd_pcm_hw_params_set_buffer_size(pcm_handle, hwparams, 
size*periods)>>2) < 0) {
+               printf("ALSA: Error setting buffersize.\n");
+               return -1;
+       }
 
-  /* buffer size, in frames */
-  if ((err = snd_pcm_hw_params_set_buffer_size(pcm_handle, hwparams, 
size*periods)>>2) < 0) {
-    printf("ALSA: Error setting buffersize.\n");
-    return -1;
-  }
+       if ((err = snd_pcm_hw_params(pcm_handle, hwparams)) < 0) {
+               printf("ALSA: Error setting HW params.\n");
+               return -1;
+       }
+}
 
-  if ((err = snd_pcm_hw_params(pcm_handle, hwparams)) < 0) {
-    printf("ALSA: Error setting HW params.\n");
-    return -1;
-  }
 
+static int
+pcmout_alsa_open(gint16 *b, guint16 size, guint16 rate, guint8 stereo) 
+{
+       int channels = (stereo) ? 2 : 1;
+       snd_pcm_hw_params_t *hwparams;
+       char *alt_device = "default"; /* Not present everywhere */
+       snd_pcm_hw_params_alloca(&hwparams);
+
+       buffer = b;
+       buffer_size = size;
+
+       printf("ALSA: Opening '%s'\n", default_device);
+       if (alsa_try_init(default_device, size, rate, channels, hwparams)) {
+               printf("ALSA: Trying alternative '%s'\n", alt_device);
+               if (alsa_try_init(alt_device, size, rate, channels, hwparams)) {
+                       printf("ALSA: Alternative also failed\n");
+                       return -1;
+               }
+       } else printf("Initialisation done\n");
+
 #if 0
-  snd_pcm_dump(pcm_handle, output);
+       snd_pcm_dump(pcm_handle, output);
 #endif
 
-  pthread_create (&thread, NULL, sound_thread, NULL);
+       pthread_create (&thread, NULL, sound_thread, NULL);
 
-  return 0;
+       return 0;
 }
 
-static int pcmout_alsa_close() {
-  int err;
+static int
+pcmout_alsa_close()
+{
+       int err;
   
-  run = 0;
+       run = 0;
 
-  pthread_join(thread, NULL);
+       pthread_join(thread, NULL);
 
-  if ((err = snd_pcm_drop(pcm_handle)) < 0) {
-    printf("ALSA:  Can't stop PCM device\n");
-  }
-  if ((err = snd_pcm_close(pcm_handle)) < 0) {
-    printf("ALSA:  Can't close PCM device\n");
-  }
+       alsa_stop();
 
-  return 0;
+       return 0;
 }
 
+static int
+pcmout_alsa_set_parameter(pcmout_driver_t *_, char *attr, char *value)
+{
+       if (strcmp(attr, "device") == 0)
+               default_device = value;
+       else
+               return -1;
+
+       return 0;
+}
+
 pcmout_driver_t pcmout_driver_alsa = {
   "alsa",
-  "v0.01",
-  NULL,
+  "v0.2",
+  &pcmout_alsa_set_parameter,
   &pcmout_alsa_open,
   &pcmout_alsa_close
 };





reply via email to

[Prev in Thread] Current Thread [Next in Thread]