gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Audio > A random thought about ADPCM streaming via hardware (NDS)

#174940 - DiscoStew - Fri Aug 06, 2010 5:39 pm

Now, if this is not applicable or messes up the audio too much, then we can forget it, but the other day, I was thinking about this idea.

With how the hardware deals with ADPCM playback, it loads the initial sample and step index before running the compressed data following. When it reaches the point where it loops back, the initial sample and step index are reloaded, and playback continues. Therefore, the only way to stream the audio via hardware is if you happen to reloop with the same sample and step index initially started.

So, what if before we compressed audio to the ADPCM format, after every certain block of data, we'd change the sample to be exactly like the initial sample? To go further, we could take the initial sample, and then the samples after a set data size, and then average them out, and write the average value in their places before compression.

To go even further, what about a variable-block method, where each block isn't the same size? As far as I can tell from GBATek, while the starting loop address shouldn't be changed, what about the length? If the length could be changed mid-playback, then we could take the idea above, and enhance with variable block compression, where the initial value will still be an average, but that average can be more based on samples actually close to the originals.

Anyone understand what I'm saying?
_________________
DS - It's all about DiscoStew

#174959 - sverx - Mon Aug 09, 2010 4:36 pm

I wonder if it's really possible. I mean, you should not simply start again with the same sample you had in the beginning, you should also bring the step index back to its initial value.

#174960 - DiscoStew - Mon Aug 09, 2010 5:28 pm

Yes, I meant both the initial sample and step index.
_________________
DS - It's all about DiscoStew

#174961 - Ruben - Mon Aug 09, 2010 6:51 pm

I'm not 100% sure, but the length part seems that it would work. I can imagine that the loop point can't be changed because it loads its sample and index from there, but the final sample has no effect on it, therefore it should be changeable, but it'd have to be tested on hardware first.

And about averaging: I'd say use ~5% x-fading to the sample rather than simply average one sample, as then you may get a very noticeable bias change.

But other than that, it definitely seems doable.

#174962 - sverx - Tue Aug 10, 2010 2:16 pm

btw I noticed that sox converts PCM wav into ADPCM wav file 'in chunks' (each one having its header) so I guess it's possible to stream them using a timer to restart the audio channel after each chunk...