amrFileCodec.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // amrFileCodec.h
  3. // amrDemoForiOS
  4. //
  5. // Created by Tang Xiaoping on 9/27/11.
  6. // Copyright 2011 test. All rights reserved.
  7. //
  8. #ifndef amrFileCodec_h
  9. #define amrFileCodec_h
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <stdio.h>
  13. #include "interf_dec.h"
  14. #include "interf_enc.h"
  15. #define AMR_MAGIC_NUMBER "#!AMR\n"
  16. #define PCM_FRAME_SIZE 160 // 8khz 8000*0.02=160
  17. #define MAX_AMR_FRAME_SIZE 32
  18. #define AMR_FRAME_COUNT_PER_SECOND 50
  19. typedef struct
  20. {
  21. char chChunkID[4];
  22. int nChunkSize;
  23. }XCHUNKHEADER;
  24. typedef struct
  25. {
  26. short nFormatTag;
  27. short nChannels;
  28. int nSamplesPerSec;
  29. int nAvgBytesPerSec;
  30. short nBlockAlign;
  31. short nBitsPerSample;
  32. }WAVEFORMAT;
  33. typedef struct
  34. {
  35. short nFormatTag;
  36. short nChannels;
  37. int nSamplesPerSec;
  38. int nAvgBytesPerSec;
  39. short nBlockAlign;
  40. short nBitsPerSample;
  41. short nExSize;
  42. }WAVEFORMATX;
  43. typedef struct
  44. {
  45. char chRiffID[4];
  46. int nRiffSize;
  47. char chRiffFormat[4];
  48. }RIFFHEADER;
  49. typedef struct
  50. {
  51. char chFmtID[4];
  52. int nFmtSize;
  53. WAVEFORMAT wf;
  54. }FMTBLOCK;
  55. // WAVE音频采样频率是8khz
  56. // 音频样本单元数 = 8000*0.02 = 160 (由采样频率决定)
  57. // 声道数 1 : 160
  58. // 2 : 160*2 = 320
  59. // bps决定样本(sample)大小
  60. // bps = 8 --> 8位 unsigned char
  61. // 16 --> 16位 unsigned short
  62. int EncodeWAVEFileToAMRFile(const char* pchWAVEFilename, const char* pchAMRFileName, int nChannels, int nBitsPerSample);
  63. // 将AMR文件解码成WAVE文件
  64. int DecodeAMRFileToWAVEFile(const char* pchAMRFileName, const char* pchWAVEFilename);
  65. #endif