Convert PCM to XGM

SGDK only sub forum

Moderator: Stef

Post Reply
cloudstrifer
Very interested
Posts: 77
Joined: Mon Feb 19, 2018 7:31 pm

Convert PCM to XGM

Post by cloudstrifer » Fri Jan 24, 2020 7:05 pm

Hi.

I want to convert PCM to XGM, just 1 channel, is it possible?

Thank you!

Stef
Very interested
Posts: 3004
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Convert PCM to XGM

Post by Stef » Fri Jan 24, 2020 9:31 pm

Not sure what you mean exactly by converting PCM to XGM.
At least you ca declare your PCM resource as WAV resource then use the XGM driver to play it (whatever PCM channel you use for that).

cero
Very interested
Posts: 267
Joined: Mon Nov 30, 2015 1:55 pm

Re: Convert PCM to XGM

Post by cero » Sat Jan 25, 2020 10:52 am

I suppose he wants to emulate a WAV using either synth or PSG, like those ancient speech synthesizers did. It'd sound bad/metallic/robotic/etc, and I don't think any such kit exists for Genesis.

Stef
Very interested
Posts: 3004
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Convert PCM to XGM

Post by Stef » Mon Jan 27, 2020 3:07 pm

If that is really what he want then yeah, you don't have tools for that and honestly i think that results won't be good anyway.
I tried long a time ago to make a tool which could convert a PCM sample (single sound obviously) into a FM patch (kind of). It's definitely *very* complicated to develop that kind of tool (involve many mathematics and my maths aren't that great) and that would come with many limitations.

haroldoop
Very interested
Posts: 118
Joined: Sun Apr 29, 2007 10:04 pm
Location: Belo Horizonte, MG, Brazil

Re: Convert PCM to XGM

Post by haroldoop » Tue Jan 28, 2020 11:36 pm

There's a tool like that designed for the Sega Master System:
https://github.com/maxim-zhao/wav_to_psg

Stef
Very interested
Posts: 3004
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Convert PCM to XGM

Post by Stef » Wed Jan 29, 2020 11:50 am

Oh no that is something completely different here, the tool you show just convert a WAV/PCM to PSG data taking in consideration the PSG constraints to filter/process the PCM data and obtain the best quality out of it (from the PSG). The resulting PSG data size is close to the PCM data, it's just downgraded PCM.
Converting PCM to FM is a complete different beast, at least if you intend to convert a PCM sound (which is probably about some KB of data) to a FM patch (only a few bytes of data) otherwise there is no use in trying to output raw PCM sample data with FM channel as the YM2612 does have a PCM channel.

Sik
Very interested
Posts: 915
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Convert PCM to XGM

Post by Sik » Wed Jan 29, 2020 5:11 pm

Well, you could attempt to add up sine waves (so size still tied to length, but still much smaller than full blown PCM)… but even if it was reduced to a single sound (e.g. speech) I'm not sure how far you can get with just a few sine waves (unless you want to start eating multiple FM channels). I recall Streets of Rage doing some weird stuff with channel 3 with sound effects though…

That said, I think the original post was about converting PCM into a XGM-friendly format :​P (which it already does for sound effects)
Sik is pronounced as "seek", not as "sick".

haroldoop
Very interested
Posts: 118
Joined: Sun Apr 29, 2007 10:04 pm
Location: Belo Horizonte, MG, Brazil

Re: Convert PCM to XGM

Post by haroldoop » Wed Jan 29, 2020 11:59 pm

One way to translate PCM to FM would be to treat it as a seq2seq machine learning problem.

The training sets could be generated by generating random sequences of FM commands and the corresponding PCMs; then the model could be trained to do the reverse mapping from the examples.

Stef
Very interested
Posts: 3004
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Convert PCM to XGM

Post by Stef » Thu Jan 30, 2020 12:05 pm

haroldoop wrote:
Wed Jan 29, 2020 11:59 pm
One way to translate PCM to FM would be to treat it as a seq2seq machine learning problem.

The training sets could be generated by generating random sequences of FM commands and the corresponding PCMs; then the model could be trained to do the reverse mapping from the examples.
Interested in experimenting it ? :D

haroldoop
Very interested
Posts: 118
Joined: Sun Apr 29, 2007 10:04 pm
Location: Belo Horizonte, MG, Brazil

Re: Convert PCM to XGM

Post by haroldoop » Thu Jan 30, 2020 10:53 pm

Stef wrote:
Thu Jan 30, 2020 12:05 pm
haroldoop wrote:
Wed Jan 29, 2020 11:59 pm
One way to translate PCM to FM would be to treat it as a seq2seq machine learning problem.

The training sets could be generated by generating random sequences of FM commands and the corresponding PCMs; then the model could be trained to do the reverse mapping from the examples.
Interested in experimenting it ? :D
Maybe. :P

i did start planing something like that a few years ago, though with the objective of converting sound into chiptunes; any way, I never got beyond the initial planning phase. In fact, that's one of the reasons why I had implemented txt2vgm; the idea was to convert a bunch of VGM files into both wave files (which would be further processed into spectrograms) and vgm2txt files; the model would be trained to translate spectrograms into text files, which could then, finally, be converted into VGM using txt2vgm.

Stef
Very interested
Posts: 3004
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Convert PCM to XGM

Post by Stef » Fri Jan 31, 2020 9:40 am

I think that is an interesting project :) When i was looking to develop my "PCMtoFM" tools i started to read some scientific literatures about it. I found some interesting articles but never got to time to investigate them in depth unfortunately, at this time IA or genetic algorithm weren't as efficient as today so i think things get better and better. You can have a look on them as some are definitely replicating what you want to do (genetic algo to find best FM parameters):

Genetic algorithm to improve FM parameters:
http://citeseerx.ist.psu.edu/viewdoc/do ... 1&type=pdf
https://ieeexplore.ieee.org/abstract/document/701371
https://www.tandfonline.com/doi/abs/10. ... 2000150852

FM Synthesis-Based Audio Coding:
http://www.aes.org/e-lib/browse.cfm?elib=8434

Speech synthesis with FM:
https://www.sciencedirect.com/science/a ... 8485901112

FM Synthesis of Real Instruments (just a synthesizer manual here):
http://www.javelinart.com/FM_Synthesis_ ... uments.pdf

haroldoop
Very interested
Posts: 118
Joined: Sun Apr 29, 2007 10:04 pm
Location: Belo Horizonte, MG, Brazil

Re: Convert PCM to XGM

Post by haroldoop » Fri Jan 31, 2020 11:15 pm

Interesting concept; I imagine that the genetic algorithm could be either be used directly, or to provide training data for other ML; I intend to take a look at some of them. :)

Post Reply