Hey all
I’ve been learning some basic stuff about FMOD(C++ API) now. However, I got stuck in the low-level stuff related to the pcmreadcallback.I supposed to write my sound and channel representation to handle the sound playback, pause, and stop.
struct CustomSound
{
friend struct CustomChannel;
public:
CustomSound( const char* i_path );
~CustomSound();
private:
U32 m_samplingRate;
U16 m_numChannels;
U16 m_bitsPerSample;
PCM16* m_pData;
U32 m_count;
}; // The code for the custom sound representation
struct CustomChannel
{
public:
CustomChannel() : m_position( 0 ), m_pSound( nullptr ) {};
void Play( FMOD_PG::CustomSound* i_pSound );
void Stop();
void WriteSoundData( PCM16* i_pData, int i_count );
inline void SetPaused( bool i_paused ) { m_paused = i_paused; };
inline bool GetPaused() { return m_paused; };
private:
FMOD_PG::CustomSound* m_pSound;
int m_position;
bool m_paused;
}; // The code for the custom channel
I also used the pcmreadcallback to write the PCM data into it through my custom channel.
FMOD_RESULT F_CALLBACK WriteSoundData( FMOD_SOUND* i_pSound, void* i_pData, unsigned int i_length )
{
static FMOD_PG::AudioManager* pManager = FMOD_PG::AudioManager::getInstance();
memset( i_pData, 0, i_length );
FMOD_PG::PCM16* pcmData = (FMOD_PG::PCM16*)i_pData;
int pcmDataCount = i_length / 2;
pManager->GetCustomChannel()->WriteSoundData( pcmData, pcmDataCount );
return FMOD_OK;
} // The code for writing the data through the callback.
My issue is that this callback will only be called when I created the sound with the createinfo once. Regarding the pause function, it seems that there is no way for me to reinvoke the callback and write new PCM data into it. So, I wonder that is there any way I can invoke this callback explicitly? Alternatively, maybe is there anything wrong with my approach?
Thanks,
Tezika