- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我目前正在开发一个 VOIP 应用程序。为此,我使用 PortAudio 库检索和播放声音,并使用 Opus 库编码和解码声音数据包。
目前,我成功地使用了 PortAudio。我的程序只是做:
音质绝对好。
我现在正在尝试对声音数据包进行编码和解码。我编写了一个 EncodeManagerClass 来执行此操作,我的程序现在执行以下操作:
但现在,音质绝对糟糕(而且在 VOIP 应用程序中显然是有问题的)。
这是我的 EncodeManager
类:
class EncodeManager {
// ctor - dtor
public:
EncodeManager(void);
~EncodeManager(void);
// coplien form
private:
EncodeManager(const EncodeManager &) {}
const EncodeManager &operator=(const EncodeManager &) { return *this; }
// encode - decode
public:
Sound::Encoded encode(const Sound::Decoded &sound);
Sound::Decoded decode(const Sound::Encoded &sound);
// attributes
private:
OpusEncoder *mEncoder;
OpusDecoder *mDecoder;
};
这是源文件:
EncodeManager::EncodeManager(void) {
int error;
mEncoder = opus_encoder_create(Sound::SAMPLE_RATE, Sound::NB_CHANNELS, OPUS_APPLICATION_VOIP, &error);
if (error != OPUS_OK)
throw new SoundException("fail opus_encoder_create");
mDecoder = opus_decoder_create(Sound::SAMPLE_RATE, Sound::NB_CHANNELS, &error);
if (error != OPUS_OK)
throw new SoundException("fail opus_decoder_create");
}
EncodeManager::~EncodeManager(void) {
if (mEncoder)
opus_encoder_destroy(mEncoder);
if (mDecoder)
opus_decoder_destroy(mDecoder);
}
Sound::Encoded EncodeManager::encode(const Sound::Decoded &sound) {
Sound::Encoded encoded;
encoded.buffer = new unsigned char[sound.size];
encoded.size = opus_encode_float(mEncoder, sound.buffer, Sound::FRAMES_PER_BUFFER, encoded.buffer, sound.size);
if (encoded.size < 0)
throw new SoundException("fail opus_encode_float");
return encoded;
}
Sound::Decoded EncodeManager::decode(const Sound::Encoded &sound) {
Sound::Decoded decoded;
decoded.buffer = new float[Sound::FRAMES_PER_BUFFER * Sound::NB_CHANNELS];
decoded.size = opus_decode_float(mDecoder, sound.buffer, sound.size, decoded.buffer, Sound::FRAMES_PER_BUFFER, 0);
if (decoded.size < 0)
throw new SoundException("fail opus_decode_float");
return decoded;
}
这是我的主要内容:
int main(void) {
SoundInputDevice input;
SoundOutputDevice output;
EncodeManager encodeManager;
input.startStream();
output.startStream();
while (true) {
Sound::Decoded *sound;
input >> sound;
if (sound) {
Sound::Encoded encodedSound = encodeManager.encode(*sound);
Sound::Decoded decodedSound = encodeManager.decode(encodedSound);
output << &decodedSound;
}
}
return 0;
}
附加信息:
const int SAMPLE_RATE = 48000;
const int NB_CHANNELS = 2;
const int FRAMES_PER_BUFFER = 480;
我已经尝试使用 opus_encode_ctl
(带宽、比特率、VBR)配置 opus 编码器,但它根本不起作用:音质仍然很差。
即使我更改 SAMPLE_RATE 或 FRAME_PER_BUFFER,音质也不会提高...
我是否遗漏了有关 PortAudio/Opus 的内容?
最佳答案
我终于找到了解决办法。
问题不是来自 Opus,而是来自主要...
if (sound) {
Sound::Encoded encodedSound = encodeManager.encode(*sound);
Sound::Decoded decodedSound = encodeManager.decode(encodedSound);
output << &decodedSound;
}
在这里,我将一个局部变量传递到我的输出流。但是输出流是异步工作的:所以我的变量在播放声音打包之前就被销毁了。
使用指针是解决问题最简单的方法。我个人决定稍微重构一下我的代码。
关于c++ - Portaudio + 作品 : Horrible sound quality,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26401807/
我见过很多网页都有一个简单的声音开/声音关按钮,当你按下声音时,它会播放音乐或一些 mp3 文件,当你按下声音时,它会关闭。 我该怎么做? 你好,我没打算使用 Flash -- 如果有一个标准插件我可
我正在尝试将 sound.Sound() 函数应用于循环中的 numpy 数组。具体来说,我想循环执行以下操作。 a_wave 到 d_wave 是 numpy 数组。 stim_a = sound.
我有一个项目需要我显示上传声音的波形。声音始终是 MP3,大部分时间是 22.05 kHz 单声道,只有语音。该项目是用 Flex/ActionScript 3 编写的。它旨在在浏览器中运行,但如果有
我正在尝试对 FMOD 库中的 Sound.readData 和 Sound.lock 之间的差异进行排序(我正在使用 C#/C++ 进行编程,但我会使用任何语言来回答!)。最终目标是创建波形 Vie
我在录制我的应用程序播放的系统声音时遇到问题。与“会说话的汤姆猫”iOS 应用程序类似,我的应用程序应录制屏幕视频和声音。屏幕录制和转换为视频,工作正常,问题是使用核心音频录制音频。我是第一次使用 C
我正在使用 Java 声音通过 Clip.start() 方法播放大量声音样本。 鉴于此,控制播放音量的最佳方式是什么? 特别是,我非常希望该解决方案能够跨平台可靠地工作。 最佳答案 FloatCon
我正在尝试实现一个循环播放一系列音调的应用程序。 实际上,我使用 OpenAL 并且我对这种框架的经验是积极的,因为我也可以发出声音。 这是场景: 从 CAF 文件中加载短声音(3 秒) 循环播放该声
我正在尝试使用javax.sound.sampled库中的一些类。但是,即使在我新手看来,文件就在那里,Android Studio也不会导入它们。。是不是有什么东西没放好?。AndroidStudi
当我在游戏中移动时,我的声音不是完整播放,而是循环播放几毫秒。 这是我的代码: using System.Collections; using System.Collections.Generic;
每当我在 Android 设备上的 LibGDX 游戏中播放音效时,游戏都会卡顿。我已经在三款三星设备上尝试过这款游戏: 在 Galaxy S7 Edge (2016, Android 8) 和 Ga
我创建了一个应用程序,它播放小轨道的播放列表,一切正常,直到 Windows Phone 8.1 更新 问题是 -> 轨道结束时有奇怪的滴答声” 所以我尝试在 xbox 音乐播放器中播放轨道它也有相同
我已阅读 How to use selected value of UIPickerView as time interval for notifications?一遍又一遍,但我不知道如何将答案应用
每当我使用 Java 中的 SourceDataLine 类读取构成音频的字节时,我都会在播放时听到烦人的嗡嗡声背景噪音。谁能告诉我如何才能完全摆脱它?提前致谢。 更新:我已经发布了代码,但我的实际目
这感觉像是我在这个网站上提出的第 100 个 Java Sound 相关问题,但我无法在 Java Sound API 或 jsresources.org 的任何地方找到答案。我正在制作一个多轨录音机
我已经使用 Parse.com 在我的应用程序中实现了推送通知系统,一切正常! 我唯一的问题是当通知到达时:它不播放任何声音! 我进入设置(在我的平板电脑中),在通知下,我看到了这个: 如您所见,“声
本文整理了Java中com.bugvm.sound.YSourceDataLine类的一些代码示例,展示了YSourceDataLine类的具体用法。这些代码示例主要来源于Github/Stackov
本文整理了Java中com.bugvm.sound.YTargetDataLine类的一些代码示例,展示了YTargetDataLine类的具体用法。这些代码示例主要来源于Github/Stackov
本文整理了Java中com.bugvm.sound.YNative类的一些代码示例,展示了YNative类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,
本文整理了Java中com.bugvm.sound.YClip类的一些代码示例,展示了YClip类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些
本文整理了Java中com.bugvm.sound.YLine类的一些代码示例,展示了YLine类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些
我是一名优秀的程序员,十分优秀!