⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 effect_position.c

📁 SDL_mixer 是一个基于 SDL 的混音器
💻 C
📖 第 1 页 / 共 4 页
字号:
		    case 2:            		f = (_Eff_build_volume_table_u8()) ? _Eff_position_table_u8 :                                                 		_Eff_position_u8;	    		break;	    	    case 4:                        f = _Eff_position_u8_c4;	    		break;	    	    case 6:                        f = _Eff_position_u8_c6;	    		break;	    }            break;        case AUDIO_S8:	    switch (channels) {		    case 1:		    case 2:            		f = (_Eff_build_volume_table_s8()) ? _Eff_position_table_s8 :                                                 		_Eff_position_s8;	    		break;	    	    case 4:                        f = _Eff_position_s8_c4;	    		break;	    	    case 6:                        f = _Eff_position_s8_c6;	    		break;	    }            break;        case AUDIO_U16LSB:	    switch (channels) {		    case 1:		    case 2:            		f = _Eff_position_u16lsb;	    		break;	    	    case 4:            		f = _Eff_position_u16lsb_c4;	    		break;	    	    case 6:            		f = _Eff_position_u16lsb_c6;	    		break;	    }            break;        case AUDIO_S16LSB:	    switch (channels) {		    case 1:		    case 2:            		f = _Eff_position_s16lsb;	    		break;	    	    case 4:            		f = _Eff_position_s16lsb_c4;	    		break;	    	    case 6:            		f = _Eff_position_s16lsb_c6;	    		break;	    }            break;        case AUDIO_U16MSB:	    switch (channels) {		    case 1:		    case 2:            		f = _Eff_position_u16msb;	    		break;	    	    case 4:            		f = _Eff_position_u16msb_c4;	    		break;	    	    case 6:            		f = _Eff_position_u16msb_c6;	    		break;	    }            break;        case AUDIO_S16MSB:	    switch (channels) {		    case 1:		    case 2:            		f = _Eff_position_s16msb;	    		break;	    	    case 4:            		f = _Eff_position_s16msb_c4;	    		break;	    	    case 6:            		f = _Eff_position_s16msb_c6;	    		break;	    }            break;        default:            Mix_SetError("Unsupported audio format");    }    return(f);}static Uint8 speaker_amplitude[6];static void set_amplitudes(int channels, int angle, int room_angle){    int left = 255, right = 255;    int left_rear = 255, right_rear = 255, center = 255;        /* unwind the angle...it'll be between 0 and 359. */    while (angle >= 360) angle -= 360;    while (angle < 0) angle += 360;    if (channels == 2)    {        /*         * We only attenuate by position if the angle falls on the far side         *  of center; That is, an angle that's due north would not attenuate         *  either channel. Due west attenuates the right channel to 0.0, and         *  due east attenuates the left channel to 0.0. Slightly east of         *  center attenuates the left channel a little, and the right channel         *  not at all. I think of this as occlusion by one's own head.  :)         *         *   ...so, we split our angle circle into four quadrants...         */        if (angle < 90) {            left = 255 - ((int) (255.0f * (((float) angle) / 89.0f)));        } else if (angle < 180) {            left = (int) (255.0f * (((float) (angle - 90)) / 89.0f));        } else if (angle < 270) {            right = 255 - ((int) (255.0f * (((float) (angle - 180)) / 89.0f)));        } else {            right = (int) (255.0f * (((float) (angle - 270)) / 89.0f));        }    }    if (channels == 4 || channels == 6)    {        /*         *  An angle that's due north does not attenuate the center channel.         *  An angle in the first quadrant, 0-90, does not attenuate the RF.         *         *   ...so, we split our angle circle into 8 ...	 *	 *             CE	 *             0	 *     LF      |         RF	 *             |	 *  270<-------|----------->90	 *             |	 *     LR      |         RR	 *            180	 *            */        if (angle < 45) {            left = ((int) (255.0f * (((float) (180 - angle)) / 179.0f)));            left_rear = 255 - ((int) (255.0f * (((float) (angle + 45)) / 89.0f)));            right_rear = 255 - ((int) (255.0f * (((float) (90 - angle)) / 179.0f)));        } else if (angle < 90) {            center = ((int) (255.0f * (((float) (225 - angle)) / 179.0f)));            left = ((int) (255.0f * (((float) (180 - angle)) / 179.0f)));            left_rear = 255 - ((int) (255.0f * (((float) (135 - angle)) / 89.0f)));            right_rear = ((int) (255.0f * (((float) (90 + angle)) / 179.0f)));        } else if (angle < 135) {            center = ((int) (255.0f * (((float) (225 - angle)) / 179.0f)));            left = 255 - ((int) (255.0f * (((float) (angle - 45)) / 89.0f)));            right = ((int) (255.0f * (((float) (270 - angle)) / 179.0f)));            left_rear = ((int) (255.0f * (((float) (angle)) / 179.0f)));        } else if (angle < 180) {            center = 255 - ((int) (255.0f * (((float) (angle - 90)) / 89.0f)));            left = 255 - ((int) (255.0f * (((float) (225 - angle)) / 89.0f)));            right = ((int) (255.0f * (((float) (270 - angle)) / 179.0f)));            left_rear = ((int) (255.0f * (((float) (angle)) / 179.0f)));        } else if (angle < 225) {            center = 255 - ((int) (255.0f * (((float) (270 - angle)) / 89.0f)));            left = ((int) (255.0f * (((float) (angle - 90)) / 179.0f)));            right = 255 - ((int) (255.0f * (((float) (angle - 135)) / 89.0f)));            right_rear = ((int) (255.0f * (((float) (360 - angle)) / 179.0f)));        } else if (angle < 270) {            center = ((int) (255.0f * (((float) (angle - 135)) / 179.0f)));            left = ((int) (255.0f * (((float) (angle - 90)) / 179.0f)));            right = 255 - ((int) (255.0f * (((float) (315 - angle)) / 89.0f)));            right_rear = ((int) (255.0f * (((float) (360 - angle)) / 179.0f)));        } else if (angle < 315) {            center = ((int) (255.0f * (((float) (angle - 135)) / 179.0f)));            right = ((int) (255.0f * (((float) (angle - 180)) / 179.0f)));            left_rear = ((int) (255.0f * (((float) (450 - angle)) / 179.0f)));            right_rear = 255 - ((int) (255.0f * (((float) (angle - 225)) / 89.0f)));        } else {            right = ((int) (255.0f * (((float) (angle - 180)) / 179.0f)));            left_rear = ((int) (255.0f * (((float) (450 - angle)) / 179.0f)));            right_rear = 255 - ((int) (255.0f * (((float) (405 - angle)) / 89.0f)));        }    }    if (left < 0) left = 0; if (left > 255) left = 255;    if (right < 0) right = 0; if (right > 255) right = 255;    if (left_rear < 0) left_rear = 0; if (left_rear > 255) left_rear = 255;    if (right_rear < 0) right_rear = 0; if (right_rear > 255) right_rear = 255;    if (center < 0) center = 0; if (center > 255) center = 255;    if (room_angle == 90) {    	speaker_amplitude[0] = (Uint8)left_rear;    	speaker_amplitude[1] = (Uint8)left;    	speaker_amplitude[2] = (Uint8)right_rear;    	speaker_amplitude[3] = (Uint8)right;    }    else if (room_angle == 180) {	if (channels == 2) {    	    speaker_amplitude[0] = (Uint8)right;    	    speaker_amplitude[1] = (Uint8)left;	}	else {    	    speaker_amplitude[0] = (Uint8)right_rear;    	    speaker_amplitude[1] = (Uint8)left_rear;    	    speaker_amplitude[2] = (Uint8)right;    	    speaker_amplitude[3] = (Uint8)left;	}    }    else if (room_angle == 270) {    	speaker_amplitude[0] = (Uint8)right;    	speaker_amplitude[1] = (Uint8)right_rear;    	speaker_amplitude[2] = (Uint8)left;    	speaker_amplitude[3] = (Uint8)left_rear;    }    else {    	speaker_amplitude[0] = (Uint8)left;    	speaker_amplitude[1] = (Uint8)right;    	speaker_amplitude[2] = (Uint8)left_rear;    	speaker_amplitude[3] = (Uint8)right_rear;    }    speaker_amplitude[4] = (Uint8)center;    speaker_amplitude[5] = 255;}int Mix_SetPosition(int channel, Sint16 angle, Uint8 distance);int Mix_SetPanning(int channel, Uint8 left, Uint8 right){    Mix_EffectFunc_t f = NULL;    int channels;    Uint16 format;    position_args *args = NULL;    Mix_QuerySpec(NULL, &format, &channels);    if (channels != 2 && channels != 4 && channels != 6)    /* it's a no-op; we call that successful. */        return(1);    if (channels > 2) {    	/* left = 255 =>  angle = -90;  left = 0 => angle = +89 */    	int angle = (int)left;    	angle = 127 - angle;	angle = -angle;    	angle = angle * 90 / 128; /* Make it larger for more effect? */	return( Mix_SetPosition(channel, angle, 0) );    }    f = get_position_effect_func(format, channels);    if (f == NULL)        return(0);    args = get_position_arg(channel);    if (!args)        return(0);        /* it's a no-op; unregister the effect, if it's registered. */    if ((args->distance_u8 == 255) && (left == 255) &&        (right == 255) && (args->in_use))    {        return(Mix_UnregisterEffect(channel, f));    }    args->left_u8 = left;    args->left_f = ((float) left) / 255.0f;    args->right_u8 = right;    args->right_f = ((float) right) / 255.0f;    args->room_angle = 0;    if (!args->in_use) {        args->in_use = 1;        return(Mix_RegisterEffect(channel, f, _Eff_PositionDone, (void *) args));    }    return(1);}int Mix_SetDistance(int channel, Uint8 distance){    Mix_EffectFunc_t f = NULL;    Uint16 format;    position_args *args = NULL;    int channels;    Mix_QuerySpec(NULL, &format, &channels);    f = get_position_effect_func(format, channels);    if (f == NULL)        return(0);    args = get_position_arg(channel);    if (!args)        return(0);    distance = 255 - distance;  /* flip it to our scale. */        /* it's a no-op; unregister the effect, if it's registered. */    if ((distance == 255) && (args->left_u8 == 255) &&        (args->right_u8 == 255) && (args->in_use))    {        return(Mix_UnregisterEffect(channel, f));    }    args->distance_u8 = distance;    args->distance_f = ((float) distance) / 255.0f;    if (!args->in_use) {        args->in_use = 1;        return(Mix_RegisterEffect(channel, f, _Eff_PositionDone, (void *) args));    }    return(1);}int Mix_SetPosition(int channel, Sint16 angle, Uint8 distance){    Mix_EffectFunc_t f = NULL;    Uint16 format;    int channels;    position_args *args = NULL;    Sint16 room_angle;    Mix_QuerySpec(NULL, &format, &channels);    f = get_position_effect_func(format, channels);    if (f == NULL)        return(0);        /* unwind the angle...it'll be between 0 and 359. */    while (angle >= 360) angle -= 360;    while (angle < 0) angle += 360;    args = get_position_arg(channel);    if (!args)        return(0);        /* it's a no-op; unregister the effect, if it's registered. */    if ((!distance) && (!angle) && (args->in_use))        return(Mix_UnregisterEffect(channel, f));    if (channels == 2)    {	if (angle > 180)		room_angle = 180; /* exchange left and right channels */	else room_angle = 0;    }    if (channels == 4 || channels == 6)    {	if (angle > 315) room_angle = 0;	else if (angle > 225) room_angle = 270;	else if (angle > 135) room_angle = 180;	else if (angle > 45) room_angle = 90;	else room_angle = 0;    }    distance = 255 - distance;  /* flip it to scale Mix_SetDistance() uses. */    set_amplitudes(channels, angle, room_angle);    args->left_u8 = speaker_amplitude[0];    args->left_f = ((float) speaker_amplitude[0]) / 255.0f;    args->right_u8 = speaker_amplitude[1];    args->right_f = ((float) speaker_amplitude[1]) / 255.0f;    args->left_rear_u8 = speaker_amplitude[2];    args->left_rear_f = ((float) speaker_amplitude[2]) / 255.0f;    args->right_rear_u8 = speaker_amplitude[3];    args->right_rear_f = ((float) speaker_amplitude[3]) / 255.0f;    args->center_u8 = speaker_amplitude[4];    args->center_f = ((float) speaker_amplitude[4]) / 255.0f;    args->lfe_u8 = 255;    args->lfe_f = 255.0f;    args->distance_u8 = distance;    args->distance_f = ((float) distance) / 255.0f;    args->room_angle = room_angle;    if (!args->in_use) {        args->in_use = 1;        return(Mix_RegisterEffect(channel, f, _Eff_PositionDone, (void *) args));    }    return(1);}/* end of effects_position.c ... */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -