- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在记录来自麦克风的 float 流(应该是静音)
我设置了缓冲区大小为 256 个 float 的音频队列
典型的缓冲区如下所示:
PACKET 0.004791, 0.012512,0.008423,0.000122,-0.000519,-0.002991,-0.000031,0.001801,-0.000641, 0.001190,-0.003143,-0.001587,0.001587,-0.015503,-0.019440,-0.015167,-0.017670, -0.018158,-0.019928,-0.019409,-0.024017,-0.019684,-0.024719,-0.044128,-0.043579, -0.043152,-0.046417,-0.045380,-0.050079,-0.050262,-0.049164,-0.040710,-0.036713, -0.051056,-0.045868,-0.035034,-0.033722,-0.028534,-0.027161,-0.022186,-0.018036, -0.012207,0.004303,-0.000824,-0.000610,0.014496,0.018005,0.019745,0.019226, 0.016144,0.013184,0.009003,0.014557,0.003357,-0.011353,-0.007751,-0.007660, -0.006409,-0.003357,-0.003510,-0.001038,-0.000092,0.007690,0.002655,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,-0.006897,-0.000549,0.003174,0.003540,0.003632, 0.004578,0.005280,0.001831,0.014771,0.014954,0.001801,0.009247,0.011139, 0.005249,0.008087,0.008636,0.007385,0.007263,0.016571,0.020264,0.010590, 0.014801,0.023132,0.027039,0.031128,0.031799,0.037109,0.038757,0.049438, 0.057098,0.042786,0.045593,0.052032,0.045380,0.045227,0.045837,0.043793, 0.041931,0.043976,0.046570,0.030182,0.024475,0.029877,0.026184,0.026001, 0.026611,0.031921,0.035736,0.040710,0.053070,0.042572,0.039917,0.051636, 0.053009,0.053528,0.053009,0.054962,0.055603,0.053833,0.060638,0.050171, 0.041779,0.049194,0.046356,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.041931, 0.038879,0.034515,0.031494,0.026337,0.034576,0.028992,0.014038,0.018127, 0.017822,0.015137,0.015778,0.013519,0.015564,0.014832,0.023285,0.022034, 0.006317,0.010254,0.010742,0.004303,0.003784,-0.000153,-0.002502, ~
我不明白为什么输入信号中似乎有随机的零串。似乎有什么不连续的地方。
我首先想到也许我有左声道和右声道,而右声道总是记录零。但查看我的代码,我已经清楚地将其设置为单个 channel 。
然后我想也许这些只是信号中的沉默之地。但这没有意义。如果我只有十几个零,那么 0.000000 肯定会出现非常非常小的数字,例如 0.000007 .000014,但非零数字似乎在 0.01 左右。
我刚刚尝试将音频输入切换到外部 USB 麦克风,这提高了分辨率。非零数字现在似乎在 0.001 左右。但仍然存在明显的不连续性...
请问芯片上是否进行了一些四舍五入到0的计算,如果是这种情况,可以校准吗?到底是怎么回事?
我注意到的第二个非常奇怪的问题是流氓值(value)观。
这是一个示例数据包,其中包含其中一些值(这次使用 USB 麦克风;您可以看到分辨率如何提高):
~ PACKET -0.001343, -0.001190,-0.001526,-0.001373,-0.000946,-0.001526,-0.001221,-0.001190,-0.001221, -0.001251,-0.001373,-0.001190,-0.001312,-0.001312,-0.001434,-0.001282,-0.001312, -0.001099,-0.001007,-0.001221,-0.001160,-0.001312,-0.001343,-0.001221,-0.001007, -0.001099,-0.001404,-0.001068,-0.001038,-0.001404,-0.001038,-0.001190,-0.001404, -0.001099,-0.001282,-0.001221,-0.001007,-0.001007,-0.001099,-0.001221,-0.001160, -0.001038,-0.001038,-0.001007,-0.000946,-0.001129,-0.000916,-0.000946,-0.000946, -0.000946,-0.000824,-0.000824,-0.001007,-0.000763,-0.001038,-0.000854,-0.000977, -0.000916,-0.000641,-0.000977,-0.000916,-0.000946,-0.000732,-0.000824,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, -0.000000,2.000000,-2.000000,0.000000,-0.000000,36893488147419103232.000000,-36893488147419103232.000000,0.000000, -0.000000,8589934592.000000,-8589934592.000000,0.000000,-0.000000,158456325028528675187087900672.000000,-158456325028528675187087900672.000000,0.000000, -0.000000,131072.000000,-131072.000000,0.000000,-0.000000,2417851639229258349412352.000000,-2417851639229258349412352.000000,0.000000, -0.000000,562949953421312.000000,-562949953421312.000000,0.000031,-0.000031,10384593717069655257060992658440192.000000,-10384593717069655257060992658440192.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,
这让我很困惑。这些故障的发生率很低;不到十分之一的帧。
这是否意味着我必须预处理我的音频流?
上次我使用音频设备时,我从未这样做过。我只是将音频直接输入到音调检测例程中。那没有问题。所以我想知道我是否也遇到了故障......
我的内置 MacBook 麦克风和外置 USB 麦克风均出现故障
这是我的代码:
//
// MicRecord.m
// PitchDetect
//
// Created by Pi on 05/01/2011.
//
#import "MicRecord.h"
void AudioInputCallback(
void * inUserData,
AudioQueueRef inAQ,
AudioQueueBufferRef inBuffer,
const AudioTimeStamp * inStartTime,
UInt32 inNumberPacketDescriptions,
const AudioStreamPacketDescription * inPacketDescs) ;
@implementation MicRecord
@synthesize fftFrame;
/*
- (id) init
{
if (self = [super init])
{
[self setupWithSampleRate: 44100
buffers: 12
bufLen: 512 ];
}
return self;
}
*/
// - - - - - - - -
- (void) setupWithSampleRate: (int) in_sampRate
buffers: (int) in_nBuffers
step: (int) in_step
frameSize: (int) in_frameSize
target: (id) in_target
sel: (SEL) in_sel
{
sampRate = in_sampRate;
nBuffers = in_nBuffers;
bufLen = in_step;
frameSize = in_frameSize;
targ = in_target;
sel = in_sel;
audioBuffer = calloc(nBuffers, sizeof(AudioQueueBufferRef *) );
[self setupAudioFormat];
[self setupAudioQueue];
fftFrame = calloc(frameSize, sizeof(float) );
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- (void) setupAudioFormat
{
// Set the format to 32 bit, single channel, floating point, linear PCM
const int four_bytes_per_float = 4;
const int eight_bits_per_byte = 8;
memset(& dataFormat,
(int) 0x00,
sizeof(dataFormat) );
dataFormat.mSampleRate = sampRate;
dataFormat.mFormatID = kAudioFormatLinearPCM;
dataFormat.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
dataFormat.mBytesPerPacket = four_bytes_per_float;
dataFormat.mFramesPerPacket = 1;
dataFormat.mBytesPerFrame = four_bytes_per_float;
dataFormat.mChannelsPerFrame = 1;
dataFormat.mBitsPerChannel = four_bytes_per_float * eight_bits_per_byte;
}
// - - - - - - - - - - - - - - - - -
- (void) setupAudioQueue
{
currentPacket = 0;
OSStatus status;
status = AudioQueueNewInput(& dataFormat,
AudioInputCallback,
self,
CFRunLoopGetCurrent(),
kCFRunLoopCommonModes,
0,
& queue);
for(int i = 0; i < nBuffers; i++)
{
status = AudioQueueAllocateBuffer(queue,
bufLen,
& audioBuffer[i]);
status = AudioQueueEnqueueBuffer(queue,
audioBuffer[i], 0, NULL);
}
status = AudioQueueFlush (queue);
printf("Status: %d", (int) status);
}
// - - - - - - - - - - - - - - - - -
- (void) start
{
OSStatus status = AudioQueueStart(queue, NULL);
printf("Status: %d", (int) status);
}
// - - - - - - - - - - - - - - -
- (void) stop
{
AudioQueueStop(queue, true);
for(int i = 0; i < nBuffers; i++)
AudioQueueFreeBuffer(queue, audioBuffer[i]);
AudioQueueDispose(queue, true);
}
// - - - - - - - - - -
- (void) dealloc
{
[self stop];
free (audioBuffer);
[super dealloc];
}
@end
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
void AudioInputCallback(
void * inUserData,
AudioQueueRef inAQ,
AudioQueueBufferRef inBuffer,
const AudioTimeStamp * inStartTime,
UInt32 inNumberPacketDescriptions,
const AudioStreamPacketDescription * inPacketDescs
)
{
MicRecord * x = (MicRecord *) inUserData;
//if(inNumberPacketDescriptions == 0 && recordState->dataFormat.mBytesPerPacket != 0)
//{
// inNumberPacketDescriptions = inBuffer->mAudioDataByteSize / recordState->dataFormat.mBytesPerPacket;
//}
if (0)
printf("Handling buffer %d\n", (int) x->currentPacket);
int step = x->bufLen;
if (inBuffer->mAudioDataBytesCapacity != step)
{
printf("---");
}
static int k = -1;
k++;
static float lastVal = 0;
static int count = 0;
if (k < 32) {
if (k == 0)
printf("\nfloat buf[32*%d=%d] = {", step, 32*step);
float * in_buf = (float *) inBuffer->mAudioData;
printf("\n ~\nPACKET\n");
for (int i = 0; i < step; i++)
{
/*
if (fabs(in_buf[i]) < .0001 && fabs(lastVal) > .0001)
{
printf("%d Nonzeros\n",count);
count = 0;
}
if (fabs(in_buf[i]) > .0001 && fabs(lastVal) < .0001)
{
printf("%d Zeros\n",count);
count = 0;
}
count++;
lastVal = in_buf[i];*/
printf("%f,", in_buf[i] );
if (i % 8 == 0)
printf("\n");
//if (count % (8 * 64) == 0)
// printf("\n");
count++;
}
if (k == 31)
printf("}\n");
}
// shifty frame data down by 'step' elements
// to make room for new data
// imagine cutting out elts [0] thru [step-1] (ie 'step' of them)
// first new elt at pos [0] will be [step]
memmove(& x->fftFrame[0], // dest first
& x->fftFrame[step], // src
x->frameSize - step
);
memcpy(& x->fftFrame[x->frameSize - step],
inBuffer->mAudioData,
step * sizeof(float)
);
x->currentPacket += inNumberPacketDescriptions;
// }
AudioQueueEnqueueBuffer(x->queue, inBuffer, 0, NULL);
[x->targ performSelector: x->sel];
}
最佳答案
我的第一个建议是将所有 printf
移出最低级别的回调。如果这些速度很慢,则完全有可能您在这里或那里缺少缓冲区。我不知道这是否会显示为您正在观察的零 block 或虚假样本,但有可能。
如果填充队列的速度比清空队列的速度快,会发生什么情况?
关于iOS 音频队列 : glitches in audio float-stream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4654791/
我遇到一种情况,我需要从某个主题读取(正在进行的)消息并将它们放入另一个 Queue 中。我怀疑我是否需要 jms Queue 或者我可以对内存中的 java Queue 感到满意。我将通过同一 jv
队列也是一种操作受限的线性数据结构,与栈很相似。 01、定义 栈的操作受限表现为只允许在队列的一端进行元素插入操作,在队列的另一端只允许删除操作。这一特性可以总结为先进先出(First In
队列的定义 队列(Queue):先进先出的线性表 队列是仅在队尾进行插入和队头进行删除操作的线性表 队头(front):线性表的表头端,即可删除端 队尾(rear):线性表的表尾端,即可插入端 由于这
Redis专题-队列 首先,想一想 Redis 适合做消息队列吗? 1、消息队列的消息存取需求是什么?redis中的解决方案是什么? 无非就是下面这几点: 0、数据可以顺序读
0. 学习目标 栈和队列是在程序设计中常见的数据类型,从数据结构的角度来讲,栈和队列也是线性表,是操作受限的线性表,它们的基本操作是线性表操作的子集,但从数据类型的角度来讲,它们与线性表又有着巨大的不
我想在 redis + Flask 和 Python 中实现一个队列。我已经用 RQ 实现了这样的查询,如果你有 Flask 应用程序和任务在同一台服务器上工作,它就可以正常工作。我想知道是否有可能创
我正在使用 Laravel 5.1,我有一个大约需要 2 分钟来处理的任务,这个任务特别是生成报告...... 现在,很明显,我不能让用户在我接受用户输入的同一页面上等待 2 分钟,而是我应该在后台处
我正在使用 Azure 队列,并且有多个不同的进程从队列中读取数据。 我的系统的构建方式假设每条消息只读取一次。 这个Microsoft article声称 Azure 队列具有至少一次传送保证,这可
我正在创建一个Thread::Queue元素数组。 我这样做是这样的: for (my $i=0; $i new; } 但是,当我在每个队列中填充这样的元素时 $queues[$index]->enq
我试图了解如何将我的 Mercurial 补丁推送到远程存储库(例如 bitbucket.org),而不必先应用它们(实际上提交它们)。我的动机是在最终完成之前首先对我的工作进行远程备份,并且能够与其
我的本地计算机上有一个 Mercurial 队列补丁,我需要与同事共享该补丁,但我不想将其提交到上游存储库。有没有一种简单的方法可以打包该补丁并与他分享? 最佳答案 mq 将补丁作为不带扩展名的文
Java 中是否有任何类提供与 Queue 相同的功能,但有返回对象的选项,并且不要删除它,只需将其设置在集合末尾? 最佳答案 Queue不直接提供这样的方法。但是,您可以使用 poll 和 add
我在Windows上使用Tortoise svn客户端,我需要能够一次提交来自不同子文件夹的更改文件-一次提交。像在提交之前将文件添加到队列中之类的?我该怎么做? Windows上是否还有另一个svn
好吧,我正在尝试对我的 DSAQueue 类进行单元测试,它显示我的 isEmpty()、isFull() 和 dequeue() 方法失败。 以下是我的 DSAQueue 代码。我认为我的 Dequ
我想尽量减少对传入请求的数据库查询。它目前需要写入 6 个不同的表。在返回响应之前不需要完成处理。因此,我考虑了 laravel 队列,但我想知道我是否也可以摆脱写入队列/作业表所需的单独查询。我可以
我正在学习队列数据结构。我想用链表创建队列。我想编程输出:10 20程序输出:队列为空-1 队列为空-1 我哪里出错了? 代码如下: class Node { int x; Node next
“当工作人员有空时,他们会根据主题的优先级列表从等待请求池中进行选择。在时间 t 到达的所有请求都可以在时间 t 进行分配。如果两名工作人员同时有空,则安排优先权分配给最近的工作最早安排的人。如果仍然
我正在开发一个巨大的应用程序,它使用一些子菜单、模式窗口、提示等。 现在,我想知道在此类应用程序中处理 Esc 和单击外部事件的正确方法。 $(document).keyup(function(e)
所以 如果我有一个队列 a --> b --> NULL; 当我使用函数时 void duplicate(QueueNodePtr pHead, QueueNodePtr *pTail) 它会给 a
我正在尝试为键盘输入实现 FIFO 队列,但似乎无法让它工作。我可以让键盘输入显示在液晶显示屏上,但这就是我能做的。我认为代码应该读取键盘输入并将其插入队列,然后弹出键盘输入并将值读取到液晶屏幕上。有
我是一名优秀的程序员,十分优秀!