Audio is dead silent, howver, it is much closer now than before.

audioplugins
Elliott Liggett 2021-08-01 15:24:31 -07:00
rodzic f922789e2d
commit 19d1ab4863
1 zmienionych plików z 49 dodań i 18 usunięć

Wyświetl plik

@ -303,7 +303,7 @@ void audioHandler::setupLADSP()
// setup for the plugin:
int lPluginIndex;
pre_control = 0.01f;
pre_control = 0.99f;
void *pvPluginHandle = loadLADSPAPluginLibrary(pcPluginFilename);
dlerror();
@ -323,11 +323,12 @@ void audioHandler::setupLADSP()
}
BUF_SIZE = (this->chunkSize);
BUF_SIZE = 1112; // hard coding what seems to be the correct value here.
qDebug(logAudio()) << __PRETTY_FUNCTION__ << ": Setting BUF_SIZE to " << BUF_SIZE; // 960
BUF_SIZE = 2728; // starting with the largest likely size
qDebug(logAudio()) << __PRETTY_FUNCTION__ << ": Setting BUF_SIZE to " << BUF_SIZE;
qDebug(logAudio()) << __PRETTY_FUNCTION__ << ": Setting sample rate to: " << SAMPLE_RATE;
pInBuffer[0]= (float*)malloc(sizeof(LADSPA_Data) * BUF_SIZE/2);
pInBuffer[1]= (float*)malloc(sizeof(LADSPA_Data) * BUF_SIZE/2);
@ -403,16 +404,16 @@ void audioHandler::setupLADSP()
void audioHandler::runPlugin()
{
int numread=0;
// numread actually sets the
int numSamplesToProcess= BUF_SIZE/2;
if (psDescriptor->activate != NULL)
psDescriptor->activate(handle);
// grab audio (already done, no sound file to read from)
// sfload does this: copy from input file to pInBuffer, at size BUF_SIZE
// Crash here:
psDescriptor->run(handle, numread); // run the audio through the plugin. Number of pieces processed is numread. Compare to size of data needing to be read and run again if needed.
qDebug(logAudio()) << "Number of samples processed: " << numread;
psDescriptor->run(handle, numSamplesToProcess); // run the audio through the plugin. Number of pieces processed is numread. Compare to size of data needing to be read and run again if needed.
//qDebug(logAudio()) << "Number of samples processed: " << numSamplesToProcess;
}
void audioHandler::setVolume(unsigned char volume)
@ -669,20 +670,45 @@ void audioHandler::incomingAudio(audioPacket inPacket)
pluginMutex.lock();
// out has size inPacket.data = BUF_SIZE
// pOut/inBuffer[1] has size BUF_SIZE/2
// inPacket.data has size BUF_SIZE
// pluginOutput16bitInterlaced has size BUF_SIZE
// Flow:
// inPacket --> out --> pInBuffer --> runPlugin() --> pOutBuffer --> pluginOutput16bitInterlaced --> inPacket
//
// Note, size of qint16 array is data.size() / 2 .
//
qint16* out = (qint16*)inPacket.data.constData();
qDebug() << "about to make byte array:";
// Why does the next line down crash!?!?!
qDebug() << "made byte array.";
BUF_SIZE = inPacket.data.size() / 2; // divide by two because the inPacket is 8 bits per member
// and all our usage is at 16 bits per.
qDebug(logAudio()) << "size of inPacket data: " << inPacket.data.size();
qDebug(logAudio()) << "size of BUF_SIZE: " << BUF_SIZE;
// --- Input and Output buffer strategy:
// The plugin does not look at the size of the allocation. And the pointer
// needs to be to the same original location as the plugin runs
// Therefore, we allocate a large amount in the setupLADSPA() function,
// and simply adjust the BUF_SIZE so that the runPlugin() call only goes
// as far as is needed into the memory.
// I think these lines caused the pointer location at the base of the array to change, no good.
// pInBuffer[0]= (float*)realloc(pInBuffer[0], sizeof(LADSPA_Data) * BUF_SIZE / 2);
// pInBuffer[1]= (float*)realloc(pInBuffer[1], sizeof(LADSPA_Data) * BUF_SIZE / 2);
// pOutBuffer[0]= (float*)realloc(pOutBuffer[0], sizeof(LADSPA_Data) * BUF_SIZE / 2);
// pOutBuffer[1]= (float*)realloc(pOutBuffer[1], sizeof(LADSPA_Data) * BUF_SIZE / 2);
pluginOutput16bitInterlaced = (uint16_t *)malloc(sizeof(uint16_t) * inPacket.data.size() );
//qDebug(logAudio()) << "size of inPacket data: " << inPacket.data.size();
//qDebug(logAudio()) << "size of BUF_SIZE: " << BUF_SIZE;
// Allocated for 16 bit samples, interlaced stereo
pluginOutput16bitInterlaced = (uint16_t *)malloc(sizeof(uint16_t) * BUF_SIZE );
// Copy data from "out" to pInBuffer:
// copyDataIn();
@ -698,12 +724,14 @@ void audioHandler::incomingAudio(audioPacket inPacket)
pInBuffer[1][n/2] = (out[n+1] - mid) * scalingFactor;
}
control = pre_control;
// control is a number that the plugin has a pointer to.
// In this case, control is a float from 0 to 1.
control = pre_control = 0.9;
runPlugin();
// copy data back out from pOutBuffer to inPacket.data
// pOut/inBuffer[0] has size BUF_SIZE/2
// pOut/inBuffer[1] has size BUF_SIZE/2
// Maybe the issue is here?
@ -715,9 +743,12 @@ void audioHandler::incomingAudio(audioPacket inPacket)
// copyDataOut();
for(int i=0; i < BUF_SIZE; i++)
// CAREFUL, get the 16 bits into the 8 bit format carefully:
for(int i=0; i < BUF_SIZE*2; i+=2)
{
inPacket.data[i] = pluginOutput16bitInterlaced[i];
inPacket.data[i] = pluginOutput16bitInterlaced[i/2] & 0x0f;
inPacket.data[i+1] = (pluginOutput16bitInterlaced[i/2] & 0xf0 >> 8);
}