Hi all ! I just learned about the Opus codec and would like to try it out on my NRF52 (Cortex-M4) target. I've been struggling a bit with the "trival_example.c" setup but repeatedly run into "hard fault" crashes when stepping through the code. Firstly; for a "bare bone" configuration, does the following compiler directives make sense ? UDEFS = -DOPUS_BUILD -DFIXED_POINT -DDISABLE_FLOAT_API \ -DOPUS_ARM_INLINE_EDSP -DEMBEDDED_ARM -DNONTHREADSAFE_PSEUDOSTACK \ -DOVERRIDE_OPUS_ALLOC -DOVERRIDE_OPUS_FREE \ -D'opus_alloc(x)=NULL' -D'opus_free(x)=NULL' Secondly; With the "overide" directives above no dynamic memory allocation is supposed to happen. However, the following call chain (obviously) cause a crash: opus_encode(..)-> opus_encode_native(..)->ALLOC_STACK->opus_alloc_scratch(..)->opus_alloc(..) Is this a bug or what am I missing here ? Any advise on how to get a basic encode/decode example working would be most appriciated. Thanks ! \Eric
Hello Eric, I have ported the codec on an M4F device and the document for the same is on the following link http://opus-codec.org/docs/ During my porting I did notice that the codec does consume quite some amount of SRAM. What is the NRF52 SRAM size? Regards Amit On Wed, Oct 18, 2017 at 3:40 PM, Eric <eric at wiebols.se> wrote:> Hi all ! > > I just learned about the Opus codec and would like to try it out on my > NRF52 (Cortex-M4) target. I've been struggling a bit with the > "trival_example.c" setup but repeatedly run into "hard fault" crashes when > stepping through the code. > > > Firstly; for a "bare bone" configuration, does the following compiler > directives make sense ? > > UDEFS = -DOPUS_BUILD -DFIXED_POINT -DDISABLE_FLOAT_API \ > -DOPUS_ARM_INLINE_EDSP -DEMBEDDED_ARM -DNONTHREADSAFE_PSEUDOSTACK \ > -DOVERRIDE_OPUS_ALLOC -DOVERRIDE_OPUS_FREE \ > -D'opus_alloc(x)=NULL' -D'opus_free(x)=NULL' > > > Secondly; With the "overide" directives above no dynamic memory allocation > is supposed to happen. However, the following call chain (obviously) cause > a crash: > > opus_encode(..)-> opus_encode_native(..)->ALLOC_ > STACK->opus_alloc_scratch(..)->opus_alloc(..) > > Is this a bug or what am I missing here ? > > Any advise on how to get a basic encode/decode example working would be > most appriciated. > > Thanks ! > > \Eric > > _______________________________________________ > opus mailing list > opus at xiph.org > http://lists.xiph.org/mailman/listinfo/opus >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.xiph.org/pipermail/opus/attachments/20171018/14c825f9/attachment.html>
On 10/18/2017 01:40 PM, Eric wrote:> Secondly; With the "overide" directives above no dynamic memory > allocation is supposed to happen. However, the following call chain > (obviously) cause a crash: > > opus_encode(..)-> > opus_encode_native(..)->ALLOC_STACK->opus_alloc_scratch(..)->opus_alloc(..)NONTHREADSAFE_PSEUDOSTACK requires a working allocator. You should select either vararrays or alloca(). Both should work on any gcc-based Cortex-M toolchain. (For that matter, malloc() and free() should work fine too, unless you have other reasons to avoid them)
Thomas Daede wrote:> NONTHREADSAFE_PSEUDOSTACK requires a working allocator. You should > select either vararrays or alloca(). Both should work on any gcc-basedNo, NONTHREADSAFE_PSEUDOSTACK is the one designed to not use alloca or vararrays. You will need to override opus_alloc_scratch(), however. You can simply declare a static array of size GLOBAL_STACK_SIZE bytes and make opus_alloc_scratch() return its address. Maybe Jean-Marc knows a less-cumbersome way to do this.
On 18/10/17 04:40 PM, Eric wrote:> UDEFS = -DOPUS_BUILD -DFIXED_POINT -DDISABLE_FLOAT_API \ > -DOPUS_ARM_INLINE_EDSP -DEMBEDDED_ARM -DNONTHREADSAFE_PSEUDOSTACK \ > -DOVERRIDE_OPUS_ALLOC -DOVERRIDE_OPUS_FREE \ > -D'opus_alloc(x)=NULL' -D'opus_free(x)=NULL' > > > Secondly; With the "overide" directives above no dynamic memory > allocation is supposed to happen. However, the following call chain > (obviously) cause a crash:Presumably, you're using the init() calls and not the create() calls (which require allocation). In that case, you'll want to also define OVERRIDE_OPUS_ALLOC_SCRATCH and have opus_alloc_scratch() return a buffer where to put the stack (as Tim pointed out). Otherwise you can use alloca() or VLAs, but you have to somehow give Opus some way to get memory. With the above options, you're basically preventing Opus from having any stack space. Cheers, Jean-Marc