@stream-io/noise-cancellation-react-native 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/LICENSE +219 -0
- package/README.md +9 -0
- package/android/build.gradle +90 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/io/getstream/rn/noisecancellation/NoiseCancellationAudioProcessingController.kt +15 -0
- package/android/src/main/java/io/getstream/rn/noisecancellation/NoiseCancellationReactNative.kt +26 -0
- package/android/src/main/java/io/getstream/rn/noisecancellation/NoiseCancellationReactNativeModule.kt +55 -0
- package/android/src/main/java/io/getstream/rn/noisecancellation/NoiseCancellationReactNativePackage.kt +17 -0
- package/dist/commonjs/index.js +140 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/package.json +1 -0
- package/dist/commonjs/types.js +2 -0
- package/dist/commonjs/types.js.map +1 -0
- package/dist/module/index.js +132 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/package.json +1 -0
- package/dist/module/types.js +2 -0
- package/dist/module/types.js.map +1 -0
- package/dist/typescript/index.d.ts +77 -0
- package/dist/typescript/index.d.ts.map +1 -0
- package/dist/typescript/types.d.ts +27 -0
- package/dist/typescript/types.d.ts.map +1 -0
- package/ios/Classes/AudioFilters.swift +22 -0
- package/ios/Classes/AudioManager.h +19 -0
- package/ios/Classes/AudioManager.m +50 -0
- package/ios/Classes/AudioProcessingAdapter.h +26 -0
- package/ios/Classes/AudioProcessingAdapter.m +105 -0
- package/ios/Classes/NeuralEngineProvider.swift +12 -0
- package/ios/Classes/NoiseCancellationFilter.swift +83 -0
- package/ios/Classes/NoiseCancellationManagerObjc.m +32 -0
- package/ios/Classes/StreamAudioFilterCapturePostProcessingModule.swift +88 -0
- package/ios/Classes/StreamAudioProcessingModule.swift +58 -0
- package/ios/Headers/NoiseCancellationManagerObjc.h +12 -0
- package/ios/NoiseCancellationManager.swift +42 -0
- package/ios/NoiseCancellationReactNative-Bridging-Header.h +2 -0
- package/ios/NoiseCancellationReactNative.mm +23 -0
- package/ios/NoiseCancellationReactNative.swift +45 -0
- package/ios/Utils/DisposableBag/DisposableBag.swift +82 -0
- package/ios/Utils/Queues/LockQueuing.swift +22 -0
- package/ios/Utils/Queues/RecursiveQueue.swift +40 -0
- package/ios/Utils/Queues/UnfairQueue.swift +57 -0
- package/ios/Utils/SerialActor/SerialActor.swift +64 -0
- package/ios/Utils/SerialActor/SerialActorQueue.swift +84 -0
- package/package.json +69 -0
- package/src/index.ts +141 -0
- package/src/types.ts +30 -0
- package/stream-io-noise-cancellation-react-native.podspec +49 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { NativeModules, Platform } from 'react-native';
|
|
4
|
+
const LINKING_ERROR = `The package '@stream-io/noise-cancellation-react-native' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
|
|
5
|
+
ios: "- You have run 'pod install'\n",
|
|
6
|
+
default: ''
|
|
7
|
+
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
8
|
+
const NoiseCancellationReactNative = NativeModules.NoiseCancellationReactNative ? NativeModules.NoiseCancellationReactNative : new Proxy({}, {
|
|
9
|
+
get() {
|
|
10
|
+
throw new Error(LINKING_ERROR);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A wrapper around the native stream noise cancellation SDK.
|
|
16
|
+
*/
|
|
17
|
+
export class NoiseCancellation {
|
|
18
|
+
listeners = {};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Checks if the noise cancellation is supported on this platform.
|
|
22
|
+
* Make sure you call this method before trying to enable the noise cancellation.
|
|
23
|
+
*/
|
|
24
|
+
isSupported = () => true;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Checks if the noise cancellation can be automatically enabled for the current device.
|
|
28
|
+
* In react native, it will be auto enabled only if the device supports advanced audio processing.
|
|
29
|
+
*/
|
|
30
|
+
canAutoEnable = deviceSupportsAdvancedAudioProcessing;
|
|
31
|
+
init = () => Promise.resolve();
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Enables the noise cancellation.
|
|
35
|
+
*/
|
|
36
|
+
enable = () => {
|
|
37
|
+
NoiseCancellationReactNative.setEnabled(true);
|
|
38
|
+
this.dispatch('change', true);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Disables the noise cancellation.
|
|
43
|
+
*/
|
|
44
|
+
disable = () => {
|
|
45
|
+
NoiseCancellationReactNative.setEnabled(false);
|
|
46
|
+
this.dispatch('change', false);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Disposes the instance and releases all resources.
|
|
51
|
+
*/
|
|
52
|
+
dispose = async () => Promise.resolve();
|
|
53
|
+
|
|
54
|
+
// no-op in React Native
|
|
55
|
+
setSuppressionLevel = () => {};
|
|
56
|
+
isEnabled = async () => {
|
|
57
|
+
return isEnabled();
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A utility method convenient for our Microphone filters API.
|
|
62
|
+
* Not relevant in React Native.
|
|
63
|
+
*/
|
|
64
|
+
toFilter = () => mediaStream => {
|
|
65
|
+
return {
|
|
66
|
+
output: mediaStream
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Registers the given callback to the event type;
|
|
72
|
+
*
|
|
73
|
+
* @param event the event to listen.
|
|
74
|
+
* @param callback the callback to call.
|
|
75
|
+
*/
|
|
76
|
+
on = (event, callback) => {
|
|
77
|
+
(this.listeners[event] ??= []).push(callback);
|
|
78
|
+
return () => {
|
|
79
|
+
this.off(event, callback);
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Unregisters the given callback for the event type.
|
|
85
|
+
*
|
|
86
|
+
* @param event the event.
|
|
87
|
+
* @param callback the callback to unregister.
|
|
88
|
+
*/
|
|
89
|
+
off = (event, callback) => {
|
|
90
|
+
const listeners = this.listeners[event] || [];
|
|
91
|
+
this.listeners[event] = listeners.filter(cb => cb !== callback);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Dispatches a new event payload for the given event type.
|
|
96
|
+
*
|
|
97
|
+
* @param event the event.
|
|
98
|
+
* @param payload the payload.
|
|
99
|
+
*/
|
|
100
|
+
dispatch = (event, payload) => {
|
|
101
|
+
const listeners = this.listeners[event] || [];
|
|
102
|
+
for (const listener of listeners) {
|
|
103
|
+
listener(payload);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Checks if noise cancellation is currently enabled.
|
|
110
|
+
* @returns A promise that resolves with a boolean indicating if noise cancellation is enabled.
|
|
111
|
+
*/
|
|
112
|
+
export const isEnabled = () => {
|
|
113
|
+
return NoiseCancellationReactNative.isEnabled();
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Enables or disables noise cancellation.
|
|
118
|
+
* @param enabled - Whether to enable or disable noise cancellation.
|
|
119
|
+
* @returns A promise that resolves when the operation is complete.
|
|
120
|
+
*/
|
|
121
|
+
export const setEnabled = enabled => {
|
|
122
|
+
return NoiseCancellationReactNative.setEnabled(enabled);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Checks if the device supports advanced audio processing required for noise cancellation.
|
|
127
|
+
* @returns A promise that resolves with a boolean indicating if the device supports advanced audio processing.
|
|
128
|
+
*/
|
|
129
|
+
export const deviceSupportsAdvancedAudioProcessing = () => {
|
|
130
|
+
return NoiseCancellationReactNative.deviceSupportsAdvancedAudioProcessing();
|
|
131
|
+
};
|
|
132
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","NoiseCancellationReactNative","Proxy","get","Error","NoiseCancellation","listeners","isSupported","canAutoEnable","deviceSupportsAdvancedAudioProcessing","init","Promise","resolve","enable","setEnabled","dispatch","disable","dispose","setSuppressionLevel","isEnabled","toFilter","mediaStream","output","on","event","callback","push","off","filter","cb","payload","listener","enabled"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"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","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["types.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Events, INoiseCancellation } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* A wrapper around the native stream noise cancellation SDK.
|
|
4
|
+
*/
|
|
5
|
+
export declare class NoiseCancellation implements INoiseCancellation {
|
|
6
|
+
private readonly listeners;
|
|
7
|
+
/**
|
|
8
|
+
* Checks if the noise cancellation is supported on this platform.
|
|
9
|
+
* Make sure you call this method before trying to enable the noise cancellation.
|
|
10
|
+
*/
|
|
11
|
+
isSupported: () => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Checks if the noise cancellation can be automatically enabled for the current device.
|
|
14
|
+
* In react native, it will be auto enabled only if the device supports advanced audio processing.
|
|
15
|
+
*/
|
|
16
|
+
canAutoEnable: () => Promise<boolean>;
|
|
17
|
+
init: () => Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Enables the noise cancellation.
|
|
20
|
+
*/
|
|
21
|
+
enable: () => void;
|
|
22
|
+
/**
|
|
23
|
+
* Disables the noise cancellation.
|
|
24
|
+
*/
|
|
25
|
+
disable: () => void;
|
|
26
|
+
/**
|
|
27
|
+
* Disposes the instance and releases all resources.
|
|
28
|
+
*/
|
|
29
|
+
dispose: () => Promise<void>;
|
|
30
|
+
setSuppressionLevel: () => void;
|
|
31
|
+
isEnabled: () => Promise<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* A utility method convenient for our Microphone filters API.
|
|
34
|
+
* Not relevant in React Native.
|
|
35
|
+
*/
|
|
36
|
+
toFilter: () => (mediaStream: MediaStream) => {
|
|
37
|
+
output: MediaStream;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Registers the given callback to the event type;
|
|
41
|
+
*
|
|
42
|
+
* @param event the event to listen.
|
|
43
|
+
* @param callback the callback to call.
|
|
44
|
+
*/
|
|
45
|
+
on: <E extends keyof Events, T = Events[E]>(event: E, callback: T) => () => void;
|
|
46
|
+
/**
|
|
47
|
+
* Unregisters the given callback for the event type.
|
|
48
|
+
*
|
|
49
|
+
* @param event the event.
|
|
50
|
+
* @param callback the callback to unregister.
|
|
51
|
+
*/
|
|
52
|
+
off: <E extends keyof Events, T = Events[E]>(event: E, callback: T) => void;
|
|
53
|
+
/**
|
|
54
|
+
* Dispatches a new event payload for the given event type.
|
|
55
|
+
*
|
|
56
|
+
* @param event the event.
|
|
57
|
+
* @param payload the payload.
|
|
58
|
+
*/
|
|
59
|
+
private dispatch;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Checks if noise cancellation is currently enabled.
|
|
63
|
+
* @returns A promise that resolves with a boolean indicating if noise cancellation is enabled.
|
|
64
|
+
*/
|
|
65
|
+
export declare const isEnabled: () => Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* Enables or disables noise cancellation.
|
|
68
|
+
* @param enabled - Whether to enable or disable noise cancellation.
|
|
69
|
+
* @returns A promise that resolves when the operation is complete.
|
|
70
|
+
*/
|
|
71
|
+
export declare const setEnabled: (enabled: boolean) => Promise<boolean>;
|
|
72
|
+
/**
|
|
73
|
+
* Checks if the device supports advanced audio processing required for noise cancellation.
|
|
74
|
+
* @returns A promise that resolves with a boolean indicating if the device supports advanced audio processing.
|
|
75
|
+
*/
|
|
76
|
+
export declare const deviceSupportsAdvancedAudioProcessing: () => Promise<boolean>;
|
|
77
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAmB1D;;GAEG;AACH,qBAAa,iBAAkB,YAAW,kBAAkB;IAC1D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiD;IAE3E;;;OAGG;IACH,WAAW,gBAAc;IAEzB;;;OAGG;IACH,aAAa,QAsG0C,OAAO,CAAC,OAAO,CAAC,CAtGjB;IAEtD,IAAI,sBAA2B;IAE/B;;OAEG;IACH,MAAM,aAGJ;IAEF;;OAEG;IACH,OAAO,aAGL;IAEF;;OAEG;IACH,OAAO,sBAAiC;IAGxC,mBAAmB,aAAY;IAE/B,SAAS,yBAEP;IAEF;;;OAGG;IACH,QAAQ,SAAU,aAAa,WAAW;;MAExC;IAEF;;;;;OAKG;IACH,EAAE,GAAI,CAAC,SAAS,MAAM,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,UAAU,CAAC,gBAKhE;IAEF;;;;;OAKG;IACH,GAAG,GAAI,CAAC,SAAS,MAAM,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,UAAU,CAAC,UAGjE;IAEF;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAQd;CACH;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,QAAO,OAAO,CAAC,OAAO,CAE3C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,SAAS,OAAO,KAAG,OAAO,CAAC,OAAO,CAE5D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,qCAAqC,QAAO,OAAO,CAAC,OAAO,CAEvE,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface INoiseCancellation {
|
|
2
|
+
isSupported: () => boolean | Promise<boolean>;
|
|
3
|
+
init: () => Promise<void>;
|
|
4
|
+
canAutoEnable?: () => Promise<boolean>;
|
|
5
|
+
isEnabled: () => Promise<boolean>;
|
|
6
|
+
enable: () => void;
|
|
7
|
+
disable: () => void;
|
|
8
|
+
dispose: () => Promise<void>;
|
|
9
|
+
setSuppressionLevel: (level: number) => void;
|
|
10
|
+
toFilter: () => (mediaStream: MediaStream) => {
|
|
11
|
+
output: MediaStream;
|
|
12
|
+
};
|
|
13
|
+
on: <E extends keyof Events, T = Events[E]>(event: E, callback: T) => () => void;
|
|
14
|
+
off: <E extends keyof Events, T = Events[E]>(event: E, callback: T) => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A list of events one can subscribe to.
|
|
18
|
+
*/
|
|
19
|
+
export type Events = {
|
|
20
|
+
/**
|
|
21
|
+
* Fires when Noise Cancellation state changes.
|
|
22
|
+
*
|
|
23
|
+
* @param enabled true when enabled, false otherwise.
|
|
24
|
+
*/
|
|
25
|
+
change: (enabled: boolean) => void;
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9C,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,SAAS,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAClC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,mBAAmB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,WAAW,KAAK;QAC5C,MAAM,EAAE,WAAW,CAAC;KACrB,CAAC;IACF,EAAE,EAAE,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,EACxC,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,CAAC,KACR,MAAM,IAAI,CAAC;IAChB,GAAG,EAAE,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,IAAI,CAAC;CAC7E;AAED;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB;;;;OAIG;IACH,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CACpC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright © 2024 Stream.io Inc. All rights reserved.
|
|
3
|
+
|
|
4
|
+
//
|
|
5
|
+
|
|
6
|
+
import Foundation
|
|
7
|
+
import stream_react_native_webrtc
|
|
8
|
+
|
|
9
|
+
/// AudioFilter protocol defines the structure for audio filtering implementations.
|
|
10
|
+
public protocol AudioFilter: Sendable {
|
|
11
|
+
/// Unique identifier for the audio filter.
|
|
12
|
+
var id: String { get }
|
|
13
|
+
|
|
14
|
+
/// Initializes the audio filter with specified sample rate and number of channels.
|
|
15
|
+
func initialize(sampleRate: Int, channels: Int)
|
|
16
|
+
|
|
17
|
+
/// Applies the defined audio effect to the given audio buffer.
|
|
18
|
+
func applyEffect(to audioBuffer: inout RTCAudioBuffer)
|
|
19
|
+
|
|
20
|
+
/// Releases resources associated with the audio filter.
|
|
21
|
+
func release()
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <WebRTC/WebRTC.h>
|
|
3
|
+
#import "AudioProcessingAdapter.h"
|
|
4
|
+
|
|
5
|
+
@interface AudioManager : NSObject
|
|
6
|
+
|
|
7
|
+
@property(nonatomic, strong) RTCDefaultAudioProcessingModule* _Nonnull audioProcessingModule;
|
|
8
|
+
|
|
9
|
+
@property(nonatomic, strong) AudioProcessingAdapter* _Nonnull capturePostProcessingAdapter;
|
|
10
|
+
|
|
11
|
+
@property(nonatomic, strong) AudioProcessingAdapter* _Nonnull renderPreProcessingAdapter;
|
|
12
|
+
|
|
13
|
+
+ (_Nonnull instancetype)sharedInstance;
|
|
14
|
+
|
|
15
|
+
- (void)addLocalAudioRenderer:(nonnull id<RTCAudioRenderer>)renderer;
|
|
16
|
+
|
|
17
|
+
- (void)removeLocalAudioRenderer:(nonnull id<RTCAudioRenderer>)renderer;
|
|
18
|
+
|
|
19
|
+
@end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#import "AudioManager.h"
|
|
2
|
+
#import "AudioProcessingAdapter.h"
|
|
3
|
+
|
|
4
|
+
@implementation AudioManager {
|
|
5
|
+
RTCDefaultAudioProcessingModule* _audioProcessingModule;
|
|
6
|
+
AudioProcessingAdapter* _capturePostProcessingAdapter;
|
|
7
|
+
AudioProcessingAdapter* _renderPreProcessingAdapter;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@synthesize capturePostProcessingAdapter = _capturePostProcessingAdapter;
|
|
11
|
+
@synthesize renderPreProcessingAdapter = _renderPreProcessingAdapter;
|
|
12
|
+
@synthesize audioProcessingModule = _audioProcessingModule;
|
|
13
|
+
|
|
14
|
+
+ (instancetype)sharedInstance {
|
|
15
|
+
static dispatch_once_t onceToken;
|
|
16
|
+
static AudioManager* sharedInstance = nil;
|
|
17
|
+
dispatch_once(&onceToken, ^{
|
|
18
|
+
sharedInstance = [[self alloc] init];
|
|
19
|
+
});
|
|
20
|
+
return sharedInstance;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
- (instancetype)init {
|
|
24
|
+
if (self = [super init]) {
|
|
25
|
+
_audioProcessingModule = [[RTCDefaultAudioProcessingModule alloc] init];
|
|
26
|
+
_capturePostProcessingAdapter = [[AudioProcessingAdapter alloc] init];
|
|
27
|
+
_renderPreProcessingAdapter = [[AudioProcessingAdapter alloc] init];
|
|
28
|
+
_audioProcessingModule.capturePostProcessingDelegate = _capturePostProcessingAdapter;
|
|
29
|
+
_audioProcessingModule.renderPreProcessingDelegate = _renderPreProcessingAdapter;
|
|
30
|
+
}
|
|
31
|
+
return self;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
- (void)addLocalAudioRenderer:(nonnull id<RTCAudioRenderer>)renderer {
|
|
35
|
+
[_capturePostProcessingAdapter addAudioRenderer:renderer];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
- (void)removeLocalAudioRenderer:(nonnull id<RTCAudioRenderer>)renderer {
|
|
39
|
+
[_capturePostProcessingAdapter removeAudioRenderer:renderer];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
- (void)addRemoteAudioSink:(nonnull id<RTCAudioRenderer>)sink {
|
|
43
|
+
[_renderPreProcessingAdapter addAudioRenderer:sink];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
- (void)removeRemoteAudioSink:(nonnull id<RTCAudioRenderer>)sink {
|
|
47
|
+
[_renderPreProcessingAdapter removeAudioRenderer:sink];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <WebRTC/WebRTC.h>
|
|
3
|
+
|
|
4
|
+
@protocol ExternalAudioProcessingDelegate
|
|
5
|
+
|
|
6
|
+
- (void)audioProcessingInitializeWithSampleRate:(size_t)sampleRateHz channels:(size_t)channels;
|
|
7
|
+
|
|
8
|
+
- (void)audioProcessingProcess:(RTC_OBJC_TYPE(RTCAudioBuffer) * _Nonnull)audioBuffer;
|
|
9
|
+
|
|
10
|
+
- (void)audioProcessingRelease;
|
|
11
|
+
|
|
12
|
+
@end
|
|
13
|
+
|
|
14
|
+
@interface AudioProcessingAdapter : NSObject <RTCAudioCustomProcessingDelegate>
|
|
15
|
+
|
|
16
|
+
- (nonnull instancetype)init;
|
|
17
|
+
|
|
18
|
+
- (void)addProcessing:(id<ExternalAudioProcessingDelegate> _Nonnull)processor;
|
|
19
|
+
|
|
20
|
+
- (void)removeProcessing:(id<ExternalAudioProcessingDelegate> _Nonnull)processor;
|
|
21
|
+
|
|
22
|
+
- (void)addAudioRenderer:(nonnull id<RTCAudioRenderer>)renderer;
|
|
23
|
+
|
|
24
|
+
- (void)removeAudioRenderer:(nonnull id<RTCAudioRenderer>)renderer;
|
|
25
|
+
|
|
26
|
+
@end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#import "AudioProcessingAdapter.h"
|
|
2
|
+
#import <WebRTC/RTCAudioRenderer.h>
|
|
3
|
+
#import <os/lock.h>
|
|
4
|
+
|
|
5
|
+
@implementation AudioProcessingAdapter {
|
|
6
|
+
NSMutableArray<id<RTCAudioRenderer>>* _renderers;
|
|
7
|
+
NSMutableArray<id<ExternalAudioProcessingDelegate>>* _processors;
|
|
8
|
+
os_unfair_lock _lock;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
- (instancetype)init {
|
|
12
|
+
self = [super init];
|
|
13
|
+
if (self) {
|
|
14
|
+
_lock = OS_UNFAIR_LOCK_INIT;
|
|
15
|
+
_renderers = [[NSMutableArray<id<RTCAudioRenderer>> alloc] init];
|
|
16
|
+
_processors = [[NSMutableArray<id<ExternalAudioProcessingDelegate>> alloc] init];
|
|
17
|
+
}
|
|
18
|
+
return self;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
- (void)addProcessing:(id<ExternalAudioProcessingDelegate> _Nonnull)processor {
|
|
22
|
+
os_unfair_lock_lock(&_lock);
|
|
23
|
+
[_processors addObject:processor];
|
|
24
|
+
os_unfair_lock_unlock(&_lock);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
- (void)removeProcessing:(id<ExternalAudioProcessingDelegate> _Nonnull)processor {
|
|
28
|
+
os_unfair_lock_lock(&_lock);
|
|
29
|
+
_processors = [[_processors
|
|
30
|
+
filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject,
|
|
31
|
+
NSDictionary* bindings) {
|
|
32
|
+
return evaluatedObject != processor;
|
|
33
|
+
}]] mutableCopy];
|
|
34
|
+
os_unfair_lock_unlock(&_lock);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
- (void)addAudioRenderer:(nonnull id<RTCAudioRenderer>)renderer {
|
|
38
|
+
os_unfair_lock_lock(&_lock);
|
|
39
|
+
[_renderers addObject:renderer];
|
|
40
|
+
os_unfair_lock_unlock(&_lock);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
- (void)removeAudioRenderer:(nonnull id<RTCAudioRenderer>)renderer {
|
|
44
|
+
os_unfair_lock_lock(&_lock);
|
|
45
|
+
_renderers = [[_renderers
|
|
46
|
+
filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject,
|
|
47
|
+
NSDictionary* bindings) {
|
|
48
|
+
return evaluatedObject != renderer;
|
|
49
|
+
}]] mutableCopy];
|
|
50
|
+
os_unfair_lock_unlock(&_lock);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
- (void)audioProcessingInitializeWithSampleRate:(size_t)sampleRateHz channels:(size_t)channels {
|
|
54
|
+
os_unfair_lock_lock(&_lock);
|
|
55
|
+
for (id<ExternalAudioProcessingDelegate> processor in _processors) {
|
|
56
|
+
[processor audioProcessingInitializeWithSampleRate:sampleRateHz channels:channels];
|
|
57
|
+
}
|
|
58
|
+
os_unfair_lock_unlock(&_lock);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
- (AVAudioPCMBuffer*)toPCMBuffer:(RTC_OBJC_TYPE(RTCAudioBuffer) *)audioBuffer {
|
|
62
|
+
AVAudioFormat* format =
|
|
63
|
+
[[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatInt16
|
|
64
|
+
sampleRate:audioBuffer.frames * 100.0
|
|
65
|
+
channels:(AVAudioChannelCount)audioBuffer.channels
|
|
66
|
+
interleaved:NO];
|
|
67
|
+
AVAudioPCMBuffer* pcmBuffer =
|
|
68
|
+
[[AVAudioPCMBuffer alloc] initWithPCMFormat:format
|
|
69
|
+
frameCapacity:(AVAudioFrameCount)audioBuffer.frames];
|
|
70
|
+
if (!pcmBuffer) {
|
|
71
|
+
NSLog(@"Failed to create AVAudioPCMBuffer");
|
|
72
|
+
return nil;
|
|
73
|
+
}
|
|
74
|
+
pcmBuffer.frameLength = (AVAudioFrameCount)audioBuffer.frames;
|
|
75
|
+
for (int i = 0; i < audioBuffer.channels; i++) {
|
|
76
|
+
float* sourceBuffer = [audioBuffer rawBufferForChannel:i];
|
|
77
|
+
int16_t* targetBuffer = (int16_t*)pcmBuffer.int16ChannelData[i];
|
|
78
|
+
for (int frame = 0; frame < audioBuffer.frames; frame++) {
|
|
79
|
+
targetBuffer[frame] = sourceBuffer[frame];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return pcmBuffer;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
- (void)audioProcessingProcess:(RTC_OBJC_TYPE(RTCAudioBuffer) *)audioBuffer {
|
|
86
|
+
os_unfair_lock_lock(&_lock);
|
|
87
|
+
for (id<ExternalAudioProcessingDelegate> processor in _processors) {
|
|
88
|
+
[processor audioProcessingProcess:audioBuffer];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
for (id<RTCAudioRenderer> renderer in _renderers) {
|
|
92
|
+
[renderer renderPCMBuffer:[self toPCMBuffer:audioBuffer]];
|
|
93
|
+
}
|
|
94
|
+
os_unfair_lock_unlock(&_lock);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
- (void)audioProcessingRelease {
|
|
98
|
+
os_unfair_lock_lock(&_lock);
|
|
99
|
+
for (id<ExternalAudioProcessingDelegate> processor in _processors) {
|
|
100
|
+
[processor audioProcessingRelease];
|
|
101
|
+
}
|
|
102
|
+
os_unfair_lock_unlock(&_lock);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
// Copyright © 2024 Stream.io Inc. All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
|
|
6
|
+
import Foundation
|
|
7
|
+
import Combine
|
|
8
|
+
import stream_react_native_webrtc
|
|
9
|
+
|
|
10
|
+
/// A concrete implementation of `AudioFilter` that applies noise cancellation effects.
|
|
11
|
+
public final class NoiseCancellationFilter: AudioFilter, @unchecked Sendable {
|
|
12
|
+
|
|
13
|
+
public typealias InitializeClosure = (Int, Int) -> Void
|
|
14
|
+
public typealias ProcessClosure = (Int, Int, Int, UnsafeMutablePointer<Float>) -> Void
|
|
15
|
+
public typealias ReleaseClosure = () -> Void
|
|
16
|
+
|
|
17
|
+
private var isActive: Bool = false
|
|
18
|
+
private let serialQueue = SerialActorQueue()
|
|
19
|
+
|
|
20
|
+
private let name: String
|
|
21
|
+
private let initializeClosure: (Int, Int) -> Void
|
|
22
|
+
private let processClosure: (Int, Int, Int, UnsafeMutablePointer<Float>) -> Void
|
|
23
|
+
private let releaseClosure: () -> Void
|
|
24
|
+
|
|
25
|
+
/// Initializes a new instance of `NoiseCancellationFilter`.
|
|
26
|
+
/// - Parameters:
|
|
27
|
+
/// - name: The name identifier for the filter.
|
|
28
|
+
/// - initialize: The closure to initialize the filter with sample rate and channels.
|
|
29
|
+
/// - process: The closure to apply noise cancellation processing.
|
|
30
|
+
/// - release: The closure to release the filter.
|
|
31
|
+
public init(
|
|
32
|
+
name: String,
|
|
33
|
+
initialize: @escaping InitializeClosure,
|
|
34
|
+
process: @escaping ProcessClosure,
|
|
35
|
+
release: @escaping ReleaseClosure
|
|
36
|
+
) {
|
|
37
|
+
self.name = name
|
|
38
|
+
initializeClosure = initialize
|
|
39
|
+
processClosure = process
|
|
40
|
+
releaseClosure = release
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// MARK: - AudioFilter
|
|
44
|
+
|
|
45
|
+
/// The identifier of the filter.
|
|
46
|
+
public var id: String { name }
|
|
47
|
+
|
|
48
|
+
/// Initializes the filter with the specified sample rate and number of channels.
|
|
49
|
+
/// - Parameters:
|
|
50
|
+
/// - sampleRate: The sample rate in Hz.
|
|
51
|
+
/// - channels: The number of audio channels.
|
|
52
|
+
public func initialize(sampleRate: Int, channels: Int) {
|
|
53
|
+
serialQueue.async { [weak self] in
|
|
54
|
+
guard let self, !isActive else { return }
|
|
55
|
+
self.initializeClosure(sampleRate, channels)
|
|
56
|
+
self.isActive = true
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/// Applies noise cancellation processing to the audio buffer.
|
|
62
|
+
/// - Parameter buffer: The audio buffer to which the effect is applied.
|
|
63
|
+
public func applyEffect(to buffer: inout RTCAudioBuffer) {
|
|
64
|
+
guard isActive else {
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
processClosure(
|
|
68
|
+
buffer.channels,
|
|
69
|
+
buffer.bands,
|
|
70
|
+
buffer.frames,
|
|
71
|
+
buffer.rawBuffer(forChannel: 0)
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// Releases the filter by stopping noise cancellation for the active call.
|
|
76
|
+
public func release() {
|
|
77
|
+
serialQueue.async { [weak self] in
|
|
78
|
+
guard let self else { return }
|
|
79
|
+
isActive = false
|
|
80
|
+
releaseClosure() // Invoke the release closure.
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#import "NoiseCancellationManagerObjc.h"
|
|
2
|
+
#import "stream_io_noise_cancellation_react_native/stream_io_noise_cancellation_react_native-Swift.h"
|
|
3
|
+
|
|
4
|
+
@interface NoiseCancellationManagerObjc ()
|
|
5
|
+
@end
|
|
6
|
+
|
|
7
|
+
@implementation NoiseCancellationManagerObjc
|
|
8
|
+
|
|
9
|
+
+ (instancetype)sharedInstance {
|
|
10
|
+
static NoiseCancellationManagerObjc *sharedInstance = nil;
|
|
11
|
+
static dispatch_once_t onceToken;
|
|
12
|
+
dispatch_once(&onceToken, ^{
|
|
13
|
+
sharedInstance = [[NoiseCancellationManagerObjc alloc] init];
|
|
14
|
+
});
|
|
15
|
+
return sharedInstance;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
- (instancetype)init {
|
|
19
|
+
self = [super init];
|
|
20
|
+
if (self) {
|
|
21
|
+
// Initialization if needed
|
|
22
|
+
}
|
|
23
|
+
return self;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
- (void)registerProcessor {
|
|
27
|
+
// Call the Swift implementation
|
|
28
|
+
NoiseCancellationManager *swiftManager = [NoiseCancellationManager getInstance];
|
|
29
|
+
[swiftManager registerProcessor];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@end
|