This commit is contained in:
2026-02-12 21:00:02 -08:00
parent 77f8236347
commit 8bdbf227ca
1141 changed files with 1010880 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
## VS1053
The VS1053 is a chip that can decode Ogg Vorbis / MP3 / AAC / WMA / FLAC / MIDI
So there is no need for the microcontroller to do any decoding.

View File

@@ -0,0 +1,49 @@
/**
* @file player-sd-vs1053.ino
* @brief Audio player which sends the output to a VS1053 module. Using a module with built in SD card
*
* @author Phil Schatzmann
* @copyright GPLv3
*/
// install https://github.com/pschatzmann/arduino-vs1053.git
#include "AudioTools.h"
#include "AudioTools/AudioLibs/VS1053Stream.h"
#include "AudioTools/Disk/AudioSourceSD.h"
#include "AudioTools/AudioCodecs/CodecCopy.h"
const char *startFilePath="/";
const char* ext="mp3";
AudioSourceSD source(startFilePath, ext);
VS1053Stream vs1053; // final output
AudioPlayer player(source, vs1053, *new CopyDecoder());
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
// setup output
auto cfg = vs1053.defaultConfig();
cfg.is_encoded_data = true; // vs1053 is accepting encoded data
// Use your custom pins or define in AudioCodnfig.h
//cfg.cs_pin = VS1053_CS;
//cfg.dcs_pin = VS1053_DCS;
//cfg.dreq_pin = VS1053_DREQ;
//cfg.reset_pin = VS1053_RESET;
vs1053.begin(cfg);
vs1053.setVolume(1.0); // full volume
// setup player
player.begin();
// select file with setPath() or setIndex()
//player.setPath("/ZZ Top/Unknown Album/Lowrider.mp3");
//player.setIndex(1); // 2nd file
}
void loop() {
player.copy();
}

View File

@@ -0,0 +1,51 @@
/**
* @file player-sdfat-vs1053.ino
* @brief Audio player which sends the output to a VS1053 module. Using a module with built in SD card
*
* @author Phil Schatzmann
* @copyright GPLv3
*/
// install https://github.com/pschatzmann/arduino-vs1053.git
// install https://github.com/greiman/SdFat
#include "AudioTools.h"
#include "AudioTools/AudioLibs/VS1053Stream.h"
#include "AudioTools/Disk/AudioSourceSDFAT.h"
#include "AudioTools/AudioCodecs/CodecCopy.h"
const char *startFilePath="/";
const char* ext="mp3";
SdSpiConfig sd_cfg(PIN_CS, SHARED_SPI, SPI_CLOCK);
AudioSourceSDFAT source(startFilePath, ext, sd_cfg);
VS1053Stream vs1053; // final output
AudioPlayer player(source, vs1053, *new CopyDecoder());
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
// setup output
auto cfg = vs1053.defaultConfig();
cfg.is_encoded_data = true; // vs1053 is accepting encoded data
// Use your custom pins or define in AudioCodnfig.h
//cfg.cs_pin = VS1053_CS;
//cfg.dcs_pin = VS1053_DCS;
//cfg.dreq_pin = VS1053_DREQ;
//cfg.reset_pin = VS1053_RESET;
vs1053.begin(cfg);
vs1053.setVolume(1.0); // full volume
// setup player
player.begin();
// select file with setPath() or setIndex()
//player.setPath("/ZZ Top/Unknown Album/Lowrider.mp3");
//player.setIndex(1); // 2nd file
}
void loop() {
player.copy();
}

View File

@@ -0,0 +1,48 @@
/**
* @file streams-generator-vs1053
* @author Phil Schatzmann
* @brief Generate Test Tone
* @version 0.1
* @date 2022-08-10
*
* @copyright Copyright (c) 2022
*
*/
// install https://github.com/pschatzmann/arduino-vs1053.git
#include "AudioTools.h"
#include "AudioTools/AudioLibs/VS1053Stream.h"
AudioInfo info(44100, 2, 16);
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
VS1053Stream out; // VS1053 output
StreamCopy copier(out, sound); // copy sound to decoder
void setup(){
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning); // Info is causing a lot of noise
// Setup sine wave
sineWave.begin(info, N_A4);
// setup output
auto cfg = out.defaultConfig();
cfg.copyFrom(info);
// Use your custom pins or define in AudioCodnfig.h
//cfg.cs_pin = VS1053_CS;
//cfg.dcs_pin = VS1053_DCS;
//cfg.dreq_pin = VS1053_DREQ;
//cfg.reset_pin = VS1053_RESET;
if (!out.begin(cfg)){
Serial.println("SPI Error");
stop();
}
}
void loop(){
copier.copy();
}

View File

@@ -0,0 +1,74 @@
/**
* @file streams-midi-vs1053.ino
* @author Phil Schatzmann
* @brief Demo that shows how to send streaming midi commands to the vs1053
* @version 0.1
* @date 2022-08-23
*
* @copyright Copyright (c) 2022
*
*/
#include "AudioTools.h"
#include "AudioTools/AudioLibs/VS1053Stream.h"
VS1053Stream vs1053; // final output
uint16_t note = 65; // 0 to 128
uint16_t amplitude = 128; // 0 to 128
int channel = 0;
uint8_t instrument = 0;
//Send a MIDI note-on message. Like pressing a piano key
void noteOn(uint8_t channel, uint8_t note, uint8_t attack_velocity=100) {
vs1053.sendMidiMessage( (0x90 | channel), note, attack_velocity);
}
//Send a MIDI note-off message. Like releasing a piano key
void noteOff(uint8_t channel, uint8_t note, uint8_t release_velocity=100) {
vs1053.sendMidiMessage( (0x80 | channel), note, release_velocity);
}
void selectInstrument(uint8_t channel, uint8_t instrument ){
// Continuous controller 0, bank select: 0 gives you the default bank depending on the channel
// 0x78 (percussion) for Channel 10, i.e. channel = 9 , 0x79 (melodic) for other channels
vs1053.sendMidiMessage(0xB0| channel, 0, 0x00); //0x00 default bank
// Patch change, select instrument
vs1053.sendMidiMessage(0xC0| channel, instrument, 0);
}
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
// setup vs1053
auto cfg = vs1053.defaultConfig();
cfg.is_midi = true; // vs1053 is accepting streaming midi data
// Use your custom pins or define in AudioCodnfig.h
//cfg.cs_pin = VS1053_CS;
//cfg.dcs_pin = VS1053_DCS;
//cfg.dreq_pin = VS1053_DREQ;
//cfg.reset_pin = VS1053_RESET;
vs1053.begin(cfg);
vs1053.setVolume(1.0);
}
void loop() {
Serial.println();
Serial.print("playing ");
Serial.println(++note);
noteOn(channel, note, amplitude );
delay(900);
noteOff(channel, note, 20 );
delay(200);
if (note>=90) {
note = 64;
Serial.println();
Serial.print("selecting Instrument ");
Serial.println(++instrument);
selectInstrument(channel, instrument);
}
}

View File

@@ -0,0 +1,68 @@
/**
* @file streams-midi-vs1053.ino
* @author Phil Schatzmann
* @brief Demo that shows how to send streaming midi commands to the vs1053
* This example using my https://github.com/pschatzmann/arduino-midi.git library
* @version 0.1
* @date 2022-08-23
*
* @copyright Copyright (c) 2022
*
*/
#include "AudioTools.h"
#include "AudioTools/AudioLibs/VS1053Stream.h"
#include "Midi.h"
VS1053Stream vs1053; // final output
MidiStreamOut midi_out(vs1053);
uint8_t note = 65; // 0 to 128
uint8_t amplitude = 128; // 0 to 128
uint8_t instrument = 0;
void selectInstrument(uint8_t instrument, uint8_t bank=0x00){
// Continuous controller 0, bank select: 0 gives you the default bank depending on the channel
// 0x78 (percussion) for Channel 10, i.e. channel = 9 , 0x79 (melodic) for other channels
//vs1053.sendMidiMessage(0xB0| channel, 0, 0x00); //0x00 default bank
midi_out.controlChange(BANK_SELECT, bank);
// Patch change, select instrument
midi_out.programChange(instrument);
}
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
// setup vs1053
auto cfg = vs1053.defaultConfig();
cfg.is_midi = true; // vs1053 is accepting streaming midi data
// Use your custom pins or define in AudioCodnfig.h
//cfg.cs_pin = VS1053_CS;
//cfg.dcs_pin = VS1053_DCS;
//cfg.dreq_pin = VS1053_DREQ;
//cfg.reset_pin = VS1053_RESET;
vs1053.begin(cfg);
vs1053.setVolume(1.0);
}
void loop() {
Serial.println();
Serial.print("playing ");
Serial.println(++note);
midi_out.noteOn(note, amplitude );
delay(900);
midi_out.noteOff(note, 20 );
delay(200);
if (note>=90) {
note = 64;
Serial.println();
Serial.print("selecting Instrument ");
Serial.println(++instrument);
selectInstrument(instrument);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,40 @@
/**
* @file streams-memory_midi-vs1953.ino
* @author Phil Schatzmann
* @brief The module can play Midi Files: Compile with Partition Scheme Hughe APP. The midi file was converted with xxd to a header file.
* It seems that only midi files type 0 are supported.
* @version 0.1
* @date 2021-01-24
*
* @copyright Copyright (c) 2021
*
*/
#include "AudioTools.h"
#include "AudioTools/AudioLibs/VS1053Stream.h"
#include "bora0.h"
VS1053Stream out; // output
MemoryStream music(bora0_midi, bora0_midi_len);
StreamCopyT<int16_t> copier(out, music); // copies sound into i2s
void setup(){
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
auto config = out.defaultConfig(TX_MODE);
config.is_encoded_data = true; // vs1053 is accepting encoded midi data
//config.cs_pin = VS1053_CS;
//config.dcs_pin = VS1053_DCS;
//config.dreq_pin = VS1053_DREQ;
//config.reset_pin = VS1053_RESET;
out.begin(config);
}
void loop(){
if (!copier.copy()){
delay(60000); //
out.end();
stop();
}
}

View File

@@ -0,0 +1,42 @@
/**
* @file streams-url_mp3-audiokit.ino
* @author Phil Schatzmann
* @brief Copy MP3 stream from url and output it on vs1053
* @version 0.1
* @date 2021-96-25
*
* @copyright Copyright (c) 2021
*/
// install https://github.com/pschatzmann/arduino-vs1053.git
#include "AudioTools.h"
#include "AudioTools/AudioLibs/VS1053Stream.h"
#include "AudioTools/Communication/AudioHttp.h"
URLStream url("ssid","password"); // or replace with ICYStream to get metadata
VS1053Stream vs1053; // final output
StreamCopy copier(vs1053, url); // copy url to decoder
void setup(){
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
// setup vs1053
auto cfg = vs1053.defaultConfig();
cfg.is_encoded_data = true; // vs1053 is accepting encoded data
// Use your custom pins or define in AudioCodnfig.h
//cfg.cs_pin = VS1053_CS;
//cfg.dcs_pin = VS1053_DCS;
//cfg.dreq_pin = VS1053_DREQ;
//cfg.reset_pin = VS1053_RESET;
vs1053.begin(cfg);
// mp3 radio
url.begin("http://stream.srg-ssr.ch/m/rsj/mp3_128","audio/mp3");
}
void loop(){
copier.copy();
}

View File

@@ -0,0 +1,37 @@
/**
* @file streams-vs1053-serial.ino
* @author Phil Schatzmann
* @brief Reads audio data from the VS1053 microphone
*
* @author Phil Schatzmann
* @copyright GPLv3
*/
#include "AudioTools.h"
#include "AudioTools/AudioLibs/VS1053Stream.h"
AudioInfo info(1600, 1, 16);
VS1053Stream in; // Access VS1053/VS1003 as stream
CsvOutput<int16_t> csvOutput(Serial);
StreamCopy copier(csvOutput, in); // copy in to csvOutput
// Arduino Setup
void setup(void) {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
auto cfg = in.defaultConfig(RX_MODE);
cfg.copyFrom(info);
cfg.input_device = VS1053_MIC; // or VS1053_AUX
in.begin(cfg);
// make sure that we have the correct channels set up
csvOutput.begin(info);
}
// Arduino loop - copy data
void loop() {
copier.copy();
}