This commit is contained in:
Gary Wang 2024-10-13 21:07:45 +08:00
parent 044bb34390
commit f0c07f0b30
4 changed files with 37 additions and 2 deletions

7
.editorconfig Normal file
View File

@ -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

View File

@ -20,6 +20,12 @@ find_package(Qt6 6.6 COMPONENTS Widgets Multimedia Network LinguistTools REQUIRE
find_package(KF6Codecs 6.1.0) find_package(KF6Codecs 6.1.0)
find_package(PkgConfig) 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) if (USE_QTEXTCODEC)
find_package(Qt6 6.6 COMPONENTS Core5Compat REQUIRED) find_package(Qt6 6.6 COMPONENTS Core5Compat REQUIRED)
endif() endif()
@ -84,7 +90,7 @@ if (TARGET KF6::Codecs)
target_link_libraries (${EXE_NAME} PRIVATE KF6::Codecs) target_link_libraries (${EXE_NAME} PRIVATE KF6::Codecs)
endif () 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) if (USE_QTEXTCODEC)
target_compile_definitions(${EXE_NAME} PRIVATE USE_QTEXTCODEC=1) target_compile_definitions(${EXE_NAME} PRIVATE USE_QTEXTCODEC=1)

View File

@ -17,6 +17,8 @@
#include <QMediaPlayer> #include <QMediaPlayer>
#include <QMediaMetaData> #include <QMediaMetaData>
#include <QAudioOutput> #include <QAudioOutput>
#include <QAudioBuffer>
#include <QAudioBufferOutput>
#include <QPropertyAnimation> #include <QPropertyAnimation>
#include <QFileDialog> #include <QFileDialog>
#include <QTime> #include <QTime>
@ -32,6 +34,8 @@
#include <QMessageBox> #include <QMessageBox>
#include <QStringBuilder> #include <QStringBuilder>
#include <kissfft.hh>
constexpr QSize miniSize(490, 160); constexpr QSize miniSize(490, 160);
constexpr QSize fullSize(490, 420); constexpr QSize fullSize(490, 420);
@ -41,14 +45,16 @@ MainWindow::MainWindow(QWidget *parent)
, m_mediaDevices(new QMediaDevices(this)) , m_mediaDevices(new QMediaDevices(this))
, m_mediaPlayer(new QMediaPlayer(this)) , m_mediaPlayer(new QMediaPlayer(this))
, m_audioOutput(new QAudioOutput(this)) , m_audioOutput(new QAudioOutput(this))
, m_audioBufferOutput(new QAudioBufferOutput(this))
, m_lrcbar(new LrcBar(nullptr)) , m_lrcbar(new LrcBar(nullptr))
, m_playlistManager(new PlaylistManager(this)) , m_playlistManager(new PlaylistManager(this))
{ {
ui->setupUi(this); ui->setupUi(this);
m_playlistManager->setAutoLoadFilterSuffixes({ 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->setAudioOutput(m_audioOutput);
m_mediaPlayer->setAudioBufferOutput(m_audioBufferOutput);
m_mediaPlayer->setLoops(QMediaPlayer::Infinite); m_mediaPlayer->setLoops(QMediaPlayer::Infinite);
ui->playlistView->setModel(m_playlistManager->model()); ui->playlistView->setModel(m_playlistManager->model());
@ -400,6 +406,19 @@ void MainWindow::initConnections()
m_audioOutput->setDevice(m_mediaDevices->defaultAudioOutput()); 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<QAudioBuffer::S16S>();
for (int i = 0; i < buffer.sampleCount(); ++i) {
// ...?
}
}
// TODO: draw spectrum
});
connect(m_mediaPlayer, &QMediaPlayer::sourceChanged, this, [=](){ connect(m_mediaPlayer, &QMediaPlayer::sourceChanged, this, [=](){
QUrl fileUrl(m_mediaPlayer->source()); QUrl fileUrl(m_mediaPlayer->source());
@ -438,6 +457,7 @@ void MainWindow::initConnections()
setAudioMetadataForDisplay(metadata.stringValue(QMediaMetaData::Title), setAudioMetadataForDisplay(metadata.stringValue(QMediaMetaData::Title),
metadata.stringValue(QMediaMetaData::Author), metadata.stringValue(QMediaMetaData::Author),
metadata.stringValue(QMediaMetaData::AlbumTitle)); metadata.stringValue(QMediaMetaData::AlbumTitle));
setAudioPropertyInfoForDisplay(-1, metadata.value(QMediaMetaData::AudioBitRate).toInt() / 1000, -1, metadata.stringValue(QMediaMetaData::FileFormat));
#endif // NO_TAGLIB #endif // NO_TAGLIB
QVariant coverArt(metadata.value(QMediaMetaData::ThumbnailImage)); QVariant coverArt(metadata.value(QMediaMetaData::ThumbnailImage));
if (!coverArt.isNull()) { if (!coverArt.isNull()) {

View File

@ -14,6 +14,7 @@ namespace Ui { class MainWindow; }
class QMediaDevices; class QMediaDevices;
class QMediaPlayer; class QMediaPlayer;
class QAudioOutput; class QAudioOutput;
class QAudioBufferOutput;
class QPropertyAnimation; class QPropertyAnimation;
QT_END_NAMESPACE QT_END_NAMESPACE
@ -92,6 +93,7 @@ private:
QMediaDevices *m_mediaDevices; QMediaDevices *m_mediaDevices;
QMediaPlayer *m_mediaPlayer; QMediaPlayer *m_mediaPlayer;
QAudioOutput *m_audioOutput; QAudioOutput *m_audioOutput;
QAudioBufferOutput *m_audioBufferOutput;
LrcBar *m_lrcbar; LrcBar *m_lrcbar;
QPropertyAnimation *m_fadeOutAnimation; QPropertyAnimation *m_fadeOutAnimation;
PlaylistManager *m_playlistManager; PlaylistManager *m_playlistManager;