I want to call C++ method in pure c code, and I follow a article. The bridge is below:
extern "C" {
void setSampleRateForC(SoundTouch *p, uint rate) {p->setSampleRate(rate);}
void setChannelsForC(SoundTouch *p, uint channels){ p->setChannels(channels);}
void setTempoChangeForC(SoundTouch *p, float tempo ){ p->setTempoChange(tempo);}
void setRateChangeForC(SoundTouch *p, float rate ){ p->setRateChange(rate);}
void setPitchSemiTonesForC(SoundTouch *p, float pitch) {p->setPitchSemiTones(pitch);}
BOOL setSettingForC(SoundTouch *p, int settingId, int value) { return p->setSetting(settingId, value);}
void setRateForC(SoundTouch *p, uint rate) {p->setRate(rate);}
void setTempoForC(SoundTouch *p, float tempo ){ p->setTempo(tempo);}
void setPitchForC(SoundTouch *p, float pitch) {p->setPitch(pitch);}
void putSamplesForC(SoundTouch *p,
const SAMPLETYPE *samples, ///< Pointer to sample buffer.
uint numSamples ///< Number of samples in buffer. Notice
///< that in case of stereo-sound a single sample
///< contains data for both channels.
){ p->putSamples(samples, numSamples);}
uint receiveSamplesForC(SoundTouch *p, SAMPLETYPE *output, ///< Buffer where to copy output samples.
uint maxSamples ///< How many samples to receive at max.
) {
return p->receiveSamples(output, maxSamples);
}
SoundTouch *getInstance(){
return getInstance();
}
but when i call the getIntance() in my c code, and the program is crashed. so I want to know, what's wrong with the code.
LOGE("%s init SoundTouch begin", THIS_FILE);
pSoundTouch = soundtouch::getInstance();
LOGE("%s", THIS_FILE);
But only find init SoundTouch begin in logcat, and the next log is not appear in the logcat. please help me. thank you. and the getInstance() is:
SoundTouch *SoundTouch::getInstance(){
return new SoundTouch();
}