How to create SFX for Moonsound's FM registers ?

Page 3/5
1 | 2 | | 4 | 5

Par norakomi

Paragon (1150)

Portrait de norakomi

02-02-2022, 10:49

Thank a lot for all the helpful tips.

So to summarize:

1. Hex edit Moonblaster 1.4 to playback on 60fps.
2. Create sfx in MoonBlaster 1.4 or MoonBlaster FM.
3. Convert the sfx to VGM format (this is done how exactly ? A conversion script in OpenMsx ?)
4. Playback the VGM datastream in game. (VGMPlay 1.3 ? http://www.grauw.nl/projects/vgmplay-msx/) ?

Is this correct ?

Par Grauw

Ascended (10820)

Portrait de Grauw

02-02-2022, 13:28

norakomi wrote:

2. Create sfx in MoonBlaster 1.4 or MoonBlaster FM.

I would stick to MoonBlaster 1.4 for simplicity unless you really need 4-op voices or the extra waveforms.

norakomi wrote:

3. Convert the sfx to VGM format (this is done how exactly ? A conversion script in OpenMsx ?)

The vgm_rec function is built-in to openMSX. Type help vgm_rec for usage info.

norakomi wrote:

4. Playback the VGM datastream in game. (VGMPlay 1.3 ? http://www.grauw.nl/projects/vgmplay-msx/) ?

I think using VGMPlay and the VGM format directly is overkill, VGMPlay would also be complicated to integrate.

VGM is a quite simple data format that essentially consists of a stream of commands like “set sound chip X register Y to value Z” mixed with “wait N time”. You can make a script to convert it to an even simpler format specific for sound effects in your game that consists of “register, value”, “wait 1 interrupt” and “end of effect” commands.

A playback routine can then be as simple as:

; hl = effect commands
SFX_Play:
    ld (SFX_pointer),hl    ; set effect stream to start playing
    ret

SFX_InterruptHandler:
    ld hl,(SFX_pointer)    ; get current command pointer
    call SFX_NextCommand   ; process commands
    ld (SFX_pointer),hl    ; store new command pointer
    ret                    ; return from interrupt

; hl = command pointer
SFX_NextCommand:
    ld a,(hl)              ; get command byte
    inc hl                 ; move pointer to next byte
    cp 0FEH                ; check command byte value
    jr c,SFX_WriteCommand  ; 00-FD: write command (register, value pair)
    jr z,SFX_EndCommand    ;    FE: end command
    ret                    ;    FF: wait 1 interrupt (return until next interrupt)

; a = register number
; hl = command pointer
SFX_WriteCommand:
    out (0C4H),a           ; output register number to OPL4
    ld a,(hl)              ; get value byte
    inc hl                 ; move pointer to next byte
    out (0C5H),a           ; output register value to OPL4
    jr SFX_NextCommand     ; process the next command

; hl = command pointer
SFX_EndCommand:
    dec hl                 ; just stay on the end command
    ret                    ; next interrupt it will get the end command again, and again

SFX_pointer:
    dw SFX_dummyEffect     ; command pointer, initially pointing to a dummy effect

SFX_dummyEffect:
    db 0FEH                ; dummy effect consisting of only end command

Par Thom

Paladin (711)

Portrait de Thom

02-02-2022, 14:01

Frantic by ANMA has sound effects for both PSG and FM and its source can be found here: https://github.com/stompetower/frantic/blob/main/src/replaye...

Par norakomi

Paragon (1150)

Portrait de norakomi

02-02-2022, 17:09

Thanks again for all the tips and examples. Much appreciated.

@grauw on a sidenote.

For a OPL4 music track that uses 24 channels.
Playback with the Moonblaster replayer would be extremely slow and to save cpu cycles it might be an idea to use VGMPlay to play the music.
Do you think this is a feasible option in a game environment?

Is it doable to have (the core of) VGMPlay run in a game ?
And how would you deal with the playback of songs that are let's say >50kb ?

Par Grauw

Ascended (10820)

Portrait de Grauw

02-02-2022, 17:54

It’s feasible for sure. There are other games that take this approach as well, for example Ghost and Goblins does (I made the data converter & playback routine), and so does Bengalack’s new game. The benefit is that the player is quick, the downside is that the data size is much bigger in comparison.

How much bigger? It depends on the input data. Recording a VGM and passing it through vgm_facc and vgm_opt will give a rough idea. But 24-channel tracks will not be small. I wouldn’t be surprised if a track that’s 50 kB in source format would balloon into more than 200 kB in register log stream format. Can’t say for sure, but just to set expectations.

I wouldn’t use VGMPlay directly, there is a lot of cruft in it that isn’t relevant for this use case, like support for many different sound chips, different timer sources, disk I/O and memory mapping, gzip decompression routines, etc.

But in a similar fashion as in the code above, without too much effort you can make a simple player for either VGM directly (possibly copy/pasting bits of VGMPlay source code) or for a simplified OPL4-only format converted from VGM (to make data size a bit more compact).

It will be more complex than the example above though, because you need to support loading wavekits into sample RAM, have variable length waits, and also add extra wait cycles for instrument changes (they require some delay between I/O). But nothing insurmountable.

Par norakomi

Paragon (1150)

Portrait de norakomi

11-02-2022, 11:19

I wanna try to stream music that I record in Openmsx with vgm_rec

@Grauw

I just did a few tests recording in MBWave.
I recorded in Openmsx like so:
vgm_rec start Moonsound
And I stopped 10 seconds later like this:
vgm_rec stop
Filesize was 700kb.
Tried several times, every time huge files for a song that uses no more than 4 channels, playback time just a few seconds.

Quote:

passing it through vgm_facc and vgm_opt will give a rough idea.

How is this done ?

Par norakomi

Paragon (1150)

Portrait de norakomi

15-02-2022, 11:06

@Grauw,

Could you please assist on how to pass the recorded vgm files through vgm_facc and vgp_opt ?
Are these separate tools independently of Openmsx ?

If I type "vgm_facc", "help vgm_facc", "vgm_opt" or "help vgm_opt" in the console I just get Unknown/Invalid Command.

Par Grauw

Ascended (10820)

Portrait de Grauw

15-02-2022, 11:35

Hey norakomi,

The VGM tools are command line applications, you can find them here:

https://vgmrips.net/forum/viewtopic.php?t=207

Check the Readme.txt for information about vgm_facc and vgm_cmp. (I misremembered the name vgm_opt, you’ll want to use vgm_cmp instead.)

After these optimisations you can probably expect to reduce the size by about an additional 50% to ⅔rd by converting it to a custom format.

Par norakomi

Paragon (1150)

Portrait de norakomi

15-02-2022, 13:21

I only find vgm_cmp.exe on that link.
The file won't run, asking for a missing zlib1.dll file.
After downloading this, and putting this file in the windows/System32 and windows/SysWow64 folder, as suggested by some youtuber (I have no idea wtf I'm doing here), the program still won't run: "The application was unable to start correctly (0xc0000007b).

Ehhhh... any idea what might have gone wrong ?
And what about the vgm_facc ? Where can I find that, and what's the difference between the two ?

And even when I do manage to compress the vgm file, how do I even play it back ?

*****
Update.
I found the sources (also vgm_facc), found the help file, and there was even the zlib1.dll file included.

I managed to get it to work, and compressed the vgm tune with vgm_cmp.

Cool. Next step, how to play this back on the msx ?

And you mention I can convert it to a custom format ??? How do I do that ?

And last question......

How deep does this rabbit hole go ? I'm not sure about this, looool Running Naked in a Field of Flowers Running Naked in a Field of Flowers Running Naked in a Field of Flowers

Page 3/5
1 | 2 | | 4 | 5