OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 11:41 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Does the PC Speaker PWM trick work on emulators?
PostPosted: Fri Sep 02, 2022 3:34 pm 
Offline
Member
Member

Joined: Mon Dec 07, 2020 8:09 am
Posts: 212
From wiki:

Quote:
Playing the Audio

When the PIT interrupts you you need to program PIT timer 2 so that it puts the PC Speaker in the "out" position for a fraction of 60 microseconds. For 8 bit audio the number of microseconds can be calculated like this:

microseconds = (sample * 60) / 255;

For more information see the Wikipedia article Pulse-width modulation. There is also sample code posted in the forum here.


Wasn't able to get this to work in Qemu, maybe the following assumption made by the wiki page doesn't apply to emulators?

Quote:
The PC Speaker takes approximately 60 millionths of a second to change positions.


Based on my "research", without this kind of trick, it will be extremely dfficult to play a simple wav file through the eumlated pc speaker.



Could there be another short cut that I somehow overlooked?


Top
 Profile  
 
 Post subject: Re: Does the PC Speaker PWM trick work on emulators?
PostPosted: Fri Sep 02, 2022 4:41 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
PC speaker PWM is pretty much nonexistent outside of 30-year-old games, so you might have better luck with an emulator that can run 30-year-old games like DOSBox or MAME.


Top
 Profile  
 
 Post subject: Re: Does the PC Speaker PWM trick work on emulators?
PostPosted: Fri Sep 02, 2022 4:45 pm 
Offline
Member
Member

Joined: Fri Feb 11, 2022 4:55 am
Posts: 435
Location: behind the keyboard
My PC has it aswell as QEMU, I tried it on both so I think there is a problem with your code.

Devc1,


Top
 Profile  
 
 Post subject: Re: Does the PC Speaker PWM trick work on emulators?
PostPosted: Fri Sep 02, 2022 5:34 pm 
Offline
Member
Member

Joined: Mon Dec 07, 2020 8:09 am
Posts: 212
Octocontrabass wrote:
PC speaker PWM is pretty much nonexistent outside of 30-year-old games, so you might have better luck with an emulator that can run 30-year-old games like DOSBox or MAME.


Yeah this trick probably belongs to 30 years ago in terms of practical usage. Yet it is so ingenious that I somehow can't resist the temptation to re-implement it. Yet I don't have access to a box with a real pc speaker in it now :(

Good point about the game emulators, I never knew that dosbox is also a system emulator.


Last edited by xeyes on Mon Sep 05, 2022 3:23 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Does the PC Speaker PWM trick work on emulators?
PostPosted: Sat Sep 03, 2022 12:31 am 
Offline
Member
Member

Joined: Sat Nov 21, 2009 5:11 pm
Posts: 852
I remember my 3 year old self being impressed by Digger's PWM soundtrack for its novelty, but PC speakers are not known for their high fidelity, so this will generally sound awful. The traditional speakers that were used in very old PCs would do okay but the piezo ones are probably unsuitable due to high distortion and poor frequency response. I once hacked a Java toy robot to do this with its tiny sad beeper and it was pretty much impossible to make out what the words were.


Top
 Profile  
 
 Post subject: Re: Does the PC Speaker PWM trick work on emulators?
PostPosted: Mon Sep 05, 2022 3:21 pm 
Offline
Member
Member

Joined: Mon Dec 07, 2020 8:09 am
Posts: 212
After patching dosbox and playing with various options on my side, the PWM trick worked :D

I'd say that the playing back is over 90% intelligible and the sound quality, or the richness of the sound, is way above what a simple frequency generator is supposed to be able achieve.

Dosbox turns out to be a capable and fast emulator as well. The ability to precisely control the emulated clock rate also helps with timing. As long as you don't use certain features such as PAE, and be careful about how you handle pagefaults, it works well without much patching.

There is also a fork named Dosbox-x that has a lot more features, including TTF fonts and IDE emulation, but seems to be slightly more buggy.

Gigasoft wrote:
I remember my 3 year old self being impressed by Digger's PWM soundtrack for its novelty, but PC speakers are not known for their high fidelity, so this will generally sound awful. The traditional speakers that were used in very old PCs would do okay but the piezo ones are probably unsuitable due to high distortion and poor frequency response. I once hacked a Java toy robot to do this with its tiny sad beeper and it was pretty much impossible to make out what the words were.


Call me as impressed as a 3 year old :lol:

Of course, rather than hifi, this is more like lofi. But it's certainly fun to see (hear) the awesome result of the creativity that people had when working with such limited hardware back then, lively.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 68 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group