Implementing simple high and low pass filters in C

前端 未结 2 1108
无人共我
无人共我 2021-02-02 03:05

Trying to use portaudio to record some data, then use an algorithmic filter to change the recorded voice and then play it back. I\'ve verified a lot of it (coming from example)

相关标签:
2条回答
  • 2021-02-02 03:58

    It looks like you're trying to free a stack variable. The only time you have to call free is when you've previously called malloc (or one of its friends like calloc) or when the documentation for a library function you're calling says you need to free a pointer that it returns.

    Incidentally, any time you do free a pointer, a good practice is to set it to NULL immediately afterwards.

    Stack variables go away as soon as they're out of scope. This might help you understand better.

    0 讨论(0)
  • 2021-02-02 04:04

    The problem is that data.recordedSamples now (at the time of free()) points towards a structure allocated on the stack, not on the heap!

    Since you had this instruction:

    data.recordedSamples = filteredArray;
    

    The

    if( data.recordedSamples )
    

    is of no use, since the adress id valid, but not consistent: it is never allocated with malloc() and it is not on the heap, but on the stack!

    At the moment when you are calling free(), that adress could well point towards the stack of another function.

    Copy your filtered data back over the original recordedSamples if you want, just do not re-assign that pointer.

    edit:

    use this:

    for(i = 0; i<numSamples; i++) {
        data.recordedSamples[i] = filteredArray[i];
    }
    
    0 讨论(0)
提交回复
热议问题