我是iOS编程的新手,目前正致力于解调FSK信号的项目。我改编了Michael Tyson循环缓冲区实现,但是当我尝试注销样本以查看它是否类似于方波时,我看到的是一个常数值'67638612'。我已经有一个通过audiojack的麦克风发送FSK调制信号的电路。 这是我用来注销样本的代码:
// Init circular buffer
BOOL TPCircularBufferInit(TPCircularBuffer *buffer, int32_t length);
// Listing 10.28 Initial Setup of Render Callback from RemoteIO
static OSStatus InputFSKDemodulationRenderCallback (
void *inRefCon, // A pointer to a struct containing the complete audio data
// to play, as well as state information such as the
// first sample to play on this invocation of the callback.
AudioUnitRenderActionFlags *ioActionFlags, // Unused here. When generating audio, use ioActionFlags to indicate silence
// between sounds; for silence, also memset the ioData buffers to 0.
const AudioTimeStamp *inTimeStamp, // Unused here.
UInt32 inBusNumber, // The mixer unit input bus that is requesting some new
// frames of audio data to play.
UInt32 inNumberFrames, // The number of frames of audio to provide to the buffer(s)
// pointed to by the ioData parameter.
AudioBufferList *ioData // On output, the audio data to play. The callback's primary
// responsibility is to fill the buffer(s) in the
// AudioBufferList.
) {
AudioStruct* effectState = (AudioStruct*) inRefCon;
// Listing 10.29 Copying Captured Samples to Play-Out Buffer in RemoteIO Render Callback
// Just copy samples
UInt32 bus1 = 1;
CheckError(AudioUnitRender(effectState->rioUnit,
ioActionFlags,
inTimeStamp,
bus1,
inNumberFrames,
ioData),
"Couldn't render from RemoteIO unit");
// Listing 10.30 Performing FSK demodulation Effect on a Buffer of Samples
// Walk the samples
AudioUnitSampleType* outSample = (AudioUnitSampleType* )ioData->mBuffers[0].mData;
AudioUnitSampleType sample = (AudioUnitSampleType) &outSample;
memset(outSample, 0, inNumberFrames * kUnitSize * 2);
// if (effectState->bufferIsReady && !effectState->playbackWasInterrupted){
for (int bufCount = 0; bufCount<ioData->mNumberBuffers; bufCount++){
int currentFrame = 0;
while (currentFrame <= inNumberFrames) {
// Pull audio from circular buffer
int32_t availableBytes;
AudioUnitSampleType *bufferTail = TPCircularBufferTail( &effectState->circularBuffer, &availableBytes);
memcpy(outSample, bufferTail, MIN(availableBytes, inNumberFrames * kUnitSize * 2) );
TPCircularBufferConsume(&effectState->circularBuffer, MIN(availableBytes, inNumberFrames * kUnitSize * 2) );
effectState->currentSampleNum += MIN(availableBytes / (kUnitSize * 2), inNumberFrames);
NSLog(@" currentsamplenumber is: %ld", sample);
控制台上的这就是我所看到的:
2013-08-26 15:55:27.886 ElisaDongle[880:907] hardwareSampleRate = 44100.000000
RIO started!
2013-08-26 15:55:28.013 ElisaDongle[880:6403] currentsamplenumber is: 67638612
2013-08-26 15:55:28.016 ElisaDongle[880:6403] currentsamplenumber is: 67638612
2013-08-26 15:55:28.018 ElisaDongle[880:6403] currentsamplenumber is: 67638612
2013-08-26 15:55:28.020 ElisaDongle[880:6403] currentsamplenumber is: 67638612
2013-08-26 15:55:28.022 ElisaDongle[880:6403] currentsamplenumber is: 67638612
2013-08-26 15:55:28.024 ElisaDongle[880:6403] currentsamplenumber is: 67638612
2013-08-26 15:55:28.026 ElisaDongle[880:6403] currentsamplenumber is: 67638612
2013-08-26 15:55:28.031 ElisaDongle[880:6403] currentsamplenumber is: 67638612
2013-08-26 15:55:28.036 ElisaDongle[880:6403] currentsamplenumber is: 67638612
2013-08-26 15:55:28.038 ElisaDongle[880:6403] currentsamplenumber is: 67638612
2013-08-26 15:55:28.041 ElisaDongle[880:6403] currentsamplenumber is: 67638612
拜托,我需要帮助。有什么我做错了或错过了。随意问我任何问题。