Esp-radio
Esp-radio copied to clipboard
Stations with redirect will not work when SPIRAM enabled
Hi Ed, I noticed that if SPIRAM enabled then stations with redirect wont work. Here is output
D: New preset/file requested (1/0) from n0d.radiojar.com/hcrb063nn3quv
D: Connect to new host n0d.radiojar.com/hcrb063nn3quv
D: Connect to n0d.radiojar.com on port 80, extension /hcrb063nn3quv
D: Connected to server
D: Switch to HEADER
D: Access-Control-Allow-Origin: *
D: No data input
D: No data input
D: Trying other station/file...
D: STOP requested
D: New preset/file requested (8/0) from stream.live.vc.bbcmedia.co.uk/bbc_world_service
Although ringbuf works perfectly fine
Yes, I know. That is because there is a delay (a number of input bytes). The redirect info is less than that number and is therefore not handled.
Is there a quick way to fix it? Thanks
Also please see my version spiram.cpp without external library.
//******************************************************************************************
// SPI RAM routines. *
//******************************************************************************************
// Use SPI RAM as a circular buffer with chunks of 32 bytes. *
//******************************************************************************************
#include <SPI.h>
#define SRAM_SIZE 131072 // Total size SPI ram in bytes
#define CHUNKSIZE 32 // Chunk size
#define SRAM_CH_SIZE 4096 // Total size SPI ram in chunks
#define SRAM_CS 10 // GPIO1O SRAM CS pin
#define SRAM_FREQ 16e6 // The 23LC1024 supports theorically up to 20MHz
// SRAM opcodes
#define SRAM_READ 0x03
#define SRAM_WRITE 0x02
// Global variables
uint16_t chcount ; // Number of chunks currently in buffer
uint32_t readinx ; // Read index
uint32_t writeinx ; // write index
//******************************************************************************************
// SPI RAM routines. *
//******************************************************************************************
// Use SPI RAM as a circular buffer with chunks of 32 bytes. *
//******************************************************************************************
void spiramWrite ( uint32_t addr, uint8_t *buff, uint32_t size )
{
int i = 0;
SPI.beginTransaction ( SPISettings(SRAM_FREQ, MSBFIRST, SPI_MODE0 ) ) ;
while ( size-- ) {
digitalWrite ( SRAM_CS, LOW ) ;
uint32_t data = (0x02 << 24) | (addr++ & 0x00ffffff);
SPI.transfer16(data >> 16); // Transfer MSB
SPI.transfer16(data & 0xFFFF); // Transfer LSB
SPI.transfer(buff[i++]);
digitalWrite ( SRAM_CS, HIGH ) ;
if (i % 32 == 0) yield(); // Yield to reset the watchdog every 32 iterations
}
SPI.endTransaction();
}
void spiramRead ( uint32_t addr, uint8_t *buff, uint32_t size )
{
int i = 0;
SPI.beginTransaction ( SPISettings(SRAM_FREQ, MSBFIRST, SPI_MODE0 ) ) ;
while ( size-- ) {
digitalWrite ( SRAM_CS, LOW ) ;
uint32_t data = (0x03 << 24) | (addr++ & 0x00ffffff);
SPI.transfer16(data >> 16); // Transfer MSB
SPI.transfer16(data & 0xFFFF); // Transfer LSB
buff[i++] = SPI.transfer(0x00);
digitalWrite ( SRAM_CS, HIGH ) ;
if (i % 32 == 0) yield(); // Yield to reset the watchdog every 32 iterations
}
SPI.endTransaction();
}
//******************************************************************************************
// S P A C E A V A I L A B L E *
//******************************************************************************************
// Returns true if bufferspace is available. *
//******************************************************************************************
bool spaceAvailable()
{
return ( chcount < SRAM_CH_SIZE ) ;
}
//******************************************************************************************
// D A T A A V A I L A B L E *
//******************************************************************************************
// Returns the number of chunks available in the buffer. *
//******************************************************************************************
uint16_t dataAvailable()
{
return chcount ;
}
//******************************************************************************************
// G E T F R E E B U F F E R S P A C E *
//******************************************************************************************
// Return the free buffer space in chunks. *
//******************************************************************************************
uint16_t getFreeBufferSpace()
{
return ( SRAM_CH_SIZE - chcount ) ; // Return number of chunks available
}
//******************************************************************************************
// B U F F E R W R I T E *
//******************************************************************************************
// Write one chunk (32 bytes) to SPI RAM. *
// No check on available space. See spaceAvailable(). *
//******************************************************************************************
void bufferWrite ( uint8_t *b )
{
spiramWrite ( writeinx * CHUNKSIZE, b, CHUNKSIZE ) ; // Put byte in SRAM
writeinx = ( writeinx + 1 ) % SRAM_CH_SIZE ; // Increment and wrap if necessary
chcount++ ; // Count number of chunks
}
//******************************************************************************************
// B U F F E R R E A D *
//******************************************************************************************
// Read one chunk in the user buffer. *
// Assume there is always something in the bufferpace. See dataAvailable() *
//******************************************************************************************
void bufferRead ( uint8_t *b )
{
spiramRead ( readinx * CHUNKSIZE, b, CHUNKSIZE ) ; // return next chunk
readinx = ( readinx + 1 ) % SRAM_CH_SIZE ; // Increment and wrap if necessary
chcount-- ; // Count is now one less
}
//******************************************************************************************
// B U F F E R R E S E T *
//******************************************************************************************
void bufferReset()
{
readinx = 0 ; // Reset ringbuffer administration
writeinx = 0 ;
chcount = 0 ;
}
//******************************************************************************************
// S P I R A M S E T U P *
//******************************************************************************************
void spiramSetup()
{
SPI.begin();
pinMode ( SRAM_CS, OUTPUT ) ;
digitalWrite ( SRAM_CS, HIGH ) ;
digitalWrite ( SRAM_CS, HIGH ) ;
delay ( 50 ) ;
digitalWrite ( SRAM_CS, LOW ) ;
delay ( 50 ) ;
digitalWrite ( SRAM_CS, HIGH ) ;
SPI.beginTransaction ( SPISettings ( SRAM_FREQ, MSBFIRST, SPI_MODE0 ) ) ;
digitalWrite ( SRAM_CS, LOW ) ;
SPI.transfer ( 0x01 ) ; // Write mode register
SPI.transfer ( 0x00 ) ; // Set byte mode
digitalWrite ( SRAM_CS, HIGH ) ;
SPI.endTransaction();
bufferReset() ; // Reset ringbuffer administration
}
I have no way to test it.
I tested it and it works fine
so, what is the problem?
No issue with the code itself. Just redirect is not working
Hi @Edzelf I was trying to modify https://github.com/Edzelf/Esp-radio/blob/65f20ce4a5334ed1a272d046e8ed7f6b73dbb5e5/Esp_radio.ino#L2478
with no success.
Would you be able to advise how it can be done, maybe you can give me a clue? Thanks
Hi @Edzelf Is there any chance to make redirect working while SPIRAM option is enabled? Thanks