C (asm)操作声卡...

Yofoo 2002-03-08 06:48:05
不用驱动程序 通过I/O 操作
读MIC ,play wav,midi文件
最好有C 的源代码
...全文
76 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
shilong 2002-06-28
  • 打赏
  • 举报
回复
const SPEAKER_PORT = $61;
PIT_CONTROL = $43;
PIT_CHANNEL_2 = $42;
PIT_FREQ = $1234DD;

DELAY_LENGTH = 100;

procedure PlaySound(sound : PChar; length : word);
var count_values : array[0..255] of byte;
i, loop : word;
begin

{ Set up the count table }
for i := 0 to 255 do
count_values[i] := i * 54 div 255;

{ Set up the PIT and connect the speaker to it }
Port[PIT_CONTROL] := $90;
Port[SPEAKER_PORT] := Port[SPEAKER_PORT] or 3;

{ Play the sound }

asm cli end;
for i := 0 to length - 1 do
begin
Port[PIT_CHANNEL_2] := count_values[byte(sound^)];
for loop := 0 to DELAY_LENGTH do;
Port[PIT_CHANNEL_2] := count_values[byte(sound^)];
for loop := 0 to DELAY_LENGTH do;
sound := sound + 1;
end;
asm sti end;

{ Reprogram the speaker for normal operation }
Port[SPEAKER_PORT] := Port[SPEAKER_PORT] and $FC;
Port[PIT_CONTROL] := $B6;
end;
coldcrane 2002-06-28
  • 打赏
  • 举报
回复
#define SUCCESS 1
#define FAIL 0
#define DSP_PLAY 0x49
#define DSP_RECORD 0x45
void WriteData(char achar)
{while(((inportb(0x22c))&0x80));
outportb(0x22c,achar);
}
void ReadData(char *achar)
{while(!(inportb(0x22e)&'\x80'));
*achar=inportb(0x22a);
}
int Initialize(void)
{char inchar;
outportb(0x226,'\x01');
outportb(0x226,'\x00');
ReadData(&inchar);
if(inchar=='\xaa')return SUCCESS;
else return FAIL;
}
int SetDMA(int page,int offset,int length,unsigned char play_or_record)
{outportb(0x0a,'\x05');
outportb(0x0c,'\x00');
outportb(0x0b,play_or_record);
outportb(0x02,offset&0x00ff);
outportb(0x02,(offset&0xff00)>>8);
outportb(0x83,page);
outportb(0x03,(length&0x00ff)-1);
outportb(0x03,((length&0xff00)>>8)-1);
outportb(0x0a,1);
return SUCCESS;
}
void StartPlay(int page_no,int page_offset,int page_length,unsigned char sr)
{/*pint=pointer->nowpage++;*/
inportb(0x22e);
WriteData(0xd1);
outportb(0x224,'\x04');
outportb(0x225,255);
WriteData('\x40');
WriteData(sr/*0xa6*/);
SetDMA(page_no,page_offset,page_length,DSP_PLAY);
enable();
WriteData('\x14');
WriteData((page_length&0x00ff)-1);
WriteData(((page_length&0x00ff)>>8)-1);
}

void exitnow(char *msg)
{printf("\n%s\n",msg);
exit(0);
}

void StartRecord(int page_no,int page_offset,int page_length,unsigned char sr)
{inportb(0x22e);
WriteData(0xd1);
outportb(0x224,'\x04');
outportb(0x225,155);
WriteData('\x40');
WriteData(sr/*0xa6*/);
SetDMA(page_no,page_offset,page_length,DSP_RECORD);
enable();
WriteData('\x14');
WriteData((page_length&0x00ff)-1);
WriteData(((page_length&0x00ff)>>8)-1);
}
Yofoo 2002-06-28
  • 打赏
  • 举报
回复
UP
Yofoo 2002-04-05
  • 打赏
  • 举报
回复
我以前见过用PAA+ASM写的一个,怎么没人理我。
Yofoo 2002-03-11
  • 打赏
  • 举报
回复
I/O 220H
IRQ 05H
DMA 01H

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧