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

STF103VE CUBE IAR opus codec 移植

[复制链接]
迷雾向前 发布时间:2017-1-18 16:21
本帖最后由 迷雾向前 于 2017-1-20 11:22 编辑 2 O2 H: t$ M8 c1 b0 E0 C6 e3 R
4 E1 D; q0 f" M+ h2 V" Z6 J, L
计划在机器上STF103VE  跑opus codec 进行编解码,中途停了,写一下做个记录。
/ r+ U$ w  ^6 D0 m; R3 `
0 _4 G9 Y  M1 s  s& k0 f6 i; s* Z" [
首先用CUBE 快速生成代码。
1 \; j) p! R7 [- E) K- A( |+ qClock 配置如下,我用的是内部时钟(应该没连接外部晶振):/ j7 W4 \& i6 w2 O2 _( L

clock 配置

clock 配置

. K* W# r) q, \% N
2 W; d* f. o0 G- z/ {5 Q3 GEnable FreeRTOS ,heap 配置为 20K,enc 结构需要13k Ram。
6 C! H% n2 u  P  Z

FreeRTOS config

FreeRTOS config
* x7 `: O& \- I9 [) I9 L( X
用于编解码的Task 的Stack 改为1024Word,即4K(小了会reset)
, }" `0 F9 Z7 k9 y2 F

Task Stack

Task Stack
( j$ D6 b4 K5 s1 I! S5 z
2 d6 g, v7 J% o- A
系统heap 需要改大,$ f+ h) e. [6 j4 N( N0 [

System Heap

System Heap

, @# d+ W! l( t* S
# l5 z; X3 ^6 z' |$ _将OPUS 代码copy 到工程里面,将如下文件加入到编译(没权限添加更多图片,只能用文字描述了)
  X. g9 k# y9 \1 ~; ~
5 c# R; L9 a* w5 @7 fopus-1.1.3/silk/ana_filt_bank_1.c  K8 i" K, }1 S% [
opus-1.1.3/silk/bwexpander.c! g0 l: F, z* t  L$ b* @% V3 i# r
opus-1.1.3/silk/control_audio_bandwidth.c+ H0 v4 @, ?! ~4 q7 I- Y
opus-1.1.3/silk/code_signs.c
4 a  A4 g5 H! X9 A" kopus-1.1.3/silk/CNG.c
0 Z' ^  R& r' h3 M# V& topus-1.1.3/silk/fixed/schur64_FIX.c! r' l, K( \. ]
opus-1.1.3/silk/control_codec.c7 _. i% P/ T+ b2 ^2 D! p
opus-1.1.3/silk/debug.c0 G% K( u( R0 o+ N4 F
opus-1.1.3/silk/control_SNR.c
; {9 y. Q4 b" F# f* Bopus-1.1.3/silk/fixed/residual_energy16_FIX.c
* H& P+ ]# _4 \  ^opus-1.1.3/silk/fixed/residual_energy_FIX.c
8 C6 p1 p  D# i: ^$ _: \$ _% Sopus-1.1.3/silk/fixed/warped_autocorrelation_FIX.c
9 X! i/ z4 M& |9 d, Xopus-1.1.3/silk/biquad_alt.c
; T% k. B- b7 v$ z( |" eopus-1.1.3/silk/bwexpander_32.c
9 m8 e4 q  @7 V( x& eopus-1.1.3/silk/check_control_input.c" W5 Q1 r, S0 t% X' m( y  {
opus-1.1.3/silk/A2NLSF.c
9 L7 x7 q4 \4 E1 A- o  fopus-1.1.3/silk/fixed/schur_FIX.c& y0 t- i% k( X4 q# f* \0 j# }0 ]
opus-1.1.3/silk/fixed/solve_LS_FIX.c
  Q) C- k7 z' X$ G. [opus-1.1.3/silk/fixed/vector_ops_FIX.c
9 R+ E  Q5 o% z7 H: u+ Dopus-1.1.3/silk/encode_pulses.c+ `+ S! d2 Y3 k# a
opus-1.1.3/silk/log2lin.c5 u1 V3 w# k0 `; z6 m& J
opus-1.1.3/silk/enc_API.c0 g9 Y6 D  f4 d" \4 B/ G
opus-1.1.3/silk/HP_variable_cutoff.c" S- c% Y  m: R* W3 P
opus-1.1.3/silk/init_decoder.c2 M# d) Z, s% F, E! Q
opus-1.1.3/silk/init_encoder.c8 `8 K; P8 v7 E& t" G: S4 F
opus-1.1.3/silk/decode_indices.c
, p1 M0 k4 p, ^) G- d/ W  }opus-1.1.3/silk/inner_prod_aligned.c
! |' n4 k  r1 D% B* m4 t& I$ hopus-1.1.3/silk/decode_frame.c; Q; Q1 K" h3 R
opus-1.1.3/silk/decode_pulses.c
5 [# ^, _& q9 z% @" ]$ O" mopus-1.1.3/silk/gain_quant.c
* U% {( M, m$ h. `; z1 Z' dopus-1.1.3/silk/interpolate.c
/ J" G4 ~& r3 p8 Aopus-1.1.3/silk/lin2log.c  I; @% p4 j1 P! B
opus-1.1.3/silk/decode_parameters.c5 k* N2 ~! G+ A
opus-1.1.3/silk/dec_API.c; g( M8 s, o: h9 q+ q
opus-1.1.3/silk/decode_core.c
- Z) P( w" h6 G3 J! mopus-1.1.3/silk/decode_pitch.c8 a$ G( l( y1 Q0 f6 g: Q1 d
opus-1.1.3/silk/decoder_set_fs.c9 I, V* ~# k( c8 p
opus-1.1.3/silk/encode_indices.c
+ a; p( c/ X1 h# m  \opus-1.1.3/silk/quant_LTP_gains.c
! i2 X% X! F8 P1 Oopus-1.1.3/silk/NSQ.c8 \7 T* {7 }% N' X. R2 ?0 D
opus-1.1.3/silk/resampler.c
7 S7 m0 i& G: [opus-1.1.3/silk/NLSF_del_dec_quant.c" S8 ?( x5 I" Z. c# g
opus-1.1.3/silk/NLSF2A.c
! m+ f$ `( D3 d! k) R) P7 `opus-1.1.3/silk/NLSF_stabilize.c" T+ R- k( P9 S& o/ C3 f/ n. q5 f6 U
opus-1.1.3/silk/NLSF_unpack.c
1 n. y" O. v8 [# X' C+ `opus-1.1.3/silk/NLSF_VQ.c
: i; R# T$ h/ z$ ]4 Lopus-1.1.3/silk/LPC_inv_pred_gain.c
, q* h. l- ]2 p  z7 N6 I# O: Topus-1.1.3/silk/NLSF_VQ_weights_laroia.c& j2 d' @+ t8 f* q8 w
opus-1.1.3/silk/pitch_est_tables.c: C& q+ Y6 E, N" b" o) `+ W' s4 `
opus-1.1.3/silk/NSQ_del_dec.c
0 ^- A; ^. B9 ?) E* O/ \opus-1.1.3/silk/PLC.c
0 t0 z! x7 d% W2 Qopus-1.1.3/silk/NLSF_decode.c5 |0 J. i! q+ J- g: v# I5 @
opus-1.1.3/silk/NLSF_encode.c: r2 I$ C3 F, z! y
opus-1.1.3/silk/LP_variable_cutoff.c+ y% m1 g1 V3 L9 D" \& j' W
opus-1.1.3/silk/LPC_analysis_filter.c
  h) D& T3 }2 h5 P5 V  uopus-1.1.3/silk/process_NLSFs.c
9 I' r5 L$ t8 ^/ \, zopus-1.1.3/silk/stereo_find_predictor.c
( J* A$ D* h% Z- v9 N# V2 Popus-1.1.3/silk/stereo_MS_to_LR.c
8 r0 o3 x  r9 Q5 O$ q( I. B& o: C+ Qopus-1.1.3/silk/resampler_private_AR2.c* p, @$ s3 r- N# l( ]! N
opus-1.1.3/silk/resampler_down2_3.c
' {+ ^  t6 d+ @; X! popus-1.1.3/silk/stereo_LR_to_MS.c7 R) y/ A0 k0 }% {  z
opus-1.1.3/silk/stereo_encode_pred.c
! k% \( ], X2 Q- y/ N5 d3 Eopus-1.1.3/silk/resampler_down2.c
  L# N- z1 J  X# z) c3 r& t) [opus-1.1.3/silk/sigm_Q15.c
0 b9 O1 ?7 {6 o: ~. n4 sopus-1.1.3/silk/resampler_rom.c1 X" S1 s# J) l, ?! r
opus-1.1.3/silk/sort.c9 }- N) w9 U; V( @
opus-1.1.3/silk/resampler_private_down_FIR.c
( E2 |& ~: I. \! }: ?: Z" s& `" {opus-1.1.3/silk/resampler_private_up2_HQ.c
9 \+ [& e! Q7 [* ropus-1.1.3/silk/stereo_decode_pred.c$ \& P6 B+ |* W; o  B' k' m
opus-1.1.3/silk/shell_coder.c
0 K9 m- \$ {# K6 B- z* c" J, kopus-1.1.3/silk/resampler_private_IIR_FIR.c; E# g) i9 d* _
opus-1.1.3/src/repacketizer.c
8 ]# G, z5 D5 O" ropus-1.1.3/silk/sum_sqr_shift.c; Q9 h7 o4 k# z- @2 c: L& D; y
opus-1.1.3/silk/table_LSF_cos.c
, a& e& i) [. ?! {+ N5 A& E. W7 yopus-1.1.3/silk/tables_NLSF_CB_WB.c5 s8 s4 s% H% v& c7 j
opus-1.1.3/silk/stereo_quant_pred.c
8 B  A. [7 i$ K6 E; kopus-1.1.3/silk/VAD.c
9 u8 V8 @; E+ o0 H7 i2 J8 N* @4 aopus-1.1.3/silk/tables_gain.c( x5 o6 I$ ?, K. n
opus-1.1.3/silk/tables_pulses_per_block.c
8 d" |9 K, ^1 |' n1 B/ q' [#opus-1.1.3/stm32_m3/opus_main.c: i4 g1 S4 t0 [% w% d% o
opus-1.1.3/src/opus_encoder.c
0 Z: m0 D' t! F' E6 J7 U4 Wopus-1.1.3/silk/tables_NLSF_CB_NB_MB.c  I7 s( P! j8 }( l+ v) \
opus-1.1.3/silk/tables_other.c- X9 a& m$ z) Y9 ]& {
opus-1.1.3/src/opus.c
- x* w! s) r  jopus-1.1.3/silk/tables_pitch_lag.c
6 b8 F/ }* _( R! _opus-1.1.3/src/opus_decoder.c  T7 ^% F' L& C/ V; _
opus-1.1.3/silk/VQ_WMat_EC.c: ]' i4 e/ ^1 m" j
opus-1.1.3/silk/tables_LTP.c

9 b6 W5 l$ D! K4 G+ s- A8 {opus-1.1.3/celt/entdec.c
4 I: T1 r7 k4 ~% }8 wopus-1.1.3/celt/entenc.c7 L* ~9 g( S3 |1 w. \- O1 Z; H
opus-1.1.3/celt/cwrs.c
5 p9 o/ v0 J" ]6 Fopus-1.1.3/celt/mathops.c( E3 O2 B/ m: q1 j" |
opus-1.1.3/celt/kiss_fft.c
  u, n: r! o' U/ x9 \% a- [" popus-1.1.3/celt/celt_lpc.c* n) m5 F- X% K! ]% `% i
opus-1.1.3/celt/mdct.c
+ h, X% W+ m8 f7 M  qopus-1.1.3/celt/modes.c
+ F" f6 P2 V) @# E2 Gopus-1.1.3/celt/bands.c
6 ~2 W% G* t$ p% y& l( A+ oopus-1.1.3/celt/pitch.c8 r( ~( n% g' e  ?% z+ b, m& }
opus-1.1.3/celt/celt_encoder.c
5 J7 i+ H7 F. H" Dopus-1.1.3/celt/laplace.c! n. G( O+ R- B6 h! I0 M: `  B, {
opus-1.1.3/celt/celt_decoder.c
; p9 ?; _) k- j2 v1 a6 f! R8 gopus-1.1.3/celt/entcode.c! L- c1 }# L) V9 U( C& g
opus-1.1.3/celt/celt.c
/ g# P* j+ O0 ~/ ]* \( A& V/ copus-1.1.3/silk/fixed/noise_shape_analysis_FIX.c
8 Z, d' Q  G" A+ Y  R3 Qopus-1.1.3/silk/fixed/process_gains_FIX.c
- _: H& M3 T, P+ R( [opus-1.1.3/silk/fixed/regularize_correlations_FIX.c$ w7 J* g4 f3 s6 [8 y1 M$ t$ R% q6 h: i
opus-1.1.3/silk/fixed/autocorr_FIX.c5 ?2 X; L6 d  d/ ~- u4 ?
opus-1.1.3/celt/quant_bands.c
4 V2 s. g  o8 z3 ^. P2 p) Uopus-1.1.3/silk/fixed/encode_frame_FIX.c
4 a- V% ]7 N; @+ _opus-1.1.3/silk/fixed/corrMatrix_FIX.c- R3 S9 T# L8 ^/ ~( {2 X
opus-1.1.3/silk/fixed/find_LTP_FIX.c
5 c2 m6 b0 m# O! y8 d7 ]6 C8 mopus-1.1.3/silk/fixed/pitch_analysis_core_FIX.c: x) v1 M. T# Y4 f
opus-1.1.3/silk/fixed/prefilter_FIX.c
' Q( J( s( S3 a+ U5 popus-1.1.3/celt/rate.c
8 K) K7 m/ s8 q* {1 A7 k" popus-1.1.3/silk/fixed/find_pitch_lags_FIX.c, g9 \0 u' _+ {+ s
opus-1.1.3/silk/fixed/burg_modified_FIX.c
1 R; X) X0 N6 K& D# popus-1.1.3/silk/fixed/LTP_analysis_filter_FIX.c
, B* b* ^% ~" _! ~opus-1.1.3/celt/vq.c( m0 O$ ]9 t, Y0 V3 u( c2 Q
opus-1.1.3/silk/fixed/find_LPC_FIX.c
4 S) U; f1 j1 S/ U: t5 Aopus-1.1.3/silk/fixed/find_pred_coefs_FIX.c
( j& ?3 j& `& H& u6 P! }# ?opus-1.1.3/silk/fixed/apply_sine_window_FIX.c" E4 i9 \0 C9 o; h$ P+ x
opus-1.1.3/silk/fixed/k2a_FIX.c2 `- v% H5 i! }+ R4 d
opus-1.1.3/silk/fixed/LTP_scale_ctrl_FIX.c
' c* h) p7 ], e8 r5 _opus-1.1.3/silk/fixed/k2a_Q16_FIX.c
% g1 v  q! p% ?; T  Q; x

+ W4 @8 N# I# k  C; R# Y# z+ ?# g我为opus-1.1.3建立了单独的group,并将这个group 的 【Override inherited settings 】勾上
  m, Y0 t6 C+ |$ `3 L  ?5 {2 V3 Z% P

opus config

opus config

* T5 @; b- W* J: l3 Z在【Proprocessor】里增加如下include 目录
& O9 I) U, Z) U% S5 x% L$PROJ_DIR$/../opus-1.1.3/include
7 K. T$ a: C  q0 w6 M8 T$PROJ_DIR$/../opus-1.1.3/celt
% H! \9 x' @' K6 ?/ T; L' {( r, H* N$PROJ_DIR$/../opus-1.1.3/silk7 h6 t5 y) m! W2 j0 _9 J
$PROJ_DIR$/../opus-1.1.3/silk/fixed* P1 i8 ~4 X4 N* H+ C
$PROJ_DIR$/../opus-1.1.3/stm32_m3

1 r; B: ^0 J# F. i* h: O增加:HAVE_CONFIG_H 到【Defined symbols】
$ Q# V) R/ F, r% I$ n opus include.JPG 1 O* u1 z3 ~% n, ^8 S9 a
将【Language 1 】中的【Allow VLA】勾上,目的是#define VAR_ARRAYS   1 后能便宜通过。9 H# ~% h! D, G( a9 E& h
, s+ @5 `  {" |$ M' v/ R1 N: m
copy opus-1.1.3/win32 到 opus-1.1.3/stm32_m3,建立config.h 和 version.h" c: @; ^0 P8 W, e5 T; ?5 W1 m+ N% |
config.h:% W. Y5 K/ _( ]) v" e/ }
#ifndef CONFIG_H3 k) J3 S1 ?8 L7 J1 U8 a
#define CONFIG_H

# Q, P0 L1 M# ]; q' i/ q& @//#define USE_ALLOCA            1
' {8 x; M& L6 n+ Y5 ?/ I# Q* k3 t#define VAR_ARRAYS   1  X# x/ O/ D: Z
/* Comment out the next line for floating-point code */6 P6 K4 X$ _2 Z$ U/ C
/*#define FIXED_POINT           1 */
: w" r$ K5 V; Y7 i
#define OPUS_BUILD            1- v% x% g% r" O* O; z3 x
#define DISABLE_FLOAT_API 1+ `3 @2 V$ `2 k
#define FIXED_POINT 11 ~' E( V. W' m6 Y' h
#define REMOVE_FOR_MALLOC
9 j5 a" b* l9 p9 a1 X4 o* I
//以上部分内容为增加部分,其他的与win32下同名文件相同
  I3 A5 ~! C1 b#endif /* CONFIG_H */
2 z0 [6 B: V7 S
8 _/ v: I4 q1 V2 G1 ^; v6 Pversion.h
: X0 Z4 Q; u- K- D" T5 N, P* M/ G#ifndef __VERSION_H__6 O5 O; b: a1 S7 i" ]# }
#define __VERSION_H__

( \+ u4 I+ o, A" e  I4 }" G* h#define PACKAGE_VERSION  "1.1.3"
: g3 ?  t$ t2 c6 b+ `2 B#endif /*__VERSION_H__*/
+ l* [  q' U" h! y7 s* }: J2 e8 ?! B" m( g' O7 V9 ^" v2 W
encode 和decode 代码:
/ C4 C  y% V. a) J
, d+ m1 j- A; {' O7 Y2 C' ?pusDecoder *dec;2 I% w/ O+ ~3 q
  static int offset = 0;
& D$ p+ ^- J' e' Q6 ~2 _4 h  int size = 0;
- K. u: I! [  E9 O+ A0 A  const unsigned char *packet;
8 B6 X1 B6 U1 @! @3 Y2 t& {  int i = 0;$ k1 K1 ?4 c9 ^
  int frame_size = 0;
; Z5 ~0 W' j, s" k, h  int max_size = 0;$ O& g* e* n6 B5 e) W& `
  char buffer[36];
$ B: R' q; C" L. g0 c0 C7 ^# |* a/ e
, r% }: }- `9 a+ ]: \4 m, g   
' h% ~- f2 }) i- Z6 s, n9 g3 o$ Z- Q  uint32_t start = osKernelSysTick();
/ @& f3 ]# y$ M/ ~3 J3 F& \  . ~+ R6 g" x) W* i
  OpusEncoder *enc = NULL;$ ]  e2 P, c& w$ U# j0 R0 \
  static int len = 10;
$ t, K) c0 c2 Y0 o2 e# K$ s
  
0 |( S  j3 Z. d( p' j& c1 Q2 d5 p7 b  size = opus_encoder_get_size(channels);
& V" }# ^. l) S  enc = pvPortMalloc(size);
" ]- D3 ~7 w8 Y5 ], D, u  error = opus_encoder_init(enc, Fs, channels, OPUS_APPLICATION_RESTRICTED_LOWDELAY);

5 k4 c! k0 s( _4 y& H  opus_encoder_ctl(enc, OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_20_MS));  V2 _, _& t. t9 |  P
  //opus_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_VOICE));
! Q) r& J( Y& x; c  opus_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC));  y- F: {7 G2 V" a- m; L) @2 u
  
7 s( P2 Y) ~3 }7 z2 u% f# E! `  d7 y  len = opus_encode(enc, audio_frame + offset, Fs/50/*20ms*/, opus_buffer, sizeof(opus_buffer));
8 `7 p4 F0 K  t5 e, d% R/ E  offset += Fs/50;$ C: c! j: x" x* b( E& R% R, t
  if(offset >= sizeof(audio_frame)/sizeof(uint16_t))
) _! z; V. i+ r, t$ v* w5 `    offset = 0;
0 w; ^6 R2 @$ D0 t9 B  vPortFree(enc);
0 w# `4 k; z1 D. Y4 ]
  OpusDecoder *st  = (OpusDecoder *)pvPortMalloc(opus_decoder_get_size(channels));9 n% M( o8 R" _$ k/ d. C( ?
  error = opus_decoder_init(st, Fs, channels);
! `! `- e, J  j/ x1 e* L  9 _% N+ m( N+ ^9 X8 A

; T2 P5 x* a$ N) m. Y  frame_size = opus_decode(st, opus_buffer, len, pcm, PCM_BUFFER_SIZE, 0);
* g5 A6 `& W  c3 d( ]9 ?

: }' @6 w& p5 M3 I对了,我改了这两个宏,
8 c: o8 F' {0 [* T#define MAX_FS_KHZ                              8 /*16 --> 8 modify for memory*/+ |- W' _" D! t6 n/ ]3 u
#define MAX_API_FS_KHZ                          8 /*48 --> 8 modify for memory/' I, ?+ t3 w+ b/ y- o' w* ]' U
原因是,如果不修改opus_encoder_get_size(1); 返回的是27k,改完后还得13k,实在是没有那么多ram. |: `& D* s: X
size = opus_encoder_get_size(1);
& T* ]9 M; a" x5 ~enc = pvPortMalloc(size);# l! X! h! [5 G1 y( S# J

4 {8 a4 n. l  j7 @总结,64k ram 感觉刚刚够,还没有增加其他的功能,解压缩20ms 数据用了6-7ms,编码我忘记了,记得编解码用了33ms,有点高。
- s2 S. y! k, [! D9 t声音可以用DAC(PA4)播放出来,需要外加功放,不加功放声音很不好。经过opus 压缩解压后声音损失较大,音乐还能听出来,但很多噪声。( k# D6 M( E/ T8 D) g$ `& H, Z6 R& g
3 @" V" j1 h9 W( [

评分

参与人数 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 手机版