I 마이크 오는 수레 스트림을 기록하고있는 글리치 (침묵 있어야)아이폰 OS AudioQueues 오디오 플로트 스트림
내가 256 개 플로트
전형적인에게의 버퍼 사이즈 설정 오디오 큐가 버퍼는 다음과 같다 :
내가 이해할 수없는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.011353, -0.007751, -0.007660, -0.006409, -0.003357, -0.003510, -0.001038, -0.000092,0.007690,0.002655,0.000000, .000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000, .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, .000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, .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.0453 80,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 ~
왜 나는 것 같다 입력 신호에 0의 무작위 묶음이 있습니다. 불연속적인 것으로 보인다.
내가 처음에는 왼쪽 및 오른쪽 채널을 사용하고 오른쪽 채널이 항상 0으로 기록되었다고 생각했습니다. 그러나 내 코드를 살펴보면 단일 채널에 대해 명확하게 설정했습니다.
그런데 나는 이것이 신호에 침묵의 장소라고 생각했습니다.하지만 그건 의미가 없습니다. 만약 내가 방금 12 개 0이 있다면, 0.000000은 매우 작은 숫자가 .000007 .000014와 같을 것이라고 기대하지만, 0이 아닌 숫자는 0.01 마크 근처에있는 것처럼 보입니다.
방금 오디오 입력을 외장 USB 마이크로 전환하려고 시도했지만 해상도가 향상되었습니다. 0이 아닌 숫자는 이제 0.001 마크 주위에있는 것 같습니다. 하지만 여전히 눈에 띄는 불연속성이 있습니다 ...
어떤 계산이 칩이 0으로 반올림되어 수행되고 있는지 궁금합니다.이 경우 교정 할 수 있습니까? 무슨 일 이니?
두 번째로 정말 이상한 문제는 불량 값입니다.
여기이 값의 일부가 포함 된 샘플 패킷 (의 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, .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, .000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, .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, .000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, .000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, .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.00 0000,0.000000, -0.000000,8589934592.000000, -8589934592.000000,0.000000, -0.000000158456325028528675187087900672.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.00003110384593717069655257060992658440192.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,
이 나를 혼란. 이러한 글리치의 발생은 낮습니다. 10 프레임 중 하나보다 적습니다.
오디오 스트림을 미리 처리해야합니까?
전회 오디오 유닛을 사용하고 있었지만 결코 그렇게하지 않았습니다. 필자는 오디오를 피치 감지 루틴으로 직접 연결했습니다. 그리고 그것은 아무런 문제가 없었습니다.
//
// 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];
}
나는이 문제를 해결하기 위해 투표를하고 있는데, 문제는 내 자신의 장난스런 코딩이라고 발견했다. 나는 n * sizeof (float)보다는 malloc'd (n)을 가지고 있었기 때문에 무작위로 쓰레기를 읽었습니다. –
질문을 빠르고 쉽게 삭제할 수도 있습니다. 다행히 문제를 발견했습니다. – mtrw