-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07bfcfd
commit 2c95afd
Showing
44 changed files
with
18,026 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#pragma once | ||
|
||
#include <QApplication> | ||
#include <QAudioOutput> | ||
#include <QIODevice> | ||
#include <QDebug> | ||
|
||
class AudioPlayer { | ||
public: | ||
AudioPlayer() { | ||
|
||
} | ||
|
||
void SetFormat(int dst_nb_samples, int rate, int sample_size, int nch) { | ||
QAudioFormat format; | ||
format.setSampleRate(rate); // 采样率 | ||
format.setChannelCount(nch); // 声道数 | ||
format.setSampleSize(sample_size); // 采样大小 | ||
format.setCodec("audio/pcm"); // 音频编码格式 | ||
format.setByteOrder(QAudioFormat::LittleEndian); // 字节顺序 | ||
format.setSampleType(QAudioFormat::SignedInt); // 采样类型 | ||
|
||
int len = dst_nb_samples * format.channelCount() * format.sampleSize()/8; | ||
|
||
|
||
// 创建 QAudioOutput 对象 | ||
audioOutput = new QAudioOutput(format); | ||
|
||
audioOutput->setVolume(1.0); // 设置音量(0.0 - 1.0) | ||
|
||
// 打开音频输出 | ||
outputDevice = audioOutput->start(); | ||
} | ||
|
||
void writeData(const char* data, qint64 len) { | ||
//audioData.insert(0, data, len); | ||
|
||
outputDevice->write(data, len); | ||
} | ||
|
||
void Close() | ||
{ | ||
|
||
if (outputDevice != nullptr) | ||
{ | ||
outputDevice->close(); | ||
delete outputDevice; | ||
outputDevice = NULL; | ||
} | ||
if (audioOutput) | ||
{ | ||
//audioOutput->stop(); | ||
audioOutput = NULL; | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
private: | ||
QIODevice* outputDevice; | ||
|
||
QAudioOutput* audioOutput; | ||
}; | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup /> | ||
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<QtLastBackgroundBuild>2024-04-27T07:48:48.9239996Z</QtLastBackgroundBuild> | ||
</PropertyGroup> | ||
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<QtLastBackgroundBuild>2024-04-27T07:48:48.9958274Z</QtLastBackgroundBuild> | ||
</PropertyGroup> | ||
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<QtLastBackgroundBuild>2024-04-27T07:48:49.1263235Z</QtLastBackgroundBuild> | ||
</PropertyGroup> | ||
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<QtLastBackgroundBuild>2024-04-27T07:48:49.2096193Z</QtLastBackgroundBuild> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.