PC speaker WAV player source Altough I've posted that on osdev.org, it can be fully integrated into DexOS and in case of no soundcard, you can play WAV files, even the 22,050 kHz (PCM) ones! ;)
Of course, the quality isn't as on e.g. Sound blaster, but it does the trick.
Anyways, here it is:
http://forum.osdev.org/viewtopic.php?f=13&t=17293
Dex- 06-22-2008
Nice work inflater, it's the first ver i have seen work :).
Here is the DexOS ver (its just a quick hack)
; PC speaker wave player PCSPEAKR.ASM
;; Copyright (C) 2008 J. Bogin a.k.a. Inflater
;;; Converted to run on DexOS.
use32
ORG 0x400000
jmp start
db 'DEX2'
;----------------------------------------------------;
; Start of program. ;
;----------------------------------------------------;
start:
mov ax,18h
mov ds,ax
mov es,ax
;----------------------------------------------------;
; Get calltable address. ;
;----------------------------------------------------;
mov edi,Functions
mov al,0
mov ah,0x0a
int 40h
mov eax,20h
call [GetIntVector]
mov [OldInClockTickAddress],edx
mov eax,20h
mov edx,irq0_int
call [SetIntVector]
PlayWAV:
mov [WAVSamplingRate],6000
mov [WAVFileSize],bufferSize-buffer
mov esi,FileLoaded
xor ecx,ecx
mov cx,[WAVSamplingRate]
call ProgramPIT
mov ecx,[WAVFileSize]
mov [EnableDigitized],1
Play_Repeat:
lodsb
hlt
loop Play_Repeat
mov [EnableDigitized],0
mov ecx,0x00000000
call ProgramPIT
call Sound_Off
ExitHere:
mov edx,[OldInClockTickAddress]
mov eax,20h
call [SetIntVector]
int 70h
call [WaitForKeyPress]
ret
ProgramPIT:
pushad
call [InterruptTimer]
popad
ret
irq0_int:
cmp [EnableDigitized],1
jne NoDigitizedSound
cmp al,0x80
jb TurnOffBeeper
mov bx,[WAVSamplingRate]
call Sound_On
jmp Sound_Done
TurnOffBeeper:
call Sound_Off
Sound_Done:
inc esi
NoDigitizedSound:
mov al,0x20
out 0xa0,al
out 0x20,al
iret
Sound_On:
mov ax,0x34dd
mov dx,0x0012
cmp dx,bx
jnc Done1
div bx
mov bx,ax
in al,0x61
test al,3
jnz A99
or al,3
out 0x61,al
mov al,0xb6
out 0x43,al
A99:
mov al,bl
out 0x42,al
mov al,bh
out 0x42,al
Done1:
ret
Sound_Off:
in al,0x61
and al,11111100b
out 0x61,al
ret
WAVSamplingRate dw 0
WAVFileSize dd 0
EnableDigitized db 0
OldInClockTickAddress dd 0
FileLoaded:
buffer:
file "test.wav"
bufferSize:
;----------------------------------------------------;
; calltable include goes here. ;
;----------------------------------------------------;
include 'Dex.inc'
hidnplayr- 06-22-2008
Would it be useable as a module?
For simple games as my invaders for instance...
(unless somebody is whiling to write a driver for a soundcard i own)
inflater- 06-23-2008
I've uploaded on that topic on osdev two sample WAV files. And the result? Use a biggest PC speaker you've got. :lol: If it's only a 3mm diameter piezoelectric one, you'll get a quality like in the second WAV file uploaded :D.
Or maybe you could desolder the piezoelectric speaker from the mainboard and solder in some headphones or e.g. bigger speaker from these made in china toys :)
Dex- 06-23-2008
Also hidnplayr, i have some demo using the speaker, that will give good sounds for your game (eg: shooting sounds etc).
I will upload them later.
rhyno_dagreat- 06-24-2008
How do you play without a soundcard? That's what I was trying to figure out earlier!
EDIT: I just realized, you're talking about the PC speaker, not external speakers! :lol:
My bad, sorry.
Good work, though! :D
rCX- 06-24-2008
Good job. The only thing I know how to do is to print the bell character. :D
GhostXoP™- 06-28-2008
nice, we need the os to use or get a startup sound
inflater- 06-29-2008
My OS uses the "chimes" sound from Windows 95. And, using a executable compressor, my kernel has only 11,6 kB. :)
So, be sure to pack your kernels :D
GhostXoP™- 06-29-2008
thats cool but im not going to try to compress mine, my goal is to try to get mine to b compatable and fast, and heavy weight
Dex- 06-29-2008
thats cool but im not going to try to compress mine, my goal is to try to get mine to b compatable and fast, and heavy weight
compatable and fast cool, but heavy weight is not a good goal.
GhostXoP™- 07-01-2008
well, the bigger has a reason, to do more things, hook in more devices, backups, frameworks, moduals, more system files to insure better quallity, and use below 512 mb of ram.
hidnplayr- 07-09-2008
dex, where are your fancy sounds? i want to play invaders! :p
Maybe i could try to get one of my sb16 compatible cards working...
Dex- 07-10-2008
Sorry, i thought you did not need them because you did not answer, i will up load them later today.
I also have a play wav demo with DMA and SB built in, for DexOS if you want it let me know.
You should also look into mids as they use a standard port.
Dex.