-1

I'm trying to use the audio library BASS in my application. I'm trying to use a method which triggers a callback when it detects a beat in the music.

This is my current code:

void* (^myBlock)(DWORD, double, void *) = ^(DWORD handle, double time, void *user) {
    return nil;
};

BASS_FX_BPM_BeatDecodeGet(bpmStream, 0.0, playBackDuration, BASS_FX_BPM_BKGRND, myBlock,NULL);

The callback is defined in the header file as:

typedef void (CALLBACK BPMBEATPROC)(DWORD chan, double beatpos, void *user);

The error message is:

Passing 'void *(^)(DWORD, double, void *)' to parameter of incompatible type 'BPMBEATPROC *' (aka 'void (*)(DWORD, double, void *)')

I'm pretty sure the block only needs a small modification, but I'm not familiar with Objective-C.

LucidLime
  • 1
  • 1
  • 1
    your block is returning a `void*` when the typedef is expecting just `void`. – Daniel A. White Jan 30 '15 at 20:24
  • What is your question? – Razib Jan 30 '15 at 20:27
  • 1
    @Razib He is asking why he can't pass his block as a callback. – NobodyNada Jan 30 '15 at 20:28
  • @Razib Yes, sorry. I would like to know how to change the block so it will work. I changed void* to void. This is the new error message: Passing 'void (^)(DWORD, double, void *)' to parameter of incompatible type 'BPMBEATPROC *' (aka 'void (*)(DWORD, double, void *)') – LucidLime Jan 30 '15 at 20:32

1 Answers1

0

You are passing a block that returns a void* to a parameter that expects a function pointer that returns nothing (void).

You need to declare your block as a function returning void and pass it as the callback:

void myFunction(DWORD handle, double time, void *user) {
    //function code here
}

And then pass it to the library just like the block:

BASS_FX_BPM_BeatDecodeGet(bpmStream, 0.0, playBackDuration, BASS_FX_BPM_BKGRND, myFunction,NULL);

For more information about function pointers, see How do function pointers in C work?.

Community
  • 1
  • 1
NobodyNada
  • 7,529
  • 6
  • 44
  • 51