We try to use two samples from FMOD engine, SimpleEvent and Output_mp3, to output a mp3 file for a given event.
We first build the output_mp3L64.dll using output_mp3 project. and then use following code.
The problem is output_state->readfrommixer(output_state, destptr, l); always returns FMOD_ERR_INTERNAL. Please help us to indicate why, thank you!
/*==============================================================================
Simple Event Example
Copyright (c), Firelight Technologies Pty, Ltd 2012-2019.
This example demonstrates the various ways of playing an event.
Explosion Event
This event is played as a one-shot and released immediately after it has been
created.
Looping Ambience Event
A single instance is started or stopped based on user input.
Cancel Event
This instance is started and if already playing, restarted.
==============================================================================*/
#include “fmod_studio.hpp”
#include “fmod.hpp”
#include “common.h”
int FMOD_Main()
{
void* extraDriverData = NULL;
Common_Init(&extraDriverData);
FMOD::Studio::System* system = NULL;
ERRCHECK(FMOD::Studio::System::create(&system));
// The example Studio project is authored for 5.1 sound, so set up the system output mode to match
FMOD::System* coreSystem = NULL;
ERRCHECK(system->getCoreSystem(&coreSystem));
unsigned int pluginHandle = 0;
ERRCHECK(coreSystem->loadPlugin("output_mp3L64.dll", &pluginHandle));
ERRCHECK(coreSystem->setOutputByPlugin(pluginHandle));
ERRCHECK(coreSystem->setSoftwareFormat(0, FMOD_SPEAKERMODE_5POINT1, 0));
ERRCHECK(system->initialize(1024, FMOD_STUDIO_INIT_NORMAL, FMOD_INIT_NORMAL, extraDriverData));
FMOD::Studio::Bank* masterBank = NULL;
ERRCHECK(system->loadBankFile(Common_MediaPath("Master.bank"), FMOD_STUDIO_LOAD_BANK_NORMAL, &masterBank));
FMOD::Studio::Bank* stringsBank = NULL;
ERRCHECK(system->loadBankFile(Common_MediaPath("Master.strings.bank"), FMOD_STUDIO_LOAD_BANK_NORMAL, &stringsBank));
FMOD::Studio::Bank* sfxBank = NULL;
ERRCHECK(system->loadBankFile(Common_MediaPath("Sound2D.bank"), FMOD_STUDIO_LOAD_BANK_NORMAL, &sfxBank));
// Get the Single Explosion event
FMOD::Studio::EventDescription* eventDescription = NULL;
ERRCHECK(system->getEvent("event:/Sound2D/ui_boss_1", &eventDescription));
// Get instance
FMOD::Studio::EventInstance* eventInstance = NULL;
ERRCHECK(eventDescription->createInstance(&eventInstance));
ERRCHECK(eventInstance->start());
// Wait for the event to finish playing
FMOD_STUDIO_PLAYBACK_STATE state;
do {
ERRCHECK(eventInstance->getPlaybackState(&state));
ERRCHECK(system->update());
Common_Sleep(50);
} while (state != FMOD_STUDIO_PLAYBACK_STOPPED);
// Release the event instance after playback
ERRCHECK(eventInstance->release());
ERRCHECK(sfxBank->unload());
ERRCHECK(stringsBank->unload());
ERRCHECK(masterBank->unload());
ERRCHECK(system->release());
Common_Close();
return 0;
}