0
0

I’m trying to create an input plugin using [url=http://adplug.sourceforge.net/:3vy6h1uq]Adplug[/url:3vy6h1uq] and need some help.

I’ve compiled adplug without any problems and can also play songs, althugh they play to fast or stutters.

Basically I want to "convert" this code and use it in the FMOD read callback

[code:3vy6h1uq]
static long minicnt = 0;
long i, towrite = buf_size;
char *pos = audiobuf;

// Prepare audiobuf with emulator output
while(towrite > 0) {
while(minicnt < 0) {
minicnt += freq;
playing = p->update();
}
i = min(towrite, (long)(minicnt / p->getrefresh() + 4) & ~3);
opl->update((short *)pos, i);
pos += i * getsampsize(); towrite -= i;
minicnt -= (long)(p->getrefresh() * i);
}

// call output driver
output(audiobuf, buf_size * getsampsize());
[/code:3vy6h1uq]

I gave it a shot, but for example I don’t know how to use the buffer exactly

[code:3vy6h1uq]FMOD_RESULT F_CALLBACK read(FMOD_CODEC_STATE codec, void *buffer, unsigned int size, unsigned int *read)
{
adplugin
ad = (adplugin*)codec->plugindata;

static long minicnt = 0;
long i, towrite = size;

while(towrite &gt; 0)
{

    while(minicnt &lt; 0)
    {
        minicnt += ad-&gt;adwaveformat.frequency;
        ad-&gt;player-&gt;update();
    }
    i = min(towrite, (long)(minicnt / ad-&gt;player-&gt;getrefresh() + 4) &amp; ~3);
    ad-&gt;opl-&gt;update((short *)buffer, i);
    //buffer += i * (ad-&gt;adwaveformat.channels * (16/8));
    towrite -= i;
    minicnt -= (long)(ad-&gt;player-&gt;getrefresh() * i);
}

*read=size;
return FMOD_OK;

}
[/code:3vy6h1uq]
Any sound c++ guru that can help me out?

  • You must to post comments
0
0

have you looked in the examples? There is an example of how to do this. basically, you have to fill the buffer that the readcallback parameter passes. You fill it according to Length. If the adlib supports filling the buffer in one shot, then you dont need to worry about anything else. But if it only gives you a little chunk at a time then you have to keep adding to the buffer until length.

I did something like this with the SNESAPU dll. After compiling it I set it up for use with FMOD. later when I get home I can dig up some examples for you. Here is some code for the snes emulator in C#. I’ll try to grab some of my C examples later.

[code:2kyi24lq]
public PluginErrors Decode(IntPtr soundraw, IntPtr data, uint datalen)
{
unsafe
{
short* stereo16bitbuffer = (short*)data.ToPointer();
EmuAPU(stereo16bitbuffer, (int)datalen >> 2, (char)1);
}

        //return error codes
        return PluginErrors.OK;
    }

[/code:2kyi24lq]

of course I dont know how your adlib works, so i cant go into more detail, but this just shows how you can do the buffer. the main thing is datalen >> 2

EDIT:
actually, you just sparked my interest in this… I may have to get the library and try this on my own player =)

  • You must to post comments
0
0

What example exactly?

I think it’s that getrefresh() thing that has to be taken in account of, since that can very depending on what format adlib plays. That’s why my trying out code without it sometimes play too fast or somtimes too slow..

Let me know if you come up with something, and those examples you mentioned.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.