nukeykt / Nuked-OPN2

Cycle-accurate Yamaha YM3438(YM2612) emulator
GNU Lesser General Public License v2.1
214 stars 15 forks source link

Problems making a Teensy-Synth object #18

Closed dcoredump closed 2 years ago

dcoredump commented 2 years ago

Hi @nukeykt and many thanks for this cool project!

I tried to use your code to make a Teensy C++ audio object out of it. But for this I would have to fill a 128 byte buffer in the update() method (at 44100 Hz). I can't quite figure out how to do this. Can you give me a hint?

I thought I could use the OPN2_Clock() function, but this seems to calculate only a single sample, doesn't it?

I would be very happy if you could give me a short hint.

Greetings, Holger

Wohlstand commented 2 years ago

Do you want to output the audio from off this?

I thought I could use the OPN2_Clock() function, but this seems to calculate only a single sample, doesn't it?

Correct, by default it outputs only one sample and you should query it as many times as your final buffer is. You may find the slightly-extended version of this emulator: https://github.com/Wohlstand/libOPNMIDI/blob/master/src/chips/nuked/ym3438.h https://github.com/Wohlstand/libOPNMIDI/blob/master/src/chips/nuked/ym3438.c where are friendly overlays has been added to generate the output. Keep the note, you will need to use the OPN2_GenerateStream() or OPN2_GenerateStreamMix() calls to get the 44100 output, however, it's better you will use a different resampler (for example, ZitaResampler or libsamplerate) as built-in resample is a simple linear one. Or, you may just take the internal processing code and use it with the mainstream emulator directly. Also note, you should use OPN2_WriteBuffered() to pass the data into the chip that will be proceeded by OPN2_GenerateStream() or OPN2_GenerateStreamMix(). The default emulator using logic is the similar to the dealing with the real chip.

dcoredump commented 2 years ago

Hi @Wohlstand,

many thanks for your fast answer! This is was I was looking for - great! Currently my only question is how to use the clock parameter for OPN2_Reset(chip_r, rate, clock)? For rate I am using 44100 but what is the value for clock?

TIA, Holger

Wohlstand commented 2 years ago

For rate I am using 44100 but what is the value for clock?

You can use one of two known Sega clock values used for PAL and for NTSC

Wohlstand commented 2 years ago

You can use any sample rate you want, but the clock is usually the constant, I do use 7670454 at libOPNMIDI.

dcoredump commented 2 years ago

See Issue #19