mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-05-19 03:35:32 +01:00
applied platformio structure
This commit is contained in:
14
lib/spotify/cspot/bell/example/CMakeLists.txt
Normal file
14
lib/spotify/cspot/bell/example/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
project(bell_example)
|
||||
cmake_minimum_required(VERSION 3.18)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../ ${CMAKE_CURRENT_BINARY_DIR}/bell)
|
||||
|
||||
file(GLOB SOURCES "*.cpp")
|
||||
include_directories(".")
|
||||
|
||||
add_executable(bell_example ${SOURCES})
|
||||
target_link_libraries(bell_example bell ${CMAKE_DL_LIBS} ${THINGS_TO_LINK})
|
||||
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
|
||||
103
lib/spotify/cspot/bell/example/main.cpp
Normal file
103
lib/spotify/cspot/bell/example/main.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#include <memory.h>
|
||||
#include <atomic>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "AudioCodecs.h"
|
||||
#include "AudioContainers.h"
|
||||
#include "BellHTTPServer.h"
|
||||
#include "BellTask.h"
|
||||
#include "CentralAudioBuffer.h"
|
||||
#include "Compressor.h"
|
||||
#include "DecoderGlobals.h"
|
||||
#include "EncodedAudioStream.h"
|
||||
#include "HTTPClient.h"
|
||||
#include "PortAudioSink.h"
|
||||
|
||||
#include <BellDSP.h>
|
||||
#include <BellLogger.h>
|
||||
|
||||
std::shared_ptr<bell::CentralAudioBuffer> audioBuffer;
|
||||
std::atomic<bool> isPaused = false;
|
||||
|
||||
class AudioPlayer : bell::Task {
|
||||
public:
|
||||
std::unique_ptr<PortAudioSink> audioSink;
|
||||
std::unique_ptr<bell::BellDSP> dsp;
|
||||
|
||||
AudioPlayer() : bell::Task("player", 1024, 0, 0) {
|
||||
this->audioSink = std::make_unique<PortAudioSink>();
|
||||
this->audioSink->setParams(44100, 2, 16);
|
||||
this->dsp = std::make_unique<bell::BellDSP>(audioBuffer);
|
||||
startTask();
|
||||
}
|
||||
|
||||
void runTask() override {
|
||||
while (true) {
|
||||
if (audioBuffer->hasAtLeast(64) || isPaused) {
|
||||
auto chunk = audioBuffer->readChunk();
|
||||
|
||||
if (chunk != nullptr && chunk->pcmSize > 0) {
|
||||
// this->dsp->process(chunk->pcmData, chunk->pcmSize, 2, 44100,
|
||||
// bell::BitWidth::BW_16);
|
||||
|
||||
this->audioSink->feedPCMFrames(chunk->pcmData, chunk->pcmSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
bell::setDefaultLogger();
|
||||
bell::createDecoders();
|
||||
size_t size = sizeof(void*);
|
||||
audioBuffer = std::make_shared<bell::CentralAudioBuffer>(512);
|
||||
auto task = AudioPlayer();
|
||||
|
||||
auto url = "http://193.222.135.71/378";
|
||||
// std::ifstream file("aactest.aac", std::ios::binary);
|
||||
|
||||
auto req = bell::HTTPClient::get(url);
|
||||
auto container = AudioContainers::guessAudioContainer(req->stream());
|
||||
auto codec = AudioCodecs::getCodec(container.get());
|
||||
|
||||
uint32_t dataLen;
|
||||
while (true) {
|
||||
uint8_t* data = codec->decode(container.get(), dataLen);
|
||||
|
||||
if (!data) {
|
||||
std::cout << "data invalid" << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
size_t toWrite = dataLen;
|
||||
while (toWrite > 0) {
|
||||
toWrite -= audioBuffer->writePCM(data + dataLen - toWrite, toWrite, 0);
|
||||
}
|
||||
|
||||
// std::cout << dataLen << std::endl;
|
||||
}
|
||||
|
||||
// return 0;
|
||||
|
||||
// std::vector<uint8_t> frameData(1024 * 10);
|
||||
// /*
|
||||
// while (true) {
|
||||
// size_t bytes =audioStream->decodeFrame(frameData.data());
|
||||
// std::cout << bytes <<std::endl;
|
||||
|
||||
// size_t toWrite = bytes;
|
||||
|
||||
// if (!isPaused) {
|
||||
// while (toWrite > 0) {
|
||||
// toWrite -= audioBuffer->writePCM(frameData.data() + bytes - toWrite,
|
||||
// toWrite, 0);
|
||||
// }
|
||||
// }
|
||||
// }*/
|
||||
return 0;
|
||||
}
|
||||
13
lib/spotify/cspot/bell/example/scripts/dsp_spectogram.py
Normal file
13
lib/spotify/cspot/bell/example/scripts/dsp_spectogram.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import matplotlib.pyplot as plt
|
||||
from scipy import signal
|
||||
from scipy.io import wavfile
|
||||
|
||||
sample_rate, samples = wavfile.read('out.wav')
|
||||
print(sample_rate)
|
||||
frequencies, times, spectrogram = signal.spectrogram(samples, sample_rate)
|
||||
|
||||
plt.pcolormesh(times, frequencies, spectrogram)
|
||||
plt.imshow(spectrogram)
|
||||
plt.ylabel('Frequency [Hz]')
|
||||
plt.xlabel('Time [sec]')
|
||||
plt.show()
|
||||
Reference in New Issue
Block a user