0
0

I would like to play an mp3 sample backwards. My ultimate goal is to imitate scratch DJ effects with a mouse.

Is any of this possible with fmod?

  • You must to post comments
0
0

I have asked this a few times too, but currently it is not possible.
I have made a dll that emulates it a bit though. It’s a stream dsp, that stores 5 seconds of data.
When you set some variable to play reversed, it overwrites the received data with the stored data, but backwards.
For playing reversed a short time, such as for scratching, this gives a nice result.
The only problem is that the position is not yet updated, so when you put it back in normal mode, you have missed the time you played reversed. (So you cannot keep on scratching over the same part over and over)
I have done a request to handle this myself in a previous topic : “Using fmod’s mp3 decoder”, but brett hasn’t answered yet.

  • You must to post comments
0
0

Thanks for the reply.
I didn’t know how mpeg works exactly, but isn’t there a number of frames that you can decode so you are sure the last one will be correct?
Like decode 5 + number of frames needed frames and use the last ones?
Loading it as a sample will probably be too difficult, because you need way to much memory for this.
Besides, currently I don’t need to play the whole song in reverse, I just have to be able to say at any moment play reversed or play normal.

  • You must to post comments
0
0

ok, this sounds cool, but I don’t understand why it wouldn’t work in directsound.
It looks a lot like my current implementation (I have a function to set the frequency in my app, and a negative value will set the positive frequency, and activate my dsp)
The problem I currently have with it, is that decoding isn’t stopped, so I can never catch up with the stream, which results in some time being ‘lost’

here is the piece of code that makes it all possible :

void *DSP_EffectCallback(void *originalbuffer, void *newbuffer, int length, int param)
{
int count;
signed short *srcleft, *srcright;
int mixertype = FSOUND_GetMixer();

// must be 16bit stereo integer buffer.. sorry blendmode (32bit) and fpu (32bit float) dont support this.
if (mixertype == FSOUND_MIXER_BLENDMODE || 
    mixertype == FSOUND_MIXER_QUALITY_FPU)
    return newbuffer;

srcleft   = ((signed short *)newbuffer);
srcright  = ((signed short *)newbuffer)+1;

length <<= 1; // *2 for stereo (number of 16 bit samples)

for (count = 0; count < length; count+=2)
{
    l = srcleft[count];
    r = srcright[count];

    //*** REVERSED ***
    if (b_Reversed[param])
    {
        //Store Sound in Buffer
        rev_Buffer[rev_bufposition[param]][param] = l;
        rev_bufposition[param]++;
        rev_Buffer[rev_bufposition[param]][param] = r;
        rev_bufposition[param]++;

        if (rev_bufposition[param] == 441000)
            rev_bufposition[param] = 0;

        // Play sound reversed from buffer
        if (rev_playreversed[param] == 0)
            rev_playposition[param] = rev_bufposition[param];
        else
        {
            //we fill the buffer ourselves, but reversed :smile:
            if (rev_playposition[param] == 0)
                rev_playposition[param] = 441000;
            rev_playposition[param]--;
            r = rev_Buffer[rev_playposition[param]][param];
            rev_playposition[param]--;
            l = rev_Buffer[rev_playposition[param]][param];
            //I don't think it is necessary to do this again here...
            //if (playposition[param] == 0)
            //  playposition[param] = 441000;
        }
    }

    //*** GENERAL ***
    //Normalize and write new values
    if      (l < -32768) l = -32768;
    else if (l >  32767) l =  32767;
    if      (r < -32768) r = -32768;
    else if (r >  32767) r =  32767;
    srcleft[count] = l;
    srcright[count]= r;
}
return newbuffer;

}

  • You must to post comments
0
0

If the decoding engine is fast enough (and by tests I think it’s proven ;)), then you can play Mp3s backwards. I’d say have the decoding engine decode a few frames (lets say 4, for ~1/10 of a second), play the first bit of data, bump it all up, and decode a new sample for the last part. I’m pretty sure you can kiss the CPU % goodbye, but it’s a way that I think would work.

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.