RLBoxSoundTouch.h (2774B)
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef RLBOXSOUNDTOUCH_H_ 7 #define RLBOXSOUNDTOUCH_H_ 8 9 #include "RLBoxSoundTouchTypes.h" 10 11 // Load general firefox configuration of RLBox 12 #include "mozilla/rlbox/rlbox_config.h" 13 #undef RLBOX_WASM2C_MODULE_NAME 14 #define RLBOX_WASM2C_MODULE_NAME rlboxsoundtouch 15 16 #ifdef MOZ_WASM_SANDBOXING_SOUNDTOUCH 17 // Include the generated header file so that we are able to resolve the symbols 18 // in the wasm binary 19 # include "rlboxsoundtouch.wasm.h" 20 # define RLBOX_USE_STATIC_CALLS() rlbox_wasm2c_sandbox_lookup_symbol 21 # include "mozilla/rlbox/rlbox_wasm2c_sandbox.hpp" 22 #else 23 // Extra configuration for no-op sandbox 24 # define RLBOX_USE_STATIC_CALLS() rlbox_noop_sandbox_lookup_symbol 25 # include "mozilla/rlbox/rlbox_noop_sandbox.hpp" 26 #endif 27 28 #include "mozilla/rlbox/rlbox.hpp" 29 #include "AudioStream.h" 30 // Use abort() instead of exception in SoundTouch. 31 #define ST_NO_EXCEPTION_HANDLING 1 32 #include "soundtouch/SoundTouchFactory.h" 33 34 #if defined(WIN32) 35 #if defined(BUILDING_SOUNDTOUCH) 36 #define RLBOX_SOUNDTOUCH_API __declspec(dllexport) 37 #else 38 #define RLBOX_SOUNDTOUCH_API __declspec(dllimport) 39 #endif 40 #else 41 #define RLBOX_SOUNDTOUCH_API __attribute__((visibility("default"))) 42 #endif 43 44 namespace mozilla { 45 46 class RLBoxSoundTouch { 47 public: 48 RLBOX_SOUNDTOUCH_API 49 RLBoxSoundTouch(); 50 RLBOX_SOUNDTOUCH_API 51 bool Init(); 52 RLBOX_SOUNDTOUCH_API 53 ~RLBoxSoundTouch(); 54 55 RLBOX_SOUNDTOUCH_API 56 void setSampleRate(uint aRate); 57 RLBOX_SOUNDTOUCH_API 58 void setChannels(uint aChannels); 59 RLBOX_SOUNDTOUCH_API 60 void setPitch(double aPitch); 61 RLBOX_SOUNDTOUCH_API 62 void setSetting(int aSettingId, int aValue); 63 RLBOX_SOUNDTOUCH_API 64 void setTempo(double aTempo); 65 RLBOX_SOUNDTOUCH_API 66 uint numChannels(); 67 RLBOX_SOUNDTOUCH_API 68 tainted_soundtouch<uint> numSamples(); 69 RLBOX_SOUNDTOUCH_API 70 tainted_soundtouch<uint> numUnprocessedSamples(); 71 RLBOX_SOUNDTOUCH_API 72 void setRate(double aRate); 73 RLBOX_SOUNDTOUCH_API 74 void putSamples(const mozilla::AudioDataValue* aSamples, uint aNumSamples); 75 RLBOX_SOUNDTOUCH_API 76 uint receiveSamples(mozilla::AudioDataValue* aOutput, uint aMaxSamples); 77 RLBOX_SOUNDTOUCH_API 78 void flush(); 79 80 private: 81 bool mCreated{false}; 82 uint mChannels{0}; 83 rlbox_sandbox_soundtouch mSandbox; 84 tainted_soundtouch<mozilla::AudioDataValue*> mSampleBuffer{nullptr}; 85 uint mSampleBufferSize{1}; 86 tainted_soundtouch<soundtouch::SoundTouch*> mTimeStretcher{nullptr}; 87 88 RLBOX_SOUNDTOUCH_API 89 void resizeSampleBuffer(uint aNewSize); 90 }; 91 92 } // namespace mozilla 93 #endif