PCM audio playback. File reading. Animation.

Started by crcasey, November 14, 2016, 11:07:41 PM

Previous topic - Next topic

crcasey

Since the Vectrex32 has all the horsepower and direct access to the sound generator I was wondering if you could add a PLAYPCM statement to the basic using this technique?

https://www.msx.org/forum/development/msx-development/crystal-clean-pcm-8bit-samples-poor-psg

This is a non-linear mixing library to play back pcm on a three voice PSG.

Here is a sample PCM playback from this library on a MSX system.  Not great, but hay it will come out with a Vectrex buzz anyway.

I am guessing a lot more people will be able to mix a wav file to pcm than can program good 8 bit beats.

http://www.bluemsx.com/psgenc/royksopp.mp3

I haven't finished reading the basic spec doc, only the system doc.  I didn't see a file read command to open a stream object from a file to feed say a PCM player.  Is that baked in already?

The ability to read a stream and rewind a stream would come in handy for animated sprites that could dynamically read in drawing points to an active line sprite def that had the same center.  Once the animation loop finishes you rewind the file pointer.

Sorry the scope of the post outgrew itself as I had thoughts.

-Cecil


Vectrex32

I like this PlayPCM suggestion: I'll add it to my list of things to do.

There is no File I/O at this point. I've been thinking I should add it, if for no other reason than to let you store high scores for games.

Thank you,
  Bob


Malban

#3
Hi,

while I think it is a cool suggestion, I also think it would be very difficult to do...!

Reasoning:
- the Vectrex 32 has NO direct access to the PSG, it goes thru the vectrex
- therefor on the vectrex side a program has to poke all pcm values to the amplifier logic
- in order to do that with a reasonable sample quality it must do so regularily
say you want to achieve 10000 kHz sampling rate (which is quite good - but far from fantastic).

You have to output the samples values to thru the DAC every 150 cycles.

The actual output (by code generated by Vec32) would look something like:

                   
                    LDA      #SAMPLE                          ; load the next sample_byte to A
                    STA      VIA_port_a                       ; store in reg A in 6522 (DAC)
                    LDA      #VIA_TO_DAC_OUT          ; load the calculated VIA B
                    STA      VIA_port_b                        ; write back to reg B in 6522
                    LDA      #RESTORE_VIA                  ; load the calculated VIA B
                    STA      VIA_port_b                        ; write back to reg B in 6522


Optimized that is about 30 cycles, so that leaves 120 cycles to do other stuff, like drawing vectors.

The above has to called quite regular - as said about every 150 cycles, so each of the used other routines like:
- query joystick
- draw vectorlists
- wait for frame to finish
- move to position
etc

Has to be reprogrammed, that it can be "interrupted".

"Interrupted" in marks - since an interrupt would not work,
a) it takes alone very many cycles (pushing and popping) )
b) accessing via in vectrex ->  it is in general a very bad idea to interrupt

While other programs have proven that PCM output does actually work - it is very hard to do so in a "general" way.
If I were bob - I would put that on the backburner for version V5.0 of Vectrex 32 :-).

Also:
For third generation vectrex, PCM output done the "usual" way does not work at all (or only very very quietly).
(ah, well vectrex32 does not work on noBuzz machines anyway...)

I may offer an alternative suggestions:

a) a native vectrex32 lharc unpacker, you can probably find the corresponding "C" sourcecode around any corner of the internet. With that and an additional few lines (really - few lines), you could provide support for play back ym files directly (directly as in unpack it on the vec32 side, and provide the vectrex with only the register values it needs for its update round - which at maximum would be 13 bytes)!
e.g. A nice ym file of Ben Daglish might be 6kb which is nothing for Vec32 but unpacked it is about 180kb) - which can not nearly be used by vectrex. 

Malban

@Bob:
You can take that as a challenge and prove me wrong!