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.

170 lines
3.9KB

  1. /*
  2. Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
  3. This file is part of aubio.
  4. aubio is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. aubio is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with aubio. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include "aubio_priv.h"
  16. #include "cvec.h"
  17. cvec_t * new_cvec(uint_t length) {
  18. cvec_t * s;
  19. if ((sint_t)length <= 0) {
  20. return NULL;
  21. }
  22. s = AUBIO_NEW(cvec_t);
  23. s->length = length/2 + 1;
  24. s->norm = AUBIO_ARRAY(smpl_t,s->length);
  25. s->phas = AUBIO_ARRAY(smpl_t,s->length);
  26. return s;
  27. }
  28. void del_cvec(cvec_t *s) {
  29. AUBIO_FREE(s->norm);
  30. AUBIO_FREE(s->phas);
  31. AUBIO_FREE(s);
  32. }
  33. void cvec_norm_set_sample (cvec_t *s, smpl_t data, uint_t position) {
  34. s->norm[position] = data;
  35. }
  36. void cvec_phas_set_sample (cvec_t *s, smpl_t data, uint_t position) {
  37. s->phas[position] = data;
  38. }
  39. smpl_t cvec_norm_get_sample (cvec_t *s, uint_t position) {
  40. return s->norm[position];
  41. }
  42. smpl_t cvec_phas_get_sample (cvec_t *s, uint_t position) {
  43. return s->phas[position];
  44. }
  45. smpl_t * cvec_norm_get_data (const cvec_t *s) {
  46. return s->norm;
  47. }
  48. smpl_t * cvec_phas_get_data (const cvec_t *s) {
  49. return s->phas;
  50. }
  51. /* helper functions */
  52. void cvec_print(const cvec_t *s) {
  53. uint_t j;
  54. AUBIO_MSG("norm: ");
  55. for (j=0; j< s->length; j++) {
  56. AUBIO_MSG(AUBIO_SMPL_FMT " ", s->norm[j]);
  57. }
  58. AUBIO_MSG("\n");
  59. AUBIO_MSG("phas: ");
  60. for (j=0; j< s->length; j++) {
  61. AUBIO_MSG(AUBIO_SMPL_FMT " ", s->phas[j]);
  62. }
  63. AUBIO_MSG("\n");
  64. }
  65. void cvec_copy(const cvec_t *s, cvec_t *t) {
  66. if (s->length != t->length) {
  67. AUBIO_ERR("trying to copy %d elements to %d elements \n",
  68. s->length, t->length);
  69. return;
  70. }
  71. #if defined(HAVE_INTEL_IPP)
  72. aubio_ippsCopy(s->phas, t->phas, (int)s->length);
  73. aubio_ippsCopy(s->norm, t->norm, (int)s->length);
  74. #elif defined(HAVE_MEMCPY_HACKS)
  75. memcpy(t->norm, s->norm, t->length * sizeof(smpl_t));
  76. memcpy(t->phas, s->phas, t->length * sizeof(smpl_t));
  77. #else
  78. uint_t j;
  79. for (j=0; j< t->length; j++) {
  80. t->norm[j] = s->norm[j];
  81. t->phas[j] = s->phas[j];
  82. }
  83. #endif
  84. }
  85. void cvec_norm_set_all(cvec_t *s, smpl_t val) {
  86. #if defined(HAVE_INTEL_IPP)
  87. aubio_ippsSet(val, s->norm, (int)s->length);
  88. #else
  89. uint_t j;
  90. for (j=0; j< s->length; j++) {
  91. s->norm[j] = val;
  92. }
  93. #endif
  94. }
  95. void cvec_norm_zeros(cvec_t *s) {
  96. #if defined(HAVE_INTEL_IPP)
  97. aubio_ippsZero(s->norm, (int)s->length);
  98. #elif defined(HAVE_MEMCPY_HACKS)
  99. memset(s->norm, 0, s->length * sizeof(smpl_t));
  100. #else
  101. cvec_norm_set_all (s, 0.);
  102. #endif
  103. }
  104. void cvec_norm_ones(cvec_t *s) {
  105. cvec_norm_set_all (s, 1.);
  106. }
  107. void cvec_phas_set_all (cvec_t *s, smpl_t val) {
  108. #if defined(HAVE_INTEL_IPP)
  109. aubio_ippsSet(val, s->phas, (int)s->length);
  110. #else
  111. uint_t j;
  112. for (j=0; j< s->length; j++) {
  113. s->phas[j] = val;
  114. }
  115. #endif
  116. }
  117. void cvec_phas_zeros(cvec_t *s) {
  118. #if defined(HAVE_INTEL_IPP)
  119. aubio_ippsZero(s->phas, (int)s->length);
  120. #elif defined(HAVE_MEMCPY_HACKS)
  121. memset(s->phas, 0, s->length * sizeof(smpl_t));
  122. #else
  123. cvec_phas_set_all (s, 0.);
  124. #endif
  125. }
  126. void cvec_phas_ones(cvec_t *s) {
  127. cvec_phas_set_all (s, 1.);
  128. }
  129. void cvec_zeros(cvec_t *s) {
  130. cvec_norm_zeros(s);
  131. cvec_phas_zeros(s);
  132. }
  133. void cvec_logmag(cvec_t *s, smpl_t lambda) {
  134. #if defined(HAVE_INTEL_IPP)
  135. aubio_ippsMulC(s->norm, lambda, s->norm, (int)s->length);
  136. aubio_ippsAddC(s->norm, 1.0, s->norm, (int)s->length);
  137. aubio_ippsLn(s->norm, s->norm, (int)s->length);
  138. #else
  139. uint_t j;
  140. for (j=0; j< s->length; j++) {
  141. s->norm[j] = LOG(lambda * s->norm[j] + 1);
  142. }
  143. #endif
  144. }