Skip to content

Commit

Permalink
Fixes, add new test
Browse files Browse the repository at this point in the history
  • Loading branch information
Eliastik committed Jun 2, 2024
1 parent fd1f24a commit 6b18bc2
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dist/cjs/SimpleSoundStudioLibrary.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cjs/SimpleSoundStudioLibrary.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/esm/SimpleSoundStudioLibrary.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/esm/SimpleSoundStudioLibrary.js.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions lib/audioEditor/AudioProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ export default class AudioProcessor extends AbstractAudioElement implements Audi

this.eventEmitter.emit(EventType.OFFLINE_AUDIO_RENDERING_FINISHED);
} else { // Compatibility mode
this.bufferPlayer.setCompatibilityMode(this.filterManager.currentNodes!.output, durationAudio);
this.initialRenderingDone = true;
if (this.filterManager.currentNodes) {
this.bufferPlayer.setCompatibilityMode(this.filterManager.currentNodes.output, durationAudio);
this.initialRenderingDone = true;
}
}

this.eventEmitter.emit(EventType.AUDIO_RENDERING_FINISHED);
Expand Down
2 changes: 1 addition & 1 deletion lib/audioEditor/FilterManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default class FilterManager extends AbstractAudioElement implements Filte
});
}

async connectNodes(context: BaseAudioContext, buffer: AudioBuffer, keepCurrentInputOutput: boolean, isCompatibilityMode: boolean) {
async connectNodes(context: BaseAudioContext, buffer: AudioBuffer, keepCurrentInputOutput: boolean, isCompatibilityMode: boolean): Promise<void> {
if (!this._entryPointFilter) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/audioEditor/interfaces/FilterManagerInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default interface FilterManagerInterface {
* @param keepCurrentInputOutput Keep current first input/output nodes?
* @param isCompatibilityMode Is compatibility mode enabled?
*/
connectNodes(context: BaseAudioContext, buffer: AudioBuffer, keepCurrentInputOutput: boolean, isCompatibilityMode: boolean): void;
connectNodes(context: BaseAudioContext, buffer: AudioBuffer, keepCurrentInputOutput: boolean, isCompatibilityMode: boolean): Promise<void>;

/**
* Disconnect old audio nodes
Expand Down
64 changes: 59 additions & 5 deletions tests/AudioEditor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ import SountouchWrapperFilter from "../lib/filters/SountouchWrapperFilter";
import VocoderRenderer from "../lib/filters/VocoderRenderer";
import { MockAudioBuffer } from "./AudioBufferMock";
import { MockAudioContext } from "./AudioContextMock";
import { mockAudioProcessor, mockBufferManager, mockContextManager, mockFilterManager, mockRendererManager, mockSaveBufferManager, mockBufferPlayer, mockEventEmitter } from "./AudioEditorObjectsMock";
import EventEmitter from "../lib/utils/EventEmitter";
import { mockAudioProcessor, mockBufferManager, mockContextManager, mockFilterManager, mockRendererManager, mockSaveBufferManager, mockBufferPlayer, mockEventEmitter, mockRendererManagerWithFakeRenderedBuffer } from "./AudioEditorObjectsMock";
import { EventType } from "../lib/model/EventTypeEnum";

(AudioContext as any) = MockAudioContext;
(AudioBuffer as any) = MockAudioBuffer;
import EventEmitter from "../lib/utils/EventEmitter";
import BufferPlayer from "../lib/bufferPlayer/BufferPlayer";
import AudioProcessor from "../lib/audioEditor/AudioProcessor";
import GenericConfigService from "../lib/services/GenericConfigService";

describe("AudioEditor", () => {
let audioEditor: AudioEditor;

beforeEach(() => {
(AudioContext as any) = MockAudioContext;
(AudioBuffer as any) = MockAudioBuffer;
(OfflineAudioContext as any) = MockAudioContext;

audioEditor = new AudioEditor(
mockFilterManager,
mockRendererManager,
Expand Down Expand Up @@ -218,6 +222,56 @@ describe("AudioEditor", () => {
expect(mockAudioProcessor.setupOutput).toHaveBeenCalled();
});

test("render audio should enable compatibility mode even when initial rendering is disabled", async () => {
const eventEmitter = new EventEmitter();

const bufferPlayer = new BufferPlayer(mockContextManager);

const audioProcessor = new AudioProcessor(
mockFilterManager,
mockRendererManagerWithFakeRenderedBuffer,
mockContextManager,
bufferPlayer,
mockBufferManager
);

const audioEditor2 = new AudioEditor(
mockFilterManager,
mockRendererManager,
mockContextManager,
mockSaveBufferManager,
audioProcessor,
mockBufferManager,
bufferPlayer
);

const genericConfigService = new GenericConfigService();

(audioProcessor as any).injectDependencies(null, null, genericConfigService, eventEmitter);
(audioEditor2 as any).injectDependencies(null, null, genericConfigService, eventEmitter);

genericConfigService.setConfig(Constants.PREFERENCES_KEYS.DISABLE_INITIAL_RENDERING, "true");
genericConfigService.setConfig(Constants.PREFERENCES_KEYS.COMPATIBILITY_MODE_ENABLED, "true");

jest.spyOn(bufferPlayer, "setCompatibilityMode");

audioEditor2.loadBuffer(new MockAudioBuffer(2, 10000, 44100));
expect(audioProcessor.initialRenderingDone).toBe(false);

await audioEditor2.renderAudio();

expect(bufferPlayer.compatibilityMode).toBe(true);

audioEditor2.exit();

audioEditor2.loadBuffer(new MockAudioBuffer(2, 10000, 44100));
expect(audioProcessor.initialRenderingDone).toBe(false);

await audioEditor2.renderAudio();

expect(bufferPlayer.compatibilityMode).toBe(true);
});

test("should return order and id correctly", () => {
expect(audioEditor.order).toBe(-1);
expect(audioEditor.id).toBe(Constants.AUDIO_EDITOR);
Expand Down
2 changes: 1 addition & 1 deletion tests/AudioEditorObjectsMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const mockBufferPlayer = {
compatibilityMode: false,
loop: false,
loadBuffer: jest.fn(),
setCompatibilityMode: jest.fn(),
setCompatibilityMode: jest.fn(() => (mockBufferPlayer as any).compatibilityMode = true),
} as unknown as BufferPlayerInterface;

const mockEventEmitter = {
Expand Down

0 comments on commit 6b18bc2

Please sign in to comment.