FM PCM Player 1.0 released

FM PCM Player 1.0 released

by Grauw on 12-01-2020, 16:55
Topic: Software
Languages:

Grauw released a PCM player for the YM2413 OPLL MSX-MUSIC.

Not only does it play PCM in high 8-bit quality, but it also shows a nice wave visualisation effect while doing so. It requires MSX2, MSX-DOS2, and several megabytes of memory is recommended.

It works by forcing the phase generator to hold on a specified phase using test register bit 2. This allows it to index into the sine table and produce accurate near 8-bit sample playback with a simple inverse lookup table.

The playback is timed by synchronizing to the VDP line drawing frequency, which provides a good high-frequency timer on MSX2 that is CPU speed independent. Additionally it lets it render the nice visualisation.

You can see the FM PCM player in action in this video (Youtube).

Relevant link: FM PCM Player project page
Relevant link: Forum thread

Media browser (2)

  • FM PCM Player 1.0 released
  • FM PCM Player 1.0 released

Comments (24)

By Pencioner

Scribe (1546)

Pencioner's picture

12-01-2020, 22:59

Nice job! I would never expect that pure FM chip could do that Wink

I'm wondering how well does it work with the FPGA implementations of OPLL. Can't test myself right now as i'm packing stuff (moving to new apartment soon) but i'll do when i have a chance if nobody tries it before

By Giangiacomo Zaffini 2

Champion (282)

Giangiacomo Zaffini 2's picture

13-01-2020, 00:28

How long before cheap 8Mbytes-16Mbytes mapped RAM cartridges since they're becoming needed more and more? Tongue

Good work Grauw! (as always!) Big smile

By edoz

Prophet (2473)

edoz's picture

13-01-2020, 09:26

Wow! How is this possible?! The sound is just very good! Nice!

By ericb59

Paragon (1099)

ericb59's picture

13-01-2020, 13:52

Oh great.
Does it possible to use it to play samples stored in VRAM just like the PCMplay of the Turbo-R ?
If Yes, it will be good for my next upcoming project !

By msd

Paragon (1510)

msd's picture

13-01-2020, 13:53

Very cool. Can this only be done with the YM2413?

By Parn

Paladin (833)

Parn's picture

13-01-2020, 14:21

Very nice, @Grauw!

msd wrote:

Very cool. Can this only be done with the YM2413?

Grauw's tool is specifically for the OPLL. But there are already other ways of playing 8-bit samples in MSX-Audio (it has PCM and ADPCM), SCC, PSG and of course OPL4 (which supports up to 16-bit 44.1kHz samples).

EDIT: Actually Grauw's tool also supports the turboR PCM, which means it also works in the latest OCM firmware, albeit in turboR PCM mode instead of OPLL mode, since current FPGA implementations don't support what's needed for this to work.

By Grauw

Ascended (10707)

Grauw's picture

13-01-2020, 16:02

ericb59 wrote:

Does it possible to use it to play samples stored in VRAM just like the PCMplay of the Turbo-R ?
If Yes, it will be good for my next upcoming project !

Yes, that is a simple matter of replacing an ld a,(hl) by an in a,(98H).

msd wrote:

Very cool. Can this only be done with the YM2413?

In principle it can be done with all Yamaha OP* chips since all of them have the phase generator hold function in the test register.

However there is one catch; the OPLL has a 9-bit f-num, and by setting only the LSB you can reach the entire amplitude range quite easily. The OPL series however have a 10-bit f-num, and as a result the LSB only has half the range. It is preferred to only change one register because if you need to change multiple it will introduce noise. I think the LSB’s range can be increased by involving the modulator though.

I want to experiment with getting this to work on the OPL series as well, just for completeness’ sake. For OPL4 the benefit would be that this allows streaming PCM of arbitrary length, something which it normally can’t do. As for MSX-AUDIO and OPNA, they have a more direct register in their ADPCM unit that allows PCM output without silencing FM playback, so that is the more obvious option. Nevertheless it would also be interesting to try it out on the OPN series.

By msd

Paragon (1510)

msd's picture

13-01-2020, 16:51

@Parn I mean.. Is the YM2413 the only FM chip used on MSX where you can use this method.

By Parn

Paladin (833)

Parn's picture

13-01-2020, 18:16

Sorry for not getting at first! As @Grauw said, it's not, but it's the one where it would be most useful at first.

By Giangiacomo Zaffini 2

Champion (282)

Giangiacomo Zaffini 2's picture

13-01-2020, 19:30

@Grauw: I read from You that the same technique should work on OPN chip? Did I read it right?

By Pac

Scribe (6966)

Pac's picture

13-01-2020, 20:00

Excellent work! Wink I didn't follow the forum thread (sorry), is this solution suitable for games?

By Grauw

Ascended (10707)

Grauw's picture

13-01-2020, 21:24

Giangiacomo Zaffini 2 wrote:

@Grauw: I read from you that the same technique should work on OPN chip? Did I read it right?

I haven’t confirmed it yet, but I think it should work since on the OPN series register 21H (test) bit 3 has the PG reset/hold function. Then the same principles should apply. If we’re unlucky though it freezes the count but does not reset, I do read something along those lines in some of the notes, but they may have misinterpreted their measurements.

For the OPL series I’m pretty confident it will work like the OPLL (the test register bit is also the same).

PAC wrote:

Excellent work! Wink I didn't follow the forum thread (sorry), is this solution suitable for games?

Well not during live gameplay since it takes 100% CPU while the sample is playing. But you can have quick attack samples like in Rune Master 2, or ones like in the Fray turboR version intro.

By Grauw

Ascended (10707)

Grauw's picture

15-01-2020, 00:35

Grauw wrote:

In principle it can be done with all Yamaha OP* chips since all of them have the phase generator hold function in the test register.

I tried it tonight and I can confirm that indeed this can also work on MSX-AUDIO and MoonSound.

Quote:

However there is one catch; the OPLL has a 9-bit f-num, and by setting only the LSB you can reach the entire amplitude range quite easily. The OPL series however have a 10-bit f-num, and as a result the LSB only has half the range. It is preferred to only change one register because if you need to change multiple it will introduce noise. I think the LSB’s range can be increased by involving the modulator though.

I can also confirm this is indeed the case. Tonight’s test therefore used carrier multiplier 8 (instead of 4 on the OPLL) to index in a quarter sine. I can double the amplitude by selecting the additive algorithm but it does have DC offset. I will fiddle around with modulator settings next to get rid of the DC offset.

By msd

Paragon (1510)

msd's picture

15-01-2020, 11:18

Quote:

. It is preferred to only change one register because if you need to change multiple it will introduce noise.

Isn't update of the f-num completed by writing to the low byte of the f-num (or the other way around). So I think it shouldn't introduce noise

By Grauw

Ascended (10707)

Grauw's picture

15-01-2020, 14:36

I don't think so, it is like that on the OPN series but not on OPL.

But, for implementing this technique on OPN that is actually an interesting observation.

By mohai

Paladin (1003)

mohai's picture

17-01-2020, 13:55

Nice ! Big smile
It is really impressive.
I am not very skilled in sound generation. Would it be possible to replay more than one sample at once?
Maybe lowering the sample rate a little?
I am thinking about mod-like player.
... and regarding mod player: Could the old mod-player for Turbo R be modded to get full stereo using both PCM and your OPLL routine?

By Grauw

Ascended (10707)

Grauw's picture

17-01-2020, 20:38

mohai wrote:

Nice ! Big smile It is really impressive. I am not very skilled in sound generation. Would it be possible to replay more than one sample at once? Maybe lowering the sample rate a little?

Thanks! The number of channels can be up to 9, however since the YM2413 has a wait requirement of 96 cycles per access, the maximum frequency for >1 channels is determined by the formula 3579545 / 96 / <channel-count>. E.g. for 2 channels the maximum is 18643 Hz and for 4 channels it is 9322 Hz.

However instead of using multiple channels you might as well add all the samples together and play them on a single channel. The downside is a small reduction in bit-depth but on the upside you can have a higher frequency which in my opinion is more important for good sound quality.

Bit-depth affects the noise floor, which isn’t audible during loud music, while frequency determines whether it sounds bright or muffled overall.

mohai wrote:

I am thinking about mod-like player.
... and regarding mod player: Could the old mod-player for Turbo R be modded to get full stereo using both PCM and your OPLL routine?

For turboR the answer is simple since a MOD player has been done before Smile. The FM method doesn’t really add significant overhead compared to the internal DAC, so it should work equally well. However since its MSX-MUSIC and DAC are output through the same mono jack, you won’t get any stereo, so you might as well just use the internal DAC.

By hope-hunter

Rookie (22)

hope-hunter's picture

20-02-2022, 08:57

@Grauw
I'd like to know: Are all the synthesizer functions unusable during the sample reproduction? All the channels still halted? In other words: is it possible to reproduce something on the other channels that don't need the same technics?

Thank you! Great job! Smile

By Grauw

Ascended (10707)

Grauw's picture

20-02-2022, 14:06

Thanks hope-hunter. Indeed the normal FM synthesis is not possible during the sample playback. The test register bit used by this technique disables the phase increase across all channels…

By hope-hunter

Rookie (22)

hope-hunter's picture

21-02-2022, 10:53

@Grauw Ok, but still it's very good!

In the past, I did manage to play samples on PSG at 3~7Khz in MSX-BASIC, also using VDP IE1. It was very nice. Runs well both on execution or editon time. When running "Files" statement it hangs a little naturally, but proceed without problems. You can run a Basic program, change screen mode, etc. But the system in general turns very slow, of course. I think that would works for a RPG game for example. Using OPLL would eliminate the noise of low resolution.

I also really believes that is possible to create a MOD PLAY for 4 or 6 channels, if the MSX program, first, read all the data and creates ("pre-renderizes") all need notes before to play. The mixing can be a simple SUM.

I was also interesting to reproduce a stereo wave, since some systems has PSG output on the LEFT and OPLL on the RIGHT (I doens't like this, but...). A data could be renderize to PSGx3 channels (LEFT) + FM (RIGHT). In the past, I made a stereo using PSG only (2 and 3). It was very nice to hear on BlueMSX, but for voice and SFX. For music, at low freq/rate, the stereo doesn't appear so much and 1 channels PSG is very noisly.

I hope that OpenMSX implements your OPLL emulation. Did you have some answer about it?

I'm only dreaming... Big smile

By hope-hunter

Rookie (22)

hope-hunter's picture

21-02-2022, 10:48

Well, one more thinking, I also have interesting in modify my OPLL to create a better stereo, like a "professional mixing".
In a studio mixing, we generally use a standart for drums panoramic that works great. It was nice to reproduce it like this.
The bass works better on center. The Snare Drum could be also on center. The toms, Hi-Hat and Crash has their own panoramic: Tom a little to left (or according his frequency), Hi-Hat a little to right, and crash a little more to right or left (or also according his frequency).
On tone instruments, each channel could be reproduce with a different panoramic. Like: Center, Center, Left, Left, Right, Right or another "scenes" to select.
I'm like to try manually do this using two OPLLs CI, masking the bits. But maybe more easy to emulate this.
I think this improvement would not change the originally os the old OPLL musics and it would be all automatic. Wink

By hope-hunter

Rookie (22)

hope-hunter's picture

21-02-2022, 10:59

LOL, another doubt. LOL!
And about the Drums channel? In many systems it is at the LEFT. It is possible to generate a stereo wave applying your techincs to the drums channel? It would be played on the other side?

By Grauw

Ascended (10707)

Grauw's picture

21-02-2022, 11:54

hope-hunter wrote:

I hope that OpenMSX implements your OPLL emulation. Did you have some answer about it?

OpenMSX has integrated Nuke.YKT’s Nuked-OPLL core since version 16, which is accurate enough to play back PCM.

hope-hunter wrote:

And about the Drums channel? In many systems it is at the LEFT. It is possible to generate a stereo wave applying your techincs to the drums channel? It would be played on the other side?

Hmm good question. I haven’t looked in to it, but a problem is that you can not define a custom instrument, so you can’t set a high multiplier on the carrier, and the range and amplitude of values you can output will be limited.

By hope-hunter

Rookie (22)

hope-hunter's picture

22-02-2022, 09:18

Ok, understood!
I'll try to run your application on OpenMSX, I hadn't tried yet cause I still was using DOS1 on it. But now, I'm going to create a DOS2 setup.