[Coco] Assembly audio routines
Zippster
zippster278 at gmail.com
Mon Mar 20 13:50:58 EDT 2017
I’d have to agree with your disagreement Dave. : )
You are only losing precision.
When you write your 8 bit unsigned audio (0-255 centered at 128) to the DAC and
lose the 2 LSBs, it’s automatically converted to unsigned 6-bit (0-63 centered at 32).
You’ll have the wrong values if you left-shift the bits. It’s the signal centering that may be a little confusing I think.
With shifting, a centered 128 becomes a 0, a near to center 131 becomes a 3, etc.
At first glance this would seem to introduce a lot of noise or distortion rather than clean things up…
Definitely not a proper conversion to 6-bit, anyway.
- Ed
> On Mar 20, 2017, at 12:06 PM, Dave Philipsen <dave at davebiz.com> wrote:
>
> I would have to disagree with that statement. The high bits are called 'most significant' for a reason! 😀
>
> Dave
>
>> On Mar 20, 2017, at 10:26 AM, Bill Pierce via Coco <coco at maltedmedia.com> wrote:
>>
>> Glen, that's pretty interesting. I wonder why absolutely no music software I've delt with uses this method? I have sources for most Musica players including the last version of Musica (provided by Lester Hands), Orchestra90, and several others and all seem to mask the 2 bits (except orch90 which uses a different method). The message Robert was answering was from Remy who wrote the "SidPlayer" for the Coco, so I would imagine he was working on that at the time.
>>
>> One thing to remember though, since you're cutting the bottom 2 bits from the signal, you're losing fidelity. Something I've seen done in several players is to shift all wave bytes 2 bits to the left to help clean up the sound (Musica does this before playing the song). I "think" it's better to lose 2 high bits rather than 2 low bits.
>>
>>
>>
>>
>>
>>
>> Bill Pierce
>> "Charlie stole the handle, and the train it won't stop going, no way to slow down!" - Ian Anderson - Jethro Tull
>>
>>
>>
>> My Music from the Tandy/Radio Shack Color Computer 2 & 3
>> https://sites.google.com/site/dabarnstudio/
>> Co-Contributor, Co-Editor for CocoPedia
>> http://www.cocopedia.com/wiki/index.php/Main_Page
>> Global Moderator for TRS-80/Tandy Color Computer Forums
>> http://www.tandycoco.com/forum/
>>
>> E-Mail: ooogalapasooo at aol.com
>>
>>
>>
>>
>>
>>
>> -----Original Message-----
>> From: Glen Hewlett <glen.hewlett at sympatico.ca>
>> To: CoCoList for Color Computer Enthusiasts <coco at maltedmedia.com>
>> Sent: Sun, Mar 19, 2017 10:06 pm
>> Subject: Re: [Coco] Assembly audio routines
>>
>> Hi All,I found the message from the www.coco3.com <http://www.coco3.com/> website, from Robert Gault. I haven’t tried this yet but I will soon…Cheers,GlenRobert GaultFebruary 23, 2010 at 11:31 pm <http://www.coco3.com/community/2010/02/vblank-and-hblank/#comment-58057>Hi remz,The code looks like it should work although I don’t know how well you can read both sides of the same pulse. If there is a problem, the alternative would be to just look for the side of the pulse you want instead of both. Also, the sizes of the VSYNC and HSYNC pulses are known, so if for some reason you want to trigger on the front rather than the back of the pulse, you could just count cycles rather than re-trigger.As to your question about reading $FF00 or $FF02, that clears the interrupt flag of the respective byte $FF01 or $FF03.Data Direction needs to be =1 if you want the PIA in its functional mode. With that bit =0, the PIA is set to its adjustment mode where you can select whether a bit is incoming or outgoing.As an example, a music program does not want to waste time masking bits 0&1 at $FF20 when sending a signal to the DAC. Therefore you mightlda $FF21pshs aanda #%00110011 force bit2 lowsta $FF21 $FF20 now data direction registerlda #%11111100 output on DAC, input on RS-232 & CDIsta $FF20puls asta $FF21Now a mask of the two low bits is not needed when sending data to $FF20.Heres a link to the discussion:http://www.coco3.com/community/2010/02/vblank-and-hblank/ <http://www.coco3.com/community/2010/02/vblank-and-hblank/>> On Mar 19, 2017, at 9:32 PM, Glen Hewlett <glen.hewlett at sympatico.ca> wrote:> > Hi Bill,> > Thanks for that but I’m sure that I read somewhere that if you send a byte to some address (must be in the PIA) that it will turn off those two bits, so you don’t have to worry about masking those bits before sending the audio samples to $FF20. Which would be one less instruction to worry about, speed wise.> > Cheers,> Glen> >> On Mar 19, 2017, at 9:14 PM, Bill Pierce via Coco <coco at maltedmedia.com> wrote:>> >> G
>> len, you need to mask the 2 bits or they will produce garbage to the serial I/O.>> >> >> >> >> >> >> Bill Pierce>> "Charlie stole the handle, and the train it won't stop going, no way to slow down!" - Ian Anderson - Jethro Tull>> >> >> >> My Music from the Tandy/Radio Shack Color Computer 2 & 3>> https://sites.google.com/site/dabarnstudio/>> Co-Contributor, Co-Editor for CocoPedia>> http://www.cocopedia.com/wiki/index.php/Main_Page>> Global Moderator for TRS-80/Tandy Color Computer Forums>> http://www.tandycoco.com/forum/>> >> E-Mail: ooogalapasooo at aol.com>> >> >> >> >> >> >> -----Original Message----->> From: Glen Hewlett <glen.hewlett at sympatico.ca>>> To: CoCoList for Color Computer Enthusiasts <coco at maltedmedia.com>>> Sent: Sun, Mar 19, 2017 7:43 pm>> Subject: Re: [Coco] Assembly audio routines>> >> Hi Ed,Thanks for the info, I thought that might be how it worked. So I guess it’s really a matter of quality of sound vs speed of the game at this point. I’m looking forward to getting some sounds out of my CoCo using assembly language, it sounds pretty straight forward.I remember reading either on this list or some old forum where someone was saying you can send a byte I think to the PIA and it will set the CoCo to ignore bits 0 & 1 of $FF20 so you don’t have to worry about them and send garbage data to the RS-232 output or the Cassette data input lines. Does this sound familiar to you?I’ll see if I can dig it up again.Your sample playback is amazing sounding from the CoCo.Cheers,Glen> On Mar 19, 2017, at 5:59 PM, Zippster <zippster278 at gmail.com> wrote:> > Hi Glen,> > If you want to play back audio samples on the CoCo (using the DAC I assume), then it’s> fairly simple. Format your audio as 8 bit unsigned mono. Grab a byte at a time and shoot> it at the DAC $FF20 at whatever your sample rate is. You’ll have to work the code out to> write a byte to the DAC at precise intervals (# of cycles).> > That’s really all there is to it for samples using the DAC. You’ll lose some precision because> the D
>> AC is 6-bits vs 8, but it can still sound very good depending on your sample rate.> > Playing samples will tie up your code though if you plan to have a lot of other stuff> going on at the same time, as you have to service the DAC constantly during playback.> > This is audio playing through the 6-bit DAC at 44.5KHz (1 byte every 20 cycles) from> some code I’ve written that will do continuous playback from the CoCo SDC.> > <https://drive.google.com/open?id=0B1sgl615FlGnNzE3YVRhX3ZnSnM <https://drive.google.com/open?id=0B1sgl615FlGnNzE3YVRhX3ZnSnM>>> > Of course, at this bit rate it ties the system up pretty well at .89MHz.> > - Ed> > > >> On Mar 19, 2017, at 4:35 PM, Glen Hewlett <glen.hewlett at sympatico.ca> wrote:>> >> Hi Evan,>> >> Thanks for the info, I looked at your code and it will be useful if I want to play tones from the computer like the sound command in DECB. But what I’m looking for is some code to play back audio samples (PCM audio data) like wav files. I think this is the only way I can keep the game going at the same time as playing sound effects/music. As I understand it will take using the FIRQ and sending certain number of sampled bytes every time the FIRQ is triggered. So it will have to be very optimized code.>> >> Cheers,>> Glen>> >>> On Mar 19, 2017, at 5:18 PM, Evan Wright via Coco <coco at maltedmedia.com> wrote:>>> >>> Here is the github repository for the CoCo project I recently did.>>> https://github.com/evancwright/CoCo>>> >>> If you look in floodit_cart.asm there is a routine which plays the intro melody to the game. I never did get sound working in an unblocking fashion, though, It looks like the ISR checks the values for the length and freq of the tone to play, then loops until the sound is done playing.>>> I used this as a reference...http://www.lomont.org/Software/Misc/CoCo/Lomont_CoCoHardware.pdf>>> >>> Hope this is at least somewhat useful.>>> -Evan>>> >>> >>> >>> | >>> | >>> | >>> | | |>>> >>> |>>> >>> |>>> | >>> | | >>> evancwright/CoCo>>> TRS-80 CoCo Proje
>> cts | |>>> >>> |>>> >>> |>>> >>> >>> >>> >>> On Sunday, March 19, 2017 1:34 PM, Glen Hewlett <glen.hewlett at sympatico.ca> wrote:>>> >>> >>> Hi All,>>> >>> Does anyone have some example code for playing audio samples in an assembly program? I’m making some nice speed improvements in my Pac Man transcode and I thought it would be nice to test with some sound added to the game. If someone has some code I can take a look at that would be great.>>> >>> Cheers,>>> Glen>>> >>> -- >>> Coco mailing list>>> Coco at maltedmedia.com>>> https://pairlist5.pair.net/mailman/listinfo/coco>>> >>> >>> >>> >>> -- >>> Coco mailing list>>> Coco at maltedmedia.com>>> https://pairlist5.pair.net/mailman/listinfo/coco>> >> >> -- >> Coco mailing list>> Coco at maltedmedia.com>> https://pairlist5.pair.net/mailman/listinfo/coco> > > -- > Coco mailing list> Coco at maltedmedia.com> https://pairlist5.pair.net/mailman/listinfo/coco-- Coco mailing listCoco at maltedmedia.comhttps://pairlist5.pair.net/mailman/listinfo/coco>> >> -- >> Coco mailing list>> Coco at maltedmedia.com>> https://pairlist5.pair.net/mailman/listinfo/coco> > > -- > Coco mailing list> Coco at maltedmedia.com> https://pairlist5.pair.net/mailman/listinfo/coco-- Coco mailing listCoco at maltedmedia.comhttps://pairlist5.pair.net/mailman/listinfo/coco
>>
>> --
>> Coco mailing list
>> Coco at maltedmedia.com
>> https://pairlist5.pair.net/mailman/listinfo/coco
>
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
More information about the Coco
mailing list