Commit addab6e9 authored by BERTHAUT Florent's avatar BERTHAUT Florent
Browse files

Fixed volume control

parent 32fd85b9
......@@ -17,11 +17,8 @@ void Gdpd::_register_methods() {
int Gdpd::audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *userData){
Gdpd* gdpd = static_cast<Gdpd*>(userData);
int ticks = nBufferFrames / 64;
gdpd->m_pd.processFloat(ticks, (float*)inputBuffer, (float*)outputBuffer);
for(int b=0; b<nBufferFrames; ++b) {
((float*)outputBuffer)[b]*=gdpd->get_volume();
}
gdpd->processAudio(outputBuffer, inputBuffer, nBufferFrames, streamTime,
status, userData);
return 0;
}
......@@ -63,8 +60,8 @@ int Gdpd::init(int nbInputs, int nbOutputs, int sampleRate) {
unsigned int sr = m_audio.getDeviceInfo(outParams.deviceId).preferredSampleRate;
outParams.deviceId = m_audio.getDefaultOutputDevice();
inParams.deviceId = m_audio.getDefaultOutputDevice();
outParams.nChannels = nbInputs;
inParams.nChannels = nbOutputs;
outParams.nChannels = m_nbInputs = nbInputs;
inParams.nChannels = m_nbOutputs = nbOutputs;
m_bufferFrames = 128;
RtAudio::StreamOptions options;
......@@ -89,6 +86,19 @@ int Gdpd::init(int nbInputs, int nbOutputs, int sampleRate) {
return 0;
}
void Gdpd::processAudio(void *outputBuffer, void *inputBuffer,
unsigned int nBufferFrames, double streamTime,
RtAudioStreamStatus status, void *userData) {
int ticks = nBufferFrames / libpd_blocksize();
m_pd.processFloat(ticks, (float*)inputBuffer, (float*)outputBuffer);
//volume control on the output
for(int b=0; b<nBufferFrames*m_nbOutputs; ++b) {
((float*)outputBuffer)[b]*=m_vol;
}
}
void Gdpd::openfile(godot::String baseStr, godot::String dirStr) {
std::wstring baseWs = baseStr.unicode_str();
std::string baseS(baseWs.begin(), baseWs.end());
......
......@@ -26,6 +26,8 @@ private:
RtAudio m_audio;
unsigned int m_bufferFrames;
float m_vol;
int m_nbInputs;
int m_nbOutputs;
public:
static void _register_methods();
......@@ -57,7 +59,12 @@ public:
//rtaudio
static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *userData);
static int audioCallback(void *outputBuffer, void *inputBuffer,
unsigned int nBufferFrames, double streamTime,
RtAudioStreamStatus status, void *userData);
void processAudio(void *outputBuffer, void *inputBuffer,
unsigned int nBufferFrames, double streamTime,
RtAudioStreamStatus status, void *userData);
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment