我正在使用Portaudio和opus在VOIP客户端上工作.我从一个帧中读取麦克风 - 使用Opus对每个帧进行编码并将其放入列表--pop列表中的第一个元素并对其进行解码 - 使用portaudio读取它
如果我在没有编码声音的情况下做同样的事情,那么效果很好.但是当我使用Opus时我的声音很糟糕,我无法理解声音(这对于voip客户端来说是不好的)
HandlerOpus::HandlerOpus(int sample_rate, int num_channels)
{
this->num_channels = num_channels;
this->enc = opus_encoder_create(sample_rate, num_channels, OPUS_APPLICATION_VOIP, &this->error);
this->dec = opus_decoder_create(sample_rate, num_channels, &this->error);
opus_int32 rate;
opus_encoder_ctl(enc, OPUS_GET_BANDWIDTH(&rate));
this->encoded_data_size = rate;
}
HandlerOpus::~HandlerOpus(void)
{
opus_encoder_destroy(this->enc);
opus_decoder_destroy(this->dec);
}
unsigned char *HandlerOpus::encodeFrame(const float *frame, int frame_size)
{
unsigned char *compressed_buffer;
int ret;
compressed_buffer = new (unsigned char[this->encoded_data_size]);
ret = opus_encode_float(this->enc, frame, frame_size, compressed_buffer, this->encoded_data_size);
return (compressed_buffer);
}
float *HandlerOpus::decodeFrame(const unsigned char *data, int frame_size)
{
int ret;
float *frame = new …Run Code Online (Sandbox Code Playgroud) 在阅读了这个问题之后:"如何区分共享和全局内存的指针?" ,我决定尝试isspacep.local,isspacep.global并isspacep.shared在一个简单的测试程序.
本地和共享内存的测试始终有效,但全局内存测试并不总是有效,例如,在调试模式下编译设备代码时(-G).
起初我以为编译器检测到我使用虚拟向量作为全局内存并以不同方式处理它,所以我使用-Xcicc -O0 -Xptxas -O0(参见"完全禁用NVCC上的优化").如果我计算sm_30,则正确检测全局内存.但是,如果我使用sm_20或计算,sm_21则不会检测到全局内存.请注意-G,任何sm >= 20作品.
这里有什么我想念的吗?使用时是否有一个额外的标志给编译器-G可以解释这些差异?
nvcc test_pointer.cu -arch = sm_20 -Xcicc -O0 -Xptxas -O0 -Xptxas -v -o test_pointer
#include <stdio.h>
#include <cuda.h>
#define CUDA_CHECK_ERROR() __cuda_check_errors(__FILE__, __LINE__)
#define CUDA_SAFE_CALL(err) __cuda_safe_call(err, __FILE__, __LINE__)
inline void __cuda_check_errors(const char *filename, const int line_number)
{
cudaError err = cudaDeviceSynchronize();
if(err != cudaSuccess)
{ …Run Code Online (Sandbox Code Playgroud) 到目前为止,我可以读取每一行并将其打印到控制台:
void readFile(){
string line;
ifstream myfile("example1.pgm");
if (myfile.is_open()){
while (myfile.good()){
getline (myfile,line);
cout << line;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,pgm文件显然在数据开始之前总是有以下内容:
P2
# test.pgm
24 7
15
Run Code Online (Sandbox Code Playgroud)
我如何调整我的代码,以便检查"P2"是否存在,忽略任何注释(#),并存储变量和后续像素数据?
我有点失落,对c ++很陌生,所以任何帮助都是有用的.
谢谢
这个问题是我提出的另一个问题的副产品boost::fusion.我们的想法是使用boost::fusion迭代包含N维数组的大型C风格结构.这些阵列的计算是通过Eigen.通过使用boost::fusion,可以对整个C结构应用简单的算术运算,例如标量乘法或向量加法.
在处理二进制操作时,我使用boost::fusion::zip形成单个序列,并boost::fusion::for_each迭代其他序列.
问题boost::fusion::zip是它构建const序列,而我需要修改其中一个值(例如,添加的返回值).因此,我最终使用const_cast修改该值(Eigen向量),但由于某种原因我不能result_ref在add()函数中使用a .这是为什么?
而且,有没有更好(或更简单)的方法来实现我想要做的事情?boost::fusion::zip可能不是最合适的,但我找不到任何其他简单的方法来做到这一点.
#include <iostream>
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/algorithm/iteration/for_each.hpp>
#include <boost/fusion/include/for_each.hpp>
#include <boost/fusion/algorithm/transformation/zip.hpp>
#include <boost/fusion/include/zip.hpp>
#include <boost/bind.hpp>
#include <boost/fusion/container/vector/vector30.hpp>
#include <boost/fusion/include/vector30.hpp>
#include <boost/fusion/sequence/intrinsic/at_c.hpp>
#include <boost/fusion/include/at_c.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <Eigen/Core>
template <class type_const_ref>
struct remove_const_ref
{
typedef typename boost::remove_reference <type_const_ref>::type type_const;
typedef typename boost::remove_const <type_const_ref>::type type_ref;
typedef …Run Code Online (Sandbox Code Playgroud) 在为CUDA编译器进行错误报告时,我最终在gcc的预处理步骤中发现了这种奇怪的行为。我目前使用gcc 4.8.2。
#include <assert.h>
int main()
{
int a = 1;
assert (a >= 0);
assert (a
>= 0);
}
Run Code Online (Sandbox Code Playgroud)
gcc -E -x c ++ -m64 -g -o“ test.cpp4.ii”“ test.cpp”
# 2 "test.cpp" 2
int main()
{
int a = 1;
((a >= 0) ? static_cast<void> (0) : __assert_fail ("a >= 0", "test.cpp", 6, __PRETTY_FUNCTION__));
((a >= 0) ? static_cast<void> (0) : __assert_fail ("a >= 0",
"test.cpp"
# 7 "test.cpp" 3 4
,
8
# 7 "test.cpp" …Run Code Online (Sandbox Code Playgroud) 我正在使用CUDA 5/VC 2008将图像从彩色转换为灰度.
CUDA内核是:
__global__ static void rgba_to_grayscale( const uchar4* const rgbaImage, unsigned char * const greyImage,
int numRows, int numCols)
{
int pos = blockIdx.x * blockDim.x + threadIdx.x;
if (pos < numRows * numCols) {
uchar4 zz = rgbaImage[pos];
float out = 0.299f * zz.x + 0.587f * zz.y + 0.114f * zz.z;
greyImage[pos] = (unsigned char) out;
}
}
Run Code Online (Sandbox Code Playgroud)
C++函数是:
inline unsigned char rgba_to_grayscale( uchar4 rgbaImage)
{
return (unsigned char) 0.299f * rgbaImage.x + 0.587f * rgbaImage.y …Run Code Online (Sandbox Code Playgroud) 我正在使用 Pyaudio 从麦克风捕获音频,并尝试使用 opus 编解码器对其进行编码/解码。我正在使用 SvartalF 制作的 libopus 绑定(https://github.com/svartalf/python-opus。
这是我的代码:
import pyaudio
from opus import encoder, decoder
def streaming(p):
chunk = 960
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 48000
streamin = p.open(format = FORMAT,
channels = CHANNELS,
rate = RATE,
input = True,
input_device_index = 7,
frames_per_buffer = chunk)
streamout = p.open(format = FORMAT,
channels = CHANNELS,
rate = 48000,
output = True,
output_device_index = p.get_default_input_device_info()["index"],
frames_per_buffer = chunk)
enc = encoder.Encoder(RATE,CHANNELS,'voip')
dec = decoder.Decoder(RATE,CHANNELS)
data …Run Code Online (Sandbox Code Playgroud) 首先,我对 CUDA 编程相当陌生,所以我对这样一个简单的问题表示歉意。我已经研究了在 GPU 内核调用中确定 dimGrid 和 dimBlock 的最佳方法,但由于某种原因,我还没有完全让它工作。
我的家用 PC 上有一块GeForce GTX 580(计算能力 2.0)。每块 1024 个线程等。我可以让我的代码在这台 PC 上正常运行。我的 GPU 正在填充大小为 988*988 的距离数组。下面是部分代码:
#define SIZE 988
__global__ void createDistanceTable(double *d_distances, double *d_coordinates)
{
int col = blockIdx.x * blockDim.x + threadIdx.x;
int row = blockIdx.y * blockDim.y + threadIdx.y;
if(row < SIZE && col < SIZE)
d_distances[row * SIZE + col] =
acos(__sinf(d_coordinates[row * 2 + 0])*
__sinf(d_coordinates[col * 2 + 0])+__cosf(d_coordinates[row * 2 + 0])* …Run Code Online (Sandbox Code Playgroud) 我有一个关于代码和平的问题.
...............
cv::Mat image;
image = cv::imread(filename.c_str(), CV_LOAD_IMAGE_COLOR);
if (image.empty()) {
std::cerr << "Couldn't open file: " << filename << std::endl;
exit(1);
}
cv::cvtColor(image, imageRGBA, CV_BGR2RGBA);
imageGrey.create(image.rows, image.cols, CV_8UC1);
*inputImage = (uchar4 *)imageRGBA.ptr<unsigned char>(0);
*greyImage = imageGrey.ptr<unsigned char>(0);
Run Code Online (Sandbox Code Playgroud)
据我所知,我们创建了一个openCV mat对象.将图像读入其中.但是为什么我们使用filename.c_str()?而不只是文件名?为什么我们将BGR转换为RGBA?
cv::cvtColor(image, imageRGBA, CV_BGR2RGBA);我在文档中读到imread将图像读取为RGB而不是BGR.对我们来说最令人困惑的是这部分:
*inputImage = (uchar4 *)imageRGBA.ptr<unsigned char>(0);
*greyImage = imageGrey.ptr<unsigned char>(0);
Run Code Online (Sandbox Code Playgroud)
这里发生了什么事?为什么我们需要所有这些演员?我知道这是一个很多问题,但我真的想知道这里发生了什么.)