Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions android/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

/* Implementation *************************************************************/

CSound::CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData, void* arg ),
CSound::CSound ( void (*fpNewProcessCallback) ( CVector<float>& psData, void* arg ),
Comment thread
hselasky marked this conversation as resolved.
void* arg,
const int iCtrlMIDIChannel,
const bool ,
Expand Down Expand Up @@ -193,7 +193,7 @@ int CSound::Init ( const int iNewPrefMonoBufferSize )
iOpenSLBufferSizeStereo = 2 * iOpenSLBufferSizeMono;

// create memory for intermediate audio buffer
vecsTmpAudioSndCrdStereo.Init ( iOpenSLBufferSizeStereo );
vecfTmpAudioSndCrdStereo.Init ( iOpenSLBufferSizeStereo );

// TEST
#if ( SYSTEM_SAMPLE_RATE_HZ != 48000 )
Expand All @@ -205,7 +205,7 @@ int CSound::Init ( const int iNewPrefMonoBufferSize )
// 48 kHz / 16 kHz = factor 3 (note that the buffer size mono might
// be divisible by three, therefore we will get a lot of drop outs)
iModifiedInBufSize = iOpenSLBufferSizeMono / 3;
vecsTmpAudioInSndCrd.Init ( iModifiedInBufSize );
vecfTmpAudioInSndCrd.Init ( iModifiedInBufSize );

return iOpenSLBufferSizeMono;
}
Expand Down Expand Up @@ -238,19 +238,17 @@ oboe::DataCallbackResult CSound::onAudioReady ( oboe::AudioStream* oboeStream, v
memset ( audioData, 0, sizeof(float) * numFrames * oboeStream->getChannelCount() );

// Only copy data if we have data to copy, otherwise fill with silence
if ( !pSound->vecsTmpAudioSndCrdStereo.empty() )
if ( !pSound->vecfTmpAudioSndCrdStereo.empty() )
{
for ( int frmNum = 0; frmNum < numFrames; ++frmNum )
{
for ( int channelNum = 0; channelNum < oboeStream->getChannelCount(); channelNum++ )
{
// copy sample received from server into output buffer

// convert to 32 bit
const int32_t iCurSam = static_cast<int32_t> (
pSound->vecsTmpAudioSndCrdStereo [frmNum * oboeStream->getChannelCount() + channelNum] );

floatData[frmNum * oboeStream->getChannelCount() + channelNum] = (float) iCurSam / _MAXSHORT;
const float fCurSam =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you compiled and run the Android code to check that it works with your modifications? Or did you just change the code and have not compiled or tested it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I haven't check Android. Need some help here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I cannot compile Jamulus for Android. The Android development was done mainly by Simon. But as far as I know, he still had issues on the Android platform. So maybe we can live with the fact that the changes in the Android interface are very small. So I think it is ok to take your changes untested.

pSound->vecfTmpAudioSndCrdStereo [frmNum * oboeStream->getChannelCount() + channelNum];
floatData[frmNum * oboeStream->getChannelCount() + channelNum] = fCurSam;
}
}
}
Expand Down Expand Up @@ -282,13 +280,13 @@ oboe::DataCallbackResult CSound::onAudioReady ( oboe::AudioStream* oboeStream, v
{
for ( int channelNum = 0; channelNum < oboeStream->getChannelCount(); channelNum++ )
{
pSound->vecsTmpAudioSndCrdStereo[frmNum * oboeStream->getChannelCount() + channelNum] =
(short) floatData[frmNum * oboeStream->getChannelCount() + channelNum] * _MAXSHORT;
pSound->vecfTmpAudioSndCrdStereo [frmNum * oboeStream->getChannelCount() + channelNum] =
floatData[frmNum * oboeStream->getChannelCount() + channelNum];
}
}

// Tell parent class that we've put some data ready to send to the server
pSound->ProcessCallback ( pSound->vecsTmpAudioSndCrdStereo );
pSound->ProcessCallback ( pSound->vecfTmpAudioSndCrdStereo );
}

// locker.unlock();
Expand Down
6 changes: 3 additions & 3 deletions android/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
class CSound : public CSoundBase, public oboe::AudioStreamCallback//, public IRenderableAudio, public IRestartable
{
public:
CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData, void* arg ),
CSound ( void (*fpNewProcessCallback) ( CVector<float>& psData, void* arg ),
void* arg,
const int iCtrlMIDIChannel,
const bool ,
Expand All @@ -54,7 +54,7 @@ class CSound : public CSoundBase, public oboe::AudioStreamCallback//, public IRe

// these variables should be protected but cannot since we want
// to access them from the callback function
CVector<short> vecsTmpAudioSndCrdStereo;
CVector<float> vecfTmpAudioSndCrdStereo;

static void android_message_handler ( QtMsgType type,
const QMessageLogContext& context,
Expand All @@ -74,7 +74,7 @@ class CSound : public CSoundBase, public oboe::AudioStreamCallback//, public IRe
};

// TEST
CVector<short> vecsTmpAudioInSndCrd;
CVector<float> vecfTmpAudioInSndCrd;
int iModifiedInBufSize;

int iOpenSLBufferSizeMono;
Expand Down
15 changes: 6 additions & 9 deletions linux/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ int CSound::Init ( const int /* iNewPrefMonoBufferSize */ )
iJACKBufferSizeStero = 2 * iJACKBufferSizeMono;

// create memory for intermediate audio buffer
vecsTmpAudioSndCrdStereo.Init ( iJACKBufferSizeStero );
vecfTmpAudioSndCrdStereo.Init ( iJACKBufferSizeStero );

return iJACKBufferSizeMono;
}
Expand Down Expand Up @@ -259,16 +259,13 @@ int CSound::process ( jack_nframes_t nframes, void* arg )
{
for ( i = 0; i < pSound->iJACKBufferSizeMono; i++ )
{
pSound->vecsTmpAudioSndCrdStereo[2 * i] =
(short) ( in_left[i] * _MAXSHORT );

pSound->vecsTmpAudioSndCrdStereo[2 * i + 1] =
(short) ( in_right[i] * _MAXSHORT );
pSound->vecfTmpAudioSndCrdStereo[2 * i] = in_left[i];
pSound->vecfTmpAudioSndCrdStereo[2 * i + 1] = in_right[i];
}
}

// call processing callback function
pSound->ProcessCallback ( pSound->vecsTmpAudioSndCrdStereo );
pSound->ProcessCallback ( pSound->vecfTmpAudioSndCrdStereo );

// get output data pointer
jack_default_audio_sample_t* out_left =
Expand All @@ -285,10 +282,10 @@ int CSound::process ( jack_nframes_t nframes, void* arg )
for ( i = 0; i < pSound->iJACKBufferSizeMono; i++ )
{
out_left[i] = (jack_default_audio_sample_t)
pSound->vecsTmpAudioSndCrdStereo[2 * i] / _MAXSHORT;
pSound->vecfTmpAudioSndCrdStereo[2 * i];

out_right[i] = (jack_default_audio_sample_t)
pSound->vecsTmpAudioSndCrdStereo[2 * i + 1] / _MAXSHORT;
pSound->vecfTmpAudioSndCrdStereo[2 * i + 1];
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions linux/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
class CSound : public CSoundBase
{
public:
CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData, void* arg ),
CSound ( void (*fpNewProcessCallback) ( CVector<float>& psData, void* arg ),
void* arg,
const int iCtrlMIDIChannel,
const bool bNoAutoJackConnect,
Expand All @@ -78,7 +78,7 @@ class CSound : public CSoundBase

// these variables should be protected but cannot since we want
// to access them from the callback function
CVector<short> vecsTmpAudioSndCrdStereo;
CVector<float> vecfTmpAudioSndCrdStereo;
int iJACKBufferSizeMono;
int iJACKBufferSizeStero;
bool bJackWasShutDown;
Expand Down Expand Up @@ -111,7 +111,7 @@ class CSound : public CSoundBase
Q_OBJECT

public:
CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData, void* pParg ),
CSound ( void (*fpNewProcessCallback) ( CVector<float>& psData, void* pParg ),
void* pParg,
const int iCtrlMIDIChannel,
const bool ,
Expand Down
24 changes: 12 additions & 12 deletions mac/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


/* Implementation *************************************************************/
CSound::CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData, void* arg ),
CSound::CSound ( void (*fpNewProcessCallback) ( CVector<float>& psData, void* arg ),
void* arg,
const int iCtrlMIDIChannel,
const bool ,
Expand Down Expand Up @@ -848,7 +848,7 @@ int CSound::Init ( const int iNewPrefMonoBufferSize )
iCoreAudioBufferSizeStereo = 2 * iCoreAudioBufferSizeMono;

// create memory for intermediate audio buffer
vecsTmpAudioSndCrdStereo.Init ( iCoreAudioBufferSizeStereo );
vecfTmpAudioSndCrdStereo.Init ( iCoreAudioBufferSizeStereo );

return iCoreAudioBufferSizeMono;
}
Expand Down Expand Up @@ -970,8 +970,8 @@ OSStatus CSound::callbackIO ( AudioDeviceID inDevice,
for ( int i = 0; i < iCoreAudioBufferSizeMono; i++ )
{
// copy left and right channels separately
pSound->vecsTmpAudioSndCrdStereo[2 * i] = (short) ( pLeftData[iNumChanPerFrameLeft * i + iSelInInterlChLeft] * _MAXSHORT );
pSound->vecsTmpAudioSndCrdStereo[2 * i + 1] = (short) ( pRightData[iNumChanPerFrameRight * i + iSelInInterlChRight] * _MAXSHORT );
pSound->vecfTmpAudioSndCrdStereo[2 * i] = pLeftData[iNumChanPerFrameLeft * i + iSelInInterlChLeft];
pSound->vecfTmpAudioSndCrdStereo[2 * i + 1] = pRightData[iNumChanPerFrameRight * i + iSelInInterlChRight];
}

// add an additional optional channel
Expand All @@ -982,8 +982,8 @@ OSStatus CSound::callbackIO ( AudioDeviceID inDevice,

for ( int i = 0; i < iCoreAudioBufferSizeMono; i++ )
{
pSound->vecsTmpAudioSndCrdStereo[2 * i] = Double2Short (
pSound->vecsTmpAudioSndCrdStereo[2 * i] + pLeftData[iNumChanPerFrameLeft * i + iSelAddInInterlChLeft] * _MAXSHORT );
pSound->vecfTmpAudioSndCrdStereo[2 * i] = clipFloat (
pSound->vecfTmpAudioSndCrdStereo[2 * i] + pLeftData[iNumChanPerFrameLeft * i + iSelAddInInterlChLeft] );
}
}

Expand All @@ -994,19 +994,19 @@ OSStatus CSound::callbackIO ( AudioDeviceID inDevice,

for ( int i = 0; i < iCoreAudioBufferSizeMono; i++ )
{
pSound->vecsTmpAudioSndCrdStereo[2 * i + 1] = Double2Short (
pSound->vecsTmpAudioSndCrdStereo[2 * i + 1] + pRightData[iNumChanPerFrameRight * i + iSelAddInInterlChRight] * _MAXSHORT );
pSound->vecfTmpAudioSndCrdStereo[2 * i + 1] = clipFloat (
pSound->vecfTmpAudioSndCrdStereo[2 * i + 1] + pRightData[iNumChanPerFrameRight * i + iSelAddInInterlChRight] );
}
}
}
else
{
// incompatible sizes, clear work buffer
pSound->vecsTmpAudioSndCrdStereo.Reset ( 0 );
pSound->vecfTmpAudioSndCrdStereo.Reset ( 0 );
}

// call processing callback function
pSound->ProcessCallback ( pSound->vecsTmpAudioSndCrdStereo );
pSound->ProcessCallback ( pSound->vecfTmpAudioSndCrdStereo );
}

if ( ( inDevice == pSound->CurrentAudioOutputDeviceID ) && outOutputData )
Expand All @@ -1028,8 +1028,8 @@ OSStatus CSound::callbackIO ( AudioDeviceID inDevice,
for ( int i = 0; i < iCoreAudioBufferSizeMono; i++ )
{
// copy left and right channels separately
pLeftData[iNumChanPerFrameLeft * i + iSelOutInterlChLeft] = (Float32) pSound->vecsTmpAudioSndCrdStereo[2 * i] / _MAXSHORT;
pRightData[iNumChanPerFrameRight * i + iSelOutInterlChRight] = (Float32) pSound->vecsTmpAudioSndCrdStereo[2 * i + 1] / _MAXSHORT;
pLeftData[iNumChanPerFrameLeft * i + iSelOutInterlChLeft] = (Float32) pSound->vecfTmpAudioSndCrdStereo[2 * i];
pRightData[iNumChanPerFrameRight * i + iSelOutInterlChRight] = (Float32) pSound->vecfTmpAudioSndCrdStereo[2 * i + 1];
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions mac/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
class CSound : public CSoundBase
{
public:
CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData, void* arg ),
CSound ( void (*fpNewProcessCallback) ( CVector<float>& psData, void* arg ),
void* arg,
const int iCtrlMIDIChannel,
const bool ,
Expand All @@ -63,7 +63,7 @@ class CSound : public CSoundBase

// these variables should be protected but cannot since we want
// to access them from the callback function
CVector<short> vecsTmpAudioSndCrdStereo;
CVector<float> vecfTmpAudioSndCrdStereo;
int iCoreAudioBufferSizeMono;
int iCoreAudioBufferSizeStereo;
AudioDeviceID CurrentAudioInputDeviceID;
Expand Down
20 changes: 10 additions & 10 deletions src/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,16 +500,16 @@ template<class TData> class CConvBuf
}
}

void PutAll ( const CVector<TData>& vecsData )
void PutAll ( const CVector<TData>& vecfData )
{
iGetPos = 0;

std::copy ( vecsData.begin(),
vecsData.begin() + iBufferSize, // note that input vector might be larger then memory size
std::copy ( vecfData.begin(),
vecfData.begin() + iBufferSize, // note that input vector might be larger then memory size
vecMemory.begin() );
}

bool Put ( const CVector<TData>& vecsData,
bool Put ( const CVector<TData>& vecfData,
const int iVecSize )
{
// calculate the input size and the end position after copying
Expand All @@ -519,8 +519,8 @@ template<class TData> class CConvBuf
if ( iEnd <= iBufferSize )
{
// copy new data in internal buffer
std::copy ( vecsData.begin(),
vecsData.begin() + iVecSize,
std::copy ( vecfData.begin(),
vecfData.begin() + iVecSize,
vecMemory.begin() + iPutPos );

// set buffer pointer one block further
Expand All @@ -540,18 +540,18 @@ template<class TData> class CConvBuf
return vecMemory;
}

void GetAll ( CVector<TData>& vecsData,
void GetAll ( CVector<TData>& vecfData,
const int iVecSize )
{
iPutPos = 0;

// copy data from internal buffer in given buffer
std::copy ( vecMemory.begin(),
vecMemory.begin() + iVecSize,
vecsData.begin() );
vecfData.begin() );
}

bool Get ( CVector<TData>& vecsData,
bool Get ( CVector<TData>& vecfData,
const int iVecSize )
{
// calculate the input size and the end position after copying
Expand All @@ -563,7 +563,7 @@ template<class TData> class CConvBuf
// copy new data from internal buffer
std::copy ( vecMemory.begin() + iGetPos,
vecMemory.begin() + iGetPos + iVecSize,
vecsData.begin() );
vecfData.begin() );

// set buffer pointer one block further
iGetPos = iEnd;
Expand Down
Loading