Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
2.6 KiB

  1. /******************************************************************************
  2. * clusters.h *
  3. *------------*
  4. *
  5. *------------------------------------------------------------------------------
  6. * Copyright (C) 1997 Entropic Research Laboratory, Inc.
  7. * Copyright (C) 1998 Entropic, Inc
  8. * Copyright (C) 2000 Microsoft Corporation Date: 03/02/00
  9. * All Rights Reserved
  10. *
  11. ********************************************************************* PACOG ***/
  12. #ifndef __CLUSTERS_H_
  13. #define __CLUSTERS_H_
  14. #include <vector>
  15. #define MAX_CLUSTER_LEN 12
  16. #define HASHSIZE 36919
  17. struct StateInfo
  18. {
  19. char clusterName[MAX_CLUSTER_LEN];
  20. float start;
  21. float dur;
  22. short rms;
  23. short f0;
  24. short lklhood;
  25. short f0flag;
  26. int chunkIdx;
  27. };
  28. struct StateInfoVQ : public StateInfo
  29. {
  30. short leftVqIdx; /* left vq index */
  31. short rightVqIdx; /* right vq index */
  32. };
  33. struct SegInfo : public StateInfoVQ
  34. {
  35. double repDist; // Distance to cluster centroid
  36. };
  37. struct hashNode
  38. {
  39. hashNode();
  40. const char* m_pszKey;
  41. short m_sF0flag;
  42. short m_sF0aver;
  43. short m_sRmsaver;
  44. float m_fDuraver;
  45. float m_fLikaver;
  46. std::vector<SegInfo*> m_equiv;
  47. hashNode *m_pNext;
  48. };
  49. class CHash
  50. {
  51. public:
  52. CHash();
  53. ~CHash();
  54. bool Init ();
  55. hashNode* BuildEntry (const char *pszName);
  56. hashNode* Find (const char *pszName);
  57. hashNode* NextEntry(int* iIdx1, int* iIdx2);
  58. private:
  59. unsigned int HashValue (unsigned char *pszName);
  60. hashNode *m_ppHeads[HASHSIZE];
  61. };
  62. class CClusters
  63. {
  64. public:
  65. CClusters();
  66. ~CClusters();
  67. int LoadFromFile (FILE* fp);
  68. int LoadGainTable(FILE* fp);
  69. int PreComputeDist(double dDurWeight, double dRmsWeight, double dLklhoodWeight);
  70. SegInfo* GetBestExample (const char* cluster);
  71. int GetEquivalentCount (const char* cluster);
  72. SegInfo* GetEquivalent(int index);
  73. int GetStats (const char* cluster, int* f0Flag, double* f0Aver, double* rmsAver, double* durAver);
  74. private:
  75. static const int m_iHistMax;
  76. static const double m_dVerySmallProb;
  77. bool Init(int iNumSegments);
  78. int SetClusterEquivalent (int iIndex, SegInfo* pSeginfo);
  79. int ComputeStats (hashNode* cluster);
  80. static int ShortCmp (const void *a, const void *b);
  81. static int FloatCmp (const void *a, const void *b);
  82. void Debug();
  83. SegInfo* m_pSegments;
  84. int m_iNumSegments;
  85. CHash m_hash;
  86. hashNode* m_pFound;
  87. };
  88. #endif