Skip to content
Closed
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
12 changes: 7 additions & 5 deletions apps/common-app/src/examples/Record/Record.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { useRef, FC, useEffect } from 'react';
import React, { FC, useEffect, useRef } from 'react';
import {
AudioBuffer,
AudioBufferSourceNode,
AudioContext,
AudioManager,
AudioRecorder,
RecorderAdapterNode,
AudioBufferSourceNode,
AudioBuffer,
} from 'react-native-audio-api';

import { Container, Button } from '../../components';
import { View, Text } from 'react-native';
import { Text, View } from 'react-native';
import { Button, Container } from '../../components';
import { colors } from '../../styles';

const SAMPLE_RATE = 16000;
Expand Down Expand Up @@ -102,6 +102,8 @@ const Record: FC = () => {
audioBuffersRef.current.push(buffer);
});

recorderAdapterRef.current.onAudioReady = () => {};

recorderRef.current.start();

setTimeout(() => {
Expand Down
55 changes: 0 additions & 55 deletions packages/custom-node-generator/lib/generator.js

This file was deleted.

24 changes: 23 additions & 1 deletion packages/react-native-audio-api/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,27 @@ module.exports = {
files: ['./src/**/*.{ts,tsx}'],
},
],
ignorePatterns: ['lib', 'src/web-core/custom/signalsmithStretch' ],
ignorePatterns: ['lib', 'src/external/signalsmithStretch'],
settings: {
'import/resolver': {
node: {
extensions: [
'.js',
'.jsx',
'.ts',
'.tsx',
'.d.ts',
'.json',
'.web.ts',
'.web.tsx',
'.native.ts',
'.native.tsx',
'.ios.ts',
'.ios.tsx',
'.android.ts',
'.android.tsx',
],
},
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class AudioFocusListener(
private val audioAPIModule: WeakReference<AudioAPIModule>,
private val lockScreenManager: WeakReference<LockScreenManager>,
) : AudioManager.OnAudioFocusChangeListener {
private var playOnAudioFocus: Boolean = false
private var focusRequest: AudioFocusRequest? = null

override fun onAudioFocusChange(focusChange: Int) {
Expand All @@ -29,32 +28,20 @@ class AudioFocusListener(
audioAPIModule.get()?.invokeHandlerWithEventNameAndEventBody("interruption", body)
}
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> {
playOnAudioFocus = lockScreenManager.get()?.isPlaying == true
val body =
HashMap<String, Any>().apply {
put("type", "began")
put("shouldResume", playOnAudioFocus)
put("shouldResume", false)
}
audioAPIModule.get()?.invokeHandlerWithEventNameAndEventBody("interruption", body)
}
AudioManager.AUDIOFOCUS_GAIN -> {
if (playOnAudioFocus) {
val body =
HashMap<String, Any>().apply {
put("type", "ended")
put("shouldResume", true)
}
audioAPIModule.get()?.invokeHandlerWithEventNameAndEventBody("interruption", body)
} else {
val body =
HashMap<String, Any>().apply {
put("type", "ended")
put("shouldResume", false)
}
audioAPIModule.get()?.invokeHandlerWithEventNameAndEventBody("interruption", body)
}

playOnAudioFocus = false
val body =
HashMap<String, Any>().apply {
put("type", "ended")
put("shouldResume", true)
}
audioAPIModule.get()?.invokeHandlerWithEventNameAndEventBody("interruption", body)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ class AudioDecoder {
static std::shared_ptr<AudioBuffer>
makeAudioBufferFromFloatBuffer(const std::vector<float> &buffer, float outputSampleRate, int outputChannels);

static AudioFormat detectAudioFormat(const void *data, size_t size) {
static AudioFormat detectAudioFormat(
const void *data,
size_t size
) {
if (size < 12)
return AudioFormat::UNKNOWN;
const auto *bytes = static_cast<const unsigned char *>(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ AudioBus::AudioBus(size_t size, int numberOfChannels, float sampleRate)
: numberOfChannels_(numberOfChannels),
sampleRate_(sampleRate),
size_(size) {
assert(numberOfChannels > 0);
assert(size > 0);
assert(sampleRate > 0.0f);
assert(numberOfChannels < 128);
createChannels();
}

Expand Down
78 changes: 78 additions & 0 deletions packages/react-native-audio-api/prev_src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import type {
IAudioContext,
IAudioRecorder,
IOfflineAudioContext,
} from './interfaces';
import { NativeAudioAPIModule } from './specs';
import { AudioRecorderOptions } from './types';

/* eslint-disable no-var */
declare global {
var createAudioContext: (
sampleRate: number,
initSuspended: boolean
) => IAudioContext;
var createOfflineAudioContext: (
numberOfChannels: number,
length: number,
sampleRate: number
) => IOfflineAudioContext;

var createAudioRecorder: (options: AudioRecorderOptions) => IAudioRecorder;
}
/* eslint-disable no-var */

if (
global.createAudioContext == null ||
global.createOfflineAudioContext == null ||
global.createAudioRecorder == null ||
global.AudioEventEmitter == null
) {
if (!NativeAudioAPIModule) {
throw new Error(
`Failed to install react-native-audio-api: The native module could not be found.`
);
}

NativeAudioAPIModule.install();
}

// export { default as AnalyserNode } from './core/AnalyserNode';
// export { default as AudioBuffer } from './core/AudioBuffer';
// export { default as AudioBufferQueueSourceNode } from './core/AudioBufferQueueSourceNode';
// export { default as AudioBufferSourceNode } from './core/AudioBufferSourceNode';
// export { default as AudioContext } from './core/AudioContext';
// export { default as AudioDestinationNode } from './core/AudioDestinationNode';
// export { default as AudioNode } from './core/AudioNode';
// export { default as AudioParam } from './core/AudioParam';
// export { default as AudioRecorder } from './core/AudioRecorder';
// export { default as AudioScheduledSourceNode } from './core/AudioScheduledSourceNode';
// export { default as BaseAudioContext } from './core/BaseAudioContext';
// export { default as BiquadFilterNode } from './core/BiquadFilterNode';
// export { default as GainNode } from './core/GainNode';
// export { default as OfflineAudioContext } from './core/OfflineAudioContext';
// export { default as OscillatorNode } from './core/OscillatorNode';
// export { default as RecorderAdapterNode } from './core/RecorderAdapterNode';
// export { default as StereoPannerNode } from './core/StereoPannerNode';
// export { default as StreamerNode } from './core/StreamerNode';
// export { default as WorkletNode } from './core/WorkletNode';
// export { default as useSystemVolume } from './hooks/useSytemVolume';
// export { default as AudioManager } from './system';

// export {
// BiquadFilterType,
// ChannelCountMode,
// ChannelInterpretation,
// ContextState,
// OscillatorType,
// PeriodicWaveConstraints,
// WindowType,
// } from './types';

// export {
// IndexSizeError,
// InvalidAccessError,
// InvalidStateError,
// NotSupportedError,
// RangeError,
// } from './errors';
1 change: 1 addition & 0 deletions packages/react-native-audio-api/prev_src/api.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './web-core/custom';
49 changes: 49 additions & 0 deletions packages/react-native-audio-api/prev_src/core/AudioContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { IAudioContext } from '../interfaces';
import BaseAudioContext from './BaseAudioContext';
import AudioManager from '../system';
import { AudioContextOptions } from '../types';
import { NotSupportedError } from '../errors';
import { isWorkletsAvailable, workletsModule } from '../utils';

export default class AudioContext extends BaseAudioContext {
// We need to keep here a reference to this runtime to better manage its lifecycle
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
private _audioRuntime: any = null;

constructor(options?: AudioContextOptions) {
if (
options &&
options.sampleRate &&
(options.sampleRate < 8000 || options.sampleRate > 96000)
) {
throw new NotSupportedError(
`The provided sampleRate is not supported: ${options.sampleRate}`
);
}
let audioRuntime = null;
if (isWorkletsAvailable) {
audioRuntime = workletsModule.createWorkletRuntime('AudioWorkletRuntime');
}

super(
global.createAudioContext(
options?.sampleRate || AudioManager.getDevicePreferredSampleRate(),
options?.initSuspended || false,
audioRuntime
)
);
this._audioRuntime = audioRuntime;
}

async close(): Promise<void> {
return (this.context as IAudioContext).close();
}

async resume(): Promise<boolean> {
return (this.context as IAudioContext).resume();
}

async suspend(): Promise<boolean> {
return (this.context as IAudioContext).suspend();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AudioEventEmitter } from '../events';
import { OnAudioReadyEventType } from '../events/types';
import { IAudioRecorder } from '../interfaces';
import { AudioRecorderOptions } from '../types';
import AudioBuffer from './AudioBuffer';
import { OnAudioReadyEventType } from '../events/types';
import { AudioEventEmitter } from '../events';
import RecorderAdapterNode from './RecorderAdapterNode';

export default class AudioRecorder {
Expand Down
Loading