Assembly sound programming

Started by
4 comments, last by darookie 19 years, 6 months ago
I've found in one of my assembly books, code for a function that'll generate sound at a certain frequency for a certain duration in milliseconds. I've done some work with it and understand that to write simple melodies I'll just have to encode the notes/frequencies and duration of each. That's not really a problem. However, I'm not sure how to properly integrate this with the small scale game I'm writing (likely something Mario-ish). Right now, I sit in a loop that checks for a run flag. If the flag is not set, jump to begin again, otherwise check/apply input etc. The flag is set in my callback function that is called 18.2 times per second. I'm working on a better timer but I plan on it working in the same fashion anyway. My question is, if I write a little melody, how do I integrate it with my main loop? Since playing a frequency for xms blocks any further processing for xms, I obviously can't be constantly generating sound. Could I get away, in a 20 loops per second scenario, with generating sound for 1/40s each loop? I'm going to test this out after I've cleaned up some implementation details, but I though I'd ask before I spend too much time on what may be the wrong path. Cheers.
Advertisement
Are you using the PC-speaker or a sound card?
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
The speaker.
Quote:Original post by kordova
The speaker.

[wow]
If you use DOS, you can hook up with the timer interrupt.
It won't work on any recent OS, though.
Do you really want to use the PC speaker?


Quote:Original post by darookie
Quote:Original post by kordova
The speaker.

It won't work on any recent OS, though.
It's working on XP. (Probably due to XP's 16-bit emulation.)

Quote:Original post by darookie
If you use DOS, you can hook up with the timer interrupt.
Good point. That'd make more sense than putting it in the loop I suppose. I'll try it out. Thanks!

Quote:Original post by darookie
Do you really want to use the PC speaker?
I want to generate sound in a simple and painless fashion.

[Edited by - kordova on October 11, 2004 9:00:08 AM]
Quote:Original post by kordova
Quote:Original post by darookie
Do you really want to use the PC speaker?
I want to generate sound in a simple and painless fashion.

The Win32 waveout API can help you with that.
There's an article here that describes it pretty well.

Good luck,
Pat.

This topic is closed to new replies.

Advertisement