📄 sndcvt.c
字号:
float scale, float *peak){ float *floats = (float *) buf1; unsigned char *bytes = (unsigned char *) buf2; int i; scale /= SCALE_FACTOR_TO_BYTE; for (i = 0; i < len2; i++) { *floats++ = (((int) (*bytes++)) - 128) * scale; } return len2;}long cvt_from_pcm_8(void *buf1, void *buf2, long len2, float scale, float *peak){ float *floats = (float *) buf1; unsigned char *bytes = (unsigned char *) buf2; int i; scale /= SCALE_FACTOR_TO_BYTE; for (i = 0; i < len2; i++) { *floats++ = (((int) (*bytes++) ^ 128) - 128) * scale; } return len2;}long cvt_from_pcm_16(void *buf1, void *buf2, long len2, float scale, float *peak){ float *floats = (float *) buf1; short *shorts = (short *) buf2; int i; scale /= SCALE_FACTOR_TO_SHORT; for (i = 0; i < len2; i++) { *floats++ = *shorts++ * scale; } return len2;}long cvt_from_float_32(void *buf1, void *buf2, long len2, float scale, float *peak){ float *floats1 = (float *) buf1; float *floats2 = (float *) buf2; int i; for (i = 0; i < len2; i++) { *floats1++ = *floats2++ * scale; } return len2;}long cvt_from_pcm_32(void *buf1, void *buf2, long len2, float scale, float *peak){ float *floats = (float *) buf1; long *longs = (long *) buf2; int i; scale /= SCALE_FACTOR_TO_LONG; for (i = 0; i < len2; i++) { *floats++ = *longs++ * scale; } return len2;}long cvt_from_unknown(void *buf1, void *buf2, long len2, float scale, float *peak){ snd_fail("snd_convert: unknown conversion"); return 0;}/* snd.h says: #define cvt_to_unknown cvt_from_unknown */long cvt_to_alaw_8 (void *buf1, void *buf2, long len2, float scale, float *peak){ unsigned char *bytes = (unsigned char *) buf1; float *floats = (float *) buf2; long i; FASTFLOAT s, max_sample = 0.0; scale *= SCALE_FACTOR_TO_SHORT; for (i = 0; i < len2; i++) { s = scale * floats[i]; if (s > 0) { if (s > max_sample) { max_sample = s; } s += 0.5; } else { if (-s > max_sample) { max_sample = -s; } s -= 0.5; } bytes[i] = st_linear_to_ulaw ((int) s); } *peak = (float) (max_sample / SCALE_FACTOR_TO_SHORT); return len2;}long cvt_to_ulaw_8(void *buf1, void *buf2, long len2, float scale, float *peak){ unsigned char *bytes = (unsigned char *) buf1; float *floats = (float *) buf2; int i; FASTFLOAT max_sample = 0.0; scale *= SCALE_FACTOR_TO_SHORT; for (i = 0; i < len2; i++) { FASTFLOAT s = *floats++ * scale; /* round down, e.g. -4.5 => -5: */ if (s > 0) { if (s > max_sample) max_sample = s; s += 0.5; } else { if (-s > max_sample) max_sample = -s; s -= 0.5; } *bytes++ = st_linear_to_ulaw((int) s); } *peak = (float) (max_sample / SCALE_FACTOR_TO_SHORT); return len2;}long cvt_to_upcm_8(void *buf1, void *buf2, long len2, float scale, float *peak){ unsigned char *bytes = (unsigned char *) buf1; float *floats = (float *) buf2; int i; FASTFLOAT max_sample = 0.0; scale *= SCALE_FACTOR_TO_BYTE; for (i = 0; i < len2; i++) { FASTFLOAT s = *floats++ * scale; /* round down, e.g. -4.5 => -5: */ if (s > 0) { if (s > max_sample) max_sample = s; s += 0.5; } else { if (-s > max_sample) max_sample = -s; s -= 0.5; } *bytes++ = ((int) s) ^ 128; } *peak = (float) (max_sample / SCALE_FACTOR_TO_BYTE); return len2;}long cvt_to_pcm_8(void *buf1, void *buf2, long len2, float scale, float *peak){ unsigned char *bytes = (unsigned char *) buf1; float *floats = (float *) buf2; int i; FASTFLOAT max_sample = 0.0; len2 = len2; scale *= SCALE_FACTOR_TO_BYTE; for (i = 0; i < len2; i++) { FASTFLOAT s = *floats++ * scale; /* round down, e.g. -4.5 => -5: */ if (s > 0) { if (s > max_sample) max_sample = s; s += 0.5; } else { if (-s > max_sample) max_sample = -s; s -= 0.5; } *bytes++ = (int) s; } *peak = (float) (max_sample / SCALE_FACTOR_TO_BYTE); return len2;}long cvt_to_upcm_16(void *buf1, void *buf2, long len2, float scale, float *peak){ short *shorts = (short *) buf1; float *floats = (float *) buf2; int i; FASTFLOAT max_sample = 0.0; scale *= SCALE_FACTOR_TO_SHORT; for (i = 0; i < len2; i++) { FASTFLOAT s = *floats++ * scale; /* round down, e.g. -4.5 => -5: */ if (s > 0) { if (s > max_sample) max_sample = s; s += 0.5; } else { if (-s > max_sample) max_sample = -s; s -= 0.5; } *shorts++ = ((short) s) ^ 32768; // dmazzoni } *peak = (float) (max_sample / SCALE_FACTOR_TO_SHORT); return len2;}long cvt_to_pcm_16(void *buf1, void *buf2, long len2, float scale, float *peak){ short *shorts = (short *) buf1; float *floats = (float *) buf2; int i; FASTFLOAT max_sample = 0.0; scale *= SCALE_FACTOR_TO_SHORT; for (i = 0; i < len2; i++) { FASTFLOAT s = *floats++ * scale; /* round down, e.g. -4.5 => -5: */ if (s > 0) { if (s > max_sample) max_sample = s; s += 0.5; } else { if (-s > max_sample) max_sample = -s; s -= 0.5; } *shorts++ = (short) s; } *peak = (float) (max_sample / SCALE_FACTOR_TO_SHORT); return len2;}long cvt_to_float_32(void *buf1, void *buf2, long len2, float scale, float *peak){ unsigned char *longs = (unsigned char *) buf1; float *floats = (float *) buf2; int i; FASTFLOAT max_sample = 0.0; for (i = 0; i < len2; i++) { FASTFLOAT s = *floats++ * scale; if (s > max_sample) max_sample = s; if (-s > max_sample) max_sample = -s; *floats++ = (float) s; } *peak = (float) max_sample; return len2;}long cvt_to_upcm_32(void *buf1, void *buf2, long len2, float scale, float *peak){ long *longs = (long *) buf1; float *floats = (float *) buf2; int i; FASTFLOAT max_sample = 0.0; scale *= SCALE_FACTOR_TO_LONG; for (i = 0; i < len2; i++) { FASTFLOAT s = *floats++ * scale; /* round down, e.g. -4.5 => -5: */ if (s > 0) { if (s > max_sample) max_sample = s; s += 0.5; } else { if (-s > max_sample) max_sample = -s; s -= 0.5; } *longs++ = ((long) s) ^ (1 << 31); // dmazzoni } *peak = (float) (max_sample / SCALE_FACTOR_TO_LONG); return len2;}long cvt_to_pcm_32(void *buf1, void *buf2, long len2, float scale, float *peak){ long *longs = (long *) buf1; float *floats = (float *) buf2; int i; FASTFLOAT max_sample = 0.0; scale *= SCALE_FACTOR_TO_LONG; for (i = 0; i < len2; i++) { FASTFLOAT s = *floats++ * scale; /* round down, e.g. -4.5 => -5: */ if (s > 0) { if (s > max_sample) max_sample = s; s += 0.5; } else { if (-s > max_sample) max_sample = -s; s -= 0.5; } *longs++ = (long) s; } *peak = (float) (max_sample / SCALE_FACTOR_TO_LONG); return len2;}cvtfn_type cvt_from_8[] = { cvt_from_unknown, cvt_from_pcm_8, cvt_from_ulaw_8, cvt_from_alaw_8, cvt_from_unknown, cvt_from_upcm_8, cvt_from_unknown };cvtfn_type cvt_from_16[] = { cvt_from_unknown, cvt_from_pcm_16, cvt_from_unknown, cvt_from_unknown, cvt_from_unknown, cvt_from_unknown, cvt_from_unknown };cvtfn_type cvt_from_32[] = { cvt_from_unknown, cvt_from_pcm_32, cvt_from_unknown, cvt_from_unknown, cvt_from_float_32, cvt_from_unknown, cvt_from_unknown };cvtfn_type cvt_to_8[] = { cvt_to_unknown, cvt_to_pcm_8, cvt_to_ulaw_8, cvt_to_alaw_8, cvt_to_unknown, cvt_to_upcm_8, cvt_to_unknown };cvtfn_type cvt_to_16[] = { cvt_to_unknown, cvt_to_pcm_16, cvt_to_unknown, cvt_to_unknown, cvt_to_unknown, cvt_to_upcm_16, cvt_to_unknown };cvtfn_type cvt_to_32[] = { cvt_to_unknown, cvt_to_pcm_32, cvt_to_unknown, cvt_to_unknown, cvt_to_float_32, cvt_to_upcm_32, cvt_to_unknown };/* select_cvtfn -- find conversion from snd2 to snd1 *//* * conversion is based on bits and mode (channels and srate * are ignored). Either snd1 or snd2 must be of SND_MODE_FLOAT. */cvtfn_type select_cvtfn(snd_type snd1, snd_type snd2){ long mode1 = snd1->format.mode; long mode2 = snd2->format.mode; if (mode1 == SND_MODE_FLOAT) { long bits2 = snd2->format.bits; /* convert_from functions */ if (bits2 == 8) return cvt_from_8[mode2]; else if (bits2 == 16) return cvt_from_16[mode2]; else if (bits2 == 32) return cvt_from_32[mode2]; else return &cvt_from_unknown; } else if (mode2 == SND_MODE_FLOAT) { long bits1 = snd1->format.bits; /* convert_to functions */ if (bits1 == 8) return cvt_to_8[mode1]; else if (bits1 == 16) return cvt_to_16[mode1]; else if (bits1 == 32) return cvt_to_32[mode1]; else return &cvt_to_unknown; } else return &cvt_from_unknown;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -