Difference between revisions of "Streaming PCM"
(Created page with "==Introduction== This tutorial assumes that you have read and understood Streaming Music and you understand the code in SPIRamMusicDemo. Hopefully none of that is too di...")
Latest revision as of 07:07, 7 October 2017
This tutorial assumes that you have read and understood Streaming Music and you understand the code in SPIRamMusicDemo. Hopefully none of that is too difficult to figure out, and if you understand that, you should have no problem with the general idea presented here. This method requires the vsync mixer which costs 262*2=524 bytes of ram..ouch you say? I can understand the feeling, though originally early games had no choice but to use the vsync mixer. If you can afford this for your game, it opens up quite a lot of possibilities to have a large amount of good quality sound in your game(including streaming music at the same time)
This method essentially adds in to the basic method displayed in SPIRamMusicDemo. It can also be used by itself, without streaming music, rather easily. This tutorial will assume you wish to do this while also streaming music, but it should be easy to adapt it to streaming PCM only.
The method is very similar to streaming music, and what we are going to do is store some large PCM files in SPI Ram. Few games currently use PCM because it is very large and costly on the limited flash. SPI Ram is twice as large as flash, and it can be reloaded at will to allow nearly limitless possibilities. Just as in streaming music, the most common thing you will first do for this approach is to load your sound data from the SD card into SPI ram. This is easily accomplished using CunningFellows sdSimple and Jubatian's SPI Ram library. Some example code from the SPIRamMusicDemo:
This just does a one time bulk load of an SD file into SPI Ram. This file should contain streaming music(if you are using that) AND PCM data. When you have this, setup streaming music as in the demo. Now, we will need a bit of extra code so that we can take PCM data from the SPI Ram. We need to put the data directly into a variable called "mix_buf", and the location we put it into depends on which bank is currently active. The currently active bank is mix_bank. If mix_bank is 0, then we will be writing to mix_buf from 0...261, otherwise from 262...523. Unlike music which lends itself to buffering rather well, it is not practical to buffer PCM in the '644s limited ram. EVERY FRAME, all 262 bytes of PCM data should be written. In some games this might simply not be possible due to limited cycles. It is important that this happens every frame, because missing bytes and delayed write are painfully obvious versus the generally unnoticeable instances of delay for streaming music. You are directly driving a wave form here, instead of a slow stream of byte commands.
TODO--------THIS IS A PLACEHOLDER------------