Skip to content

Commit

Permalink
macOS demo works! (except ADM cannot change sample rate and channels)
Browse files Browse the repository at this point in the history
  • Loading branch information
Piasy committed Jun 15, 2018
1 parent c612ce4 commit 1b5c98b
Show file tree
Hide file tree
Showing 20 changed files with 2,257 additions and 117 deletions.
20 changes: 12 additions & 8 deletions ios_project/AudioMixer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
8634187320D3E89400C144CB /* AudioMixerTestController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 86D17F9920D3E4CA00DFFEAC /* AudioMixerTestController.mm */; };
866A956620D164D600C7694D /* AudioMixer.h in Headers */ = {isa = PBXBuildFile; fileRef = 866A956520D164D600C7694D /* AudioMixer.h */; settings = {ATTRIBUTES = (Public, ); }; };
866A956D20D165E600C7694D /* morning-mono-16k.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 866A956820D165E500C7694D /* morning-mono-16k.mp3 */; };
866A956E20D165E600C7694D /* morning.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 866A956920D165E500C7694D /* morning.mp3 */; };
Expand Down Expand Up @@ -61,7 +62,7 @@
BF_208404374351 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FR_316246524774 /* Assets.xcassets */; };
BF_232288806286 /* AudioMixer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FR_262413649868 /* AudioMixer.framework */; };
BF_387680161997 /* AudioMixer.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = FR_262413649868 /* AudioMixer.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
BF_461210773779 /* ViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = FR_653036302879 /* ViewController.mm */; };
BF_461210773779 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FR_653036302879 /* ViewController.m */; };
BF_656202648573 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = FR_166489251693 /* main.m */; };
BF_875310361989 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = FR_892106870587 /* AppDelegate.m */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -141,12 +142,13 @@
869959E520CF7D9F009946FC /* PYAAudioBuffer.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PYAAudioBuffer.mm; sourceTree = "<group>"; };
869959E820CF85CB009946FC /* audio_mixer_api.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = audio_mixer_api.cpp; sourceTree = "<group>"; };
869959EA20CF85E7009946FC /* PYAAudioMixerApi.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PYAAudioMixerApi.mm; sourceTree = "<group>"; };
869959EC20CFA502009946FC /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
86D17F9820D3E4CA00DFFEAC /* AudioMixerTestController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AudioMixerTestController.h; sourceTree = "<group>"; };
86D17F9920D3E4CA00DFFEAC /* AudioMixerTestController.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AudioMixerTestController.mm; sourceTree = "<group>"; };
FR_166489251693 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
FR_262413649868 /* AudioMixer.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AudioMixer.framework; sourceTree = BUILT_PRODUCTS_DIR; };
FR_316246524774 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
FR_592305279399 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
FR_653036302879 /* ViewController.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ViewController.mm; sourceTree = "<group>"; };
FR_653036302879 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
FR_653036302887 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
FR_892106870585 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
FR_892106870587 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -279,7 +281,6 @@
isa = PBXGroup;
children = (
866A956520D164D600C7694D /* AudioMixer.h */,
869959EC20CFA502009946FC /* Info.plist */,
869959E420CF7D9F009946FC /* PYAAudioBuffer.h */,
869959E520CF7D9F009946FC /* PYAAudioBuffer.mm */,
869959D920CF453D009946FC /* PYAAudioMixer.h */,
Expand All @@ -297,7 +298,9 @@
FR_592305279399 /* Info.plist */,
FR_166489251693 /* main.m */,
FR_653036302887 /* ViewController.h */,
FR_653036302879 /* ViewController.mm */,
FR_653036302879 /* ViewController.m */,
86D17F9820D3E4CA00DFFEAC /* AudioMixerTestController.h */,
86D17F9920D3E4CA00DFFEAC /* AudioMixerTestController.mm */,
);
path = example;
sourceTree = "<group>";
Expand Down Expand Up @@ -481,7 +484,8 @@
buildActionMask = 2147483647;
files = (
BF_875310361989 /* AppDelegate.m in Sources */,
BF_461210773779 /* ViewController.mm in Sources */,
BF_461210773779 /* ViewController.m in Sources */,
8634187320D3E89400C144CB /* AudioMixerTestController.mm in Sources */,
BF_656202648573 /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -511,7 +515,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_BITCODE = NO;
ENABLE_TESTABILITY = YES;
INFOPLIST_FILE = "$(SRCROOT)/objc/Info.plist";
INFOPLIST_FILE = "$(SRCROOT)/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down Expand Up @@ -627,7 +631,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_BITCODE = NO;
ENABLE_TESTABILITY = YES;
INFOPLIST_FILE = "$(SRCROOT)/objc/Info.plist";
INFOPLIST_FILE = "$(SRCROOT)/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down
2 changes: 2 additions & 0 deletions ios_project/objc/Info.plist → ios_project/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<string>1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2018 Piasy. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
60 changes: 60 additions & 0 deletions ios_project/example/AudioMixerTestController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
/*
* The MIT License (MIT)
*
* Copyright (c) 2018 Piasy
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
//


#import <Foundation/Foundation.h>

@interface AudioMixerTestController : NSObject

- (void)doDecodeMono;

- (void)doResample;

- (void)doDecodeAny;

- (void)doMix;

- (void)doRecordAndMix;

- (void)doStopTest;

- (int32_t)RecordedDataIsAvailable:(const void*)audioSamples
nSamples:(size_t)nSamples
nBytesPerSample:(size_t)nBytesPerSample
nChannels:(size_t)nChannels
samplesPerSec:(uint32_t)samplesPerSec
totalDelayMS:(uint32_t)totalDelayMS
clockDrift:(int32_t)clockDrift
currentMicLevel:(uint32_t)currentMicLevel
keyPressed:(bool)keyPressed;

- (size_t)NeedMorePlayData:(size_t)nSamples
nBytesPerSample:(size_t)nBytesPerSample
nChannels:(size_t)nChannels
samplesPerSec:(uint32_t)samplesPerSec
audioSamples:(void*)audioSamples;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2017 Piasy
* Copyright (c) 2018 Piasy
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -24,23 +24,31 @@
*/
//


#import <AudioMixer/AudioMixer.h>

#include <sdk/objc/Framework/Native/api/audio_device_module.h>
#include <media/engine/adm_helpers.h>

#import "ViewController.h"

#include "audio_file_decoder.h"
#include "audio_file_source.h"
#include "audio_resampler.h"
#include "audio_mixer_global.h"

#import "AudioMixerTestController.h"

#if defined(WEBRTC_IOS)
#define kChannelNum 1
#else
#define kChannelNum 2
#endif

static const int32_t kBytesPerSample = 2;

class SimpleAudioCallback : public webrtc::AudioTransport {
public:
SimpleAudioCallback(ViewController* controller) : _controller(controller) {}
SimpleAudioCallback(AudioMixerTestController* controller)
: _controller(controller) {}
~SimpleAudioCallback() {}

int32_t RecordedDataIsAvailable(
Expand Down Expand Up @@ -86,7 +94,7 @@ void PullRenderData(int bits_per_sample, int sample_rate,
int64_t* ntp_time_ms) {}

private:
ViewController* _controller;
AudioMixerTestController* _controller;
};

typedef NS_ENUM(NSInteger, TestType) {
Expand All @@ -97,9 +105,7 @@ typedef NS_ENUM(NSInteger, TestType) {
TEST_RECORD_AND_MIX,
};

@implementation ViewController {
AudioUnit _audioUnit;

@implementation AudioMixerTestController {
rtc::scoped_refptr<webrtc::AudioDeviceModule> _adm;
SimpleAudioCallback* _callback;

Expand All @@ -126,86 +132,12 @@ @implementation ViewController {
NSFileHandle* _recordAndMixDumper;
}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

CGRect screen = [[UIScreen mainScreen] bounds];

UIButton* decodeMono = [UIButton buttonWithType:UIButtonTypeSystem];
[decodeMono setTitle:@"DecodeMono" forState:UIControlStateNormal];
decodeMono.titleLabel.font = [UIFont systemFontOfSize:20.0f];
decodeMono.frame = CGRectMake((screen.size.width - 200) / 2, 80, 200, 40);

[decodeMono addTarget:self
action:@selector(doDecodeMono)
forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:decodeMono];

UIButton* resample = [UIButton buttonWithType:UIButtonTypeSystem];
[resample setTitle:@"Resample" forState:UIControlStateNormal];
resample.titleLabel.font = [UIFont systemFontOfSize:20.0f];
resample.frame = CGRectMake((screen.size.width - 200) / 2, 130, 200, 40);

[resample addTarget:self
action:@selector(doResample)
forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:resample];

UIButton* decodeAny = [UIButton buttonWithType:UIButtonTypeSystem];
[decodeAny setTitle:@"DecodeAny" forState:UIControlStateNormal];
decodeAny.titleLabel.font = [UIFont systemFontOfSize:20.0f];
decodeAny.frame = CGRectMake((screen.size.width - 200) / 2, 180, 200, 40);

[decodeAny addTarget:self
action:@selector(doDecodeAny)
forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:decodeAny];

UIButton* mix = [UIButton buttonWithType:UIButtonTypeSystem];
[mix setTitle:@"Mix" forState:UIControlStateNormal];
mix.titleLabel.font = [UIFont systemFontOfSize:20.0f];
mix.frame = CGRectMake((screen.size.width - 200) / 2, 230, 200, 40);

[mix addTarget:self
action:@selector(doMix)
forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:mix];

UIButton* recordAndMix = [UIButton buttonWithType:UIButtonTypeSystem];
[recordAndMix setTitle:@"RecordAndMix" forState:UIControlStateNormal];
recordAndMix.titleLabel.font = [UIFont systemFontOfSize:20.0f];
recordAndMix.frame =
CGRectMake((screen.size.width - 200) / 2, 280, 200, 40);

[recordAndMix addTarget:self
action:@selector(doRecordAndMix)
forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:recordAndMix];

UIButton* stop = [UIButton buttonWithType:UIButtonTypeSystem];
[stop setTitle:@"Stop" forState:UIControlStateNormal];
stop.titleLabel.font = [UIFont systemFontOfSize:20.0f];
stop.frame = CGRectMake((screen.size.width - 200) / 2, 380, 200, 40);

[stop addTarget:self
action:@selector(doStopTest)
forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:stop];
}

- (void)doDecodeMono {
NSLog(@"doDecodeMono");
_testType = TEST_DECODE_MONO;

_sampleRate = 16000;
_channelNum = 1;
_channelNum = kChannelNum;
_remainingData = 0;

_decoder = new audio_mixer::AudioFileDecoder(
Expand All @@ -226,7 +158,7 @@ - (void)doResample {
_resamplerInputSampleRate = 44100;
_resamplerInputChannelNum = 2;
_sampleRate = 16000;
_channelNum = 1;
_channelNum = kChannelNum;
_remainingData = 0;

_resampler = new audio_mixer::AudioResampler(
Expand Down Expand Up @@ -279,7 +211,7 @@ - (void)doDecodeAny {
_testType = TEST_DECODE_ANY;

_sampleRate = 48000;
_channelNum = 1;
_channelNum = kChannelNum;
_remainingData = 0;

_source = new audio_mixer::AudioFileSource(
Expand Down Expand Up @@ -320,7 +252,7 @@ - (void)doMix {
_testType = TEST_MIX;

_sampleRate = 48000;
_channelNum = 1;
_channelNum = kChannelNum;
_remainingData = 0;

NSArray* mixerSources = @[
Expand Down Expand Up @@ -381,7 +313,7 @@ - (void)doRecordAndMix {
_testType = TEST_RECORD_AND_MIX;

_sampleRate = 48000;
_channelNum = 1;
_channelNum = kChannelNum;
_remainingData = 0;

NSArray* mixerSources = @[
Expand Down Expand Up @@ -451,7 +383,12 @@ - (void)deliverRecordAndMixedData:(const void*)buf numFrames:(int32_t)numFrames
}

- (void)doStartTest {
#if defined(WEBRTC_IOS)
_adm = webrtc::CreateAudioDeviceModule();
#else
_adm = webrtc::AudioDeviceModule::Create(
webrtc::AudioDeviceModule::kPlatformDefaultAudio);
#endif
webrtc::adm_helpers::Init(_adm);
_callback = new SimpleAudioCallback(self);
_adm->RegisterAudioCallback(_callback);
Expand Down Expand Up @@ -569,9 +506,4 @@ - (NSURL*)applicationDocumentsDirectory {
lastObject];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
17 changes: 0 additions & 17 deletions ios_project/example/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,8 @@


#import <UIKit/UIKit.h>
#import <AudioUnit/AudioUnit.h>

@interface ViewController : UIViewController

- (int32_t)RecordedDataIsAvailable:(const void*)audioSamples
nSamples:(size_t)nSamples
nBytesPerSample:(size_t)nBytesPerSample
nChannels:(size_t)nChannels
samplesPerSec:(uint32_t)samplesPerSec
totalDelayMS:(uint32_t)totalDelayMS
clockDrift:(int32_t)clockDrift
currentMicLevel:(uint32_t)currentMicLevel
keyPressed:(bool)keyPressed;

- (size_t)NeedMorePlayData:(size_t)nSamples
nBytesPerSample:(size_t)nBytesPerSample
nChannels:(size_t)nChannels
samplesPerSec:(uint32_t)samplesPerSec
audioSamples:(void*)audioSamples;

@end

Loading

0 comments on commit 1b5c98b

Please sign in to comment.