Streaming Music(SD, SPI ram, Network, etc. source)

Topics related to the API, programming discussions & questions, coding tips, bugs, etc. should go here.
User avatar
D3thAdd3r
Posts: 3222
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Streaming Music(SD, SPI ram, Network, etc. source)

Post by D3thAdd3r »

I did a case study on the new compressed flash player with Alter Ego, and I am quite confident there are no issues. It took a couple minutes to build the config and trigger it from the makefile, and past that no code changes were required(of course much different than the ram based buffered version). So I think that is a pretty realistic test, as there is a wide variety of different music in the game. In total, I saved 3740 bytes on music data which I am quite please with. There was 0 difference in the sound and everything loops correctly, etc.
nicksen782 wrote: Tue Jan 16, 2018 1:10 am What is the flash/ram cost of the stock music player?
I didn't expect it, but the compressed flash player itself compiles to 256 bytes smaller than stock MIDI. So even a game that had no music, could save a little space just by adding -DMUSIC_ENGINE=STREAM to the makefile :) I got strange results with the ram player, in that it came to the same size as the compressed player(I guess, the same amount of function calls, ram reads instead of flash). I don't quite trust that outcome yet, I just thought it would be a little bigger for circular buffer code, and especially any game using it is going to require more than 256 bytes to handle looping, loading, etc. Though of course the ram version beats the compressed flash player hands down, when one goes to the trouble of offloading music entirely. In AE, if music was entirely offloaded and imagining the extra buffering stuff in user code cost ~1K, AE would save (18134+256) - (~1024) = 17366 bytes :shock:

Anyway I should wrap it all up and throw it into master since there is no major thing I can see to add at this point.
User avatar
D3thAdd3r
Posts: 3222
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Streaming Music(SD, SPI ram, Network, etc. source)

Post by D3thAdd3r »

Should also have mentioned ram size. For the compressed flash version, at least in AE, it takes 5 bytes less ram than stock.

For the ram based player, it takes 1 byte more ram than stock; but that does not include a buffer. If you can fill the buffer fast, I find 12 bytes is sufficient for most things without any slow down. So in a realistic setup, the ram based player costs probably ~13 bytes more than stock.
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: Streaming Music(SD, SPI ram, Network, etc. source)

Post by nicksen782 »

This doesn't appear to be merged into master yet. Could it be?

I was able to do SD card streaming, and SPIRAM streaming. SPIRAM was more simple. This worked good for music from SPIRAM.

What about sound effects or even short music from FLASH? Can both be done?
User avatar
D3thAdd3r
Posts: 3222
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Streaming Music(SD, SPI ram, Network, etc. source)

Post by D3thAdd3r »

I should have merged it earlier but I still did not get to it, and want to make sure I do not make any mistakes as my Git knowledge is non-existent. This is my top priority so people can use it from the start, if UCC happens this year.
nicksen782 wrote: Sun Mar 11, 2018 3:16 pm What about sound effects or even short music from FLASH? Can both be done?
Flash based music streaming is done and works perfectly though I probably didn't put the source up anywhere yet. I would expect any existing game to easily convert to this, and I would expect it would sound exactly the same(at most, a least significant bit different on volume, but not in most cases?). In the Alter Ego thread I documented some stats, and it is a big savings. Any game with music should benefit; the more the better.

Streaming sound effects...it is possible since a long time ago there was such thing as a "ram patch". Not aware of that, and a bit after it was removed, I hacked such a thing into the kernel for an old "Patch Tool" which I don't even have the source for I guess. I don't know the best way to go about it yet, but I would imagine there is basically a small buffer for each effect channel(and ditch the loop command which breaks linearity). Ultimately I don't see a way the kernel could handle it all, and there is probably going to be a lot of user code intervention. It is in the back of my mind for sure, since some games use a few K for effects. I am guessing the ram buffer gets close to 32 bytes or more, if you need sound effects on 3 channels.
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Streaming Music(SD, SPI ram, Network, etc. source)

Post by Artcfox »

D3thAdd3r wrote: Sun Mar 11, 2018 10:29 pm I should have merged it earlier but I still did not get to it, and want to make sure I do not make any mistakes as my Git knowledge is non-existent. This is my top priority so people can use it from the start, if UCC happens this year.
Let me know if you want any Git help.
User avatar
Jubatian
Posts: 1564
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Streaming Music(SD, SPI ram, Network, etc. source)

Post by Jubatian »

I did some attempt merging it before, and in the kernel it mostly seems trivial, at least I think I could do it. However the streaming music branch includes some changes within the Demos which I don't understand as it involves demos whose code I never examined. I abandoned the attempt for this.
User avatar
D3thAdd3r
Posts: 3222
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Streaming Music(SD, SPI ram, Network, etc. source)

Post by D3thAdd3r »

I will make sure SPIRamMusicDemo is good, and leave out SDMusicDemo until it is improved. The improvement would mainly be making it as asynchronous as possible, at which point it should be a decent method depending on the game requirements.

I will hold off on streaming sound effects as I expect SPI Ram based scrolling will yield much larger offloading gains. Having this (in the form of an SPI Vram video mode) will probably dictate how other usages will have to cooperate.

On streaming sound effects, my best guess currently is that the kernel should have a user callback which passes thr effect and offset the next data is required from. Then the user and kernel code could be straight forward, and the data could be agnostic as to it's origins. Though it makes little sense to me for sound effects to come from anywhere but SPI Ram, due to the nature of them.
User avatar
Jubatian
Posts: 1564
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Streaming Music(SD, SPI ram, Network, etc. source)

Post by Jubatian »

D3thAdd3r wrote: Tue Mar 13, 2018 2:29 pm I will make sure SPIRamMusicDemo is good, and leave out SDMusicDemo until it is improved. The improvement would mainly be making it as asynchronous as possible, at which point it should be a decent method depending on the game requirements.
Could you try to tidy these up in the repos? If necessary, I think you could even remove problematic demos from the master branch first (I think it is the SPIRamMusicDemo which is causing severe conflicts when attempting a merge, I dunno if it even works. If it doesn't, it can be safely discarded from master as of now anyway), and maybe attempt the merge then. It should be joined in already!
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: Streaming Music(SD, SPI ram, Network, etc. source)

Post by nicksen782 »

BUMP.

;)
User avatar
D3thAdd3r
Posts: 3222
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Streaming Music(SD, SPI ram, Network, etc. source)

Post by D3thAdd3r »

Alright I am working on cleaning this up, if there is anyone wanting to mess with it right now forget the current branches as the attached is significantly better than what I have up on github so far. I do apologize for lagging way behind, but I simply have not had enough time to do much on Uzebox lately. A haphazard dirty .tar...yes that is the best I can produce ATM, but this works AFAIK perfectly, and definitely beyond my initial expectations.

It should be bug free, flash streaming is supported(takes less code space and ram than stock, might as well use it), and ram streaming is finished. mconvert is finished, dconvert mostly is, though I have a few more features planned later on for PCM compression. The SPIRamMusic demo should show how to build a SD data file and fill it with midi and PCM data, and of course play it back. Alter Ego shows how to take any game which previously used the stock player and data format, and convert it to a streaming flash game(easy, no buffer required). On a side note, Alter Ego was converted to SDSimple(which now people want to abandon :lol: ). I am not including SDMusicDemo(available in previous posts), as this needs to be reworked. On that note, I do think the big lock there can be avoided, simply by having a decent buffer, and not blocking on the inter sector delay. That I can see, there is no way to do this in any current SD library, and direct SPI commands must be handled by the user program for that part. Doesn't seem too bad now that I am looking at it. I think in many cases a developer is not inclined to use SPI ram, and flash streaming only gets a portion of flash back versus a total offload. So showing how to utilize streaming music to the max, with nothing but the old standard kit, has a refreshed importance to me on this.
Attachments
stream-final.tar.gz
(3.53 MiB) Downloaded 330 times
Post Reply