wenjun16
小水手

UID 30796
精华
0
积分 2
帖子 2
阅读权限 10
注册 2007-11-30
状态 离线
|
偏移地址的求法
各位前辈 帮帮忙
void write_dsp(unsigned char value)
{
/*等待DSP接收一个字节*/
while ((inportb(g_base + 0xC) & 0x80) == 0x80);
/*发送字节*/
outportb (g_base + 0xC, value);
}
/****************************************************************************
** 播放内存中的部分音频流 **
****************************************************************************/
char play_back (SAMPLE *wave)
{
long LinearAddress;
unsigned short page, offset;
if ((!wave) || (!wave->sample))
{
printf("no sample!");
return 0;
}
/*开启声卡*/
write_dsp( 0xD1 );
write_dsp( 0x40 ); /*DSP第40h号命令 :设置采样频率*/
write_dsp( wave -> time_constant ); /*Write time constant*/
/*将音频流指针转换成线性地址*/
LinearAddress = FP_SEG ( wave -> sample );
LinearAddress = ( LinearAddress << 4 ) + FP_OFF ( wave->sample );
page = LinearAddress >> 16; /*计算页*/
offset = LinearAddress & 0xFFFF; /*计算页偏移*/
/*注意 :这个操作只能工作于DMA的第一通道*/
outportb (0x0A, 5); /*Mask 锁DMA通道一*/
outportb (0x0C, 0); /*清除DMA内部翻转标志*/
outportb (0x0B, 0x49); /*设置成回(播)放模式*/
/*
模式由下面几项组成:
0x49 = 二进制 01 00 10 01
| | | |
| | | +- DMA通道 01
| | +---- 读操作 (从内存到DSP)
| +------- 单一周期方式
+---------- 块方式
*/
outportb ( 0x02, offset & 0x100); /*将偏移量写入DMA控制器*/
outportb ( 0x02, offset >> 8);
outportb ( 0x83, page); /*将页面写入DMA控制器*/
outportb ( 0x03, wave->sample_lenth & 0x100);
outportb ( 0x03, wave->sample_lenth >> 8);
outportb ( 0x0A, 1 ); /*激活DMA通道一*/
write_dsp( 0x14 ); /*DSP第14h号命令 :单一周期回放*/
write_dsp( wave -> sample_lenth & 0xFF );
write_dsp( wave -> sample_lenth >> 8);
return 1;
}
为什么传02断口偏移地址的低地址是
outportb ( 0x02, offset & 0x100);
而不是
outportb ( 0x02, offset & 0xFF);
象在write_dsp( wave -> sample_lenth & 0xFF );
中他也是用的wave -> sample_lenth & 0xFF啊
|
|