内存在音频缓冲code成长 [英] memory is growing in audio buffer code

查看:233
本文介绍了内存在音频缓冲code成长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我们多次使用我们的应用程序,它是取缓冲液样品并进行处理一类code,然后通知发送回主类。
在code是C和Objective-C。

I have a code that we use many times with our apps, its a class that take the buffer samples and process it ,then send back notification to the main class. The code is c and objective-c.

它工作得很好,但有越来越多的,我可以在工具 - 分配工具中看到内存。 整体字节的持续增长,在100K第二。监守在code,它的某些部分的我知道他们是谁

It works just great, but there is a memory growing which i can see in instruments-allocations tool. the "overall bytes" is keep growing, in 100k a second. becuase of some parts of the code that i know who they are .

这是回调函数,以使问题就行了。
它发生许多次。
我也真的不明白的地方把我的 *池

this is the callback function, with the line that makes problems. it happens many times a second. I also dont really understand where to put my *pool :

    static OSStatus recordingCallback(void *inRefCon, 
                                      AudioUnitRenderActionFlags *ioActionFlags, 
                                      const AudioTimeStamp *inTimeStamp, 
                                      UInt32 inBusNumber, 
                                      UInt32 inNumberFrames, 
                                      AudioBufferList *ioData)
    {

        AudioBuffer buffer;
        buffer.mNumberChannels = 1;
        buffer.mDataByteSize = inNumberFrames * 2;
        //NSLog(@"%ld",inNumberFrames);
        buffer.mData = malloc( inNumberFrames * 2 );
        // Put buffer in a AudioBufferList
        AudioBufferList bufferList;
        bufferList.mNumberBuffers = 1;
        bufferList.mBuffers[0] = buffer;


        // block A
        OSStatus status;
        status = AudioUnitRender(audioUnit, 
                                 ioActionFlags, 
                                 inTimeStamp, 
                                 inBusNumber, 
                                 inNumberFrames, 
                                 &bufferList); 

       //end block A

         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
        int16_t *q = (int16_t *)(&bufferList)->mBuffers[0].mData;
        int16_t average ;

        for(int i=0; i < inNumberFrames; i++)
        {


            average=q[i];   

            if(average>100) // lineB 
                reducer++;

           //blockC
            if(reducer==150 )
            {

                average= preSignal + alpha*(average-preSignal);
                //NSLog(@"average:%d",average);

                //call scene
                [dict setObject:[NSNumber numberWithInt:average] forKey:@"amp" ] ;
                [[NSNotificationCenter defaultCenter] postNotificationName:@"DigitalArrived" object:nil userInfo:dict];
                reducer=0;
                preSignal=average;

            }
//end blockC

        }


         free(buffer.mData);
         [pool release];
        return noErr;


}

OK:
忽略blockC一秒钟。
去除blockA和lineB解决这一切。
只有去除他们 - 泄漏之一。

OK: ignore blockC for a second. removing blockA and lineB solve it all. removing only one of them- leaks.

我只是不能undetstand什么成长在这里。

i just cant undetstand what is growing here .

推荐答案

只是一个猜测,但里面录制的回调函数(这是一个超时间关键功能)分配一个新的NSAutoreleasePool可能是一个坏主意。

Just a guess, but allocating a new NSAutoreleasePool inside of your recording callback function (which is a super time-critical function) is probably a bad idea.

其实,你为什么在这里做这个呢?你不应该只是为整个应用程序一池,在你的main.m文件?这可能是导致你的一些泄漏。

Actually, why are you doing this here at all? Shouldn't you just have one pool for the entire app, in your main.m? This is probably causing some of your leaks.

这篇关于内存在音频缓冲code成长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆