src/audio/SDL_audiocvt.c
branchSDL-1.3
changeset 1659 14717b52abc0
parent 1428 5f52867ba65c
child 1662 782fd950bd46
child 1895 c121d94672cb
child 3863 4e23720e4278
equal deleted inserted replaced
1658:e49147870aac 1659:14717b52abc0
    25 
    25 
    26 #include "SDL_audio.h"
    26 #include "SDL_audio.h"
    27 
    27 
    28 
    28 
    29 /* Effectively mix right and left channels into a single channel */
    29 /* Effectively mix right and left channels into a single channel */
    30 void SDL_ConvertMono(SDL_AudioCVT *cvt, Uint16 format)
    30 void SDLCALL SDL_ConvertMono(SDL_AudioCVT *cvt, Uint16 format)
    31 {
    31 {
    32 	int i;
    32 	int i;
    33 	Sint32 sample;
    33 	Sint32 sample;
    34 
    34 
    35 #ifdef DEBUG_CONVERT
    35 #ifdef DEBUG_CONVERT
   167 		cvt->filters[cvt->filter_index](cvt, format);
   167 		cvt->filters[cvt->filter_index](cvt, format);
   168 	}
   168 	}
   169 }
   169 }
   170 
   170 
   171 /* Discard top 4 channels */
   171 /* Discard top 4 channels */
   172 void SDL_ConvertStrip(SDL_AudioCVT *cvt, Uint16 format)
   172 void SDLCALL SDL_ConvertStrip(SDL_AudioCVT *cvt, Uint16 format)
   173 {
   173 {
   174 	int i;
   174 	int i;
   175 	Sint32 lsample, rsample;
   175 	Sint32 lsample, rsample;
   176 
   176 
   177 #ifdef DEBUG_CONVERT
   177 #ifdef DEBUG_CONVERT
   283 	}
   283 	}
   284 }
   284 }
   285 
   285 
   286 
   286 
   287 /* Discard top 2 channels of 6 */
   287 /* Discard top 2 channels of 6 */
   288 void SDL_ConvertStrip_2(SDL_AudioCVT *cvt, Uint16 format)
   288 void SDLCALL SDL_ConvertStrip_2(SDL_AudioCVT *cvt, Uint16 format)
   289 {
   289 {
   290 	int i;
   290 	int i;
   291 	Sint32 lsample, rsample;
   291 	Sint32 lsample, rsample;
   292 
   292 
   293 #ifdef DEBUG_CONVERT
   293 #ifdef DEBUG_CONVERT
   398 		cvt->filters[cvt->filter_index](cvt, format);
   398 		cvt->filters[cvt->filter_index](cvt, format);
   399 	}
   399 	}
   400 }
   400 }
   401 
   401 
   402 /* Duplicate a mono channel to both stereo channels */
   402 /* Duplicate a mono channel to both stereo channels */
   403 void SDL_ConvertStereo(SDL_AudioCVT *cvt, Uint16 format)
   403 void SDLCALL SDL_ConvertStereo(SDL_AudioCVT *cvt, Uint16 format)
   404 {
   404 {
   405 	int i;
   405 	int i;
   406 
   406 
   407 #ifdef DEBUG_CONVERT
   407 #ifdef DEBUG_CONVERT
   408 	fprintf(stderr, "Converting to stereo\n");
   408 	fprintf(stderr, "Converting to stereo\n");
   436 	}
   436 	}
   437 }
   437 }
   438 
   438 
   439 
   439 
   440 /* Duplicate a stereo channel to a pseudo-5.1 stream */
   440 /* Duplicate a stereo channel to a pseudo-5.1 stream */
   441 void SDL_ConvertSurround(SDL_AudioCVT *cvt, Uint16 format)
   441 void SDLCALL SDL_ConvertSurround(SDL_AudioCVT *cvt, Uint16 format)
   442 {
   442 {
   443 	int i;
   443 	int i;
   444 
   444 
   445 #ifdef DEBUG_CONVERT
   445 #ifdef DEBUG_CONVERT
   446 	fprintf(stderr, "Converting stereo to surround\n");
   446 	fprintf(stderr, "Converting stereo to surround\n");
   613 	}
   613 	}
   614 }
   614 }
   615 
   615 
   616 
   616 
   617 /* Duplicate a stereo channel to a pseudo-4.0 stream */
   617 /* Duplicate a stereo channel to a pseudo-4.0 stream */
   618 void SDL_ConvertSurround_4(SDL_AudioCVT *cvt, Uint16 format)
   618 void SDLCALL SDL_ConvertSurround_4(SDL_AudioCVT *cvt, Uint16 format)
   619 {
   619 {
   620 	int i;
   620 	int i;
   621 
   621 
   622 #ifdef DEBUG_CONVERT
   622 #ifdef DEBUG_CONVERT
   623 	fprintf(stderr, "Converting stereo to quad\n");
   623 	fprintf(stderr, "Converting stereo to quad\n");
   766 	}
   766 	}
   767 }
   767 }
   768 
   768 
   769 
   769 
   770 /* Convert 8-bit to 16-bit - LSB */
   770 /* Convert 8-bit to 16-bit - LSB */
   771 void SDL_Convert16LSB(SDL_AudioCVT *cvt, Uint16 format)
   771 void SDLCALL SDL_Convert16LSB(SDL_AudioCVT *cvt, Uint16 format)
   772 {
   772 {
   773 	int i;
   773 	int i;
   774 	Uint8 *src, *dst;
   774 	Uint8 *src, *dst;
   775 
   775 
   776 #ifdef DEBUG_CONVERT
   776 #ifdef DEBUG_CONVERT
   789 	if ( cvt->filters[++cvt->filter_index] ) {
   789 	if ( cvt->filters[++cvt->filter_index] ) {
   790 		cvt->filters[cvt->filter_index](cvt, format);
   790 		cvt->filters[cvt->filter_index](cvt, format);
   791 	}
   791 	}
   792 }
   792 }
   793 /* Convert 8-bit to 16-bit - MSB */
   793 /* Convert 8-bit to 16-bit - MSB */
   794 void SDL_Convert16MSB(SDL_AudioCVT *cvt, Uint16 format)
   794 void SDLCALL SDL_Convert16MSB(SDL_AudioCVT *cvt, Uint16 format)
   795 {
   795 {
   796 	int i;
   796 	int i;
   797 	Uint8 *src, *dst;
   797 	Uint8 *src, *dst;
   798 
   798 
   799 #ifdef DEBUG_CONVERT
   799 #ifdef DEBUG_CONVERT
   813 		cvt->filters[cvt->filter_index](cvt, format);
   813 		cvt->filters[cvt->filter_index](cvt, format);
   814 	}
   814 	}
   815 }
   815 }
   816 
   816 
   817 /* Convert 16-bit to 8-bit */
   817 /* Convert 16-bit to 8-bit */
   818 void SDL_Convert8(SDL_AudioCVT *cvt, Uint16 format)
   818 void SDLCALL SDL_Convert8(SDL_AudioCVT *cvt, Uint16 format)
   819 {
   819 {
   820 	int i;
   820 	int i;
   821 	Uint8 *src, *dst;
   821 	Uint8 *src, *dst;
   822 
   822 
   823 #ifdef DEBUG_CONVERT
   823 #ifdef DEBUG_CONVERT
   839 		cvt->filters[cvt->filter_index](cvt, format);
   839 		cvt->filters[cvt->filter_index](cvt, format);
   840 	}
   840 	}
   841 }
   841 }
   842 
   842 
   843 /* Toggle signed/unsigned */
   843 /* Toggle signed/unsigned */
   844 void SDL_ConvertSign(SDL_AudioCVT *cvt, Uint16 format)
   844 void SDLCALL SDL_ConvertSign(SDL_AudioCVT *cvt, Uint16 format)
   845 {
   845 {
   846 	int i;
   846 	int i;
   847 	Uint8 *data;
   847 	Uint8 *data;
   848 
   848 
   849 #ifdef DEBUG_CONVERT
   849 #ifdef DEBUG_CONVERT
   868 		cvt->filters[cvt->filter_index](cvt, format);
   868 		cvt->filters[cvt->filter_index](cvt, format);
   869 	}
   869 	}
   870 }
   870 }
   871 
   871 
   872 /* Toggle endianness */
   872 /* Toggle endianness */
   873 void SDL_ConvertEndian(SDL_AudioCVT *cvt, Uint16 format)
   873 void SDLCALL SDL_ConvertEndian(SDL_AudioCVT *cvt, Uint16 format)
   874 {
   874 {
   875 	int i;
   875 	int i;
   876 	Uint8 *data, tmp;
   876 	Uint8 *data, tmp;
   877 
   877 
   878 #ifdef DEBUG_CONVERT
   878 #ifdef DEBUG_CONVERT
   890 		cvt->filters[cvt->filter_index](cvt, format);
   890 		cvt->filters[cvt->filter_index](cvt, format);
   891 	}
   891 	}
   892 }
   892 }
   893 
   893 
   894 /* Convert rate up by multiple of 2 */
   894 /* Convert rate up by multiple of 2 */
   895 void SDL_RateMUL2(SDL_AudioCVT *cvt, Uint16 format)
   895 void SDLCALL SDL_RateMUL2(SDL_AudioCVT *cvt, Uint16 format)
   896 {
   896 {
   897 	int i;
   897 	int i;
   898 	Uint8 *src, *dst;
   898 	Uint8 *src, *dst;
   899 
   899 
   900 #ifdef DEBUG_CONVERT
   900 #ifdef DEBUG_CONVERT
   928 	}
   928 	}
   929 }
   929 }
   930 
   930 
   931 
   931 
   932 /* Convert rate up by multiple of 2, for stereo */
   932 /* Convert rate up by multiple of 2, for stereo */
   933 void SDL_RateMUL2_c2(SDL_AudioCVT *cvt, Uint16 format)
   933 void SDLCALL SDL_RateMUL2_c2(SDL_AudioCVT *cvt, Uint16 format)
   934 {
   934 {
   935 	int i;
   935 	int i;
   936 	Uint8 *src, *dst;
   936 	Uint8 *src, *dst;
   937 
   937 
   938 #ifdef DEBUG_CONVERT
   938 #ifdef DEBUG_CONVERT
   971 		cvt->filters[cvt->filter_index](cvt, format);
   971 		cvt->filters[cvt->filter_index](cvt, format);
   972 	}
   972 	}
   973 }
   973 }
   974 
   974 
   975 /* Convert rate up by multiple of 2, for quad */
   975 /* Convert rate up by multiple of 2, for quad */
   976 void SDL_RateMUL2_c4(SDL_AudioCVT *cvt, Uint16 format)
   976 void SDLCALL SDL_RateMUL2_c4(SDL_AudioCVT *cvt, Uint16 format)
   977 {
   977 {
   978 	int i;
   978 	int i;
   979 	Uint8 *src, *dst;
   979 	Uint8 *src, *dst;
   980 
   980 
   981 #ifdef DEBUG_CONVERT
   981 #ifdef DEBUG_CONVERT
  1027 	}
  1027 	}
  1028 }
  1028 }
  1029 
  1029 
  1030 
  1030 
  1031 /* Convert rate up by multiple of 2, for 5.1 */
  1031 /* Convert rate up by multiple of 2, for 5.1 */
  1032 void SDL_RateMUL2_c6(SDL_AudioCVT *cvt, Uint16 format)
  1032 void SDLCALL SDL_RateMUL2_c6(SDL_AudioCVT *cvt, Uint16 format)
  1033 {
  1033 {
  1034 	int i;
  1034 	int i;
  1035 	Uint8 *src, *dst;
  1035 	Uint8 *src, *dst;
  1036 
  1036 
  1037 #ifdef DEBUG_CONVERT
  1037 #ifdef DEBUG_CONVERT
  1094 		cvt->filters[cvt->filter_index](cvt, format);
  1094 		cvt->filters[cvt->filter_index](cvt, format);
  1095 	}
  1095 	}
  1096 }
  1096 }
  1097 
  1097 
  1098 /* Convert rate down by multiple of 2 */
  1098 /* Convert rate down by multiple of 2 */
  1099 void SDL_RateDIV2(SDL_AudioCVT *cvt, Uint16 format)
  1099 void SDLCALL SDL_RateDIV2(SDL_AudioCVT *cvt, Uint16 format)
  1100 {
  1100 {
  1101 	int i;
  1101 	int i;
  1102 	Uint8 *src, *dst;
  1102 	Uint8 *src, *dst;
  1103 
  1103 
  1104 #ifdef DEBUG_CONVERT
  1104 #ifdef DEBUG_CONVERT
  1129 	}
  1129 	}
  1130 }
  1130 }
  1131 
  1131 
  1132 
  1132 
  1133 /* Convert rate down by multiple of 2, for stereo */
  1133 /* Convert rate down by multiple of 2, for stereo */
  1134 void SDL_RateDIV2_c2(SDL_AudioCVT *cvt, Uint16 format)
  1134 void SDLCALL SDL_RateDIV2_c2(SDL_AudioCVT *cvt, Uint16 format)
  1135 {
  1135 {
  1136 	int i;
  1136 	int i;
  1137 	Uint8 *src, *dst;
  1137 	Uint8 *src, *dst;
  1138 
  1138 
  1139 #ifdef DEBUG_CONVERT
  1139 #ifdef DEBUG_CONVERT
  1167 	}
  1167 	}
  1168 }
  1168 }
  1169 
  1169 
  1170 
  1170 
  1171 /* Convert rate down by multiple of 2, for quad */
  1171 /* Convert rate down by multiple of 2, for quad */
  1172 void SDL_RateDIV2_c4(SDL_AudioCVT *cvt, Uint16 format)
  1172 void SDLCALL SDL_RateDIV2_c4(SDL_AudioCVT *cvt, Uint16 format)
  1173 {
  1173 {
  1174 	int i;
  1174 	int i;
  1175 	Uint8 *src, *dst;
  1175 	Uint8 *src, *dst;
  1176 
  1176 
  1177 #ifdef DEBUG_CONVERT
  1177 #ifdef DEBUG_CONVERT
  1210 		cvt->filters[cvt->filter_index](cvt, format);
  1210 		cvt->filters[cvt->filter_index](cvt, format);
  1211 	}
  1211 	}
  1212 }
  1212 }
  1213 
  1213 
  1214 /* Convert rate down by multiple of 2, for 5.1 */
  1214 /* Convert rate down by multiple of 2, for 5.1 */
  1215 void SDL_RateDIV2_c6(SDL_AudioCVT *cvt, Uint16 format)
  1215 void SDLCALL SDL_RateDIV2_c6(SDL_AudioCVT *cvt, Uint16 format)
  1216 {
  1216 {
  1217 	int i;
  1217 	int i;
  1218 	Uint8 *src, *dst;
  1218 	Uint8 *src, *dst;
  1219 
  1219 
  1220 #ifdef DEBUG_CONVERT
  1220 #ifdef DEBUG_CONVERT
  1259 		cvt->filters[cvt->filter_index](cvt, format);
  1259 		cvt->filters[cvt->filter_index](cvt, format);
  1260 	}
  1260 	}
  1261 }
  1261 }
  1262 
  1262 
  1263 /* Very slow rate conversion routine */
  1263 /* Very slow rate conversion routine */
  1264 void SDL_RateSLOW(SDL_AudioCVT *cvt, Uint16 format)
  1264 void SDLCALL SDL_RateSLOW(SDL_AudioCVT *cvt, Uint16 format)
  1265 {
  1265 {
  1266 	double ipos;
  1266 	double ipos;
  1267 	int i, clen;
  1267 	int i, clen;
  1268 
  1268 
  1269 #ifdef DEBUG_CONVERT
  1269 #ifdef DEBUG_CONVERT
  1472 	cvt->rate_incr = 0.0;
  1472 	cvt->rate_incr = 0.0;
  1473 	if ( (src_rate/100) != (dst_rate/100) ) {
  1473 	if ( (src_rate/100) != (dst_rate/100) ) {
  1474 		Uint32 hi_rate, lo_rate;
  1474 		Uint32 hi_rate, lo_rate;
  1475 		int len_mult;
  1475 		int len_mult;
  1476 		double len_ratio;
  1476 		double len_ratio;
  1477 		void (*rate_cvt)(SDL_AudioCVT *cvt, Uint16 format);
  1477 		void (SDLCALL *rate_cvt)(SDL_AudioCVT *cvt, Uint16 format);
  1478 
  1478 
  1479 		if ( src_rate > dst_rate ) {
  1479 		if ( src_rate > dst_rate ) {
  1480 			hi_rate = src_rate;
  1480 			hi_rate = src_rate;
  1481 			lo_rate = dst_rate;
  1481 			lo_rate = dst_rate;
  1482 			switch (src_channels) {
  1482 			switch (src_channels) {