as_res_p.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #ifndef __AS_RES_P_H__
  2. #define __AS_RES_P_H__
  3. /* argument for RES_CMD_OPEN and RES_CMD_MEM_REQUIRE */
  4. typedef struct {
  5. /* input pcm samples parameters, both required in RES_CMD_OPEN and RES_CMD_MEM_REQUIRE */
  6. int channels;
  7. int samplerate_in;
  8. int samplerate_out;
  9. /* global memory allocated outside */
  10. void *global_buf_addr; /* must be 4 bytes aligned */
  11. int global_buf_len; /* retured by RES_CMD_MEM_REQUIRE */
  12. /* share memory allocated outside */
  13. void *share_buf_addr; /* must be 4 bytes aligned */
  14. int share_buf_len; /* retured by RES_CMD_MEM_REQUIRE */
  15. /* input/output samples per frame accepted in RES_CMD_PROCESS, returned by RES_CMD_OPEN */
  16. int input_samples;
  17. int output_samples;
  18. } as_res_open_param_t;
  19. /* argument of RES_CMD_PROCESS */
  20. typedef struct {
  21. int channel; /* 0-left, 1-right */
  22. int input_samples;
  23. int output_samples;
  24. void *input_buf;
  25. void *output_buf;
  26. } as_res_process_param_t;
  27. typedef enum {
  28. RES_CMD_OPEN = 0,
  29. RES_CMD_CLOSE,
  30. RES_CMD_PROCESS,
  31. RES_CMD_MEM_REQUIRE,
  32. } as_res_ops_cmd_t;
  33. int as_res_ops(void *hnd, as_res_ops_cmd_t cmd, unsigned int args);
  34. /*
  35. main()
  36. {
  37. as_res_open_param_t open_params;
  38. as_res_process_param_t process_params;
  39. void *handle = 0;
  40. int ret;
  41. //REQUIRE
  42. open_params.rate_in=16000;
  43. open_params.rate_out=44100;
  44. open_params.channels = 2;
  45. as_res_ops(handle, RES_CMD_MEM_REQUIRE, &open_params);
  46. //MALLOC,SYSTEM MANAGEMENT
  47. buf=(unsigned char*)malloc(open_params.require_mem_size);
  48. memset(buf,0,len);
  49. open_params.require_mem_ptr = buf;
  50. ret = as_res_ops(&handle,RES_CMD_OPEN,&params);
  51. if (ret || !handle) {
  52. printf("check Multiple instances ,max is 4 !\n");
  53. return;
  54. }
  55. //PROCESS
  56. while(1) {
  57. process_params.channel=0;//left channel
  58. process_params.input_buf = left_in_buf;
  59. process_params.output_buf = left_out_buf;
  60. process_params.input_samples = in_samples;
  61. as_res_ops(handle, RES_CMD_PROCESS, process_params);
  62. out_len = process_params.output_samples<<1;
  63. process_params.channel=1;//right channel
  64. process_params.input_buf = right_in_buf;
  65. process_params.output_buf = right_out_buf;
  66. as_res_ops(handle, RES_CMD_PROCESS, process_params);
  67. out_len = process_params.output_samples<<1;
  68. }
  69. as_res_ops(handle, RES_CMD_CLOSE, 0);
  70. }
  71. */
  72. /**
  73. * @cond INTERNAL_HIDDEN
  74. *
  75. * These are for internal use only, so skip these in
  76. * public documentation.
  77. */
  78. ////////////////////////////////////////////////////
  79. // FIR HARDWARE
  80. ////////////////////////////////////////////////////
  81. typedef struct {
  82. /* resample mode */
  83. int mode;
  84. /* history buffer (buf address must be 4 bytes aligned) */
  85. void *hist_buf;
  86. int hist_len;
  87. /* input pcm buffer (buf address must be 4 bytes aligned) */
  88. void *input_buf;
  89. int input_len;
  90. /* output pcm buffer (buf address must be 4 bytes aligned) */
  91. void *output_buf;
  92. int output_len; /* return the real processed output length */
  93. } fir_param_t;
  94. /**
  95. * @brief open fir device
  96. *
  97. * @return handle of fir device
  98. */
  99. void *fir_device_open(void);
  100. /**
  101. * @brief close fir device
  102. *
  103. * @param device handle of fir device
  104. *
  105. * @retval 0 if successful.
  106. * @retval Negative errno code if failure.
  107. */
  108. int fir_device_close(void *device);
  109. /**
  110. * @brief run fir device
  111. *
  112. * @param device handle of fir device.
  113. * @param param address of fir process parameter.
  114. *
  115. * @retval 0 if successful.
  116. * @retval Negative errno code if failure.
  117. */
  118. int fir_device_run(void *device, fir_param_t *param);
  119. /**
  120. * @endcond
  121. */
  122. #endif /* __AS_RES_P_H__ */