I build a application like:
MP3 File-> SD Card -> Arduino -> Audio PlugIn from VSide-> SCI Interface -> VS1053 -> StreamBufferReadData() -> memcpyYX -> AudioOutputSamples() -> Output on LOUT Speaker
So the Plugin and all stuff works but the output signal is very very noisy and it seems that the input signal cannot read right from StreamBufferReadData(). If I listen without a loaded plugin audio signal is how expected.
OS: Win10 64bit
Arduino Uno R3 witth IDE V2.0.2
VS1053: https://www.adafruit.com/product/1381
VSIDE 2.48 Example project: Audio Effects linked as plugin
Here is the source...I only changed that it twice Enable() and USE_SIMPLE_DSP_BOARD;
Code: Select all
/* For free support for VSIDE, please visit www.vsdsp-forum.com */
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Audio effect example for VS1053/VS1063
//
// Flanger, chorus and delay with adjustable parameters
// (see "effect.h" for the parameters)
//
// press button on board to bypass effect when program is running
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#define USE_SIMPLE_DSP_BOARD
//#define USE_PROTOTYPING_BOARD
// (define *one* of the PCB types before including board.h)
#include "board.h"
#define USE_MIC 0 // define 1 for mic-in, 0 for line-in
#include <string.h>
#include <stdlib.h>
#include "effect.h"
void InitAudioExample(u_int16 srInput,int useMicIn,u_int16 coreClock); // (see "init.c")
static s_int16 __y delayBuffer[DELAY_BUF_SZ]; // delay line (buffer in Y memory)
main(void) {
s_int16 auxBuffer[2*BLOCKSIZE]; // auxiliary audio buffer
s_int16 __y lineInBuf[2*BLOCKSIZE]; // line-in audio buffer
s_int16 __y *bufptr = delayBuffer;
s_int16 __y *flgptr = delayBuffer;
s_int16 phase = 0; // this is the (accumulator) phase for the LFO
s_int16 flangerSample = 0;
u_int16 flangerPhase = 0;
// parameters for the currently selected effect:
struct Effect effect = {DEPTH, SPEED, DELAY, DECAY, MIX, MIX};
//
effect.delay += (effect.depth/2)+1;
// initialize delay line with silence
memsetY(delayBuffer, 0, DELAY_BUF_SZ);
// disable interrupts during initialization
Disable();
// basic initialization phase
InitAudioExample(MY_SAMPLERATE,USE_MIC,CORE_CLOCK_3X);
// adjust output samplerate
SetHardware(2/*stereo output*/,MY_SAMPLERATE/*DA sample rate*/);
//
USEX(INT_ENABLE)|=(1<<INT_EN_MODU)/*AD*/|(1<<INT_EN_DAC);
// initialize audio_buffer read and write pointers
#ifdef VS1063
audioPtr.rd = audio_buffer;
audioPtr.wr = audio_buffer + 2*BLOCKSIZE;
#else
audio_rd_pointer = audio_buffer;
audio_wr_pointer = audio_buffer + 2*BLOCKSIZE;
#endif
// clear audio buffer (avoid unwanted noise in the beginning)
memsetY(audio_buffer,0,AUDIO_BUFFER_SZ);
// set up GPIO
CONFIGURE_LED_1;
CONFIGURE_BUTTON_1;
// set max volume
USEX(SCI_VOL) = 0x0101;
// enable interrupts
Enable();
Enable();
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Main loop
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
while (1) {
//
// wait until there is enough audio data to process
//
if (StreamDiff() > BLOCKSIZE*2) {
u_int16 i;
s_int16 temp = 0;
u_int32 fractDelay;
__y s_int16 *lp = lineInBuf;
s_int16 *sp = auxBuffer;
//
// read input samples (stereo, hence 2 x block size)
//
StreamBufferReadData(lineInBuf, 2*BLOCKSIZE);
//
if(BUTTON_1_PRESSED) {
effect.mix=0;
SET_LED_1_OFF;
} else {
effect.mix = effect.mixOrg;
SET_LED_1_ON;
}
//
// process BLOCKSIZE samples at one go
//
for(i=0;i<BLOCKSIZE;i++) {
// fractional delay part
s_int16 flangerOut = (s_int16)(((s_int32)*flgptr * (65535U-flangerPhase)) >> 16);
//
// advance flgptr (and wrap the cyclic buffer)
//
if (flgptr >= delayBuffer+DELAY_BUF_SZ-1) {
flgptr = delayBuffer;
} else {
flgptr++;
}
//
flangerOut += (s_int16)(((s_int32)*flgptr * flangerPhase) >> 16);
//
// add input sample to buffer with feedback (decay)
// mix dry and effect and send to output (mix)
//
*sp = (s_int16)(((s_int32)lp[0] * (32000U-effect.mix) +
(s_int32)flangerOut * effect.mix) >> 15);
*bufptr = (s_int16)(((s_int32)*sp++ * effect.decay +
(s_int32)lp[0] * (32000U-effect.decay)) >> 15);
lp += 2;
sp[0] = sp[-1]; // duplicate output to both channels
sp++;
//
// advance bufptr (and wrap the cyclic buffer)
//
if (bufptr >= delayBuffer+DELAY_BUF_SZ-1) {
bufptr = delayBuffer;
} else {
bufptr++;
}
}
//
// LFO (speed & depth)
//
phase += effect.speed;
//
// LFO value varies from 0 to 1024 (depth = max 2048)
{
u_int32 tt = (u_int32)((u_int16)abs(phase)) * effect.depth;
flangerSample = (u_int16)(tt >> 16);
flangerPhase = (u_int16)tt;
}
//
// flanger delay
//
flgptr = bufptr + flangerSample - effect.delay;
if (flgptr < delayBuffer) {
flgptr += DELAY_BUF_SZ;
}
//
// ouput sample pairs
//
AudioOutputSamples(auxBuffer, BLOCKSIZE);
} else { // StreamDiff() <= BLOCKSIZE*2
//
// limit values
//
if (effect.depth > 2048) {
effect.depth = 2048;
}
if (effect.speed > 1024) {
effect.speed = 1024;
}
if (effect.mix > 32000) {
effect.mix = 32000;
}
if (effect.decay > 32000) {
effect.decay = 32000;
}
}
}
return 0;
}