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.

104 lines
3.8KB

  1. /*
  2. * PortAudio Portable Real-Time Audio Library
  3. * Latest Version at: http://www.portaudio.com
  4. *
  5. * Copyright (c) 1999-2010 Phil Burk and Ross Bencina
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining
  8. * a copy of this software and associated documentation files
  9. * (the "Software"), to deal in the Software without restriction,
  10. * including without limitation the rights to use, copy, modify, merge,
  11. * publish, distribute, sublicense, and/or sell copies of the Software,
  12. * and to permit persons to whom the Software is furnished to do so,
  13. * subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  21. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  22. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  23. * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. */
  26. /*
  27. * The text above constitutes the entire PortAudio license; however,
  28. * the PortAudio community also makes the following non-binding requests:
  29. *
  30. * Any person wishing to distribute modifications to the Software is
  31. * requested to send the modifications to the original developer so that
  32. * they can be incorporated into the canonical version. It is also
  33. * requested that these non-binding requests be included along with the
  34. * license above.
  35. */
  36. #ifndef _WAV_WRITER_H
  37. #define _WAV_WRITER_H
  38. /*
  39. * WAV file writer.
  40. *
  41. * Author: Phil Burk
  42. */
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /* Define WAV Chunk and FORM types as 4 byte integers. */
  47. #define RIFF_ID (('R'<<24) | ('I'<<16) | ('F'<<8) | 'F')
  48. #define WAVE_ID (('W'<<24) | ('A'<<16) | ('V'<<8) | 'E')
  49. #define FMT_ID (('f'<<24) | ('m'<<16) | ('t'<<8) | ' ')
  50. #define DATA_ID (('d'<<24) | ('a'<<16) | ('t'<<8) | 'a')
  51. #define FACT_ID (('f'<<24) | ('a'<<16) | ('c'<<8) | 't')
  52. /* Errors returned by Audio_ParseSampleImage_WAV */
  53. #define WAV_ERR_CHUNK_SIZE (-1) /* Chunk size is illegal or past file size. */
  54. #define WAV_ERR_FILE_TYPE (-2) /* Not a WAV file. */
  55. #define WAV_ERR_ILLEGAL_VALUE (-3) /* Illegal or unsupported value. Eg. 927 bits/sample */
  56. #define WAV_ERR_FORMAT_TYPE (-4) /* Unsupported format, eg. compressed. */
  57. #define WAV_ERR_TRUNCATED (-5) /* End of file missing. */
  58. /* WAV PCM data format ID */
  59. #define WAVE_FORMAT_PCM (1)
  60. #define WAVE_FORMAT_IMA_ADPCM (0x0011)
  61. typedef struct WAV_Writer_s
  62. {
  63. FILE *fid;
  64. /* Offset in file for data size. */
  65. int dataSizeOffset;
  66. int dataSize;
  67. } WAV_Writer;
  68. /*********************************************************************************
  69. * Open named file and write WAV header to the file.
  70. * The header includes the DATA chunk type and size.
  71. * Returns number of bytes written to file or negative error code.
  72. */
  73. long Audio_WAV_OpenWriter( WAV_Writer *writer, const char *fileName, int frameRate, int samplesPerFrame );
  74. /*********************************************************************************
  75. * Write to the data chunk portion of a WAV file.
  76. * Returns bytes written or negative error code.
  77. */
  78. long Audio_WAV_WriteShorts( WAV_Writer *writer,
  79. short *samples,
  80. int numSamples
  81. );
  82. /*********************************************************************************
  83. * Close WAV file.
  84. * Update chunk sizes so it can be read by audio applications.
  85. */
  86. long Audio_WAV_CloseWriter( WAV_Writer *writer );
  87. #ifdef __cplusplus
  88. };
  89. #endif
  90. #endif /* _WAV_WRITER_H */