1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Added a sound api.

This commit is contained in:
Jonas 'Sortie' Termansen 2011-08-22 00:25:28 +02:00
parent 55e9d358cf
commit 4c1cb806ba
6 changed files with 96 additions and 3 deletions

View file

@ -44,7 +44,7 @@ c/h/stdio.h
COMMONOBJS=c++.o thread.o io.o memory.o string.o error.o format.o COMMONOBJS=c++.o thread.o io.o memory.o string.o error.o format.o
SORTIXOBJS:=$(addprefix sortix/,$(COMMONOBJS)) SORTIXOBJS:=$(addprefix sortix/,$(COMMONOBJS))
LIBMAXSIOBJS:=$(COMMONOBJS) sortix-vga.o sortix-keyboard.o LIBMAXSIOBJS:=$(COMMONOBJS) sortix-vga.o sortix-keyboard.o sortix-sound.o
HEADERS=\ HEADERS=\
error.h \ error.h \
io.h \ io.h \
@ -57,7 +57,8 @@ types.h \
format.h \ format.h \
keyboard.h \ keyboard.h \
sortix-vga.h \ sortix-vga.h \
sortix-keyboard.h sortix-keyboard.h \
sortix-sound.h \
OBJS:=$(LIBMAXSIOBJS) OBJS:=$(LIBMAXSIOBJS)
BINS:=libmaxsi.so BINS:=libmaxsi.so

View file

@ -0,0 +1,39 @@
/******************************************************************************
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
This file is part of LibMaxsi.
LibMaxsi is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
LibMaxsi 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 Lesser General Public License for
more details.
You should have received a copy of the GNU Lesser General Public License
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
sortix-sound.cpp
Provides access to the sound devices. This is highly unportable and is very
likely to be removed or changed radically.
******************************************************************************/
#ifndef LIBMAXSI_SORTIX_SOUND_H
#define LIBMAXSI_SORTIX_SOUND_H
namespace System
{
namespace Sound
{
// Sets the desired sound frequency on the current sound device. This is
// rather crude. A frequency of 0 disables the sound output.
void SetFrequency(unsigned frequency);
}
}
#endif

42
libmaxsi/sortix-sound.cpp Normal file
View file

@ -0,0 +1,42 @@
/******************************************************************************
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
This file is part of LibMaxsi.
LibMaxsi is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
LibMaxsi 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 Lesser General Public License for
more details.
You should have received a copy of the GNU Lesser General Public License
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
sortix-sound.cpp
Provides access to the sound devices. This is highly unportable and is very
likely to be removed or changed radically.
******************************************************************************/
#include "platform.h"
#include "syscall.h"
#include "sortix-sound.h"
namespace System
{
namespace Sound
{
DEFN_SYSCALL1_VOID(SysSetFrequency, 9, unsigned);
void SetFrequency(unsigned frequency)
{
SysSetFrequency(frequency);
}
}
}

View file

@ -38,6 +38,8 @@ namespace Sortix
void Play(nat Frequency) void Play(nat Frequency)
{ {
Log::PrintF("Playing frequency %u\n", Frequency);
//Set the PIT to the desired frequency //Set the PIT to the desired frequency
uint32_t Div = 1193180 / Frequency; uint32_t Div = 1193180 / Frequency;
CPU::OutPortB(0x43, 0xB6); CPU::OutPortB(0x43, 0xB6);
@ -52,6 +54,12 @@ namespace Sortix
CPU::OutPortB(0x61, TMP | 3); CPU::OutPortB(0x61, TMP | 3);
} }
} }
void SysSetFrequency(CPU::InterruptRegisters* R)
{
unsigned frequency = R->ebx;
if ( frequency == 0 ) { Mute(); } else { Play(frequency); }
}
} }
} }

View file

@ -31,6 +31,7 @@ namespace Sortix
{ {
void Mute(); void Mute();
void Play(nat Frequency); void Play(nat Frequency);
void SysSetFrequency(CPU::InterruptRegisters* R);
} }
} }

View file

@ -33,6 +33,7 @@
#include "panic.h" #include "panic.h"
#include "vga.h" #include "vga.h"
#include "keyboard.h" #include "keyboard.h"
#include "sound.h"
namespace Sortix namespace Sortix
{ {
@ -49,7 +50,7 @@ namespace Sortix
#endif #endif
} }
const size_t NumSyscalls = 9; const size_t NumSyscalls = 10;
const Syscall Syscalls[NumSyscalls] = const Syscall Syscalls[NumSyscalls] =
{ {
&Scheduler::SysCreateThread, &Scheduler::SysCreateThread,
@ -61,6 +62,7 @@ namespace Sortix
&VGA::SysChangeFrame, &VGA::SysChangeFrame,
&VGA::SysDeleteFrame, &VGA::SysDeleteFrame,
&Keyboard::SysReceieveKeystroke, &Keyboard::SysReceieveKeystroke,
&Sound::SysSetFrequency,
}; };
void Init() void Init()