Инструменты пользователя

Инструменты сайта


pro_spk:воспроизведение_мелодий_через_встроенный_динамик_компьютера_pc-speaker_в_gnu_linux

Это старая версия документа!


Воспроизведение мелодий через встроенный динамик компьютера (PC-Speaker) в GNU/Linux

Демонстрационная программа: spk_play.pas

program spk_play;
 
{
    Program for playing melodys on PC-Speaker.
    For GNU/Linux 64 bit version. Root priveleges needed.
    Version: 2.
    Written on FreePascal.
    Copyright (C) 2019  Artyomov Alexander
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.
 
    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
}
 
{$MODE OBJFPC}
{$ASMMODE INTEL}
{$CODEPAGE UTF8}
 
uses SysUtils,X86;
 
procedure spkon; assembler;
asm
        push    rax
        in      al, 61h
        or      al, 03h
        out     61h, al
        pop     rax
end;
procedure spkoff; assembler;
asm
        push    rax
        in      al, 61h
        or      al, 03h
        xor     al, 03h
        out     61h, al
        pop     rax
end;
procedure spk(b : word);
var hb, lb : byte;
begin
hb := hi(b); lb := lo(b);
 asm
        push    rax
        mov     al, 0B6h
        out     43h, al
        mov     al, lb
        out     42h, al
        mov     al, hb
        out     42h, al
        pop     rax
 end;
end;
 
begin
 
// Разрешить (на уровне операционной системы) своей
// программе нужные для работы с динамиком порты
// ввода-вывода 42h, 43h и 61h. Запуск программы только от рута.
fpioperm($42, 2, 1); // fpioperm($42, 1, 1); fpioperm($43, 1, 1);
fpioperm($61, 1, 1);
 
spkon; // Включить динамик.
spk(1000); // Установить частоту воспроизведения. Частота 1193280 div tone.
Sleep(100); // Подождать.
spk(2000);
Sleep(100);
spkoff; // Выключить динамик.
 
end.

Юнит: spkunit.pas

unit spkunit;
 
{$MODE OBJFPC}
{$ASMMODE INTEL}
{$CODEPAGE UTF8}
 
{
    Unit for playing melodys on PC-Speaker.
    For GNU/Linux 64 bit version. Root priveleges needed.
    Version: 3.
    Written on FreePascal (https://freepascal.org/).
    Copyright (C) 2000-2019  Artyomov Alexander
    http://self-made-free.ru/ (Ex http://aralni.narod.ru/)
    aralni@mail.ru
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.
 
    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
}
 
interface
 
uses X86;
 
procedure spk(b : word); procedure spkon; procedure spkoff;
 
implementation
 
procedure spkon; assembler;
asm
        push    rax
        in      al, 61h
        or      al, 03h
        out     61h, al
        pop     rax
end;
procedure spkoff; assembler;
asm
        push    rax
        in      al, 61h
        or      al, 03h
        xor     al, 03h
        out     61h, al
        pop     rax
end;
procedure spk(b : word);
var hb, lb : byte;
begin
hb := hi(b); lb := lo(b);
 asm
        push    rax
        mov     al, 0B6h
        out     43h, al
        mov     al, lb
        out     42h, al
        mov     al, hb
        out     42h, al
        pop     rax
 end;
end;
 
initialization
 
fpioperm($42, 2, 1);
fpioperm($61, 1, 1);
 
end.

<html> <!– Rating@Mail.ru counter –> <script> var _tmr = window._tmr || (window._tmr = []); _tmr.push({id: «2958242», type: «pageView», start: (new Date()).getTime()}); (function (d, w, id) {

if (d.getElementById(id)) return;
var ts = d.createElement("script"); ts.type = "text/javascript"; ts.async = true; ts.id = id;
ts.src = (d.location.protocol == "https:" ? "https:" : "http:") + "//top-fwz1.mail.ru/js/code.js";
var f = function () {var s = d.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ts, s);};
if (w.opera == "[object Opera]") { d.addEventListener("DOMContentLoaded", f, false); } else { f(); }

})(document, window, «topmailru-code»); </script><noscript><div> <img src=«top-fwz1.mail.ru/counter?id=2958242;js=na» style=«border:0;position:absolute;left:-9999px;» alt=«counter» /> </div></noscript> <!– Rating@Mail.ru counter –> <!– Rating@Mail.ru logo –> <a class=«footerlink» href=«https://top.mail.ru/jump?from=2958242»> <img src=«top-fwz1.mail.ru/counter?id=2958242;t=479;l=1» style=«border:0;» height=«31» width=«88» alt=«Рейтинг@Mail.ru» /></a> <!– Rating@Mail.ru logo –> </html>

pro_spk/воспроизведение_мелодий_через_встроенный_динамик_компьютера_pc-speaker_в_gnu_linux.1550074890.txt.gz · Последнее изменение: 2019/02/13 19:21 — dwadmin

Если не указано иное, содержимое этой вики предоставляется на условиях следующей лицензии: GNU Free Documentation License 1.3
GNU Free Documentation License 1.3 Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki