Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS sound support #1875

Merged
merged 16 commits into from
Sep 9, 2021
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
8 changes: 2 additions & 6 deletions Jamulus.pro
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,8 @@ win32 {
OBJECTIVE_SOURCES += ios/sound.mm
QMAKE_TARGET_BUNDLE_PREFIX = io.jamulus
QMAKE_APPLICATION_BUNDLE_NAME. = $$TARGET
LIBS += -framework CoreFoundation \
-framework CoreServices \
-framework AVFoundation \
-framework CoreMIDI \
-framework AudioToolbox \
-framework Foundation
LIBS += -framework AVFoundation \
-framework AudioToolbox
} else:android {
# we want to compile with C++14
CONFIG += c++14
Expand Down
4 changes: 4 additions & 0 deletions ios/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
</dict>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
<key>UILaunchScreen</key>
<dict/>
<key>UILaunchStoryboardName</key>
Expand Down
7 changes: 2 additions & 5 deletions ios/ios_app_delegate.mm
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#import "ios_app_delegate.h"

@interface QIOSApplicationDelegate ()
Expand All @@ -7,10 +6,8 @@ @interface QIOSApplicationDelegate ()

@implementation QIOSApplicationDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
Copy link
Collaborator

Choose a reason for hiding this comment

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

See, it's lines like this where I feel clang-format hasn't done its job right.

- ( BOOL ) application: ( UIApplication* ) application didFinishLaunchingWithOptions: ( NSDictionary* ) launchOptions

but I don't know Objective-C...

Copy link
Contributor

@emlynmac emlynmac Jun 15, 2021

Choose a reason for hiding this comment

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

too many spaces for Obj-C (referring to other review comment with lots of spaces)

Most places I have worked like a space between the type and the *
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is that "too many" as in "won't compile" or as in "not normal"?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh it's just purely a stylistic comment - there are religious discussions about how to format Obj-C....
It makes no difference to compilation.

{
return YES;
}
@end
72 changes: 19 additions & 53 deletions ios/sound.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/******************************************************************************\
* Copyright (c) 2004-2020
* Copyright (c) 2004-2021
*
* Author(s):
* ann0see based on code from Volker Fischer
* ann0see and ngocdh based on code from Volker Fischer
ngocdh marked this conversation as resolved.
Show resolved Hide resolved
*
******************************************************************************
*
Expand All @@ -23,13 +23,11 @@
\******************************************************************************/

#pragma once
#include <CoreMIDI/CoreMIDI.h>
#include <QMutex>
#include <QMessageBox>
#include "soundbase.h"
#include "global.h"

/* Classes ********************************************************************/
#import <AudioToolbox/AudioToolbox.h>

class CSound : public CSoundBase
{
Q_OBJECT
Expand All @@ -40,68 +38,36 @@ class CSound : public CSoundBase
const QString& strMIDISetup,
const bool,
const QString& );
~CSound();

virtual int Init ( const int iNewPrefMonoBufferSize );
virtual void Start();
virtual void Stop();
virtual void processBufferList ( AudioBufferList*, CSound* );

// channel selection
virtual int GetNumInputChannels() { return iNumInChanPlusAddChan; }
virtual QString GetInputChannelName ( const int iDiD ) { return sChannelNamesInput[iDiD]; }
virtual void SetLeftInputChannel ( const int iNewChan );
virtual void SetRightInputChannel ( const int iNewChan );
virtual int GetLeftInputChannel() { return iSelInputLeftChannel; }
virtual int GetRightInputChannel() { return iSelInputRightChannel; }

virtual int GetNumOutputChannels() { return iNumOutChan; }
virtual QString GetOutputChannelName ( const int iDiD ) { return sChannelNamesOutput[iDiD]; }
virtual void SetLeftOutputChannel ( const int iNewChan );
virtual void SetRightOutputChannel ( const int iNewChan );
virtual int GetLeftOutputChannel() { return iSelOutputLeftChannel; }
virtual int GetRightOutputChannel() { return iSelOutputRightChannel; }
AudioUnit audioUnit;

// these variables/functions should be protected but cannot since we want
// to access them from the callback function
CVector<short> vecsTmpAudioSndCrdStereo;
int iCoreAudioBufferSizeMono;
int iCoreAudioBufferSizeStereo;
long lCurDev;
int iNumInChan;
int iNumInChanPlusAddChan; // includes additional "added" channels
int iNumOutChan;
int iSelInputLeftChannel;
int iSelInputRightChannel;
int iSelOutputLeftChannel;
int iSelOutputRightChannel;
int iSelInBufferLeft;
int iSelInBufferRight;
int iSelInInterlChLeft;
int iSelInInterlChRight;
int iSelAddInBufferLeft;
int iSelAddInBufferRight;
int iSelAddInInterlChLeft;
int iSelAddInInterlChRight;
int iSelOutBufferLeft;
int iSelOutBufferRight;
int iSelOutInterlChLeft;
int iSelOutInterlChRight;
CVector<int> vecNumInBufChan;
CVector<int> vecNumOutBufChan;
bool isInitialized;

protected:
virtual QString LoadAndInitializeDriver ( QString strDriverName, bool );
void GetAvailableInOutDevices();
void SwitchDevice ( QString strDriverName );

QString CheckDeviceCapabilities ( const int iDriverIdx );
void GetAvailableInOutDevices();

static void callbackMIDI ( const MIDIPacketList* pktlist, void* refCon, void* );

// AVAudioSession audioSession;

MIDIPortRef midiInPortRef;

QString sChannelNamesInput[MAX_NUM_IN_OUT_CHANNELS];
QString sChannelNamesOutput[MAX_NUM_IN_OUT_CHANNELS];
AudioBuffer buffer;
AudioBufferList bufferList;
void checkStatus ( int status );
static OSStatus recordingCallback ( void* inRefCon,
AudioUnitRenderActionFlags* ioActionFlags,
const AudioTimeStamp* inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList* ioData );

QMutex Mutex;
ngocdh marked this conversation as resolved.
Show resolved Hide resolved
};
Loading