diff src/xs_length.c @ 65:bf7b647b3239

The fabled 0.8-rewrite now works to some extent
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 29 Jun 2003 22:16:04 +0000
parents 0d1df20745dd
children bf6a524cf7ca
line wrap: on
line diff
--- a/src/xs_length.c	Sun Jun 29 01:17:01 2003 +0000
+++ b/src/xs_length.c	Sun Jun 29 22:16:04 2003 +0000
@@ -97,7 +97,8 @@
  */
 t_xs_sldb_node * xs_db_get(t_xs_md5hash pHash)
 {
- gint iStartNode, iEndNode, iQNode, iFound, r, i;
+ gint iStartNode, iEndNode, iQNode, r, i;
+ gboolean iFound;
  t_xs_sldb_node *pResult;
 
  /* Check the database pointers */
@@ -109,7 +110,7 @@
  iStartNode = 0;
  iEndNode = (xs_dbnodes - 1);
  iQNode = (iEndNode / 2);
- iFound = 0;
+ iFound = FALSE;
 
  while ((!iFound) && ((iEndNode - iStartNode) > 128))
  	{
@@ -126,19 +127,19 @@
  		iStartNode = iQNode;
  		iQNode = iStartNode + ((iEndNode - iStartNode) / 2);
  		} else
- 		iFound = 1;
+ 		iFound = TRUE;
  	}
 
  /* If not found already */
  if (!iFound)
  	{
 	/* Search the are linearly */
-	iFound = 0;
+	iFound = FALSE;
 	i = iStartNode;
 	while ((i <= iEndNode) && (!iFound))
 		{
 		if (xs_db_cmphash(pHash, xs_dbindex[i]->md5Hash) == 0)
-			iFound = 1;
+			iFound = TRUE;
 			else
 			i++;
 		}
@@ -149,7 +150,7 @@
 
  	} else {
 	/* Found via binary search */
- 	pResult = xs_dbindex[iEndNode];
+ 	pResult = xs_dbindex[iQNode];
 	}
 
 
@@ -321,6 +322,8 @@
 {
  t_xs_sldb_node *pCurr;
  gint i;
+
+XSDEBUG("sldb_init()\n");
  
  /* Read the database */
  if (xs_cfg.songlenDBPath == NULL)
@@ -329,6 +332,8 @@
  if (xs_db_read(xs_cfg.songlenDBPath) < 0)
  	return -9;
 
+XSDEBUG("indexing...\n");
+
  /* Get size of db */
  pCurr = xs_database;
  xs_dbnodes = 0;
@@ -359,6 +364,7 @@
 	}
 
  /* OK */
+XSDEBUG("init ok.\n");
  return 0;
 }
 
@@ -371,6 +377,7 @@
  t_xs_sldb_node *pCurr, *pNext;
  
  /* Free the memory allocated for database */
+XSDEBUG("sldb_close()\n");
  pCurr = xs_database;
  while (pCurr)
  	{
@@ -563,14 +570,18 @@
 		{
 		dbNode = xs_db_get(dbHash);
 
-		if (dbNode && (subTune >= 0) && (subTune < dbNode->nLengths))
+		if (dbNode && (subTune >= 1) && (subTune <= dbNode->nLengths))
+			{
+			/* Get the length */
 			iResult = dbNode->sLengths[subTune - 1];
+
+			/* Take off few last seconds */
+			if (iResult > 2)
+				iResult -= 2;
+			}
   		}
 	}
-#if 0
- XSDEBUG("fname='%s', sub=%i, res=%i\n", fileName, subTune, iResult);
-#endif
-  
+
  return iResult;
 }