How Audio Buffer memory is allocated on the external SRAM

I have gone through owl source and found external SRAM is initialize if EXTERNAL_SRAM is defined as follows.


#ifdef EXTERNAL_SRAM
  SRAM_Init();
#endif /* EXTERNAL_SRAM */

#ifdef EXTERNAL_SRAM
#define EXT __attribute__ ((section (".extdata")))
#endif

but in code I could not find any entry of #defined EXTERNAL_SRAM
So I doubt how SRAM_Init(); is complied.

Also I found that in patch file buffer is created using “createMemoryBuffer” and it finally call “malloc” function. My questian is how malloc manages the location of SRAM (embedded or external) to create buffer.


 SimpleDelayPatch.hpp
-----------------------------
#define REQUEST_BUFFER_SIZE 32768

 AudioBuffer* buffer = createMemoryBuffer(1, REQUEST_BUFFER_SIZE);

StompBox.cpp

AudioBuffer* Patch::createMemoryBuffer(int channels, int samples){
  return processor->createMemoryBuffer(channels, samples);
}

MemoryBuffer.hpp
-------------------------
class ManagedMemoryBuffer : public MemoryBuffer {
public:
  ManagedMemoryBuffer(int ch, int sz) :
    MemoryBuffer((float*)malloc(ch*sz*sizeof(float)), ch, sz) {
    if(buffer == NULL){
      channels = 0;
      size = 0;
    }
  }
  ~ManagedMemoryBuffer(){
    free(buffer);
  }
};

PatchProcessor.cpp
===============

AudioBuffer* PatchProcessor::createMemoryBuffer(int channels, int size){
  MemoryBuffer* buf = new ManagedMemoryBuffer(channels, size);
  if(buf == NULL)
    return NULL;
  buffers[bufferCount++] = buf;
  buf->clear();
  return buf;
}

I have found “myalloc” function to create buffer on EXT SRAM but could not any entry which call this “myalloc”.


SRAMALLOC.H
-----------------------
void InitMem(char *ptr, int size_in_bytes);
void * myalloc(int elem_size);
void myfree(void *p);

Can anybody clear my doubt/confusion???

in makefile I have found this

CFLAGS += -DEXTERNAL_SRAM

Now I understand how SRAM_Init(); is getting complied.

But still I dont understand how Audio Buffer is allocated on EXTERNAL SRAM.

Some one please explain…

thanks

It would be much easier to answer your questions if you could tell us what you are trying to do!

Much of the code is currently being split into two: OwlWare (programvector branch) for the firmware and OwlProgram (master branch) for dynamically loaded patches.

Memory allocation happens in different ways depending on circumstances, and there are three different malloc implementations:

  • newlib (uses stubs in Libraries/syscalls)
  • FreeRTOS heap_4
  • myalloc (now called sram_alloc)

For ‘standard’ malloc calls try reading up on newlib docs, in particular _sbrk().

Hi mars

Thank you for your information. I am going through owlware master branch. Now I understand how malloc use external SRAM for memory buffer through _sbrk().

Regarding my project:

I have STMF407 Dev board having 1MB external SRAM and I have build other required stuff like codec, switch, LEDs, POT to make a Owl pedal. I have downloaded owlware master branch and patches.

In Owlware there are many more brunches and I am not sure which brunch I need to make Owl pedal with my dev board.

I think programvector branch brunch is new one. What are the deference between programvector branch & master branch???

Is master branch is well suited for my purpose??

thanks.

Ok, cool! Got any photos?

I think to get a proof-of-concept working, master is your best choice.

A lot of things have changed in the programvector branch to facilitate dynamic patch loading, i.e. load and run patches from RAM. One big difference is that we now use FreeRTOS. master is much less complicated, with everything (minus bootloader) contained in one firmware image.

On the other hand, if you want to get up-to-date with our latest code, programvector is where it’s at!

Do you like to see photo of my dev board?

One more query,

For some patches it is found that audio memory buffer has been declared as float array instead createMemoryBuffer(1, REQUEST_BUFFER_SIZE).

Now question is on which memory buffer is allocated when it is declared as simple float array. if it is external SRAM then tell me how.

How this float array memory is freed while the patch is removed from slot by putting another patch.

Also memory free concept is not clear to me when buffer is created by createMemoryBuffer(1, REQUEST_BUFFER_SIZE).

Can you explain please??

thanks.

Do you like to see photo of my dev board?

Yes please, codec and all! I love seeing what other people do with the work we’ve published.

The PatchProcessor keeps a list of buffers created by a patch and destroys them before another patch is created.
Because _sbrk() allocates memory from external SRAM, any malloc/free/new/delete call will use that memory.

How to attach image to a post???

ReverseReverbPatch.hpp

#define REVERSE_REVERB_BUF_LENGTH 20480

class ReverseReverbPatch : public Patch
{
private:

int reverb_index, reverse_cnt, reverb_time;
char reverse_flag;
float reverb_buffer[REVERSE_REVERB_BUF_LENGTH];

Look in this patch audio memory buffer has been declared as float array instead using createMemoryBuffer(1, REQUEST_BUFFER_SIZE). So _sbrk() has no role in this buffer allocation. Now my question is how this buffer is getting allocated on external SRAM. Why not buffer is allocated on internal RAM if adequate free memory is available on internal RAM.