📄 compander.asm
字号:
/*** COMPANDER.ASM ******************************************************************
* *
* ADSP-21065L EZ-LAB Companding Effect Program *
* Developed using ADSP-21065L EZ-LAB Evaluation Platform *
* *
* *
* What the compander does? *
* ------------------------ *
* Combination of a compressor and expander. The peaks signal levels above the *
* upper threshold are compressed, while lower level signals above the lower *
* threshold are expanded. *
* *
* Parameters: *
* ----------- *
* Threshold: The level at which the dynamics processor begins adjusting the *
* volume of the signal. *
* Compression Ratio: Level comparison of the input and output signals of the *
* dynamics processor past the threshold. *
* *
* Future Parameters that will be added in Rev 2.0: *
* ------------------------------------------------ *
* Attack Time: The amount of time it takes once the input signal has passed the *
* threshold for the dynamics processor to begin attenuating the signal. *
* Release Time: The amount of time it takes once the input signal has passed *
* below the threshold for the dynamics processor to stop attenuating the signal *
* *
* *
* John Tomarakos *
* ADI DSP Applications Group *
* Revision 1.0 *
* 11/20/98 *
* *
*****************************************************************************************/
/* ADSP-21065L System Register bit definitions */
#include "def21065l.h"
#include "new65Ldefs.h"
.EXTERN Left_Channel;
.EXTERN Right_Channel;
.GLOBAL Stereo_Compander;
.GLOBAL select_compander_ratios;
.GLOBAL select_compander_thresholds;
.segment /dm compand;
.var IRQ1_counter = 0x00000003;
.var IRQ2_counter = 0x00000003;
.var comp_ratio = 0.05;
.var comp_threshold = 0.5;
.var expan_ratio = 1.5;
.var expan_threshold = 0.2;
.endseg;
.segment /pm pm_code;
/* //////////////////////////////////////////////////////////////////////////// *
* *
* STEREO COMPANDER ROUTINE *
* *
* //////////////////////////////////////////////////////////////////////////// */
Stereo_Compander:
r2 = DM(Left_Channel_In); /* left input sample */
r3 = DM(Right_Channel_In); /* right input sample */
r1 = -31; /* scale the sample to the range of +/-1.0 */
f2 = float r2 by r1; /* convert fixed point sample to floating point */
f3 = float r3 by r1; /* convert fixed point sample to floating point */
f0 = DM(comp_ratio); /* f0 = ratio = 1/20 */
f1 = DM(comp_threshold); /* f1 = threshold = 0.5 */
compress_left:
f4 = abs f2;
comp(f4,f1); /* Is left channel past threshold? */
if LT jump compress_right; /* If not, check the right channel */
f4 = f4 - f1; /* signal = signal - threshold */
f4 = f4 * f0; /* signal = signal * ratio */
f4 = f4 + f1; /* signal = signal + threshold */
f2 = f4 copysign f2; /* f2 now contains compressed left channel*/
compress_right:
f4 = abs f3;
comp(f4,f1); /* Is right channel past threshold? */
if LT jump expansion; /* if not, return from subroutine */
f4 = f4 - f1; /* signal = signal - threshold */
f4 = f4 * f0; /* signal = signal * ratio */
f4 = f4 + f1; /* signal = signal + threshold */
f3 = f4 copysign f3; /* f3 now contains compressed right channel*/
expansion:
f0 = DM(expan_ratio); /* f0 = ratio = 1.4 */
f1 = DM(expan_threshold); /* f1 = threshold = 0.2 */
expand_left:
f4 = abs f2;
comp(f4,f1); /* Is left channel past threshold? */
if LT jump expand_right; /* If not, check the right channel */
f4 = f4 - f1; /* signal = signal - threshold */
f4 = f4 * f0; /* signal = signal * ratio */
f4 = f4 + f1; /* signal = signal + threshold */
f2 = f4 copysign f2; /* f2 now contains compressed left channel*/
expand_right:
f4 = abs f3;
comp(f4,f1); /* Is right channel past threshold? */
if LT jump finish_processing; /* if not, return from subroutine */
f4 = f4 - f1; /* signal = signal - threshold */
f4 = f4 * f0; /* signal = signal * ratio */
f4 = f4 + f1; /* signal = signal + threshold */
f3 = f4 copysign f3; /* f3 now contains compressed right channel*/
finish_processing:
r1 = 31; /* scale the result back up to MSBs */
r2 = fix f2 by r1; /* convert back to fixed point number */
r3 = fix f3 by r1; /* convert back to fixed point number */
/* send companded results to left and right DAC channels */
DM(Left_Channel_Out) = r2;
DM(Right_Channel_Out) = r3;
rts;
/* ------------------------------------------------------------------------------------ */
/* */
/* IRQ1 Pushbutton Interrupt Service Routine */
/* */
/* This routine allows the user to modify the compression ratio. */
/* */
/* Default before 1st IRQ push: 20:1 ratio */
/* 1st Pushbutton Press: 1:1 ratio, no compression */
/* 2nd Pushbutton Press: 2:1 ratio */
/* 3rd Pushbutton Press: 4:1 ratio */
/* 4th Pushbutton Press: 8:1 ratio */
/* 5th Pushbutton Press: 20:1 ratio */
/* 6th Pushbutton Press: Reverts back to 1st Pushbutton Press */
/* */
/* The pushbutton setting is shown by the active LED setting, all others are off */
/* FLAG 4 LED is cleared, indicating the user is modifying ratio settings. */
/* ------------------------------------------------------------------------------------ */
select_compander_ratios:
bit set mode1 SRRFH; /* enable background register file */
NOP; /* 1 CYCLE LATENCY FOR WRITING TO MODE1 REGISER!! */
r13 = 5; /* number of presets */
r15 = DM(IRQ1_counter); /* get preset count */
r15 = r15 + 1; /* increment preset */
comp (r15, r13);
if ge r15 = r15 - r15; /* reset to zero */
DM(IRQ1_counter) = r15; /* save preset count */
r10 = pass r15; /* get preset mode */
if eq jump ratio_setting_2; /* check for count == 0 */
r10 = r10 - 1;
if eq jump ratio_setting_3; /* check for count == 1 */
r10 = r10 - 1;
if eq jump ratio_setting_4; /* check for count == 3 */
r10 = r10 - 1;
if eq jump ratio_setting_5; /* check for count == 4 */
ratio_setting_1: /* count therefore, is == 5 if you are here */
/* 1:1 ratio, no compression */
f14 = 0.99999; DM(comp_ratio) = f14;
/* 1:1.2 ratio */
f14 = 1.2; DM(expan_ratio) = f14;
bit set ustat1 0x3D; /* turn on Flag5 LED */
bit clr ustat1 0x02;
dm(IOSTAT)=ustat1;
jump done;
ratio_setting_2:
/* 2:1 ratio, */
f14 = 0.50; DM(comp_ratio) = f14;
/* 1:1.3 ratio */
f14 = 1.3; DM(expan_ratio) = f14;
bit set ustat1 0x3B; /* turn on Flag6 LED */
bit clr ustat1 0x04;
dm(IOSTAT)=ustat1;
jump done;
ratio_setting_3:
/* 4:1 ratio */
f14 = 0.25; DM(comp_ratio) = f14;
/* 1:1.4 ratio */
f14 = 1.3; DM(expan_ratio) = f14;
bit set ustat1 0x37; /* turn on Flag7 LED */
bit clr ustat1 0x08;
dm(IOSTAT)=ustat1;
jump done;
ratio_setting_4:
/* 8:1 ratio */
f14 = 0.125; DM(comp_ratio) = f14;
/* 1:1.4 ratio */
f14 = 1.4; DM(expan_ratio) = f14;
bit set ustat1 0x2F; /* turn on Flag8 LED */
bit clr ustat1 0x10;
dm(IOSTAT)=ustat1;
jump done;
ratio_setting_5:
/* 20:1 ratio */
f14 = 0.05; DM(comp_ratio) = f14;
/* 1:1.5 ratio */
f14 = 1.5; DM(expan_ratio) = f14;
bit set ustat1 0x1F; /* turn on Flag9 LED */
bit clr ustat1 0x20;
dm(IOSTAT)=ustat1;
done:
rti(db);
bit clr mode1 SRRFH; /* switch back to primary register set */
nop;
/* ------------------------------------------------------------------------------------ */
/* */
/* IRQ2 Pushbutton Interrupt Service Routine */
/* */
/* This routine selects the compression threshhold, which is the level at which */
/* compression of the input signal occurs. */
/* */
/* The threshold can range from 0.0 to 0.9999 */
/* */
/* Default before 1st IRQ push: 0.5 */
/* 1st Pushbutton Press: 0.75 */
/* 2nd Pushbutton Press: 0.5 */
/* 3rd Pushbutton Press: 0.3 */
/* 4th Pushbutton Press: 0.25 */
/* 5th Pushbutton Press: 0.15 */
/* 6th Pushbutton Press: Reverts back to 1st Pushbutton Press */
/* */
/* The pushbutton setting is shown by the active LED setting, all others are off */
/* FLAG 4 LEDis set, indicating the user is modifying ratio settings. */
/* ------------------------------------------------------------------------------------ */
select_compander_thresholds:
bit set mode1 SRRFH; /* enable background register file */
NOP; /* 1 CYCLE LATENCY FOR WRITING TO MODE1 REGISER!! */
r13 = 5; /* number of presets */
r15 = DM(IRQ2_counter); /* get preset count */
r15 = r15 + 1; /* increment preset */
comp (r15, r13);
if ge r15 = r15 - r15; /* reset to zero */
DM(IRQ2_counter) = r15; /* save preset count */
r10 = pass r15; /* get preset mode */
if eq jump threshold_2; /* check for count == 0 */
r10 = r10 - 1; /* get preset mode */
if eq jump threshold_3; /* check for count == 1 */
r10 = r10 - 1; /* get preset mode */
if eq jump threshold_4; /* check for count == 2 */
r10 = r10 - 1; /* get preset mode */
if eq jump threshold_5; /* check for count == 3 */
threshold_1: /* count therefore, is == 4 if you are here */
f14 = 0.75; DM(comp_threshold) = f14;
f14 = 0.3; DM(expan_threshold) = f14;
bit set ustat1 0x2C;
bit clr ustat1 0x02; /* turn on Flag4 & Flag5 LEDs */
dm(IOSTAT)=ustat1;
jump exit;
threshold_2:
f14 = 0.5; DM(comp_threshold) = f14;
f14 = 0.2; DM(expan_threshold) = f14;
bit set ustat1 0x2A;
bit clr ustat1 0x05; /* turn on Flag4 & Flag6 LEDs */
dm(IOSTAT)=ustat1;
jump exit;
threshold_3: /* count therefore, is == 4 if you are here */
f14 = 0.30; DM(comp_threshold) = f14;
f14 = 0.2; DM(expan_threshold) = f14;
bit set ustat1 0x26;
bit clr ustat1 0x09; /* turn on Flag4 & Flag7 LEDs */
dm(IOSTAT)=ustat1;
jump exit;
threshold_4: /* count therefore, is == 4 if you are here */
f14 = 0.25; DM(comp_threshold) = f14;
f14 = 0.15; DM(expan_threshold) = f14;
bit set ustat1 0x2E;
bit clr ustat1 0x11; /* turn on Flag4 & Flag8 LEDs */
dm(IOSTAT)=ustat1;
jump exit;
threshold_5: /* count therefore, is == 4 if you are here */
f14 = 0.15; DM(comp_threshold) = f14;
f14 = 0.1; DM(expan_threshold) = f14;
bit set ustat1 0x1E;
bit clr ustat1 0x21; /* turn on Flag4 & Flag9 LEDs */
dm(IOSTAT)=ustat1;
exit:
rti(db);
bit clr mode1 SRRFH; /* switch back to primary register set */
nop;
.endseg;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -