changeset 273:f6daddca03c7

Merging in oversampling support, audio settings sanitation.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 23 Dec 2004 17:04:03 +0000
parents 4af5e6c1d968
children 051ba87da9be
files src/xmms-sid.c
diffstat 1 files changed, 50 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/xmms-sid.c	Thu Dec 23 17:03:04 2004 +0000
+++ b/src/xmms-sid.c	Thu Dec 23 17:04:03 2004 +0000
@@ -111,12 +111,24 @@
 	XS_MUTEX_UNLOCK(xs_status);
 	}
  
- /* Initialize status */
+ /* Initialize status and sanitize configuration */
  xs_memset(&xs_status, 0, sizeof(xs_status));
+ 
+ if (xs_cfg.audioFrequency < 8000)
+ 	xs_cfg.audioFrequency = 8000;
+
+ if (xs_cfg.oversampleFactor < XS_MIN_OVERSAMPLE)
+ 	xs_cfg.oversampleFactor = XS_MIN_OVERSAMPLE;
+ 	else
+ if (xs_cfg.oversampleFactor > XS_MAX_OVERSAMPLE)
+ 	xs_cfg.oversampleFactor = XS_MAX_OVERSAMPLE;
+
  xs_status.audioFrequency	= xs_cfg.audioFrequency;
  xs_status.audioBitsPerSample	= xs_cfg.audioBitsPerSample;
  xs_status.audioChannels	= xs_cfg.audioChannels;
  xs_status.audioFormat		= -1;
+ xs_status.oversampleEnable	= xs_cfg.oversampleEnable;
+ xs_status.oversampleFactor	= xs_cfg.oversampleFactor;
  
  /* Try to initialize emulator engine */
  XSDEBUG("initializing emulator engine #%i...\n", xs_cfg.playerEngine);
@@ -152,6 +164,12 @@
  
  XSDEBUG("init#2: %s, %i\n", (isInitialized) ? "OK" : "FAILED", iPlayer);
 
+ /* Get settings back, in case the chosen emulator backend changed them */
+ xs_cfg.audioFrequency		= xs_status.audioFrequency;
+ xs_cfg.audioBitsPerSample	= xs_status.audioBitsPerSample;
+ xs_cfg.audioChannels		= xs_status.audioChannels;
+ xs_cfg.oversampleEnable	= xs_status.oversampleEnable;
+
  /* Initialize song-length database */
  xs_songlen_close();
  if (xs_cfg.songlenDBEnable && (xs_songlen_init() != 0))
@@ -177,6 +195,7 @@
 
  /* Initialize and get configuration */
  xs_memset(&xs_cfg, 0, sizeof(xs_cfg));
+ xs_init_configuration();
  xs_read_configuration();
 
  /* Initialize subsystems */
@@ -256,9 +275,9 @@
  guint audioGot;
  gint songLength;
 #ifdef XS_BUF_DYNAMIC
- gchar *audioBuffer = NULL;
+ gchar *audioBuffer = NULL, *oversampleBuffer = NULL;
 #else
- gchar audioBuffer[XS_AUDIOBUF_SIZE];
+ gchar audioBuffer[XS_AUDIOBUF_SIZE], oversampleBuffer[(XS_AUDIOBUF_SIZE * XS_MAX_OVERSAMPLE)];
 #endif
 
  /* Initialize */
@@ -266,10 +285,10 @@
  XS_MUTEX_LOCK(xs_status);
  memcpy(&myStatus, &xs_status, sizeof(t_xs_status));
  myTune = xs_status.tuneInfo;
- 
- 
  XS_MUTEX_UNLOCK(xs_status);
 
+ audioBuffer = oversampleBuffer = NULL;
+
  /* Allocate audio buffer */
 #ifdef XS_BUF_DYNAMIC
  audioBuffer = (gchar *) g_malloc(XS_AUDIOBUF_SIZE);
@@ -278,11 +297,22 @@
 	XSERR("Couldn't allocate memory for audio data buffer!\n");
 	goto xs_err_exit;
  	}
+
+ if (myStatus.oversampleEnable)
+ 	{
+ 	oversampleBuffer = (gchar *) g_malloc(XS_AUDIOBUF_SIZE * myStatus.oversampleFactor);
+ 	if (oversampleBuffer == NULL)
+	 	{
+		XSERR("Couldn't allocate memory for audio oversampling buffer!\n");
+		goto xs_err_exit;
+ 		}
+	}
 #endif
 
  /*
   * Main player loop: while not stopped, loop here - play subtunes
   */
+ audioOpen = FALSE;
  doPlay = TRUE;
  while (xs_status.isPlaying && doPlay)
  {
@@ -351,7 +381,20 @@
  while (xs_status.isPlaying && myStatus.isPlaying && (xs_status.currSong == myStatus.currSong))
 	{
 	/* Render audio data */
-	audioGot = myStatus.sidPlayer->plrFillBuffer(&myStatus, audioBuffer, XS_AUDIOBUF_SIZE);
+	if (myStatus.oversampleEnable)
+		{
+		/* Perform oversampled rendering */
+		audioGot = myStatus.sidPlayer->plrFillBuffer(&myStatus,
+			oversampleBuffer, (XS_AUDIOBUF_SIZE * myStatus.oversampleFactor));
+		
+		/* Execute rate-conversion with filtering */
+		audioGot = xs_rateconv_filter(
+			audioBuffer, oversampleBuffer,
+			myStatus.audioFormat,
+			myStatus.oversampleFactor,
+			XS_AUDIOBUF_SIZE);
+		} else 
+		audioGot = myStatus.sidPlayer->plrFillBuffer(&myStatus, audioBuffer, XS_AUDIOBUF_SIZE);
 
 	/* I <3 visualice/haujobb */
 	xs_plugin_ip.add_vis_pcm(
@@ -418,6 +461,7 @@
 
 #ifdef XS_BUF_DYNAMIC
  g_free(audioBuffer);
+ g_free(oversampleBuffer);
 #endif
 
  /* Set playing status to false (stopped), thus when