energy_statistics.c 544 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. * Copyright (c) 2019 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file energy statistics interface
  8. */
  9. #include <stdint.h>
  10. #include "energy_statistics.h"
  11. uint32_t energy_statistics(const short *pcm_data, uint32_t samples_cnt)
  12. {
  13. uint32_t sample_value = 0, i;
  14. int32_t temp_value;
  15. for (i = 0; i < samples_cnt; i++)
  16. {
  17. if (pcm_data[i] < 0)
  18. temp_value = 0 - pcm_data[i];
  19. else
  20. temp_value = pcm_data[i];
  21. sample_value += (uint32_t)temp_value;
  22. }
  23. return (sample_value / samples_cnt);
  24. }