aboutsummaryrefslogtreecommitdiff
path: root/externals/oboe/apps/OboeTester/app/src/main/cpp/util
diff options
context:
space:
mode:
authorcrueter <crueter@eden-emu.dev>2025-08-04 04:50:14 +0200
committercrueter <crueter@eden-emu.dev>2025-08-04 04:50:14 +0200
commit51b170b470ed587f99a7c2a773e4464687f0d07a (patch)
tree4c03c510cfb17a5f5d6233df490d78f06dcfa7f7 /externals/oboe/apps/OboeTester/app/src/main/cpp/util
parent04e5e6453875ffa5c79cdb421a29bc19985b1049 (diff)
[cmake] refactor: Use CPM over submodules (#143)
Transfers the majority of submodules and large externals to CPM, using source archives rather than full Git clones. Not only does this save massive amounts of clone and configure time, but dependencies are grabbed on-demand rather than being required by default. Additionally, CPM will (generally) automatically search for system dependencies, though certain dependencies have options to control this. Testing shows gains ranging from 5x to 10x in terms of overall clone/configure time. Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/143 Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
Diffstat (limited to 'externals/oboe/apps/OboeTester/app/src/main/cpp/util')
-rw-r--r--externals/oboe/apps/OboeTester/app/src/main/cpp/util/WaveFileWriter.cpp140
-rw-r--r--externals/oboe/apps/OboeTester/app/src/main/cpp/util/WaveFileWriter.h187
2 files changed, 0 insertions, 327 deletions
diff --git a/externals/oboe/apps/OboeTester/app/src/main/cpp/util/WaveFileWriter.cpp b/externals/oboe/apps/OboeTester/app/src/main/cpp/util/WaveFileWriter.cpp
deleted file mode 100644
index 9e8d37d352..0000000000
--- a/externals/oboe/apps/OboeTester/app/src/main/cpp/util/WaveFileWriter.cpp
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "WaveFileWriter.h"
-
-void WaveFileWriter::WaveFileWriter::write(float value) {
- if (!mHeaderWritten) {
- writeHeader();
- }
- if (mBitsPerSample == 24) {
- writePCM24(value);
- } else {
- writePCM16(value);
- }
-}
-
-void WaveFileWriter::write(float *buffer, int32_t startSample, int32_t numSamples) {
- for (int32_t i = 0; i < numSamples; i++) {
- write(buffer[startSample + i]);
- }
-}
-
-void WaveFileWriter::writeIntLittle(int32_t n) {
- writeByte(n);
- writeByte(n >> 8);
- writeByte(n >> 16);
- writeByte(n >> 24);
-}
-
-void WaveFileWriter::writeShortLittle(int16_t n) {
- writeByte(n);
- writeByte(n >> 8);
-}
-
-void WaveFileWriter::writeFormatChunk() {
- int32_t bytesPerSample = (mBitsPerSample + 7) / 8;
-
- writeByte('f');
- writeByte('m');
- writeByte('t');
- writeByte(' ');
- writeIntLittle(16); // chunk size
- writeShortLittle(WAVE_FORMAT_PCM);
- writeShortLittle((int16_t) mSamplesPerFrame);
- writeIntLittle(mFrameRate);
- // bytes/second
- writeIntLittle(mFrameRate * mSamplesPerFrame * bytesPerSample);
- // block align
- writeShortLittle((int16_t) (mSamplesPerFrame * bytesPerSample));
- writeShortLittle((int16_t) mBitsPerSample);
-}
-
-int32_t WaveFileWriter::getDataSizeInBytes() {
- if (mFrameCount <= 0) return INT32_MAX;
- int64_t dataSize = ((int64_t)mFrameCount) * mSamplesPerFrame * mBitsPerSample / 8;
- return (int32_t)std::min(dataSize, (int64_t)INT32_MAX);
-}
-
-void WaveFileWriter::writeDataChunkHeader() {
- writeByte('d');
- writeByte('a');
- writeByte('t');
- writeByte('a');
- writeIntLittle(getDataSizeInBytes());
-}
-
-void WaveFileWriter::writeHeader() {
- writeRiffHeader();
- writeFormatChunk();
- writeDataChunkHeader();
- mHeaderWritten = true;
-}
-
-// Write lower 8 bits. Upper bits ignored.
-void WaveFileWriter::writeByte(uint8_t b) {
- mOutputStream->write(b);
- mBytesWritten += 1;
-}
-
-void WaveFileWriter::writePCM24(float value) {
- // Offset before casting so that we can avoid using floor().
- // Also round by adding 0.5 so that very small signals go to zero.
- float temp = (PCM24_MAX * value) + 0.5 - PCM24_MIN;
- int32_t sample = ((int) temp) + PCM24_MIN;
- // clip to 24-bit range
- if (sample > PCM24_MAX) {
- sample = PCM24_MAX;
- } else if (sample < PCM24_MIN) {
- sample = PCM24_MIN;
- }
- // encode as little-endian
- writeByte(sample); // little end
- writeByte(sample >> 8); // middle
- writeByte(sample >> 16); // big end
-}
-
-void WaveFileWriter::writePCM16(float value) {
- // Offset before casting so that we can avoid using floor().
- // Also round by adding 0.5 so that very small signals go to zero.
- float temp = (INT16_MAX * value) + 0.5 - INT16_MIN;
- int32_t sample = ((int) temp) + INT16_MIN;
- if (sample > INT16_MAX) {
- sample = INT16_MAX;
- } else if (sample < INT16_MIN) {
- sample = INT16_MIN;
- }
- writeByte(sample); // little end
- writeByte(sample >> 8); // big end
-}
-
-void WaveFileWriter::writeRiffHeader() {
- writeByte('R');
- writeByte('I');
- writeByte('F');
- writeByte('F');
- // Maximum size is not strictly correct but is commonly used
- // when we do not know the final size.
- const int kExtraHeaderBytes = 36;
- int32_t dataSize = getDataSizeInBytes();
- writeIntLittle((dataSize > (INT32_MAX - kExtraHeaderBytes))
- ? INT32_MAX
- : dataSize + kExtraHeaderBytes);
- writeByte('W');
- writeByte('A');
- writeByte('V');
- writeByte('E');
-}
diff --git a/externals/oboe/apps/OboeTester/app/src/main/cpp/util/WaveFileWriter.h b/externals/oboe/apps/OboeTester/app/src/main/cpp/util/WaveFileWriter.h
deleted file mode 100644
index e3cebce434..0000000000
--- a/externals/oboe/apps/OboeTester/app/src/main/cpp/util/WaveFileWriter.h
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Copyright 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// Based on the WaveFileWriter in Java from the open source JSyn library by Phil Burk
-// https://github.com/philburk/jsyn/blob/master/src/main/java/com/jsyn/util/WaveFileWriter.java
-
-#ifndef UTIL_WAVE_FILE_WRITER
-#define UTIL_WAVE_FILE_WRITER
-
-#include <cassert>
-#include <stdio.h>
-#include <algorithm>
-
-class WaveFileOutputStream {
-public:
- virtual ~WaveFileOutputStream() = default;
- virtual void write(uint8_t b) = 0;
-};
-
-/**
- * Write audio data to a WAV file.
- *
- * <pre>
- * <code>
- * WaveFileWriter writer = new WaveFileWriter(waveFileOutputStream);
- * writer.setFrameRate(48000);
- * writer.setBitsPerSample(24);
- * writer.write(floatArray, 0, numSamples);
- * writer.close();
- * </code>
- * </pre>
- *
- */
-class WaveFileWriter {
-public:
-
- /**
- * Create an object that will write a WAV file image to the specified stream.
- *
- * @param outputStream stream to receive the bytes
- * @throws FileNotFoundException
- */
- WaveFileWriter(WaveFileOutputStream *outputStream) {
- mOutputStream = outputStream;
- }
-
- /**
- * Set the number of frames per second, also known as "sample rate".
- *
- * If you call this then it must be called before the first write().
- *
- * @param frameRate default is 44100
- */
- void setFrameRate(int32_t frameRate) {
- mFrameRate = frameRate;
- }
-
- int32_t getFrameRate() const {
- return mFrameRate;
- }
-
- /**
- * Set the size of one frame.
- * For stereo, set this to 2. Default is mono = 1.
- * Also known as ChannelCount.
- *
- * If you call this then it must be called before the first write().
- *
- * @param samplesPerFrame is 2 for stereo or 1 for mono
- */
- void setSamplesPerFrame(int32_t samplesPerFrame) {
- mSamplesPerFrame = samplesPerFrame;
- }
-
- /**
- * Sets the number of frames in the file.
- *
- * If you do not know the final number of frames then that is OK.
- * Just do not call this method and the RIFF and DATA chunk sizes
- * will default to INT32_MAX. That is technically invalid WAV format
- * but is common practice.
- *
- * If you call this then it must be called before the first write().
- * @param frameCount number of frames to be written
- */
- void setFrameCount(int32_t frameCount) {
- mFrameCount = frameCount;
- }
-
- int32_t getSamplesPerFrame() const {
- return mSamplesPerFrame;
- }
-
- /** Only 16 or 24 bit samples supported at the moment. Default is 16.
- *
- * If you call this then it must be called before the first write().
- * @param bits number of bits in a PCM sample
- */
- void setBitsPerSample(int32_t bits) {
- assert((bits == 16) || (bits == 24));
- mBitsPerSample = bits;
- }
-
- int32_t getBitsPerSample() const {
- return mBitsPerSample;
- }
-
- void close() {
- }
-
- /** Write single audio data value to the WAV file. */
- void write(float value);
-
- /**
- * Write a buffer to the WAV file.
- */
- void write(float *buffer, int32_t startSample, int32_t numSamples);
-
-private:
- /**
- * Write a 32 bit integer to the stream in Little Endian format.
- */
- void writeIntLittle(int32_t n);
-
- /**
- * Write a 16 bit integer to the stream in Little Endian format.
- */
- void writeShortLittle(int16_t n);
-
- /**
- * Write an 'fmt ' chunk to the WAV file containing the given information.
- */
- void writeFormatChunk();
-
- /**
- * Write a 'data' chunk header to the WAV file. This should be followed by call to
- * writeShortLittle() to write the data to the chunk.
- */
- void writeDataChunkHeader();
-
- /**
- * Write a simple WAV header for PCM data.
- */
- void writeHeader();
-
- // Write lower 8 bits. Upper bits ignored.
- void writeByte(uint8_t b);
-
- void writePCM24(float value);
-
- void writePCM16(float value);
-
- /**
- * Write a 'RIFF' file header and a 'WAVE' ID to the WAV file.
- */
- void writeRiffHeader();
-
- int32_t getDataSizeInBytes();
-
- static constexpr int WAVE_FORMAT_PCM = 1;
- WaveFileOutputStream *mOutputStream = nullptr;
- int32_t mFrameRate = 48000;
- int32_t mSamplesPerFrame = 1;
- int32_t mFrameCount = 0; // 0 for unknown
- int32_t mBitsPerSample = 16;
- int32_t mBytesWritten = 0;
- bool mHeaderWritten = false;
- static constexpr int32_t PCM24_MIN = -(1 << 23);
- static constexpr int32_t PCM24_MAX = (1 << 23) - 1;
-
-};
-
-#endif /* UTIL_WAVE_FILE_WRITER */
-