📄 sendout.c
字号:
#include "rtdsp.h"
/* c-code to support circular output FIFO 9-4-93 PME */
extern void int_enable(),int_disable(),flush();
extern int play_fifo[];
/* global interrupt on flag */
int int_flag = 0;
void sendout(float x)
{
static int flag = 0; /* 2 samples ready flag */
static int k;
register int j;
unsigned int pin,pout;
/* round and clip to 16 bits */
asm("r4 = fix %1;
r2 = 32767;
%0 = clip r4 by r2;" : "=d" (j) : "d" (x) : "r2");
/* replaces: clip output to 16 bits
j = (int)x;
if(j > 32767) j = 32767;
else if(j < -32768) j = -32768;
*/
if(flag) {
j = k + (j << 16);
flag = 0;
/* write 2 consecutive samples into FIFO (circular buffer) */
asm volatile("bit set mode1 0x10; nop;
dm(i1,m1) = %1;
%0 = i1;
bit clr mode1 0x10; nop;" : "=d" (pin) : "d" (j));
/* keep checking the out pointer until pout gets close to pin */
/* do only while interups are enabled */
if(int_flag) {
/* determine number of samples in FIFO and
take care of circular buffer problems */
do {
asm volatile("bit set mode1 0x10; nop; \
r0 = i0; /* -out pointer */
r0 = -r0, i2 = i1; /* in pointer */
m2 = r0;
modify(i2,m2); /* in-out */
%0 = i2;
bit clr mode1 0x10; nop;" : "=d" (pout) : );
} while(pout > (FIFO_LENGTH - FIFO_LENGTH/8));
/* after the fifo empties some we get here */
}
else {
if(pin > ((int)play_fifo + FIFO_LENGTH - FIFO_LENGTH/32)) int_enable();
}
}
else {
k = j & 0xffff;
flag = 1;
}
}
/* flush all samples out of the FIFO and then disable interrupts */
void flush()
{
int pin,pout;
int j;
float sample,delta;
asm("bit set mode1 0x10; nop; \
%0 = i1; \
bit clr mode1 0x10; nop;" : "=d" (pin) : );
if(pin == (int)play_fifo) pin = (int)play_fifo+FIFO_LENGTH-1; else pin--;
/* slowly drop the output to zero to avoid pop */
j = *((int *)pin);
j = j >> 16;
delta = abs(j)/5000;
if(delta <= 1.0) delta = 1.0;
if(j > 0) {
sample = (float)j;
while(sample > 0.0) {
sendout(sample);
sample -= delta;
}
}
else {
sample = (float)j;
while(sample < 0.0) {
sendout(sample);
sample += delta;
}
}
if(!int_flag) int_enable();
asm("bit set mode1 0x10; nop; \
%0 = i1; \
bit clr mode1 0x10; nop;" : "=d" (pin) : );
if(pin == (int)play_fifo) pin = (int)play_fifo +FIFO_LENGTH-1; else pin--;
/* wait for end of samples */
do {
asm volatile("bit set mode1 0x10; nop; \
%0 = i0; \
bit clr mode1 0x10; nop;" : "=d" (pout) : );
} while(pout != pin);
int_disable();
}
/* interrupt enable function */
void int_enable()
{
/* enable real-time interrupts after clearing all pending interrupts */
asm("irptl = 0;
bit set mode1 0x00001000; ");
int_flag = 1;
}
/* interrupt disable function - disable all interrupts */
void int_disable()
{
/* disable real-time interrupts after clearing all pending interrupts,
reset pointers to circular buffers */
asm(" bit clr mode1 0x00001000; \
bit set mode1 0x10; \
nop; \
bit clr mode1 0x10;");
int_flag = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -