From f0c07f0b306d00f0f9e3f606fc82c5ee938ae986 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Sun, 13 Oct 2024 21:07:45 +0800 Subject: [PATCH] yyc12345 --- .editorconfig | 7 +++++++ CMakeLists.txt | 8 +++++++- mainwindow.cpp | 22 +++++++++++++++++++++- mainwindow.h | 2 ++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..d02e348 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 4 \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e1bcd9..8ed11c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,12 @@ find_package(Qt6 6.6 COMPONENTS Widgets Multimedia Network LinguistTools REQUIRE find_package(KF6Codecs 6.1.0) find_package(PkgConfig) +option(KISSFFT_PKGCONFIG OFF) +option(KISSFFT_STATIC ON) +option(KISSFFT_TEST OFF) +option(KISSFFT_TOOLS OFF) +add_subdirectory(kissfft EXCLUDE_FROM_ALL) + if (USE_QTEXTCODEC) find_package(Qt6 6.6 COMPONENTS Core5Compat REQUIRED) endif() @@ -84,7 +90,7 @@ if (TARGET KF6::Codecs) target_link_libraries (${EXE_NAME} PRIVATE KF6::Codecs) endif () -target_link_libraries(${EXE_NAME} PRIVATE Qt::Widgets Qt::Multimedia Qt::Network) +target_link_libraries(${EXE_NAME} PRIVATE Qt::Widgets Qt::Multimedia Qt::Network kissfft::kissfft) if (USE_QTEXTCODEC) target_compile_definitions(${EXE_NAME} PRIVATE USE_QTEXTCODEC=1) diff --git a/mainwindow.cpp b/mainwindow.cpp index 6d1b7ae..fbc20ee 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include #include #include @@ -32,6 +34,8 @@ #include #include +#include + constexpr QSize miniSize(490, 160); constexpr QSize fullSize(490, 420); @@ -41,14 +45,16 @@ MainWindow::MainWindow(QWidget *parent) , m_mediaDevices(new QMediaDevices(this)) , m_mediaPlayer(new QMediaPlayer(this)) , m_audioOutput(new QAudioOutput(this)) + , m_audioBufferOutput(new QAudioBufferOutput(this)) , m_lrcbar(new LrcBar(nullptr)) , m_playlistManager(new PlaylistManager(this)) { ui->setupUi(this); m_playlistManager->setAutoLoadFilterSuffixes({ - "*.mp3", "*.wav", "*.aiff", "*.ape", "*.flac", "*.ogg", "*.oga", "*.mpga", "*.aac" + "*.mp3", "*.wav", "*.aiff", "*.ape", "*.flac", "*.ogg", "*.oga", "*.mpga", "*.aac", "*.tta" }); m_mediaPlayer->setAudioOutput(m_audioOutput); + m_mediaPlayer->setAudioBufferOutput(m_audioBufferOutput); m_mediaPlayer->setLoops(QMediaPlayer::Infinite); ui->playlistView->setModel(m_playlistManager->model()); @@ -400,6 +406,19 @@ void MainWindow::initConnections() m_audioOutput->setDevice(m_mediaDevices->defaultAudioOutput()); }); + connect(m_audioBufferOutput, &QAudioBufferOutput::audioBufferReceived, this, [=](const QAudioBuffer& buffer) { + const QAudioFormat&& fmt = buffer.format(); + QAudioFormat::SampleFormat sampleFormat = fmt.sampleFormat(); + int channelCount = fmt.channelCount(); + if (sampleFormat == QAudioFormat::Int16 && channelCount == 2) { + const QAudioBuffer::S16S * data = buffer.constData(); + for (int i = 0; i < buffer.sampleCount(); ++i) { + // ...? + } + } + // TODO: draw spectrum + }); + connect(m_mediaPlayer, &QMediaPlayer::sourceChanged, this, [=](){ QUrl fileUrl(m_mediaPlayer->source()); @@ -438,6 +457,7 @@ void MainWindow::initConnections() setAudioMetadataForDisplay(metadata.stringValue(QMediaMetaData::Title), metadata.stringValue(QMediaMetaData::Author), metadata.stringValue(QMediaMetaData::AlbumTitle)); + setAudioPropertyInfoForDisplay(-1, metadata.value(QMediaMetaData::AudioBitRate).toInt() / 1000, -1, metadata.stringValue(QMediaMetaData::FileFormat)); #endif // NO_TAGLIB QVariant coverArt(metadata.value(QMediaMetaData::ThumbnailImage)); if (!coverArt.isNull()) { diff --git a/mainwindow.h b/mainwindow.h index a6a770b..c88834e 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -14,6 +14,7 @@ namespace Ui { class MainWindow; } class QMediaDevices; class QMediaPlayer; class QAudioOutput; +class QAudioBufferOutput; class QPropertyAnimation; QT_END_NAMESPACE @@ -92,6 +93,7 @@ private: QMediaDevices *m_mediaDevices; QMediaPlayer *m_mediaPlayer; QAudioOutput *m_audioOutput; + QAudioBufferOutput *m_audioBufferOutput; LrcBar *m_lrcbar; QPropertyAnimation *m_fadeOutAnimation; PlaylistManager *m_playlistManager;