你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STF103VE CUBE IAR opus codec 移植

[复制链接]
迷雾向前 发布时间:2017-1-18 16:21
本帖最后由 迷雾向前 于 2017-1-20 11:22 编辑 # R7 T& E" [! ]  G& N; f

& w  C# m2 n3 C  A% C计划在机器上STF103VE  跑opus codec 进行编解码,中途停了,写一下做个记录。) X$ d# y( c, t

3 ~" }' e) L# k: x. o0 u1 h& q
$ k0 ]2 i0 v% V/ V首先用CUBE 快速生成代码。
- t5 _' o% ?0 e& [9 wClock 配置如下,我用的是内部时钟(应该没连接外部晶振):
* }8 k' S' _9 o) h7 x

clock 配置

clock 配置

" `9 n, Q. Z. t% {9 |# N6 F4 W$ S7 W/ N& r* c* I
Enable FreeRTOS ,heap 配置为 20K,enc 结构需要13k Ram。
' q! p- U+ K1 p* d- t

FreeRTOS config

FreeRTOS config
: R% A. [1 l8 @* i
用于编解码的Task 的Stack 改为1024Word,即4K(小了会reset); ^9 L6 G) t) M, a

Task Stack

Task Stack
. B$ n9 e1 h. d. [8 o
, Q! R# O4 ^: x0 G0 g, E
系统heap 需要改大,* J2 e/ E" ]. F6 j1 L% D

System Heap

System Heap
" X3 {2 M1 A9 e9 b# y# \3 Q" o

4 e8 x9 ^5 k# S" H1 l将OPUS 代码copy 到工程里面,将如下文件加入到编译(没权限添加更多图片,只能用文字描述了)
# H! j3 u; O+ r* ~4 Y$ G
* t" }/ o: a) O* J& h# ?( kopus-1.1.3/silk/ana_filt_bank_1.c; K' A8 [  C% g5 [8 q% K
opus-1.1.3/silk/bwexpander.c
8 p' b: Q# e+ l$ f1 b3 c7 ?$ Lopus-1.1.3/silk/control_audio_bandwidth.c  I$ P  N- }; ^; w  u& C7 }: G. }
opus-1.1.3/silk/code_signs.c4 f- @$ a5 f* B
opus-1.1.3/silk/CNG.c
6 C/ p! g- n3 ^; Aopus-1.1.3/silk/fixed/schur64_FIX.c* P  |" o  t; z: q; I% q
opus-1.1.3/silk/control_codec.c
( A: L$ l* c9 B# Jopus-1.1.3/silk/debug.c- y0 L$ L. P1 b* P3 ]
opus-1.1.3/silk/control_SNR.c
! V$ N. q9 y; K! j1 x( Uopus-1.1.3/silk/fixed/residual_energy16_FIX.c/ v0 y# c% r7 Y8 j& g; ]$ s: h
opus-1.1.3/silk/fixed/residual_energy_FIX.c& P5 u1 S( J) S; G2 t
opus-1.1.3/silk/fixed/warped_autocorrelation_FIX.c  z% v# v. M6 T: g9 _
opus-1.1.3/silk/biquad_alt.c
: G7 S# Z& Y9 h2 {/ B8 v2 B$ S" hopus-1.1.3/silk/bwexpander_32.c
: M( o) w7 F  a* J$ @+ wopus-1.1.3/silk/check_control_input.c
* |4 y0 B$ J( {opus-1.1.3/silk/A2NLSF.c
0 P: F$ |5 g5 o& j. m: Fopus-1.1.3/silk/fixed/schur_FIX.c
, B' j! f' Q' n4 p$ H5 f* Bopus-1.1.3/silk/fixed/solve_LS_FIX.c" a# }" @5 H' C. U
opus-1.1.3/silk/fixed/vector_ops_FIX.c
% v  e; l3 Y$ t5 r- Iopus-1.1.3/silk/encode_pulses.c3 C) k- X/ w' ~! ]! O; }
opus-1.1.3/silk/log2lin.c
6 F) }( s3 r" |, n2 N# Popus-1.1.3/silk/enc_API.c
7 o% K8 P6 w5 ?; T, jopus-1.1.3/silk/HP_variable_cutoff.c
$ I# g' o" F$ k: C, `opus-1.1.3/silk/init_decoder.c
6 N: T+ A0 j# Q8 H6 A6 _2 v3 I2 A1 U, qopus-1.1.3/silk/init_encoder.c# L5 u# D8 I* O) X" M" b& t* A
opus-1.1.3/silk/decode_indices.c" i- w$ f- R9 ^% {, _4 I
opus-1.1.3/silk/inner_prod_aligned.c# @. q! h1 c6 U8 m$ S) h0 s
opus-1.1.3/silk/decode_frame.c( \/ _* w8 X, |
opus-1.1.3/silk/decode_pulses.c' L, u1 U7 {4 Q5 d" }
opus-1.1.3/silk/gain_quant.c6 N5 o5 Z% G( f. f3 C- Z9 c4 f
opus-1.1.3/silk/interpolate.c
/ @. h" V2 y$ R1 \) Gopus-1.1.3/silk/lin2log.c- h% N) V  _5 X3 F  i+ E+ x/ P
opus-1.1.3/silk/decode_parameters.c, f4 E! T0 }, }  d+ l- P
opus-1.1.3/silk/dec_API.c" Z9 P" w( Z0 m) b
opus-1.1.3/silk/decode_core.c& q; ]- L2 N- H, f
opus-1.1.3/silk/decode_pitch.c
+ w% @! z" S+ ]1 x: E; N3 i2 oopus-1.1.3/silk/decoder_set_fs.c  r3 F2 P7 P4 D! B5 a+ _( ^/ \1 _
opus-1.1.3/silk/encode_indices.c* k9 o7 k$ \( O/ t4 ?
opus-1.1.3/silk/quant_LTP_gains.c+ M  ^  k2 R, \% J
opus-1.1.3/silk/NSQ.c: r+ W+ Z* a' C2 D
opus-1.1.3/silk/resampler.c
5 i9 a/ |4 }$ ?% a+ I& bopus-1.1.3/silk/NLSF_del_dec_quant.c
4 E- ~) Z" |/ u, i  r) Y% x1 t2 u+ iopus-1.1.3/silk/NLSF2A.c% @  N6 q& q# o3 v) Y/ ]" G) [2 L
opus-1.1.3/silk/NLSF_stabilize.c& `  E  h9 a, D8 J( ?  x
opus-1.1.3/silk/NLSF_unpack.c
3 A) V7 A7 m8 ^6 M# ?' gopus-1.1.3/silk/NLSF_VQ.c
, h4 P4 O1 R' p% }" _opus-1.1.3/silk/LPC_inv_pred_gain.c8 e" L- b9 ?$ G; c
opus-1.1.3/silk/NLSF_VQ_weights_laroia.c# n& A' s4 r" T# {- `  i
opus-1.1.3/silk/pitch_est_tables.c, l, |' Z! ~6 j, x
opus-1.1.3/silk/NSQ_del_dec.c
6 s; Q9 C% d3 A+ z/ I5 O6 \0 xopus-1.1.3/silk/PLC.c
7 s7 z0 e! M" i4 C1 Mopus-1.1.3/silk/NLSF_decode.c6 a; X' t6 V3 B9 t
opus-1.1.3/silk/NLSF_encode.c+ h1 |+ g5 L& M6 D* Z, ?7 m
opus-1.1.3/silk/LP_variable_cutoff.c
8 q; n3 [2 q* I* }opus-1.1.3/silk/LPC_analysis_filter.c
$ G1 ^0 A& Q8 c; j! e  |* Dopus-1.1.3/silk/process_NLSFs.c
: x  u: m4 r7 Hopus-1.1.3/silk/stereo_find_predictor.c; G: v2 R: j  D- `1 b/ j
opus-1.1.3/silk/stereo_MS_to_LR.c
3 u! ?# o" L  W5 C4 _! [+ ]) j. Uopus-1.1.3/silk/resampler_private_AR2.c
0 ]9 }- U- N- q: |) x# Yopus-1.1.3/silk/resampler_down2_3.c
) j! \9 d+ b( B: L+ y) zopus-1.1.3/silk/stereo_LR_to_MS.c  V7 h+ e, |. ^9 r8 P
opus-1.1.3/silk/stereo_encode_pred.c- l- J* h' C% m8 d: d) U8 |
opus-1.1.3/silk/resampler_down2.c. B- w5 T- D9 x% j5 L
opus-1.1.3/silk/sigm_Q15.c
, f/ v1 L  \, N$ `opus-1.1.3/silk/resampler_rom.c) q- C5 G* F3 Q; T" q
opus-1.1.3/silk/sort.c9 |2 s7 Z( _* y/ w
opus-1.1.3/silk/resampler_private_down_FIR.c
( F( O  S/ A& |. {$ \opus-1.1.3/silk/resampler_private_up2_HQ.c- K1 S9 Q- P! K  b
opus-1.1.3/silk/stereo_decode_pred.c
+ s9 A! L  }- ~- kopus-1.1.3/silk/shell_coder.c1 n  b6 C9 b& O+ o% f5 R
opus-1.1.3/silk/resampler_private_IIR_FIR.c
+ U# `2 N* g9 a$ j) X3 C0 p3 popus-1.1.3/src/repacketizer.c' J$ j; t1 O/ z$ P0 \
opus-1.1.3/silk/sum_sqr_shift.c, s6 Q: C+ @( k# a  O- F
opus-1.1.3/silk/table_LSF_cos.c
& x+ S0 R2 [5 q/ Zopus-1.1.3/silk/tables_NLSF_CB_WB.c
' a* S2 L( b& Q8 _4 eopus-1.1.3/silk/stereo_quant_pred.c
$ }8 y( v6 }% j$ l5 t- [# ?opus-1.1.3/silk/VAD.c
0 V! j  Z6 `' K) t. R9 k: kopus-1.1.3/silk/tables_gain.c
+ @# b" J( D4 |: J  mopus-1.1.3/silk/tables_pulses_per_block.c
1 p- N5 Z2 j+ [! R7 l#opus-1.1.3/stm32_m3/opus_main.c) E# R" y0 ~* `7 [" j" R
opus-1.1.3/src/opus_encoder.c* y. h" v2 [0 i- M2 S2 @
opus-1.1.3/silk/tables_NLSF_CB_NB_MB.c
3 P8 a8 E7 W. r' xopus-1.1.3/silk/tables_other.c
" A% `6 l5 o# \+ W* b# Gopus-1.1.3/src/opus.c  |& v$ b2 t; e& ^  i. c
opus-1.1.3/silk/tables_pitch_lag.c% _7 F$ f2 x" G0 V2 v
opus-1.1.3/src/opus_decoder.c
6 @2 d" I% x- V( |opus-1.1.3/silk/VQ_WMat_EC.c8 u% o0 S6 V2 }0 a0 m# }- @6 }
opus-1.1.3/silk/tables_LTP.c
7 h" }: M, B6 e$ V0 O: H; e
opus-1.1.3/celt/entdec.c
+ R8 S& f: y: |7 Lopus-1.1.3/celt/entenc.c. T( y8 m: `. M  O7 W
opus-1.1.3/celt/cwrs.c: C$ Q' T, e5 a* `# P  X# |, X0 j
opus-1.1.3/celt/mathops.c  f% n( W; r2 O5 h
opus-1.1.3/celt/kiss_fft.c9 H2 r- S* c1 d
opus-1.1.3/celt/celt_lpc.c
. ?% h% `# T6 a  S5 copus-1.1.3/celt/mdct.c
- f8 L, }! q9 v: C% c5 Lopus-1.1.3/celt/modes.c
2 G3 q& x" ?# H6 Ropus-1.1.3/celt/bands.c
# K$ K1 I8 P7 ^- Ropus-1.1.3/celt/pitch.c  M/ k/ M; c5 q
opus-1.1.3/celt/celt_encoder.c
) f: D+ H1 Z0 p, Bopus-1.1.3/celt/laplace.c. ]# q4 Z, H2 j; U- w: u
opus-1.1.3/celt/celt_decoder.c
2 H" Y) }2 G) |3 Mopus-1.1.3/celt/entcode.c
+ c3 q, {1 J+ g' Nopus-1.1.3/celt/celt.c* U$ i" N  w. U  L- s& ]
opus-1.1.3/silk/fixed/noise_shape_analysis_FIX.c
5 I" F# ~% e( S: x3 Bopus-1.1.3/silk/fixed/process_gains_FIX.c
6 l6 b/ U' v' t2 |8 zopus-1.1.3/silk/fixed/regularize_correlations_FIX.c
" Y) g6 q  O3 O+ h/ H$ l' hopus-1.1.3/silk/fixed/autocorr_FIX.c
$ ?; u# g9 `1 B1 S4 d* p8 s  `opus-1.1.3/celt/quant_bands.c
. R7 S' v5 j9 ?! u- w  R, ropus-1.1.3/silk/fixed/encode_frame_FIX.c& T& G% A# n4 F' j) ?: e0 ^, o9 s
opus-1.1.3/silk/fixed/corrMatrix_FIX.c
0 j9 }$ r2 c% b9 [opus-1.1.3/silk/fixed/find_LTP_FIX.c
, s1 s$ M0 G: J4 Qopus-1.1.3/silk/fixed/pitch_analysis_core_FIX.c% ?* [$ T2 o) v
opus-1.1.3/silk/fixed/prefilter_FIX.c
; a9 [5 I6 B9 t# E' v" i0 O& t/ yopus-1.1.3/celt/rate.c
, c. i7 R6 B7 Eopus-1.1.3/silk/fixed/find_pitch_lags_FIX.c& o$ j! I. F6 h: C4 q- l7 a, E
opus-1.1.3/silk/fixed/burg_modified_FIX.c* M4 [. Y5 Q/ v
opus-1.1.3/silk/fixed/LTP_analysis_filter_FIX.c
# P0 R1 c5 s: n2 [opus-1.1.3/celt/vq.c+ \, Y. o" ]+ s$ |* {7 g9 P8 g2 X
opus-1.1.3/silk/fixed/find_LPC_FIX.c
# a- Y. Q& b3 u- Z% f5 aopus-1.1.3/silk/fixed/find_pred_coefs_FIX.c, R$ n: Q# x0 {
opus-1.1.3/silk/fixed/apply_sine_window_FIX.c
% H; i0 j( q% oopus-1.1.3/silk/fixed/k2a_FIX.c% O3 X4 o0 H3 l8 D+ {& a6 H+ |
opus-1.1.3/silk/fixed/LTP_scale_ctrl_FIX.c& H& T' ^6 [. O: t- Q" \
opus-1.1.3/silk/fixed/k2a_Q16_FIX.c

  P& [# n1 D' ?& j  K- `+ z& V6 n2 |1 h$ L9 b5 O: Y6 M! G
我为opus-1.1.3建立了单独的group,并将这个group 的 【Override inherited settings 】勾上6 U, b6 s8 i* q$ S/ o6 Y8 ^' Y

opus config

opus config
, h9 l! c2 \; |2 F2 J
在【Proprocessor】里增加如下include 目录
. z6 n6 X* \4 }& [2 G4 e$PROJ_DIR$/../opus-1.1.3/include
* @8 D* a: W, `, A/ M* a/ J1 t$PROJ_DIR$/../opus-1.1.3/celt
6 y$ P: L6 r  Z$PROJ_DIR$/../opus-1.1.3/silk
7 `7 F% o* a- }$PROJ_DIR$/../opus-1.1.3/silk/fixed2 Y2 s! \$ A' x
$PROJ_DIR$/../opus-1.1.3/stm32_m3

* I5 u3 d; l8 a  Q1 v& U增加:HAVE_CONFIG_H 到【Defined symbols】
) m9 X9 T' W& y3 y0 t# u: b opus include.JPG : x  H0 z- U8 g' s4 n; w
将【Language 1 】中的【Allow VLA】勾上,目的是#define VAR_ARRAYS   1 后能便宜通过。3 M  ?- ?. b8 I! h# `
! Z' q) D/ q* ~. E" y# l- t
copy opus-1.1.3/win32 到 opus-1.1.3/stm32_m3,建立config.h 和 version.h
4 k3 c, W( e6 J# B$ |config.h:
8 T/ I# W6 Q! ~' j- z#ifndef CONFIG_H
+ p6 l2 W- G. b- M#define CONFIG_H
9 ^( \: ]6 m4 X. y; g
//#define USE_ALLOCA            13 D5 j9 B) j/ m
#define VAR_ARRAYS   13 |: k3 _! b2 K' l
/* Comment out the next line for floating-point code */5 |% m8 l: L& F0 v1 |
/*#define FIXED_POINT           1 */
  s" C5 j6 t/ K7 n$ y- Q
#define OPUS_BUILD            16 j4 a" a9 G" A1 l! N
#define DISABLE_FLOAT_API 1
" u( I4 c- |8 ]; L#define FIXED_POINT 1
& t+ w1 C* q/ {1 i7 H0 R#define REMOVE_FOR_MALLOC

% b( t) m! M3 R; O5 }//以上部分内容为增加部分,其他的与win32下同名文件相同- i) i# @' P) z
#endif /* CONFIG_H */
! n2 {1 m0 ^3 ]4 U' {$ E8 K8 x- L, I& `% i* [
version.h( \/ R/ @/ L, p- i
#ifndef __VERSION_H__
+ s$ v! c* r" s( g. u1 B& |( R#define __VERSION_H__
* M$ ?" T) y0 e0 s
#define PACKAGE_VERSION  "1.1.3"
  l% b! i8 D  a) y8 I- h+ V#endif /*__VERSION_H__*/- g0 l  ]7 w7 T1 C: q

& Y8 p9 T3 M  a0 Cencode 和decode 代码:
) F: C* ]) U, B: ^" R; k& b% V* N5 e. L0 d2 \+ F# Z4 F4 S
pusDecoder *dec;
; B# a0 Q% e  |7 p* u1 {& l3 d  static int offset = 0;
. o8 i/ H/ Z! ^; u) ]; P3 l+ P1 A; p  int size = 0;7 y; S# s' l+ S. o4 v' f9 I- p* L
  const unsigned char *packet;
2 f, c2 ^5 i4 l+ Z! A  int i = 0;4 y% O5 _0 v) L4 Z7 y* V4 U
  int frame_size = 0;
/ u. L7 T1 D& o9 u2 m  int max_size = 0;
5 c- p- p( v9 ~, N+ c. K. q  char buffer[36];( Q2 H; |- r" Y4 ^& U8 e

2 {1 X4 \' O* V   , F! W* B1 a& y$ W/ Q
  uint32_t start = osKernelSysTick();' T' i8 c+ O6 v  X; j
  8 ?. J- s/ h/ z* n0 n( c8 p8 m
  OpusEncoder *enc = NULL;
! q2 i( |- `& T& C  static int len = 10;

7 P* k4 n2 d+ U2 G  
- K- `/ o; p0 j2 ?  size = opus_encoder_get_size(channels);
4 S( W$ _# q% S+ X* {; ^  enc = pvPortMalloc(size);
2 H* l7 v' K0 T, g! Z  error = opus_encoder_init(enc, Fs, channels, OPUS_APPLICATION_RESTRICTED_LOWDELAY);

7 E- b9 `* [9 W7 I5 @$ z3 K  U  opus_encoder_ctl(enc, OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_20_MS));* S# m& y  h9 M8 i4 u' @! B
  //opus_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_VOICE));& ^6 I' M# X/ Z! U2 C
  opus_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC));+ G  X% ~, x. `# v8 f
  + N; r6 b. f7 B+ _# Z5 C$ c+ r
  len = opus_encode(enc, audio_frame + offset, Fs/50/*20ms*/, opus_buffer, sizeof(opus_buffer));
  V5 l$ o' z$ A- T; N  offset += Fs/50;
& F, Z% C) a6 h  if(offset >= sizeof(audio_frame)/sizeof(uint16_t))4 z* Q& d2 X3 ?7 F8 O. i7 ?7 h
    offset = 0;. q. a" ~: R" j3 i1 K
  vPortFree(enc);
, W8 m6 E; ^( I; {
  OpusDecoder *st  = (OpusDecoder *)pvPortMalloc(opus_decoder_get_size(channels));
; `: {. V* p: i9 \+ w* w  error = opus_decoder_init(st, Fs, channels);
' i# l. V* H5 w2 \. Y2 l! G, U  4 x1 U  f0 m. ]) [  n. b% H

/ K# r; r4 @4 q4 Q) h/ {. b  frame_size = opus_decode(st, opus_buffer, len, pcm, PCM_BUFFER_SIZE, 0);

8 k2 t: _& W8 i
' |$ ^+ ?; }" u4 x% n2 ?对了,我改了这两个宏,5 E, [5 K5 r3 U7 u! [  G
#define MAX_FS_KHZ                              8 /*16 --> 8 modify for memory*/
+ j+ E' V! i* u  h! h5 N#define MAX_API_FS_KHZ                          8 /*48 --> 8 modify for memory/9 O  ^! y% ]* N: V$ ^
原因是,如果不修改opus_encoder_get_size(1); 返回的是27k,改完后还得13k,实在是没有那么多ram3 t6 J+ N& n8 _
size = opus_encoder_get_size(1);
" Q5 p0 f8 A( \4 X& }0 Lenc = pvPortMalloc(size);! s1 W- u6 b. ^* n: t8 V

0 i# [" x) \9 c  r) D3 J- Q& [总结,64k ram 感觉刚刚够,还没有增加其他的功能,解压缩20ms 数据用了6-7ms,编码我忘记了,记得编解码用了33ms,有点高。5 l  ]' x$ W/ \' j& {
声音可以用DAC(PA4)播放出来,需要外加功放,不加功放声音很不好。经过opus 压缩解压后声音损失较大,音乐还能听出来,但很多噪声。3 R- k$ L3 t* }9 R8 W. ~

! B" u, e5 R4 e: m; h  z

评分

参与人数 1 ST金币 +10 收起 理由
zero99 + 10

查看全部评分

赞 收藏 2 评论4 发布时间:2017-1-18 16:21

举报

4个回答
zero99 回答时间:2017-1-23 13:15:12
谢谢分享
新来的新手 回答时间:2017-5-9 17:34:41
楼主你好,我想问一下STM3VE 用opus编解码效果如何?
mupro 回答时间:2018-1-3 17:34:49
楼主的项目能放出来吗  感觉opus的代码很多,你上面介绍的是很多文件都不需要的
epochal 回答时间:2018-1-3 20:08:03
谢谢分享!

所属标签

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
人形机器人运动控制、感知与智能配电
半导体创新技术与应用方向
EE架构与软件定义汽车
12V/48V 汽车智能配电(SPD)
区域控制单元(ZCU)与分区架构
关注我们
st-img 微信公众号
st-img 手机版