bevis@en.ecn.purdue.edu (Jeff Bevis) (03/29/91)
Ok, I'm usually pretty reluctant to ask for help when I'm well aware that I can solve most programming problems with a little work. But I'm flat out frustrated by my latest time-waster. I'm trying to play one-shot sound samples. That's it. I've had some difficulty in understanding the behavior of the hardware as described in various books, so I will present my method of playing a sound and wait for someone to point out the obvious fault. Here's what I do: (bear in mind that I am evil and own the machine -- all interrupts, the works, myself -- I've been having a bad month) procedure to start a sound on channel 0: 1. Turn off interrupts. Nothing should interfere, but this seems to help. (master disable). 2. Shut off DMA for channel 0. (dmacon) 3. Set channel 0 volume and data to 0. Set period to 1. 4. Wait for an AUD0 interrupt flag (it won't interrupt due to the disable). 5. Write new information into audio channel in this order: period, length, pointer, volume. 6. Enable DMA for channel 0. (dmacon) 7. Clear interrupt flag for AUD0. (intreq) 8. Enable the AUD0 interrupt. (intena) 9. Enable the master interrupt bit. (intena) Now, what does the interrupt handler do, you ask? This: 10. Shut off DMA for audio channel 0. 11. Disable AUD0 interrupt. ------------------ Ok. There you have it. Here's the idea behind the madness. Lines 1-4 try to stop previous DMA from happening. I want to be able to halt a playing sound and change to new one. At lines 5-6 I start the new sound. Line 7 clears the interrupt flag that should be set from line 4. Lines 8-9 enable the interrupt, which, according to the Hardware Manual, should NOT occur until the last sample of this sound has be 'accessed'. Therefore, I expect to have my interrupt handler called after the sound has been played one time. At that time, lines 10-11 should happen and turn the sound off. What really happens is this: Most of the time, I get interrupted as soon (or soon after) I enable the audio interrupt. Thus, the sound gets squashed before I can hear so much as a pop. Other times, it works fine. The sound plays one iteration, and then stops. I don't quite get this. Where's this early interrupt coming from? It really *is* the AUD0 interrupt, I am sure. Why? Any clues? advice? free pizza? It's been a week spent on just this one problem. I think the documentation available to me has been pretty lacking in good explanations. The hardware manual from CBM doesn't give a description of how to stop a sound WITH INTENT TO RESTART A NEW ONE SOON. This is a special case, indeed, deserving of some attention. My Abacus book is vastly worse. A shame. With the hardware manual's excellent coverage of the blitter, I've done up some really spiffy (for me anyhow) graphics for my program. For that, I give CBM's authors the due credit! -- ------------------------------------------------------------------------------- "Three is never equal to four, except for very large values of three." ------------------------------------------------------------------------------- Jeff Bevis Purdue Univeristy School of Electrical Engineering