Audio.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef AUDIO_H
  2. #define AUDIO_H
  3. #include <ComDefine.h>
  4. #include <queue>
  5. #include <stdint.h>
  6. #ifndef model_sample_rate
  7. #define model_sample_rate 16000
  8. #endif
  9. #ifndef WAV_HEADER_SIZE
  10. #define WAV_HEADER_SIZE 44
  11. #endif
  12. using namespace std;
  13. class AudioFrame {
  14. private:
  15. int start;
  16. int end;
  17. int len;
  18. public:
  19. AudioFrame();
  20. AudioFrame(int len);
  21. ~AudioFrame();
  22. int set_start(int val);
  23. int set_end(int val, int max_len);
  24. int get_start();
  25. int get_len();
  26. int disp();
  27. };
  28. class Audio {
  29. private:
  30. float *speech_data;
  31. int16_t *speech_buff;
  32. int speech_len;
  33. int speech_align_len;
  34. int offset;
  35. float align_size;
  36. int data_type;
  37. queue<AudioFrame *> frame_queue;
  38. public:
  39. Audio(int data_type);
  40. Audio(int data_type, int size);
  41. ~Audio();
  42. void disp();
  43. bool loadwav(const char* filename, int32_t* sampling_rate);
  44. void wavResample(int32_t sampling_rate, const float *waveform, int32_t n);
  45. bool loadwav(const char* buf, int nLen, int32_t* sampling_rate);
  46. bool loadpcmwav(const char* buf, int nFileLen, int32_t* sampling_rate);
  47. bool loadpcmwav(const char* filename, int32_t* sampling_rate);
  48. int fetch_chunck(float *&dout, int len);
  49. int fetch(float *&dout, int &len, int &flag);
  50. void padding();
  51. void split();
  52. float get_time_len();
  53. int get_queue_size() { return (int)frame_queue.size(); }
  54. };
  55. #endif