Housekeeping of current used libraries.

Enabled compressor of dexed instances by default.
dev
Holger Wirtz 2 years ago
parent de2a893fb7
commit dcc4304c70
  1. 4
      MicroDexed.ino
  2. 2
      third-party/Synth_Dexed/src/PluginFx.cpp
  3. 6
      third-party/Synth_Dexed/src/dexed.cpp
  4. 4
      third-party/Synth_Dexed/src/dexed.h
  5. 2
      third-party/TeensyVariablePlayback/CMakeLists.txt
  6. 13
      third-party/TeensyVariablePlayback/README.md
  7. 2
      third-party/TeensyVariablePlayback/examples/CMakeLists.txt
  8. 3
      third-party/TeensyVariablePlayback/examples/sd_play_all/sd_play_all.ino
  9. 11
      third-party/TeensyVariablePlayback/library.json
  10. 2
      third-party/TeensyVariablePlayback/library.properties
  11. 17
      third-party/TeensyVariablePlayback/src/CMakeLists.txt
  12. 44
      third-party/TeensyVariablePlayback/src/IndexableFile.h
  13. 4
      third-party/TeensyVariablePlayback/src/ResamplingArrayReader.cpp
  14. 117
      third-party/TeensyVariablePlayback/src/ResamplingArrayReader.h
  15. 16
      third-party/TeensyVariablePlayback/src/ResamplingSdReader.cpp
  16. 147
      third-party/TeensyVariablePlayback/src/ResamplingSdReader.h
  17. 5
      third-party/TeensyVariablePlayback/src/TeensyVariablePlayback.h
  18. 52
      third-party/TeensyVariablePlayback/src/playarrayresmp.h
  19. 139
      third-party/TeensyVariablePlayback/src/playresmp.h
  20. 44
      third-party/TeensyVariablePlayback/src/playsdresmp.h
  21. 110
      third-party/TeensyVariablePlayback/src/waveheaderparser.h
  22. 1
      third-party/TeensyVariablePlayback/test/CMakeLists.txt
  23. 41
      third-party/TeensyVariablePlayback/test/audio/array/test_array_mono_loop_forward_playback.cpp
  24. 42
      third-party/TeensyVariablePlayback/test/audio/array/test_array_stereo_loop_forward_playback.cpp
  25. 20
      third-party/TeensyVariablePlayback/test/audio/output_test.h
  26. 50
      third-party/TeensyVariablePlayback/test/audio/wav/test_wav_mono_loop_forward_playback.cpp
  27. 42
      third-party/TeensyVariablePlayback/test/audio/wav/test_wav_stereo_loop_forward_playback.cpp
  28. 4
      third-party/TeensyVariablePlayback/test/low_level/array/ResamplingArrayFixture.h
  29. 4
      third-party/TeensyVariablePlayback/test/low_level/arraywav/ResamplingArrayWavFixture.h
  30. 4
      third-party/TeensyVariablePlayback/test/low_level/indexedfile/test_indexablefile.cpp
  31. 4
      third-party/TeensyVariablePlayback/test/low_level/sd/ResamplingReaderFixture.h
  32. 2
      third-party/TeensyVariablePlayback/test/low_level/sd/test_raw_mono_noloop_forward_double_rate_playback.cpp
  33. 2
      third-party/TeensyVariablePlayback/test/low_level/sd/test_raw_mono_noloop_forward_playback.cpp
  34. 5
      third-party/TeensyVariablePlayback/test/low_level/wav_header/test_parse_wave_header.cpp

@ -533,7 +533,7 @@ void setup() {
Serial.println(instance_id, DEC);
#endif
create_audio_dexed_chain(instance_id);
MicroDexed[instance_id]->setCompressor(true); // just a test for enabling the compressor with default values
MicroDexed[instance_id]->setCompressor(true);
}
#ifdef DEBUG
for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) {
@ -2343,7 +2343,7 @@ uint8_t drum_get_slot(uint8_t dt) {
drum_type[i] = DRUM_NONE;
Drum[i]->enableInterpolation(false);
Drum[i]->setPlaybackRate(1.0);
drum_counter=i+1;
drum_counter = i + 1;
return (i);
}
}

@ -48,11 +48,9 @@ inline static float tptlpupw(float & state , float inp , float cutoff , float sr
// return (param) * (max - min) + min;
//}
#ifdef USE_FX
static float logsc(float param, const float min, const float max, const float rolloff = 19.0f) {
return ((EXP_FUNC(param * LOG_FUNC(rolloff + 1)) - 1.0f) / (rolloff)) * (max - min) + min;
}
#endif
PluginFx::PluginFx() {
Cutoff = 1.0;

@ -74,10 +74,8 @@ Dexed::Dexed(uint8_t maxnotes, int rate)
xrun = 0;
render_time_max = 0;
#ifdef USE_DEXED_COMPRESSOR
compressor = new Compressor(samplerate);
use_compressor = false;
#endif
}
Dexed::~Dexed()
@ -190,10 +188,8 @@ void Dexed::getSamples(float32_t* buffer, uint16_t n_samples)
fx.process(buffer, n_samples); // Needed for fx.Gain()!!!
#if defined USE_DEXED_COMPRESSOR
if (use_compressor == true)
compressor->doCompression(buffer, n_samples);
#endif
}
void Dexed::getSamples(int16_t* buffer, uint16_t n_samples)
@ -1665,7 +1661,6 @@ void Dexed::getName(char* buffer)
buffer[10] = '\0';
}
#ifdef USE_DEXED_COMPRESSOR
void Dexed::setCompressor(bool enable_compressor)
{
use_compressor = enable_compressor;
@ -1725,4 +1720,3 @@ float32_t Dexed::getCompressionRatio(void)
{
return (compressor->getCompressionRatio());
}
#endif

@ -175,7 +175,6 @@ class Dexed
uint16_t getRenderTimeMax(void);
void resetRenderTimeMax(void);
void ControllersRefresh(void);
#ifdef USE_DEXED_COMPRESSOR
void setCompressor(bool comp);
bool getCompressor(void);
void setCompressorPreGain_dB(float32_t pre_gain);
@ -188,7 +187,6 @@ class Dexed
float32_t getCompressorRelease_sec(void);
float32_t getCompressorThresh_dBFS(void);
float32_t getCompressionRatio(void);
#endif
int16_t checkSystemExclusive(const uint8_t* sysex, const uint16_t len);
// Sound methods
@ -353,10 +351,8 @@ class Dexed
void getSamples(float32_t* buffer, uint16_t n_samples);
void getSamples(int16_t* buffer, uint16_t n_samples);
void compress(float32_t* wav_in, float32_t* wav_out, uint16_t n, float32_t threshold, float32_t slope, uint16_t sr, float32_t tla, float32_t twnd, float32_t tatt, float32_t trel);
#ifdef USE_DEXED_COMPRESSOR
bool use_compressor;
Compressor* compressor;
#endif
};
#endif

@ -15,13 +15,11 @@ if (NOT DEFINED BUILD_FOR_LINUX)
import_arduino_library(Wire ${DEPSPATH}/Wire utility)
import_arduino_library(arm_math ${DEPSPATH}/arm_math/src)
import_arduino_library(Audio ${DEPSPATH}/Audio utility)
import_arduino_library(LittleFS ${DEPSPATH}/LittleFS/src littlefs)
add_subdirectory(src)
add_subdirectory(examples)
else()
add_subdirectory(src)
add_subdirectory(test)
#add_subdirectory(extras/soundio/playqueue)
add_subdirectory(extras/soundio/save_raw)
add_subdirectory(extras/soundio/save_raw_sd)
add_subdirectory(extras/soundio/save_wav)

@ -9,20 +9,12 @@
[![Commits](https://img.shields.io/github/commit-activity/m/newdigate/teensy-variable-playback)](https://github.com/newdigate/teensy-variable-playback/graphs/contributors)
![s](https://img.shields.io/badge/dynamic/json?color=%23e85b46&label=Patreon&query=data.attributes.patron_count&suffix=%20patrons&url=https%3A%2F%2Fwww.patreon.com%2Fapi%2Fcampaigns%2F4105381)
play 16-bit PCM raw or wav audio samples at variable playback rates on teensy
* **Note** : this library only works with signed 16-bit integer samples. Floating point samples will not play.
play 16-bit audio samples at variable playback rates on teensy
* for best performance, use SDXC UHS 30MB/sec Application Performance Class 2 (A2) class micro sd-card.
* [sd classes on wikipedia](https://en.wikipedia.org/wiki/SD_card#cite_ref-93)
## updates
* 16/06/2022: v1.0.14:
* refactored code to generic classes
* improve memory leaks
* remove calls to StartUsingSPI(), StopUsingSPI(), __disable_irq(), __enable_irq()
* intergated with SerialFlash and LittleFS
* 25/09/2021: v1.0.13: positionMillis() implemented for AudioPlaySdResmp
* 25/08/2021: v1.0.12: Skip over RIFF tags in .wav header
* 12/08/2021: v1.0.11: When playing a mono sample, transmit on both channels (credit to @atoktoto)
* 28/07/2021: v1.0.10: Fix issues when starting playback in reverse
* 23/07/2021: v1.0.9: Fix issue which crashes teensy when playing multiple files from SD card using array of filenames
@ -108,11 +100,10 @@ graph G {
<details>
<summary>linux</summary>
You can run and test this code on your linux computer. You can write a teensy sketch, and with a few modifications, you can redirect the audio input and output to and from your soundcard. [Soundio](https://github.com/newdigate/teensy-audio-x86-stubs/tree/main/extras/soundio) bindings are optional, you can also run sketches and tests with no audio input or output.
You will need to install the following libraries.
```cmake``` ```gcc or llvm``` ```teensy-x86-stubs```[^](https://github.com/newdigate/teensy-x86-stubs) ```teensy-audio-x86-stubs```[^](https://github.com/newdigate/teensy-audio-x86-stubs) ```teensy-x86-sd-stubs```[^](https://github.com/newdigate/teensy-x86-sd-stubs) ```boost-test```
By using stub libraries, we can compile teensy code to native device architecture. To a certain extent, this allows sketches and libraries to be developed, emulated, debugged and unit-tested using linux, on your local device or a build server. In this case I have a few basic tests for the ResamplingSdReader class.
* install boost unit-test library:
* linux: ```sudo apt-get install -yq libboost-test-dev```
* macos: ```brew install boost```

@ -1,8 +1,6 @@
cmake_minimum_required(VERSION 3.5)
add_subdirectory(array)
add_subdirectory(LittleFS)
add_subdirectory(sampleloader)
add_subdirectory(sd_play_all)
add_subdirectory(sd_raw)
add_subdirectory(sd_wav)
add_subdirectory(SerialFlash)

@ -133,7 +133,6 @@ void populateFilenames(char *directory, char **filenames) {
if ((m > 0 || a > 0) && (underscore != 0)) {
filenames[index] = new char[curfile.length()+1] {0};
memcpy(filenames[index], curfile.c_str(), curfile.length());
index++;
}
files.close();
}
@ -144,4 +143,4 @@ void populateFilenames(char *directory, char **filenames) {
namespace std {
void __throw_bad_function_call() {}
void __throw_length_error(char const*) {}
}
}

@ -5,7 +5,7 @@
"keywords": "sound, audio, sample, resample, pitch, interpolation, legrange, sampler, playback, speed",
"description": "Teensy Variable Playback",
"url": "https://github.com/newdigate/teensy-variable-playback",
"version": "1.0.14",
"version": "1.0.11",
"export": {
"exclude": [
".vscode",
@ -26,10 +26,11 @@
"type": "git",
"url": "https://github.com/newdigate/teensy-variable-playback"
},
"dependencies":[{
"name": "Audio",
"frameworks": "arduino"
}],
"dependencies":
{
"name": "Audio",
"frameworks": "arduino"
},
"examples": [
"examples/*/*.ino",
"examples/*/*/*.ino"

@ -1,5 +1,5 @@
name=TeensyVariablePlayback
version=1.0.14
version=1.0.11
author=Nic Newdigate
maintainer=Nic Newdigate
sentence=Play samples at variable pitch using Teensy Audio Library

@ -3,8 +3,12 @@ project(teensy_variable_playback C CXX)
set(teensy_variable_playback_VERSION 1.0.0)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES
playsdresmp.cpp
ResamplingSdReader.cpp
ResamplingArrayReader.cpp
playarrayresmp.cpp
interpolation.cpp
)
IndexableFile.cpp)
set(HEADER_FILES
loop_type.h
@ -13,19 +17,10 @@ set(HEADER_FILES
ResamplingSdReader.h
waveheaderparser.h
ResamplingArrayReader.h
ResamplingReader.h
playarrayresmp.h
interpolation.h
TeensyVariablePlayback.h
IndexableFile.h
IndexableSerialFlashFile.h
IndexableLittleFSFile.h
IndexableSDFile.h
ResamplingLfsReader.h
ResamplingSerialFlashReader.h
playlfsresmp.h
playserialflashresmp.h
)
IndexableFile.h)
#set(CMAKE_VERBOSE_MAKEFILE 1)
if (NOT DEFINED TEENSY_VERSION)

@ -18,24 +18,19 @@ constexpr bool isPowerOf2(size_t value){
return !(value == 0) && !(value & (value - 1));
}
template<size_t BUFFER_SIZE, size_t MAX_NUM_BUFFERS, class TFile> // BUFFER_SIZE needs to be a power of two
template<size_t BUFFER_SIZE, size_t MAX_NUM_BUFFERS> // BUFFER_SIZE needs to be a power of two
class IndexableFile {
public:
static_assert(isPowerOf2(BUFFER_SIZE), "BUFFER_SIZE must be a power of 2");
virtual TFile open(const char *filename) = 0;
static constexpr size_t element_size = sizeof(int16_t);
size_t buffer_to_index_shift;
IndexableFile(const char *filename) :
IndexableFile(File file) :
_buffers(),
buffer_to_index_shift(log2(BUFFER_SIZE))
{
_filename = new char[strlen(filename)+1] {0};
memcpy(_filename, filename, strlen(filename));
buffer_to_index_shift(log2(BUFFER_SIZE)) {
_file = file;
}
virtual ~IndexableFile() {
~IndexableFile() {
close();
}
@ -54,14 +49,12 @@ public:
next->buffer = new int16_t[BUFFER_SIZE];
size_t basePos = indexFor_i << buffer_to_index_shift;
size_t seekPos = basePos * element_size;
__disable_irq();
_file.seek(seekPos);
int16_t bytesRead = _file.read(next->buffer, BUFFER_SIZE * element_size);
#ifndef TEENSYDUINO
if (!_file.available()){
_file.close();
_file = open(_filename);
}
#endif
__enable_irq();
next->buffer_size = bytesRead;
_buffers.push_back(next);
match = next;
@ -70,25 +63,20 @@ public:
}
void close() {
if (_file.available()) {
if (_file.available()) {
__disable_irq();
_file.close();
__enable_irq();
}
for (auto && x : _buffers){
for (auto && x : _buffers){
delete [] x->buffer;
delete x;
}
_buffers.clear();
if (_filename != nullptr) {
delete [] _filename;
_filename = nullptr;
}
}
protected:
TFile _file;
char *_filename;
private:
File _file;
std::vector<indexedbuffer*> _buffers;
indexedbuffer* find_with_index(uint32_t i) {
@ -103,6 +91,4 @@ protected:
}
#endif

@ -264,14 +264,14 @@ bool ResamplingArrayReader::playWav(int16_t *array, uint32_t length)
WaveHeaderParser wavHeaderParser;
wavHeaderParser.readWaveHeaderFromBuffer((const char *) array, wav_header);
if (wav_header.bit_depth != 16) {
// Serial.printf("Needs 16 bit audio! Aborting.... (got %d)", wav_header.bit_depth);
Serial.printf("Needs 16 bit audio! Aborting.... (got %d)", wav_header.bit_depth);
return false;
}
setNumChannels(wav_header.num_channels);
_header_offset = 22;
_file_size = wav_header.data_bytes + 44; //2 bytes per sample
if (_file_size > length * 2){
// Serial.printf("TeensyVariablePlayback: warning: length of array in bytes (%d) is smaller than the file data size in bytes (%d) according to the header - defaulting length to filesize...", length * 2, _file_size);
Serial.printf("TeensyVariablePlayback: warning: length of array in bytes (%d) is smaller than the file data size in bytes (%d) according to the header - defaulting length to filesize...", length * 2, _file_size);
_loop_finish = length;
} else
_loop_finish = _file_size / 2;

@ -6,44 +6,115 @@
#include <cstdint>
#include "loop_type.h"
#include "interpolation.h"
#include "ResamplingReader.h"
namespace newdigate {
class ResamplingArrayReader : public ResamplingReader<int16_t, File> {
class ResamplingArrayReader {
public:
ResamplingArrayReader() :
ResamplingReader() {
}
virtual ~ResamplingArrayReader() {
ResamplingArrayReader() {
}
void begin(void);
bool playRaw(int16_t *array, uint32_t length, uint16_t numChannels);
bool playWav(int16_t *array, uint32_t length);
bool play();
void stop(void);
bool isPlaying(void) { return _playing; }
unsigned int read(void **buf, uint16_t nbyte);
bool readNextValue(int16_t *value, uint16_t channelNumber);
void setPlaybackRate(double f) {
_playbackRate = f;
if (f < 0.0 && _bufferPosition == 0) {
//_file.seek(_file_size);
_bufferPosition = _file_size/2 - _numChannels;
}
}
float playbackRate() {
return _playbackRate;
}
void loop(uint32_t numSamples) {
__disable_irq();
_loop_start = _bufferPosition;
_loop_finish = _bufferPosition + numSamples * _numChannels;
_loopType = loop_type::looptype_repeat;
__enable_irq();
}
void setLoopType(loop_type loopType)
{
_loopType = loopType;
}
loop_type getLoopType(){
return _loopType;
}
int available(void);
void reset(void);
void close(void);
void setLoopStart(uint32_t loop_start) {
_loop_start = _header_offset + (loop_start * _numChannels);
}
int16_t getSourceBufferValue(long index) override {
return _sourceBuffer[index];
void setLoopFinish(uint32_t loop_finish) {
// sample number, (NOT byte number)
_loop_finish = _header_offset + (loop_finish * _numChannels);
}
int available(void) {
return _playing;
void setInterpolationType(ResampleInterpolationType interpolationType) {
if (interpolationType != _interpolationType) {
_interpolationType = interpolationType;
initializeInterpolationPoints();
}
}
int16_t* createSourceBuffer() override {
return _sourceBuffer;
int16_t getNumChannels() {
return _numChannels;
}
void close(void) override {
if (_playing) {
stop();
deleteInterpolationPoints();
void setNumChannels(uint16_t numChannels) {
if (numChannels != _numChannels) {
_numChannels = numChannels;
initializeInterpolationPoints();
}
}
File open(char *filename) override {
return File();
void setHeaderSizeInBytes(uint32_t headerSizeInBytes) {
_header_offset = headerSizeInBytes / 2;
if (_bufferPosition < _header_offset) {
if (_playbackRate >= 0) {
_bufferPosition = _header_offset;
} else
_bufferPosition = _loop_finish - _numChannels;
}
}
protected:
private:
volatile bool _playing = false;
int32_t _file_size;
int32_t _header_offset = 0; // == (header size in bytes ) / 2
double _playbackRate = 1.0;
double _remainder = 0.0;
loop_type _loopType = looptype_none;
int _bufferPosition = 0;
int32_t _loop_start = 0;
int32_t _loop_finish = 0;
int16_t _numChannels = -1;
uint16_t _numInterpolationPointsChannels = 0;
int16_t *_sourceBuffer = nullptr;
ResampleInterpolationType _interpolationType = ResampleInterpolationType::resampleinterpolation_none;
unsigned int _numInterpolationPoints = 0;
InterpolationData **_interpolationPoints = nullptr;
void initializeInterpolationPoints(void);
void deleteInterpolationPoints(void);
};
}
#endif //TEENSYAUDIOLIBRARY_RESAMPLINGARRAYREADER_H

@ -262,8 +262,8 @@ bool ResamplingSdReader::play(const char *filename, bool isWave, uint16_t numCha
if (!file) {
// StopUsingSPI();
// Serial.print(F("Not able to open file: "));
// Serial.println(filename);
Serial.print(F("Not able to open file: "));
Serial.println(filename);
return false;
}
@ -276,9 +276,9 @@ bool ResamplingSdReader::play(const char *filename, bool isWave, uint16_t numCha
wavHeaderParser.readWaveHeader(wav_header, file);
if (wav_header.bit_depth != 16) {
// Serial.print(F("Needs 16 bit audio! Aborting.... (got "));
// Serial.print(wav_header.bit_depth);
// Serial.println(F(")"));
Serial.print(F("Needs 16 bit audio! Aborting.... (got "));
Serial.print(wav_header.bit_depth);
Serial.println(F(")"));
__disable_irq();
file.close();
__enable_irq();
@ -290,8 +290,8 @@ bool ResamplingSdReader::play(const char *filename, bool isWave, uint16_t numCha
if (_file_size <= _header_offset * newdigate::IndexableFile<128, 2>::element_size) {
_playing = false;
// Serial.print(F("Wave file contains no samples: "));
// Serial.println(filename);
Serial.print(F("Wave file contains no samples: "));
Serial.println(filename);
// StopUsingSPI();
__disable_irq();
file.close();
@ -339,7 +339,7 @@ int ResamplingSdReader::available(void) {
void ResamplingSdReader::close(void) {
// Serial.printf("sdreader close\n");
Serial.printf("sdreader close\n");
if (_playing)
stop();

@ -10,72 +10,143 @@
#include "spi_interrupt.h"
#include "loop_type.h"
#include "interpolation.h"
#include "IndexableSDFile.h"
#include "ResamplingReader.h"
#include "IndexableFile.h"
#define RESAMPLE_BUFFER_SAMPLE_SIZE 128
#define B2M (uint32_t)((double)4294967296000.0 / AUDIO_SAMPLE_RATE_EXACT / 2.0) // 97352592
namespace newdigate {
class ResamplingSdReader : public ResamplingReader< IndexableSDFile<128, 2>, File > {
class ResamplingSdReader {
public:
ResamplingSdReader() :
ResamplingReader()
{
ResamplingSdReader() {
}
virtual ~ResamplingSdReader() {
void begin(void);
bool playRaw(const char *filename, uint16_t numChannels);
bool playWav(const char *filename);
bool play();
void stop(void);
bool isPlaying(void) { return _playing; }
unsigned int read(int16_t **buf);
bool readNextValue(int16_t *value, uint16_t channelNumber);
void setPlaybackRate(double f) {
_playbackRate = f;
if (f < 0.0 && _bufferPosition == 0) {
//_file.seek(_file_size);
_bufferPosition = _file_size / 2 - _numChannels;
}
}
int16_t getSourceBufferValue(long index) override {
return (*_sourceBuffer)[index];
double playbackRate() {
return _playbackRate;
}
int available(void)
void setLoopType(loop_type loopType)
{
return _playing;
_loopType = loopType;
}
File open(char *filename) override {
return SD.open(filename);
loop_type getLoopType(){
return _loopType;
}
void close(void) override
{
if (_playing)
stop();
if (_sourceBuffer != nullptr) {
_sourceBuffer->close();
delete _sourceBuffer;
_sourceBuffer = nullptr;
int available(void);
void reset(void);
void close(void);
void setLoopStart(uint32_t loop_start) {
_loop_start = _header_offset + (loop_start * _numChannels);
}
void setLoopFinish(uint32_t loop_finish) {
// sample number, (NOT byte number)
_loop_finish = _header_offset + (loop_finish * _numChannels);
}
void setInterpolationType(ResampleInterpolationType interpolationType) {
if (interpolationType != _interpolationType) {
_interpolationType = interpolationType;
initializeInterpolationPoints();
}
if (_filename != nullptr) {
delete [] _filename;
_filename = nullptr;
}
int16_t getNumChannels() {
return _numChannels;
}
void setNumChannels(uint16_t numChannels) {
if (numChannels != _numChannels) {
_numChannels = numChannels;
initializeInterpolationPoints();
}
deleteInterpolationPoints();
}
IndexableSDFile<128, 2>* createSourceBuffer() override {
return new IndexableSDFile<128, 2>(_filename);
void setHeaderSize(uint32_t headerSizeInBytes) {
_header_offset = headerSizeInBytes / 2;
if (_bufferPosition < _header_offset) {
if (_playbackRate >= 0) {
_bufferPosition = _header_offset;
}
}
}
uint32_t positionMillis(void) {
if (_file_size == 0) return 0;
return (uint32_t) (( (double)_bufferPosition * lengthMillis() ) / (double)(_file_size/2));
return ((uint64_t) _file_size * B2M) >> 32;
}
uint32_t lengthMillis(void) {
return ((uint64_t)_file_size * B2M) >> 32;
return ((uint64_t) _file_size * B2M) >> 32;
}
protected:
private:
volatile bool _playing = false;
uint32_t _file_size;
uint32_t _header_offset = 0; // == (header size in bytes ) / 2
double _playbackRate = 1.0;
double _remainder = 0.0;
loop_type _loopType = looptype_none;
unsigned int _bufferPosition = 0;
uint32_t _loop_start = 0;
uint32_t _loop_finish = 0;
int16_t _numChannels = -1;
uint16_t _numInterpolationPointsChannels = 0;
newdigate::IndexableFile<128, 2> *_sourceBuffer = nullptr;
ResampleInterpolationType _interpolationType = ResampleInterpolationType::resampleinterpolation_none;
unsigned int _numInterpolationPoints = 0;
InterpolationData **_interpolationPoints = nullptr;
static bool isUsingSPI;
void StartUsingSPI(){
if (!isUsingSPI) {
isUsingSPI = true;
#if defined(HAS_KINETIS_SDHC)
if (!(SIM_SCGC3 & SIM_SCGC3_SDHC)) AudioStartUsingSPI();
#else
AudioStartUsingSPI();
#endif
}
}
void StopUsingSPI() {
if (isUsingSPI) {
isUsingSPI = false;
#if defined(HAS_KINETIS_SDHC)
if (!(SIM_SCGC3 & SIM_SCGC3_SDHC)) AudioStopUsingSPI();
#else
AudioStopUsingSPI();
#endif
}
}
bool play(const char *filename, bool isWave, uint16_t numChannelsIfRaw = 0);
void initializeInterpolationPoints(void);
void deleteInterpolationPoints(void);
};
}
#endif //TEENSYAUDIOLIBRARY_RESAMPLINGSDREADER_H

@ -8,10 +8,7 @@
#include "waveheaderparser.h"
#include "ResamplingSdReader.h"
#include "ResamplingArrayReader.h"
#include "ResamplingLfsReader.h"
#include "ResamplingSerialFlashReader.h"
#include "playsdresmp.h"
#include "playarrayresmp.h"
#include "playlfsresmp.h"
#include "playserialflashresmp.h"
#endif //TEENSY_RESAMPLING_ARDUINO_SAMPLER_H

@ -11,19 +11,61 @@
#include "ResamplingArrayReader.h"
#include "playresmp.h"
class AudioPlayArrayResmp : public AudioPlayResmp<newdigate::ResamplingArrayReader>
class AudioPlayArrayResmp : public AudioPlayResmp
{
public:
AudioPlayArrayResmp(void) :
AudioPlayResmp<newdigate::ResamplingArrayReader>()
AudioPlayResmp(),
arrayReader()
{
reader = new newdigate::ResamplingArrayReader();
begin();
}
virtual ~AudioPlayArrayResmp() {
delete reader;
void begin(void);
bool playRaw(int16_t *data, uint32_t numSamples, uint16_t numChannels);
bool playRaw(const unsigned int *data, uint32_t numSamples, uint16_t numChannels);
bool playWav(int16_t *data, uint32_t fileSize);
bool playWav(const unsigned int *data, uint32_t fileSize);
void stop(void);
void close(void);
bool isPlaying(void) { return arrayReader.isPlaying(); }
uint32_t positionMillis(void);
uint32_t lengthMillis(void);
virtual void update(void);
void setPlaybackRate(float f) {
arrayReader.setPlaybackRate(f);
}
void setLoopType(loop_type t) {
arrayReader.setLoopType(t);
}
void startLoop(uint32_t samples) {
arrayReader.loop(samples);
}
void setLoopStart(uint32_t loop_start) {
arrayReader.setLoopStart(loop_start);
}
void setLoopFinish(uint32_t loop_finish) {
arrayReader.setLoopFinish(loop_finish);
}
void enableInterpolation(bool enable) {
if (enable)
arrayReader.setInterpolationType(ResampleInterpolationType::resampleinterpolation_quadratic);
else
arrayReader.setInterpolationType(ResampleInterpolationType::resampleinterpolation_none);
}
private:
uint32_t file_size;
ResamplingArrayReader arrayReader;
};

@ -5,135 +5,20 @@
#include "Audio.h"
#include "loop_type.h"
template <class TResamplingReader>
class AudioPlayResmp : public AudioStream
{
public:
AudioPlayResmp(): AudioStream(0, NULL), reader(nullptr)
{
}
virtual ~AudioPlayResmp() {
}
void begin(void)
{
reader->begin();
}
bool playRaw(const char *filename, uint16_t numChannels)
{
stop();
return reader->play(filename, false, numChannels);
}
bool playWav(const char *filename)
{
stop();
return reader->play(filename, true, 0);
}
bool playRaw(int16_t *data, uint32_t numSamples, uint16_t numChannels)
{
stop();
return reader->playRaw(data, numSamples, numChannels);
}
bool playRaw(const unsigned int *data, uint32_t numSamples, uint16_t numChannels)
{
return playRaw((int16_t *) data, numSamples, numChannels);
}
bool playWav(int16_t *data, uint32_t fileSize)
{
stop();
return reader->playWav(data, fileSize);
}
bool playWav(const unsigned int *data, uint32_t fileSize) {
return playWav((int16_t *) data, fileSize);
}
void setPlaybackRate(float f) {
reader->setPlaybackRate(f);
}
void setLoopType(loop_type t) {
reader->setLoopType(t);
}
void setLoopStart(uint32_t loop_start) {
reader->setLoopStart(loop_start);
}
void setLoopFinish(uint32_t loop_finish) {
reader->setLoopFinish(loop_finish);
}
void enableInterpolation(bool enable) {
if (enable)
reader->setInterpolationType(ResampleInterpolationType::resampleinterpolation_quadratic);
else
reader->setInterpolationType(ResampleInterpolationType::resampleinterpolation_none);
}
bool isPlaying(void) {
return reader->isPlaying();
};
void stop() {
reader->stop();
}
void update()
{
int _numChannels = reader->getNumChannels();
if (_numChannels == -1)
return;
unsigned int n;
audio_block_t *blocks[_numChannels];
int16_t *data[_numChannels];
// only update if we're playing
if (!reader->isPlaying()) return;
// allocate the audio blocks to transmit
for (int i=0; i < _numChannels; i++) {
blocks[i] = allocate();
if (blocks[i] == nullptr) return;
data[i] = blocks[i]->data;
}
if (reader->available()) {
// we can read more data from the file...
n = reader->read((void**)data, AUDIO_BLOCK_SAMPLES);
for (int channel=0; channel < _numChannels; channel++) {
memset( &blocks[channel]->data[n], 0, (AUDIO_BLOCK_SAMPLES - n) * 2);
transmit(blocks[channel], channel);
}
if(_numChannels == 1) {
transmit(blocks[0], 1);
}
} else {
reader->close();
}
for (int channel=0; channel < _numChannels; channel++) {
release(blocks[channel]);
}
}
uint32_t positionMillis()
{
return reader->positionMillis();
}
uint32_t lengthMillis()
{
return reader->lengthMillis();
}
protected:
TResamplingReader *reader;
AudioPlayResmp(void): AudioStream(0, NULL) {}
virtual ~AudioPlayResmp() {}
virtual void setPlaybackRate(float f) = 0;
virtual void setLoopType(loop_type t) = 0;
virtual void setLoopStart(uint32_t loop_start) = 0;
virtual void setLoopFinish(uint32_t loop_finish) = 0;
virtual void begin() = 0;
virtual void enableInterpolation(bool enable) = 0;
virtual bool isPlaying(void) = 0;
virtual void stop() = 0;
};
#endif // TEENSY_RESAMPLING_SDREADER_PLAYRESMP_H
#endif // TEENSY_RESAMPLING_SDREADER_PLAYRESMP_H

@ -8,24 +8,56 @@
#include "Arduino.h"
#include "AudioStream.h"
#include "SD.h"
#include "stdint.h"
#include "ResamplingSdReader.h"
#include "playresmp.h"
class AudioPlaySdResmp : public AudioPlayResmp<newdigate::ResamplingSdReader>
class AudioPlaySdResmp : public AudioPlayResmp
{
public:
AudioPlaySdResmp(void) :
AudioPlayResmp<newdigate::ResamplingSdReader>()
AudioPlayResmp(),
sdReader()
{
reader = new newdigate::ResamplingSdReader();
begin();
}
virtual ~AudioPlaySdResmp() {
delete reader;
void begin(void);
bool playRaw(const char *filename, uint16_t numChannels);
bool playWav(const char *filename);
void stop(void);
bool isPlaying(void) { return sdReader.isPlaying(); }
uint32_t positionMillis(void);
uint32_t lengthMillis(void);
virtual void update(void);
void setPlaybackRate(float f) {
sdReader.setPlaybackRate(f);
}
void setLoopType(loop_type t) {
sdReader.setLoopType(t);
}
void setLoopStart(uint32_t loop_start) {
sdReader.setLoopStart(loop_start);
}
void setLoopFinish(uint32_t loop_finish) {
sdReader.setLoopFinish(loop_finish);
}
void enableInterpolation(bool enable) {
if (enable)
sdReader.setInterpolationType(ResampleInterpolationType::resampleinterpolation_quadratic);
else
sdReader.setInterpolationType(ResampleInterpolationType::resampleinterpolation_none);
}
private:
uint32_t file_size;
ResamplingSdReader sdReader;
};

@ -14,70 +14,47 @@ using namespace std;
// from https://gist.github.com/Jon-Schneider/8b7c53d27a7a13346a643dac9c19d34f
struct wav_header {
// RIFF Header
char riff_header[4] = {0,0,0,0}; // 00 - 03 - Contains "RIFF"
int header_chunk_size = 0; // 04 - 07 - Size of the wav portion of the file, which follows the first 8 bytes. File size - 8
char wave_header[4] = {0,0,0,0}; // 08 - 11 - Contains "WAVE"
char riff_header[4]; // 00 - 03 - Contains "RIFF"
int header_chunk_size; // 04 - 07 - Size of the wav portion of the file, which follows the first 8 bytes. File size - 8
char wave_header[4]; // 08 - 11 - Contains "WAVE"
// Format Header
char fmt_header[4] = {0,0,0,0}; // 12 - 15 - Contains "fmt " (includes trailing space)
int fmt_chunk_size = 0; // 16 - 19 - Should be 16 for PCM
short audio_format = 0; // 20 - 21 - Should be 1 for PCM. 3 for IEEE Float
short num_channels = 0; // 22 - 23
int sample_rate = 0; // 24 - 27
int byte_rate = 0; // 28 - 31
short sample_alignment = 0; // 32 - 33
short bit_depth = 0; // 34 - 35
};
char fmt_header[4]; // 12 - 15 - Contains "fmt " (includes trailing space)
int fmt_chunk_size; // 16 - 19 - Should be 16 for PCM
short audio_format; // 20 - 21 - Should be 1 for PCM. 3 for IEEE Float
short num_channels; // 22 - 23
int sample_rate; // 24 - 27
int byte_rate; // 28 - 31
short sample_alignment; // 32 - 33
short bit_depth; // 34 - 35
struct wav_data_header {
// Data
char data_header[4] = {0,0,0,0}; // 36 - 39
unsigned int data_bytes = 0;// 40 - 43
char data_header[4]; // 36 - 39
unsigned int data_bytes;// 40 - 43
};
class WaveHeaderParser {
public:
bool readWaveHeader(const char *filename, wav_header &header, wav_data_header &wav_data_header) {
bool readWaveHeader(const char *filename, wav_header &header, wav_header &wav_header) {
__disable_irq();
File wavFile = SD.open(filename);
__enable_irq();
if (!wavFile) {
Serial.printf("Not able to open wave file... %s\n", filename);
return false;
}
bool result = readWaveHeader(filename, header, wavFile);
if (result) {
wavFile.seek(36);
unsigned char buffer[8];
size_t bytesRead = wavFile.read(buffer, 8);
if (bytesRead != 8) {
Serial.printf("Not able to read header... %s\n", filename);
result = false;
}
if (result) {
unsigned infoTagsSize;
result = readInfoTags(buffer, 0, infoTagsSize);
if (result) {
wavFile.seek(36 + infoTagsSize);
bytesRead = wavFile.read(buffer, 8);
if (bytesRead != 8) {
Serial.printf("Not able to read header... %s\n", filename);
return false;
}
result = readDataHeader(buffer, 0, wav_data_header);
}
}
}
bool result = readWaveHeader(header, wavFile);
wavFile.close();
return result;
}
bool readWaveHeader(const char *filename, wav_header &header, File &wavFile) {
char buffer[36];
int bytesRead = wavFile.read(buffer, 36);
if (bytesRead != 36) {
Serial.printf("expected 36 bytes (was %d)\n", bytesRead);
bool readWaveHeader(wav_header &header, File wavFile) {
char buffer[44];
__disable_irq();
int bytesRead = wavFile.read(buffer, 44);
__enable_irq();
if (bytesRead != 44) {
Serial.printf("expected 44 bytes (was %d)\n", bytesRead);
return false;
}
return readWaveHeaderFromBuffer(buffer, header);
@ -135,45 +112,18 @@ public:
auto bit_depth = static_cast<unsigned long>(b[35] << 8 | b[34]);
header.bit_depth = bit_depth;
return true;
}
bool readInfoTags(unsigned char *buffer, size_t offset, unsigned &infoTagsSize) {
if ( buffer[offset+0] == 'L'
&& buffer[offset+1] == 'I'
&& buffer[offset+2] == 'S'
&& buffer[offset+3] == 'T') {
infoTagsSize = static_cast<uint32_t>(buffer[offset+7] << 24 | buffer[offset+6] << 16 | buffer[offset+5] << 8 | buffer[offset+4]);
infoTagsSize += 8;
return true;
}
if ( buffer[offset+0] == 'd'
&& buffer[offset+1] == 'a'
&& buffer[offset+2] == 't'
&& buffer[offset+3] == 'a') {
infoTagsSize = 0;
return true;
}
Serial.println("expected 'data' or 'LIST'...");
return false;
}
bool readDataHeader(unsigned char *buffer, size_t offset, wav_data_header &data_header) {
for (int i=0; i < 4; i++)
data_header.data_header[i] = buffer[i+offset];
if (buffer[offset+0] != 'd' || buffer[offset+1] != 'a' || buffer[offset+2] != 't' || buffer[offset+3] != 'a') {
for (int i=0; i < 4; i++)
header.data_header[i] = buffer[i+36];
if (buffer[36] != 'd' || buffer[37] != 'a' || buffer[38] != 't' || buffer[39] != 'a') {
Serial.printf("expected data... (was %d)\n", buffer);
return false;
}
auto data_bytes = static_cast<unsigned long>(buffer[offset+7] << 24 | buffer[offset+6] << 16 | buffer[offset+5] << 8 | buffer[offset+4]);
data_header.data_bytes = data_bytes;
auto data_bytes = static_cast<unsigned long>(b[43] << 24 | b[42] << 16 | b[41] << 8 | b[40]);
header.data_bytes = data_bytes;
return true;
}
private:
};

@ -57,7 +57,6 @@ if (DEFINED BUILD_FOR_LINUX)
audio/wav/AudioWavFixture.h
audio/wav/test_wav_mono_loop_forward_playback.cpp
audio/wav/test_wav_stereo_loop_forward_playback.cpp
audio/wav/test_wav_tags.cpp
low_level/sd/ResamplingReaderFixture.h
low_level/sd/test_raw_mono_noloop_forward_playback.cpp

@ -14,11 +14,6 @@ extern unsigned int kick_raw_len; // in bytes, divide by 2 to get samples
BOOST_AUTO_TEST_SUITE(test_audio_array_mono_loop_forward_playback)
const uint16_t numberOfChannels = 1;
const std::string referencePath = "test/resources/reference/";
const std::string inputPath = "test/resources/input/";
const std::string outputPath = "output/";
BOOST_FIXTURE_TEST_CASE(Array_fwd_1_0000_quadratic_mono_noloop, AudioArrayFixture) {
// GUItool: begin automatically generated code
@ -30,10 +25,10 @@ BOOST_AUTO_TEST_SUITE(test_audio_array_mono_loop_forward_playback)
const double playbackRate = 1.0;
const std::string testName = "Array_fwd_1_0000_quadratic_mono_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string referenceFileName = referencePath+testName+".wav";
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = "test/resources/reference/"+testName+".wav";
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
memory.begin();
memory.enableInterpolation(true);
memory.setPlaybackRate(playbackRate);
@ -64,10 +59,10 @@ BOOST_AUTO_TEST_SUITE(test_audio_array_mono_loop_forward_playback)
const double playbackRate = 0.5;
const std::string testName = "Array_fwd_0_5000_quadratic_mono_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string referenceFileName = referencePath+testName+".wav";
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = "test/resources/reference/"+testName+".wav";
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
memory.begin();
memory.enableInterpolation(true);
memory.setPlaybackRate(playbackRate);
@ -99,10 +94,10 @@ BOOST_AUTO_TEST_SUITE(test_audio_array_mono_loop_forward_playback)
const double playbackRate = 2.0;
const std::string testName = "Array_fwd_2_0000_quadratic_mono_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string referenceFileName = referencePath+testName+".wav";
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = "test/resources/reference/"+testName+".wav";
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
memory.begin();
memory.enableInterpolation(true);
memory.setPlaybackRate(playbackRate);
@ -134,10 +129,10 @@ BOOST_AUTO_TEST_SUITE(test_audio_array_mono_loop_forward_playback)
const double playbackRate = 0.7437;
const std::string testName = "Array_fwd_0_7437_quadratic_mono_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string referenceFileName = referencePath+testName+".wav";
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = "test/resources/reference/"+testName+".wav";
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
memory.begin();
memory.enableInterpolation(true);
memory.setPlaybackRate(playbackRate);
@ -170,10 +165,10 @@ BOOST_AUTO_TEST_SUITE(test_audio_array_mono_loop_forward_playback)
const double playbackRate = 1.7437;
const std::string testName = "Array_fwd_1_7437_quadratic_mono_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string referenceFileName = referencePath+testName+".wav";
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = "test/resources/reference/"+testName+".wav";
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
memory.begin();
memory.enableInterpolation(true);
memory.setPlaybackRate(playbackRate);
@ -205,10 +200,10 @@ BOOST_AUTO_TEST_SUITE(test_audio_array_mono_loop_forward_playback)
const double playbackRate = 8.7437;
const std::string testName = "Array_fwd_8_7437_quadratic_mono_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string referenceFileName = referencePath+testName+".wav";
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = "test/resources/reference/"+testName+".wav";
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
memory.begin();
memory.enableInterpolation(true);
memory.setPlaybackRate(playbackRate);

@ -14,10 +14,6 @@ extern unsigned int stereo_souljah_raw_len;
BOOST_AUTO_TEST_SUITE(test_audio_array_stereo_loop_forward_playback)
const uint16_t numberOfChannels = 2;
const std::string referencePath = "test/resources/reference/";
const std::string inputPath = "test/resources/input/";
const std::string outputPath = "output/";
BOOST_FIXTURE_TEST_CASE(Array_fwd_1_0000_quadratic_stereo_noloop, AudioArrayFixture) {
// GUItool: begin automatically generated code
@ -30,10 +26,10 @@ BOOST_AUTO_TEST_SUITE(test_audio_array_stereo_loop_forward_playback)
const double playbackRate = 1.0;
const std::string testName = "Array_fwd_1_0000_quadratic_stereo_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string referenceFileName = referencePath+testName+".wav";
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = "test/resources/reference/"+testName+".wav";
testout.saveOutputFile(outputFile.c_str());
memory.begin();
memory.enableInterpolation(true);
memory.setPlaybackRate(playbackRate);
@ -65,10 +61,10 @@ BOOST_AUTO_TEST_SUITE(test_audio_array_stereo_loop_forward_playback)
const double playbackRate = 0.5;
const std::string testName = "Array_fwd_0_5000_quadratic_stereo_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string referenceFileName = referencePath+testName+".wav";
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = "test/resources/reference/"+testName+".wav";
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
memory.begin();
memory.enableInterpolation(true);
memory.setPlaybackRate(playbackRate);
@ -101,10 +97,10 @@ BOOST_AUTO_TEST_SUITE(test_audio_array_stereo_loop_forward_playback)
const double playbackRate = 2.0;
const std::string testName = "Array_fwd_2_0000_quadratic_stereo_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string referenceFileName = referencePath+testName+".wav";
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = "test/resources/reference/"+testName+".wav";
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
memory.begin();
memory.enableInterpolation(true);
memory.setPlaybackRate(playbackRate);
@ -137,10 +133,10 @@ BOOST_AUTO_TEST_SUITE(test_audio_array_stereo_loop_forward_playback)
const double playbackRate = 0.7437;
const std::string testName = "Array_fwd_0_7437_quadratic_stereo_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string referenceFileName = referencePath+testName+".wav";
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = "test/resources/reference/"+testName+".wav";
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
memory.begin();
memory.enableInterpolation(true);
memory.setPlaybackRate(playbackRate);
@ -174,10 +170,10 @@ BOOST_AUTO_TEST_SUITE(test_audio_array_stereo_loop_forward_playback)
const double playbackRate = 1.7437;
const std::string testName = "Array_fwd_1_7437_quadratic_stereo_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string referenceFileName = referencePath+testName+".wav";
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = "test/resources/reference/"+testName+".wav";
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
memory.begin();
memory.enableInterpolation(true);
memory.setPlaybackRate(playbackRate);
@ -210,10 +206,10 @@ BOOST_AUTO_TEST_SUITE(test_audio_array_stereo_loop_forward_playback)
const double playbackRate = 8.7437;
const std::string testName = "Array_fwd_8_7437_quadratic_stereo_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string referenceFileName = referencePath+testName+".wav";
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = "test/resources/reference/"+testName+".wav";
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
memory.begin();
memory.enableInterpolation(true);
memory.setPlaybackRate(playbackRate);

@ -21,34 +21,33 @@ public:
virtual void update(void);
void begin(void);
static void isr(void);
bool saveOutputFile(const char * path, const char* filename){
if (num_inputs == 0) return false;
void saveOutputFile(const char* filename){
if (num_inputs == 0) return;
char cwd[500];
if (getcwd(cwd, sizeof(cwd)) != NULL) {
printf("Current working dir: %s\n", cwd);
} else {
perror("getcwd() error");
}
string outputPath = string(cwd) + "/" + string(path);
string outputPath = string(cwd) + "/output/";
__filesystem::path p(outputPath);
if (! __filesystem::exists(p) )
__filesystem::create_directories(outputPath);
_filePath = outputPath + string(filename);
std::cout << "saving output audio .wav file to " << _filePath << std::endl;
_outputFile.open(_filePath, ios_base::trunc | ios_base::out);
string filePath = outputPath + string(filename);
std::cout << "saving output audio .wav file to " << filePath << std::endl;
_outputFile.open(filePath);
if (!_outputFile.is_open()) {
Serial.printf("couldn't open file for recording...%s\n", _filePath.c_str());
return false;
Serial.println("couldn't open file for recording...");
} else {
_filename = filename;
_outputFile.write((char*)test_output_wav_header, 44);
_saveToFile = true;
return true;
_saveToFile = true;
}
}
void closeOutputfile(uint16_t numChannels) {
if (!_saveToFile) return;
if (_outputFile.is_open()) {
_saveToFile = false;
char buf[4];
@ -83,7 +82,6 @@ public:
}
protected:
std::ofstream _outputFile;
std::string _filePath;
static audio_block_t *block_left_1st;
static audio_block_t *block_right_1st;
static bool update_responsibility;

@ -11,11 +11,6 @@
BOOST_AUTO_TEST_SUITE(test_audio_wav_mono_loop_forward_playback)
const uint16_t numberOfChannels = 1;
const std::string referencePath = "test/resources/reference/";
const std::string inputPath = "test/resources/input/";
const std::string outputPath = "output/";
BOOST_FIXTURE_TEST_CASE(Wav_fwd_1_0000_quadratic_mono_noloop, AudioWavFixture) {
// GUItool: begin automatically generated code
@ -23,15 +18,15 @@ BOOST_AUTO_TEST_SUITE(test_audio_wav_mono_loop_forward_playback)
TestAudioOutput testout; //xy=612,224
AudioConnection patchCord1(wave, 0, testout, 0);
// GUItool: end automatically generated code
const double playbackRate = 1.0;
const std::string testName = "Wav_fwd_1_0000_quadratic_mono_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string outputFileName = "output/" + outputFile;
const std::string referencePath = "test/resources/reference/";
const std::string referenceFileName = referencePath + testName + ".wav";
SD.setSDCardFolderPath(inputPath);
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
SD.setSDCardFolderPath(referencePath);
testout.saveOutputFile(outputFile.c_str());
wave.begin();
wave.enableInterpolation(true);
@ -63,11 +58,12 @@ BOOST_AUTO_TEST_SUITE(test_audio_wav_mono_loop_forward_playback)
const double playbackRate = 0.5;
const std::string testName = "Wav_fwd_0_5000_quadratic_mono_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string outputFileName = "output/" + outputFile;
const std::string referencePath = "test/resources/reference/";
const std::string referenceFileName = referencePath + testName + ".wav";
SD.setSDCardFolderPath(inputPath);
SD.setSDCardFolderPath(referencePath);
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
wave.begin();
wave.enableInterpolation(true);
wave.setPlaybackRate(playbackRate);
@ -99,11 +95,12 @@ BOOST_AUTO_TEST_SUITE(test_audio_wav_mono_loop_forward_playback)
const double playbackRate = 2.0;
const std::string testName = "Wav_fwd_2_0000_quadratic_mono_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string outputFileName = "output/" + outputFile;
const std::string referencePath = "test/resources/reference/";
const std::string referenceFileName = referencePath + testName + ".wav";
SD.setSDCardFolderPath(inputPath);
SD.setSDCardFolderPath(referencePath);
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
wave.begin();
wave.enableInterpolation(true);
wave.setPlaybackRate(playbackRate);
@ -135,11 +132,12 @@ BOOST_AUTO_TEST_SUITE(test_audio_wav_mono_loop_forward_playback)
const double playbackRate = 0.7437;
const std::string testName = "Wav_fwd_0_7437_quadratic_mono_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string outputFileName = "output/" + outputFile;
const std::string referencePath = "test/resources/reference/";
const std::string referenceFileName = referencePath + testName + ".wav";
SD.setSDCardFolderPath(inputPath);
SD.setSDCardFolderPath(referencePath);
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
wave.begin();
wave.enableInterpolation(true);
wave.setPlaybackRate(playbackRate);
@ -172,11 +170,12 @@ BOOST_AUTO_TEST_SUITE(test_audio_wav_mono_loop_forward_playback)
const double playbackRate = 1.7437;
const std::string testName = "Wav_fwd_1_7437_quadratic_mono_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string outputFileName = "output/" + outputFile;
const std::string referencePath = "test/resources/reference/";
const std::string referenceFileName = referencePath + testName + ".wav";
SD.setSDCardFolderPath(inputPath);
SD.setSDCardFolderPath(referencePath);
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
wave.begin();
wave.enableInterpolation(true);
wave.setPlaybackRate(playbackRate);
@ -208,11 +207,10 @@ BOOST_AUTO_TEST_SUITE(test_audio_wav_mono_loop_forward_playback)
const double playbackRate = 8.7437;
const std::string testName = "Wav_fwd_8_7437_quadratic_mono_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string referenceFileName = referencePath + testName + ".wav";
SD.setSDCardFolderPath(inputPath);
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = "test/resources/reference/"+testName+".wav";
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
wave.begin();
wave.enableInterpolation(true);
wave.setPlaybackRate(playbackRate);

@ -10,12 +10,9 @@
BOOST_AUTO_TEST_SUITE(test_audio_wav_stereo_loop_forward_playback)
const uint16_t numberOfChannels = 2;
const std::string referencePath = "test/resources/reference/";
const std::string inputPath = "test/resources/input/";
const std::string outputPath = "output/";
const uint16_t numberOfChannels = 2;
BOOST_FIXTURE_TEST_CASE(Wav_fwd_1_0000_quadratic_stereo_noloop, AudioWavFixture) {
// GUItool: begin automatically generated code
@ -28,11 +25,11 @@ BOOST_AUTO_TEST_SUITE(test_audio_wav_stereo_loop_forward_playback)
const double playbackRate = 1.0;
const std::string testName = "Wav_fwd_1_0000_quadratic_stereo_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = referencePath + testName + ".wav";
SD.setSDCardFolderPath(inputPath);
SD.setSDCardFolderPath(referencePath);
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
wave.begin();
wave.enableInterpolation(true);
wave.setPlaybackRate(playbackRate);
@ -64,11 +61,11 @@ BOOST_AUTO_TEST_SUITE(test_audio_wav_stereo_loop_forward_playback)
const double playbackRate = 0.5;
const std::string testName = "Wav_fwd_0_5000_quadratic_stereo_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = referencePath + testName + ".wav";
SD.setSDCardFolderPath(inputPath);
SD.setSDCardFolderPath(referencePath);
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
wave.begin();
wave.enableInterpolation(true);
@ -102,11 +99,10 @@ BOOST_AUTO_TEST_SUITE(test_audio_wav_stereo_loop_forward_playback)
const double playbackRate = 2.0;
const std::string testName = "Wav_fwd_2_0000_quadratic_stereo_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string referenceFileName = referencePath + testName + ".wav";
SD.setSDCardFolderPath(inputPath);
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = "test/resources/reference/"+testName+".wav";
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
wave.begin();
wave.enableInterpolation(true);
wave.setPlaybackRate(playbackRate);
@ -139,11 +135,11 @@ BOOST_AUTO_TEST_SUITE(test_audio_wav_stereo_loop_forward_playback)
const double playbackRate = 0.7437;
const std::string testName = "Wav_fwd_0_7437_quadratic_stereo_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = referencePath + testName + ".wav";
SD.setSDCardFolderPath(inputPath);
SD.setSDCardFolderPath(referencePath);
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
wave.begin();
wave.enableInterpolation(true);
wave.setPlaybackRate(playbackRate);
@ -177,11 +173,11 @@ BOOST_AUTO_TEST_SUITE(test_audio_wav_stereo_loop_forward_playback)
const double playbackRate = 1.7437;
const std::string testName = "Wav_fwd_1_7437_quadratic_stereo_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = referencePath + testName + ".wav";
SD.setSDCardFolderPath(inputPath);
SD.setSDCardFolderPath(referencePath);
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
wave.begin();
wave.enableInterpolation(true);
wave.setPlaybackRate(playbackRate);
@ -214,11 +210,11 @@ BOOST_AUTO_TEST_SUITE(test_audio_wav_stereo_loop_forward_playback)
const double playbackRate = 8.7437;
const std::string testName = "Wav_fwd_8_7437_quadratic_stereo_noloop";
const std::string outputFile = testName+".wav";
const std::string outputFileName = outputPath + outputFile;
const std::string outputFileName = "output/" + outputFile;
const std::string referenceFileName = referencePath + testName + ".wav";
SD.setSDCardFolderPath(inputPath);
SD.setSDCardFolderPath(referencePath);
testout.saveOutputFile(outputPath.c_str(), outputFile.c_str());
testout.saveOutputFile(outputFile.c_str());
wave.begin();
wave.enableInterpolation(true);
wave.setPlaybackRate(playbackRate);

@ -10,14 +10,14 @@
struct ResamplingArrayFixture {
ResamplingArrayFixture() {
resamplingArrayReader = new newdigate::ResamplingArrayReader();
resamplingArrayReader = new ResamplingArrayReader();
}
~ResamplingArrayFixture() {
delete resamplingArrayReader;
}
newdigate::ResamplingArrayReader * resamplingArrayReader;
ResamplingArrayReader * resamplingArrayReader;
};
#endif //TEENSY_RESAMPLING_SDREADER_RESAMPLINGARRAYFIXTURE_H

@ -10,14 +10,14 @@
struct ResamplingArrayWavFixture {
ResamplingArrayWavFixture() {
resamplingArrayReader = new newdigate::ResamplingArrayReader();
resamplingArrayReader = new ResamplingArrayReader();
}
~ResamplingArrayWavFixture() {
delete resamplingArrayReader;
}
newdigate::ResamplingArrayReader * resamplingArrayReader;
ResamplingArrayReader * resamplingArrayReader;
};
#endif //TEENSY_RESAMPLING_SDREADER_RESAMPLINGARRAYWAVFIXTURE_H

@ -2,7 +2,7 @@
#include "IndexedFileFixture.h"
#include <SD.h>
#include "IndexableSDFile.h"
#include "IndexableFile.h"
BOOST_AUTO_TEST_SUITE(test_indexablefile)
@ -15,7 +15,7 @@ BOOST_AUTO_TEST_SUITE(test_indexablefile)
}
SD.setSDCardFileData((char*)file_contents, sample_size * 2);
newdigate::IndexableSDFile<16, 2> indexable("blah.h"); // use max 2 buffers, with 16 elements each....
newdigate::IndexableFile<16, 2> indexable("blah.h"); // use max 2 buffers, with 16 elements each....
/*
for (int i=0; i<sample_size; i++) {

@ -10,14 +10,14 @@
struct ResamplingReaderFixture {
ResamplingReaderFixture() {
resamplingSdReader = new newdigate::ResamplingSdReader();
resamplingSdReader = new ResamplingSdReader();
}
~ResamplingReaderFixture() {
delete resamplingSdReader;
}
newdigate::ResamplingSdReader * resamplingSdReader;
ResamplingSdReader * resamplingSdReader;
};
#endif //TEENSY_RESAMPLING_SDREADER_RESAMPLINGREADERFIXTURE_H

@ -18,7 +18,7 @@ BOOST_AUTO_TEST_SUITE(test_raw_mono_noloop_forward_double_rate_playback)
SD.setSDCardFileData((char *) dataSource, size_of_datasource * 2);
}
void testReadForwardAtDoublePlaybackRate(const uint32_t size_of_datasource, newdigate::ResamplingSdReader *resamplingSdReader) {
void testReadForwardAtDoublePlaybackRate(const uint32_t size_of_datasource, ResamplingSdReader *resamplingSdReader) {
printf("test_raw_mono_noloop_forward_double_rate_playback::testReadForwardAtDoublePlaybackRate(rate:%.2f\tsamples:%d)\n", playBackRate, size_of_datasource);
int16_t dataSource[size_of_datasource];

@ -24,7 +24,7 @@ BOOST_AUTO_TEST_SUITE(test_raw_mono_noloop_forward_playback)
resamplingSdReader->begin();
resamplingSdReader->setPlaybackRate(1.0);
resamplingSdReader->play("test2.bin", false, 1);
resamplingSdReader->playRaw("test2.bin", 1);
resamplingSdReader->setLoopType(looptype_none);
resamplingSdReader->setInterpolationType(ResampleInterpolationType::resampleinterpolation_quadratic);
int16_t actual[1024];

@ -23,8 +23,7 @@ BOOST_AUTO_TEST_SUITE(WaveHeaderParsingTests)
SD.setSDCardFileData((char*) test_sndhdrdata_sndhdr_wav, test_sndhdrdata_sndhdr_wav_len);
wav_header header;
wav_data_header data_header;
bool success = waveHeaderParser->readWaveHeader("blah.wav", header, data_header);
bool success = waveHeaderParser->readWaveHeader("blah.wav", header);
BOOST_CHECK_EQUAL(success, true);
const char expectedRIFF[5] = "RIFF";
BOOST_CHECK_EQUAL_COLLECTIONS(&header.riff_header[0], &header.riff_header[3],&expectedRIFF[0], &expectedRIFF[3]);
@ -34,7 +33,7 @@ BOOST_AUTO_TEST_SUITE(WaveHeaderParsingTests)
const char expectedfmt[5] = "fmt ";
BOOST_CHECK_EQUAL_COLLECTIONS(&header.fmt_header[0], &header.fmt_header[3],&expectedfmt[0], &expectedfmt[3]);
const char expecteddata[5] = "data";
BOOST_CHECK_EQUAL_COLLECTIONS(&data_header.data_header[0], &data_header.data_header[3],&expecteddata[0], &expecteddata[3]);
BOOST_CHECK_EQUAL_COLLECTIONS(&header.data_header[0], &header.data_header[3],&expecteddata[0], &expecteddata[3]);
//BOOST_CHECK_EQUAL(File::numOpenFiles,0);
//BOOST_CHECK_EQUAL(File::numInstances,0);
}

Loading…
Cancel
Save