BlockoS / HuDK

ASM and C open source software development kit for the NEC PC Engine
http://blockos.github.io/HuDK/doc
MIT License
29 stars 4 forks source link

VGM playback & sound effects ? #67

Open lunoka opened 2 years ago

lunoka commented 2 years ago

Hello o/

I was wondering if it was possible with your sound driver to play a vgm & some sound effects at the same time? Reserving maybe 1 or 2 channels to overlap the song.

I have already made a HuC tetris clone demo but no official sound driver is available so far for this SDK. Would it be complex to switch from pure HuC to your SDK?

Btw, what soft could I use to produce the vgm, Deflemask is ok? ( + using your utility to modify the header )

Cheers

PS : the actual demo I would like to port: https://lunoka.itch.io/tetraminos-pce

BlockoS commented 2 years ago

The VGM replay is very simple. See it as a PSG register stream. It will not be that hard to add sound effects. Unfortunately it's not supported by the current replay routine.

About switching to HuC. I don't think it'll be that hard but it'll need some work. If you only need vgm replay, I can try to make it HuC friendly so that you can use it without moving to HuDK.

You can use Deflemask or Furnace to produce VGM songs. I used it on some of my old demoscene stuffs. Note that the vgm_strip tool is very simple. Moreover, VGM data can be pretty big. It may be possible to save some space with smarter encoding and some pattern matching.

lunoka commented 2 years ago

thank you very much for your answer.

To give some context, I'm into retrodev just for months now. I may have missed the golden age where people were very active on making homebrews on PCE. I've started with the SGDK from Stephane D. and wanted to port some stuff on other plateforms like PCE or SNes.

The only thing I was able to implement in my demo is a very simple sound playback with 1 channel based on a 20 year old tutorial from JyCet, making the PCE sounds like a ... Atari 2600 haha

I agree with you on the VGM size, I've used a simple midi to vgm conversion to add a playback on my SGDK version and the vgm is weighting 256 ko... it's ok for a simple demo but quite problematic for a bigger project with 10+ songs.

I know about Squirrel but I have to switch to MML and gosh ... it's troubling ( + no SFX either and only for free projects ). I wasn't able to build with the japanese Husic driver, maybe I missed something with embedding the song in asm through PCEAS but I'm very new to this, although this driver seems to be able to play music & sfx ( assuming the xpcm driver is for the sfx part ),

It's very kind of you to propose the HuC integration but I wouldn't want you to work just for me ^^; especially if I don't dig further on the PCE side. The PCE is quite underrated and It must be difficult to work on tools for this platform if no one or few ask for it. I haven't found any discord related server on PCE dev yet.

By the way, I don't really understand what is the HES format. Is it a VGM based format? I tried an export from Deflemask and it just doesn't play at all on my winamp plugin.

Cheers

BlockoS commented 2 years ago

About HuSic. It won't compile properly with recent versions of HuC. I forked HuSic some months ago. I moved it to full asm and added sfx support. Unfortunately there're not much musicians using MML around.

I don't mind adding more features to the vgm replay. If that means more PCE homebrew, it's totally worth it.

HES is just a stripped down PC Engine ROM that only contains the irq handler routines, sound routines and data. Back in the days, Deflemask HES can't be used in a game. I coded a DMF (deflemask sound format) replay routine but there's no support for sound effect. And to be honest I don't want to touch it again. I have plans to do the same kind of work for Furnace file format but I don't know when...

lunoka commented 2 years ago

I don't mind adding more features to the vgm replay. If that means more PCE homebrew, it's totally worth it.

Awesome, thank you. I think a public release of a working sound driver compatible with HuC would be great for everybody into PCE stuff.

I have plans to do the same kind of work for Furnace file format but I don't know when...

Very interesting, the Furnace file would be directly added to the rom image and played from scratch without any conversion? Software is very promising and the main dev doesn't seem to sleep considering his updates rate ^^;

Btw, actually my current demo was made with the Elmer's fork of HuC :

https://github.com/jbrandwood/huc

Is it ok or would I have to switch to Turboxray's fork if you were to modify your sound driver?

Cheers

BlockoS commented 2 years ago

Some conversion tool will be required at some point. I'll have to take a look at Furnace file format someday :D

I think Elmer's fork is the most up to date. The sound driver will be in assembly with the appropriate HuC interface. It's not a lot of work. I think it'll move to its own project. This way people won't have to choose between HuDK or magic kit.

lunoka commented 2 years ago

Awesome news , thank you!

Btw, I'm also looking forward to the mod/xm import into Furnace that seems to be on the roadmap, since I have some stuff available from my jurassic Amiga period \o/

lunoka commented 2 years ago

Hello o/

I've noticed your vgm player was quite isolated from the rest of your sdk already, so I've tried to extract it and import it in a simple test with HuC env ( last version from Elmer 02/2022 ). I've built the vgm_stripper aside and succeeded in building a rom with a tune I made with Deflemask ( thanks to TOUKO with the assembly part, I wasn't aware of the double underscore notation change in HuC 3.99 that were failing PCEAS on the vgm.s ). Unfortunately, I have some issues in the playback. Some cuts in the tempo and the volume goes to zero after a moment, here is a link to the vgm I've made just in case :

https://www.lunoka.net/files/song.vgm

It's possible I've missed something on my side. I've seen you were linking the vgm_update to the vbl between 2 disable/enable interupts in your example whereas I just call vgm_update() right after vbsync() in a while(1) loop in HuC.

And btw, is it possible to make the vgm loop ?

Cheers

BlockoS commented 2 years ago

It's possible but I think the current converter has a bug. I'm nearly done with the updated version. I'm currently working on the sound fx part. I'll push it this week (fingers crossed).

main.pce.zip

lunoka commented 2 years ago

Awesome news! I'm looking forward to it!

lunoka commented 2 years ago

and great work on the fixed playback in the rom :D, I think I'm confident now in getting more involved with Deflemask compo now I know it will be playable on my pce (as soon as I receive my flashcard )!

BlockoS commented 2 years ago

Here's the updated vim driver. The vgm_strip program now accepts a list of songs and subtracks. For example

vgm_strip -s song00.vgm -s song01.vgm -t 1 fx00.vgm -t 0 fx00.vgm -t 0 fx01.vgm output_directory

The C API is like:

void vgm_play_song(char id);

Play song id.

void vgm_stop_song();

Stop playing song.

void vgm_play_subtrack(char ch, char id);

Play subtrack id on channel ch.

void vgm_stop_subtrack(char ch);

Stops subtrack on channel ch.

void vgm_update();

Update vgm driver. It must be called every vsync.

The pce/examplefolder contains sample programs in ASM and C.

vgm_driver.zip

lunoka commented 2 years ago

Thank you very much MooZ! I will try to implement your driver into my current tetris demo this week-end.

lunoka commented 2 years ago

I'm trying to compile the new vgm stripper. If I don't use -Wall -Werror flags, the exe is generated but I have this message when using the tool: failed to expand track data

If I use -Wall -Werror, I can't compile and fail on that issue:

vgm_strip.c: In function 'output_wav': vgm_strip.c:460:49: error: unknown conversion type character 'z' in format [-Werror=format=] fprintf(state->stream, "\n .dw wav%02zx", i);

Any idea on what I'm doing wrong?

BlockoS commented 2 years ago

You are not doing anything wrong. It looks like a compiler version issue. I used clang and it looks like yours doesn't support 'z' format. Replace 'zx' by 'lx' and you'll be good.

BlockoS commented 2 years ago

I'll replace the current HuDK vgm driver with this one later. vgm_driver.zip