jamulus/android/sound.h

106 lines
3.9 KiB
C
Raw Normal View History

2015-02-04 19:17:23 +01:00
/******************************************************************************\
2020-01-01 15:41:43 +01:00
* Copyright (c) 2004-2020
2015-02-04 19:17:23 +01:00
*
* Author(s):
* Simon Tomlinson, Volker Fischer
2015-02-04 19:17:23 +01:00
*
******************************************************************************
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
2015-02-04 19:17:23 +01:00
*
\******************************************************************************/
2019-07-09 08:52:38 +02:00
#pragma once
2015-02-04 19:17:23 +01:00
/* Deprecated, moving to OBOE
* #include <SLES/OpenSLES.h>
* #include <SLES/OpenSLES_Android.h> */
#include <oboe/Oboe.h>
2015-02-04 19:17:23 +01:00
#include <QMutex>
#include "soundbase.h"
#include "global.h"
#include <QDebug>
#include <android/log.h>
2015-02-04 19:17:23 +01:00
/* Classes ********************************************************************/
class CSound : public CSoundBase, public oboe::AudioStreamCallback//, public IRenderableAudio, public IRestartable
2015-02-04 19:17:23 +01:00
{
public:
2020-04-30 22:18:11 +02:00
CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData, void* arg ),
void* arg,
const int iCtrlMIDIChannel,
const bool ,
const QString& );
2015-02-04 19:17:23 +01:00
virtual ~CSound() {}
virtual int Init ( const int iNewPrefMonoBufferSize );
virtual void Start();
virtual void Stop();
// Call backs for Oboe
virtual oboe::DataCallbackResult onAudioReady(oboe::AudioStream *oboeStream, void *audioData, int32_t numFrames);
virtual void onErrorAfterClose(oboe::AudioStream *oboeStream, oboe::Result result);
virtual void onErrorBeforeClose(oboe::AudioStream *oboeStream, oboe::Result result);
2015-02-04 19:17:23 +01:00
// these variables should be protected but cannot since we want
// to access them from the callback function
CVector<short> vecsTmpAudioSndCrdStereo;
static void android_message_handler(QtMsgType type,
const QMessageLogContext &context,
const QString &message)
{
android_LogPriority priority = ANDROID_LOG_DEBUG;
switch (type) {
case QtDebugMsg: priority = ANDROID_LOG_DEBUG; break;
case QtWarningMsg: priority = ANDROID_LOG_WARN; break;
case QtCriticalMsg: priority = ANDROID_LOG_ERROR; break;
case QtFatalMsg: priority = ANDROID_LOG_FATAL; break;
};
__android_log_print(priority, "Qt", "%s", qPrintable(message));
};
2015-02-04 19:17:23 +01:00
// TEST
CVector<short> vecsTmpAudioInSndCrd;
int iModifiedInBufSize;
int iOpenSLBufferSizeMono;
int iOpenSLBufferSizeStereo;
private:
void setupCommonStreamParams(oboe::AudioStreamBuilder *builder);
void printStreamDetails(oboe::ManagedStream &stream);
void openStreams();
void closeStreams();
void warnIfNotLowLatency(oboe::ManagedStream &stream, QString streamName);
void closeStream(oboe::ManagedStream &stream);
2015-02-04 19:17:23 +01:00
oboe::ManagedStream mRecordingStream;
oboe::ManagedStream mPlayStream;
AudioStreamCallback *mCallback;
2015-02-04 19:17:23 +01:00
// used to reach a state where the input buffer is
// empty and the garbage in the first 500ms or so is discarded
static constexpr int32_t kNumCallbacksToDrain = 10;
int32_t mCountCallbacksToDrain = kNumCallbacksToDrain;
2015-02-04 19:17:23 +01:00
// Used to reference this instance of class from within the static callback
CSound *pSound;
2015-02-04 19:17:23 +01:00
QMutex Mutex;
};