raw.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. ** Copyright (C) 1999-2011 Erik de Castro Lopo <[email protected]>
  3. **
  4. ** This program is free software; you can redistribute it and/or modify
  5. ** it under the terms of the GNU Lesser General Public License as published by
  6. ** the Free Software Foundation; either version 2.1 of the License, or
  7. ** (at your option) any later version.
  8. **
  9. ** This program is distributed in the hope that it will be useful,
  10. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ** GNU Lesser General Public License for more details.
  13. **
  14. ** You should have received a copy of the GNU Lesser General Public License
  15. ** along with this program; if not, write to the Free Software
  16. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include "sfconfig.h"
  19. #include <stdio.h>
  20. #include "sndfile.h"
  21. #include "common.h"
  22. /*------------------------------------------------------------------------------
  23. ** Public function.
  24. */
  25. int
  26. raw_open (SF_PRIVATE *psf)
  27. { int subformat, error = SFE_NO_ERROR ;
  28. subformat = SF_CODEC (psf->sf.format) ;
  29. psf->endian = SF_ENDIAN (psf->sf.format) ;
  30. if (CPU_IS_BIG_ENDIAN && (psf->endian == 0 || psf->endian == SF_ENDIAN_CPU))
  31. psf->endian = SF_ENDIAN_BIG ;
  32. else if (CPU_IS_LITTLE_ENDIAN && (psf->endian == 0 || psf->endian == SF_ENDIAN_CPU))
  33. psf->endian = SF_ENDIAN_LITTLE ;
  34. psf->blockwidth = psf->bytewidth * psf->sf.channels ;
  35. psf->dataoffset = 0 ;
  36. psf->datalength = psf->filelength ;
  37. switch (subformat)
  38. { case SF_FORMAT_PCM_S8 :
  39. error = pcm_init (psf) ;
  40. break ;
  41. case SF_FORMAT_PCM_U8 :
  42. error = pcm_init (psf) ;
  43. break ;
  44. case SF_FORMAT_PCM_16 :
  45. case SF_FORMAT_PCM_24 :
  46. case SF_FORMAT_PCM_32 :
  47. error = pcm_init (psf) ;
  48. break ;
  49. case SF_FORMAT_ULAW :
  50. error = ulaw_init (psf) ;
  51. break ;
  52. case SF_FORMAT_ALAW :
  53. error = alaw_init (psf) ;
  54. break ;
  55. case SF_FORMAT_GSM610 :
  56. error = gsm610_init (psf) ;
  57. break ;
  58. /* Lite remove start */
  59. case SF_FORMAT_NMS_ADPCM_16 :
  60. case SF_FORMAT_NMS_ADPCM_24 :
  61. case SF_FORMAT_NMS_ADPCM_32 :
  62. error = nms_adpcm_init (psf) ;
  63. break ;
  64. case SF_FORMAT_FLOAT :
  65. error = float32_init (psf) ;
  66. break ;
  67. case SF_FORMAT_DOUBLE :
  68. error = double64_init (psf) ;
  69. break ;
  70. case SF_FORMAT_DWVW_12 :
  71. error = dwvw_init (psf, 12) ;
  72. break ;
  73. case SF_FORMAT_DWVW_16 :
  74. error = dwvw_init (psf, 16) ;
  75. break ;
  76. case SF_FORMAT_DWVW_24 :
  77. error = dwvw_init (psf, 24) ;
  78. break ;
  79. case SF_FORMAT_VOX_ADPCM :
  80. error = vox_adpcm_init (psf) ;
  81. break ;
  82. /* Lite remove end */
  83. default : return SFE_BAD_OPEN_FORMAT ;
  84. } ;
  85. return error ;
  86. } /* raw_open */