convert WAV/MP3 to PSG melody

Pagina 1/5
| 2 | 3 | 4 | 5

Door Leo

Paragon (1236)

afbeelding van Leo

06-08-2009, 21:50

Hi all,

I am working on a way to translate a given wav file ( any mp3 can be converted to wav) into a song for PSG.

Of course there is pcmenc but i guess it take too much cpu ( and memory ) to be included into a rom game with actions taking place while playing song.

So the idea is more like these freware that converts wav file into midi for pc : all what i tried are ugly , i mean it is useless , i think they could not even extract a single tone.
Of course i dont expect something very close to the original but at least something pleasant to hear with some re-work but that has already the main melody more or less and rythm.

So my question is there anyone who tried this before or is there anyone that knows a good wav2mid free/shareware that can give (almost) hearable melody ?

For the moment my script gives (sometimes) hearable melody in fact it is a bit ridiculous at the begining but after a while one get used , in fact it is almost a different song as compared to the original !

PS: do you know trackID on mobiles like sonyericsson it is able to record 10secs of a song and tell you what song it is !!!

Aangemeld of registreer om reacties te plaatsen

Van AuroraMSX

Paragon (1901)

afbeelding van AuroraMSX

13-08-2009, 09:45

PS: do you know trackID on mobiles like sonyericsson it is able to record 10secs of a song and tell you what song it is !!!shazam does that, too. Pretty neat...

Van Leo

Paragon (1236)

afbeelding van Leo

13-08-2009, 13:14

Well this gives you the name of the song , i was more citing trackId in PS but the point was more like to input a wav file an output a PSG song with its limitation .

here is an example of what i can get , it is "almost hearable" it takes 6 notes per seconds ( so nothing to compare with pcmenc or other ) :



I resynthetise the PSG into wav but in fact it takes 11kb

Van pitpan

Prophet (3135)

afbeelding van pitpan

14-08-2009, 10:02

Weird but nonetheless interesting! It's like an alien version of the same song.

Van Leo

Paragon (1236)

afbeelding van Leo

14-08-2009, 15:11

i agree its weird , it did trial with "mission impossible theme" also ,
it is not possible to hear or recognize most of the time !

Van MäSäXi

Paragon (1884)

afbeelding van MäSäXi

16-08-2009, 16:39

Leo, I like the SOUND of ocarina PSG a lot! Big smile

This is MUCH BETTER than most 80s PSG tunes ever were!! Smile Crying

I would like to send you some Rock-A-Billy tracks to convert them to PSG tune!! Tongue At last I could hear Rock-A-Billy on MSX!! LOL!

Van Leo

Paragon (1236)

afbeelding van Leo

16-08-2009, 18:53

the melody has to be rather one single instrument, at least one clear main like cello or brass ... or ocarina, ( vocal works pretty bad ) , but u can send one at

montagne.leo (at)

i generally work from a low quality 11khz mono wav file


Enlighted (6493)

afbeelding van ARTRAG

17-08-2009, 15:48

ideally you have to split the input in frames,
chose the 3 psg outputs (frequency and
amplitude) that better approximate in some sense
the sound in the frame and move to the next frame...

As first approx, you can detect the 3 strongest tones
in each frame and take their frequency and amplitude
for the psg...

What is the algorithm you use?
Can you unveil the math behind?

Van Leo

Paragon (1236)

afbeelding van Leo

17-08-2009, 16:09

i can post code it is in matlab , but basically it is :

1) read wav into vector array.

2) split the vector in slots of time , i can change this value but usually 5 slots per seconds is fine.

3) for each slot i do FFT , @ 11250 Hz each and 5 slots per second i have 2000 points or so per fft i take into accoun the first 1000x point those between 0 -5625 Hz.

4) do an integration of fft result like : i take 2/3 of fft value + 1/3 previous slot value --> new value.
this give a little bit of continuity , and practically it gives some priority to the "sustain" part of a sound over a new attack, or can filters out the drums in favor to the melody.

5) i get the 3 max : i take into account the fact that 2 given maxs which frequency are the same x2 or x3, counts in fact as one tone + harmonics. ( for some wav it is good , for others it is not , i give a try to see )

4) I save the magnitude (converted in the log range of psg) and frequencies for that slot and go for next slot , i suppose i use only square wave of psg + volume and i dont use the enveloppe select function .

There are many values i can change like slots length , pre-equalize input file to enhance melody , change a little bit the strategy for some songs like 2 pass algo ...


Enlighted (5735)

afbeelding van NYYRIKKI

18-08-2009, 00:45

A bit offtopic:
I was experimenting with much more simple tone regognition long time ago... It was a simple program for MSX tR that regognized just a frequency you whistled to tR and played it back on PSG... I was hoping to add this as a user interface for MoonBlaster, but newer got that far... Maybe today it could be more easy to binary patch in as we have all these wonderful debugging environments on OpenMSX and BlueMSX. Smile


Enlighted (6493)

afbeelding van ARTRAG

18-08-2009, 02:23

leo post the matlab (or mail it to me)
it would be nice to make them run

anyway, do u maximize the abs(fft(data_chunk)).^2 ?

have u considered to maximize on fa,fb,fc,Aa,Ab,Ac

int_on_data_chunk_time( abs( data_chunk-psga(fa,Aa)-psgb(fb,Ab)-psgc(fc,Ac)).^2 )

and, moreover what about chunks of 1/50 sec?
this is the resolution of a normal psg player

Pagina 1/5
| 2 | 3 | 4 | 5