📄 compressor.asm
字号:
/*** COMPRESSOR.ASM *****************************************************************
* *
* ADSP-21065L EZLAB Compressor Effect Program *
* Developed using ADSP-21065L EZ-LAB Evaluation Platform *
* *
* *
* What the compressor does? *
* ------------------------- *
* Keeps the level of the signal within a specific dynamic range, using a *
* technique called 'gain reduction'. The objective of a compressor is to *
* make sure that the signal level does not go beyond a desired level, *
* thus restricting the dynamic range. Gain reduction will reduce the *
* amount of additional gain above a desired threshold level by a selected *
* ratio. Compressors are often used on instruments that have sharp *
* peaks, such as drums and guitars. Also, this effect is great for vocal *
* tracks, ensuring that the signal level of vocals or any other instrument *
* will not intermittently overpower other instruments , allowing for *
* more flexibility and freedom when mixing multiple channels together. *
* Another application of the compressor algorithm, is to reduce the dynamic *
* range of 'CD-quality' audio down to the dynamic range of FM transmission *
* of music by radio stations transmitters. *
* *
* 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 *
* *
* The audio data is sent out to the AD1819A Line Outputs *
* *
* *
* John Tomarakos *
* ADI DSP Applications Group *
* Revision 1.0 *
* 11/19/98 *
* *
*****************************************************************************************/
/* ADSP-21065L System Register bit definitions */
#include "def21065l.h"
#include "new65Ldefs.h"
.EXTERN Left_Channel_In;
.EXTERN Right_Channel_In;
.EXTERN Left_Channel_Out;
.EXTERN Right_Channel_Out;
.GLOBAL Stereo_Compressor;
.GLOBAL select_compression_ratio;
.GLOBAL select_threshold;
.segment /dm compress;
.var IRQ1_counter = 0x00000003;
.var IRQ2_counter = 0x00000003;
.var ratio = 0.05;
.var threshold = 0.5;
.endseg;
.segment /pm pm_code;
/* //////////////////////////////////////////////////////////////////////////// *
* *
* STEREO COMPRESSOR ROUTINE *
* *
* inputs: *
* f2 = left channel data *
* f3 = right channel data *
* *
* outputs: *
* f2 = compressed left channel data *
* f3 = compressed right channel data *
* *
********************************************************************************/
Stereo_Compressor:
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(ratio); /* f0 = ratio = 1/20 */
f1 = DM(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 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 compressor 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_compression_ratio:
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(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(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(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(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(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_threshold:
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(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(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(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(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(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 + -