memops.c 32.3 KB
Newer Older
sletz's avatar
sletz committed
1001
1002
		rm1 = r;

1003
		float_16_scaled (xp, *((int16_t*) dst));
sletz's avatar
sletz committed
1004
1005
1006

		/* Intrinsic z^-1 delay */
		idx = (idx + 1) & DITHER_BUF_MASK;
1007
		state->e[idx] = *((int16_t*) dst) - xe;
sletz's avatar
sletz committed
1008
1009
1010
1011
1012
1013
1014
1015

		dst += dst_skip;
		src++;
	}
	state->rm1 = rm1;
	state->idx = idx;
}

1016
void sample_move_dS_s16s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip) 	
sletz's avatar
sletz committed
1017
1018
{
	short z;
1019
	const jack_default_audio_sample_t scaling = 1.0/SAMPLE_16BIT_SCALING;
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
#ifdef __ARM_NEON__
	const float32x4_t vscaling = vdupq_n_f32(scaling);
	unsigned long unrolled = nsamples / 4;
	while (unrolled--) {
		int16x4_t source16x4;
		switch(src_skip) {
			case 2:
				source16x4 = vld1_s16((int16_t*)src);
				break;
			case 4:
				source16x4 = vld2_s16((int16_t*)src).val[0];
				break;
			default:
				source16x4 = vld1_lane_s16((int16_t*)src,              source16x4, 0);
				source16x4 = vld1_lane_s16((int16_t*)(src+src_skip),   source16x4, 1);
				source16x4 = vld1_lane_s16((int16_t*)(src+2*src_skip), source16x4, 2);
				source16x4 = vld1_lane_s16((int16_t*)(src+3*src_skip), source16x4, 3);
				break;
		}
		source16x4 = vreinterpret_s16_u8(vrev16_u8(vreinterpret_u8_s16(source16x4)));
		int32x4_t source32x4 = vmovl_s16(source16x4);
		src += 4 * src_skip;

		float32x4_t converted = vcvtq_f32_s32(source32x4);
		float32x4_t scaled = vmulq_f32(converted, vscaling);
		vst1q_f32(dst, scaled);
		dst += 4;
	}
	nsamples = nsamples & 3;
#endif
sletz's avatar
sletz committed
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061

	/* ALERT: signed sign-extension portability !!! */
	while (nsamples--) {
#if __BYTE_ORDER == __LITTLE_ENDIAN
		z = (unsigned char)(src[0]);
		z <<= 8;
		z |= (unsigned char)(src[1]);
#elif __BYTE_ORDER == __BIG_ENDIAN
		z = (unsigned char)(src[1]);
		z <<= 8;
		z |= (unsigned char)(src[0]);
#endif
1062
		*dst = z * scaling;
sletz's avatar
sletz committed
1063
1064
1065
1066
1067
		dst++;
		src += src_skip;
	}
}	

sletz's avatar
sletz committed
1068
1069
1070
void sample_move_dS_s16 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip) 
{
	/* ALERT: signed sign-extension portability !!! */
1071
	const jack_default_audio_sample_t scaling = 1.0/SAMPLE_16BIT_SCALING;
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
#ifdef __ARM_NEON__
	const float32x4_t vscaling = vdupq_n_f32(scaling);
	unsigned long unrolled = nsamples / 4;
	while (unrolled--) {
		int16x4_t source16x4;
		switch(src_skip) {
			case 2:
				source16x4 = vld1_s16((int16_t*)src);
				break;
			case 4:
				source16x4 = vld2_s16((int16_t*)src).val[0];
				break;
			default:
				source16x4 = vld1_lane_s16((int16_t*)src,              source16x4, 0);
				source16x4 = vld1_lane_s16((int16_t*)(src+src_skip),   source16x4, 1);
				source16x4 = vld1_lane_s16((int16_t*)(src+2*src_skip), source16x4, 2);
				source16x4 = vld1_lane_s16((int16_t*)(src+3*src_skip), source16x4, 3);
				break;
		}
		int32x4_t source32x4 = vmovl_s16(source16x4);
		src += 4 * src_skip;

		float32x4_t converted = vcvtq_f32_s32(source32x4);
		float32x4_t scaled = vmulq_f32(converted, vscaling);
		vst1q_f32(dst, scaled);
		dst += 4;
	}
	nsamples = nsamples & 3;
#endif

sletz's avatar
sletz committed
1102
	while (nsamples--) {
1103
		*dst = (*((short *) src)) * scaling;
sletz's avatar
sletz committed
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
		dst++;
		src += src_skip;
	}
}	

void memset_interleave (char *dst, char val, unsigned long bytes, 
			unsigned long unit_bytes, 
			unsigned long skip_bytes) 
{
	switch (unit_bytes) {
	case 1:
		while (bytes--) {
			*dst = val;
			dst += skip_bytes;
		}
		break;
	case 2:
		while (bytes) {
			*((short *) dst) = (short) val;
			dst += skip_bytes;
			bytes -= 2;
		}
		break;
	case 4:		    
		while (bytes) {
			*((int *) dst) = (int) val;
			dst += skip_bytes;
			bytes -= 4;
		}
		break;
	default:
		while (bytes) {
			memset(dst, val, unit_bytes);
			dst += skip_bytes;
			bytes -= unit_bytes;
		}
		break;
	}
}

/* COPY FUNCTIONS: used to move data from an input channel to an
   output channel. Note that we assume that the skip distance
   is the same for both channels. This is completely fine
   unless the input and output were on different audio interfaces that
   were interleaved differently. We don't try to handle that.
*/

void 
memcpy_fake (char *dst, char *src, unsigned long src_bytes, unsigned long foo, unsigned long bar)
{
	memcpy (dst, src, src_bytes);
}

void 
memcpy_interleave_d16_s16 (char *dst, char *src, unsigned long src_bytes,
			   unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
{
	while (src_bytes) {
		*((short *) dst) = *((short *) src);
		dst += dst_skip_bytes;
		src += src_skip_bytes;
		src_bytes -= 2;
	}
}

void 
memcpy_interleave_d24_s24 (char *dst, char *src, unsigned long src_bytes,
			   unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
{
	while (src_bytes) {
		memcpy(dst, src, 3);
		dst += dst_skip_bytes;
		src += src_skip_bytes;
		src_bytes -= 3;
	}
}

void 
memcpy_interleave_d32_s32 (char *dst, char *src, unsigned long src_bytes,
			   unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
{
	while (src_bytes) {
		*((int *) dst) = *((int *) src);
		dst += dst_skip_bytes;
		src += src_skip_bytes;
		src_bytes -= 4;
	}
}
1192
For faster browsing, not all history is shown. View entire blame