aboutsummaryrefslogtreecommitdiff
path: root/src/modules/audio_coding/codecs/isac/fix/interface/isacfix.h
blob: 28e942940fe5b9eff6a79fe8d94eb8205a86a460 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_FIX_INTERFACE_ISACFIX_H_
#define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_FIX_INTERFACE_ISACFIX_H_

/*
 * Define the fixpoint numeric formats
 */
#include "typedefs.h"


typedef struct {
  void *dummy;
} ISACFIX_MainStruct;


#if defined(__cplusplus)
extern "C" {
#endif


  /**************************************************************************
   * WebRtcIsacfix_AssignSize(...)
   *
   *  Functions used when malloc is not allowed
   *  Output the number of bytes needed to allocate for iSAC struct.
   *
   */

  WebRtc_Word16 WebRtcIsacfix_AssignSize(int *sizeinbytes);

  /**************************************************************************
   * WebRtcIsacfix_Assign(...)
   *
   * Functions used when malloc is not allowed, it
   * places a struct at the given address.
   *
   * Input:
   *      - *ISAC_main_inst   : a pointer to the coder instance.
   *      - ISACFIX_inst_Addr : address of the memory where a space is
   *                            for iSAC structure.
   *
   * Return value             : 0 - Ok
   *                           -1 - Error
   */

  WebRtc_Word16 WebRtcIsacfix_Assign(ISACFIX_MainStruct **inst,
                                     void *ISACFIX_inst_Addr);

  /****************************************************************************
   * WebRtcIsacfix_Create(...)
   *
   * This function creates an ISAC instance, which will contain the state
   * information for one coding/decoding channel.
   *
   * Input:
   *      - *ISAC_main_inst   : a pointer to the coder instance.
   *
   * Return value             : 0 - Ok
   *                           -1 - Error
   */

  WebRtc_Word16 WebRtcIsacfix_Create(ISACFIX_MainStruct **ISAC_main_inst);


  /****************************************************************************
   * WebRtcIsacfix_Free(...)
   *
   * This function frees the ISAC instance created at the beginning.
   *
   * Input:
   *      - ISAC_main_inst    : a ISAC instance.
   *
   * Return value             :  0 - Ok
   *                            -1 - Error
   */

  WebRtc_Word16 WebRtcIsacfix_Free(ISACFIX_MainStruct *ISAC_main_inst);


  /****************************************************************************
   * WebRtcIsacfix_EncoderInit(...)
   *
   * This function initializes an ISAC instance prior to the encoder calls.
   *
   * Input:
   *     - ISAC_main_inst     : ISAC instance.
   *     - CodingMode         : 0 - Bit rate and frame length are automatically
   *                                adjusted to available bandwidth on
   *                                transmission channel.
   *                            1 - User sets a frame length and a target bit
   *                                rate which is taken as the maximum short-term
   *                                average bit rate.
   *
   * Return value             :  0 - Ok
   *                            -1 - Error
   */

  WebRtc_Word16 WebRtcIsacfix_EncoderInit(ISACFIX_MainStruct *ISAC_main_inst,
                                          WebRtc_Word16  CodingMode);


  /****************************************************************************
   * WebRtcIsacfix_Encode(...)
   *
   * This function encodes 10ms frame(s) and inserts it into a package.
   * Input speech length has to be 160 samples (10ms). The encoder buffers those
   * 10ms frames until it reaches the chosen Framesize (480 or 960 samples
   * corresponding to 30 or 60 ms frames), and then proceeds to the encoding.
   *
   * Input:
   *      - ISAC_main_inst    : ISAC instance.
   *      - speechIn          : input speech vector.
   *
   * Output:
   *      - encoded           : the encoded data vector
   *
   * Return value             : >0 - Length (in bytes) of coded data
   *                             0 - The buffer didn't reach the chosen framesize
   *                                 so it keeps buffering speech samples.
   *                            -1 - Error
   */

  WebRtc_Word16 WebRtcIsacfix_Encode(ISACFIX_MainStruct *ISAC_main_inst,
                                     const WebRtc_Word16 *speechIn,
                                     WebRtc_Word16 *encoded);



  /****************************************************************************
   * WebRtcIsacfix_EncodeNb(...)
   *
   * This function encodes 10ms narrow band (8 kHz sampling) frame(s) and inserts
   * it into a package. Input speech length has to be 80 samples (10ms). The encoder
   * interpolates into wide-band (16 kHz sampling) buffers those
   * 10ms frames until it reaches the chosen Framesize (480 or 960 wide-band samples
   * corresponding to 30 or 60 ms frames), and then proceeds to the encoding.
   *
   * The function is enabled if WEBRTC_ISAC_FIX_NB_CALLS_ENABLED is defined
   *
   * Input:
   *      - ISAC_main_inst    : ISAC instance.
   *      - speechIn          : input speech vector.
   *
   * Output:
   *      - encoded           : the encoded data vector
   *
   * Return value             : >0 - Length (in bytes) of coded data
   *                             0 - The buffer didn't reach the chosen framesize
   *                                 so it keeps buffering speech samples.
   *                            -1 - Error
   */


#ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED
  WebRtc_Word16 WebRtcIsacfix_EncodeNb(ISACFIX_MainStruct *ISAC_main_inst,
                                       const WebRtc_Word16 *speechIn,
                                       WebRtc_Word16 *encoded);
#endif //  WEBRTC_ISAC_FIX_NB_CALLS_ENABLED



  /****************************************************************************
   * WebRtcIsacfix_DecoderInit(...)
   *
   * This function initializes an ISAC instance prior to the decoder calls.
   *
   * Input:
   *  - ISAC_main_inst : ISAC instance.
   *
   * Return value
   *       :  0 - Ok
   *         -1 - Error
   */

  WebRtc_Word16 WebRtcIsacfix_DecoderInit(ISACFIX_MainStruct *ISAC_main_inst);


  /****************************************************************************
   * WebRtcIsacfix_UpdateBwEstimate1(...)
   *
   * This function updates the estimate of the bandwidth.
   *
   * Input:
   *      - ISAC_main_inst    : ISAC instance.
   *      - encoded           : encoded ISAC frame(s).
   *      - packet_size       : size of the packet.
   *      - rtp_seq_number    : the RTP number of the packet.
   *      - arr_ts            : the arrival time of the packet (from NetEq)
   *                            in samples.
   *
   * Return value             : 0 - Ok
   *                           -1 - Error
   */

  WebRtc_Word16 WebRtcIsacfix_UpdateBwEstimate1(ISACFIX_MainStruct *ISAC_main_inst,
                                                const WebRtc_UWord16 *encoded,
                                                WebRtc_Word32  packet_size,
                                                WebRtc_UWord16 rtp_seq_number,
                                                WebRtc_UWord32 arr_ts);

  /****************************************************************************
   * WebRtcIsacfix_UpdateBwEstimate(...)
   *
   * This function updates the estimate of the bandwidth.
   *
   * Input:
   *      - ISAC_main_inst    : ISAC instance.
   *      - encoded           : encoded ISAC frame(s).
   *      - packet_size       : size of the packet.
   *      - rtp_seq_number    : the RTP number of the packet.
   *      - send_ts           : the send time of the packet from RTP header,
   *                            in samples.
   *      - arr_ts            : the arrival time of the packet (from NetEq)
   *                            in samples.
   *
   * Return value             :  0 - Ok
   *                            -1 - Error
   */

  WebRtc_Word16 WebRtcIsacfix_UpdateBwEstimate(ISACFIX_MainStruct *ISAC_main_inst,
                                               const WebRtc_UWord16   *encoded,
                                               WebRtc_Word32          packet_size,
                                               WebRtc_UWord16         rtp_seq_number,
                                               WebRtc_UWord32         send_ts,
                                               WebRtc_UWord32         arr_ts);

  /****************************************************************************
   * WebRtcIsacfix_Decode(...)
   *
   * This function decodes an ISAC frame. Output speech length
   * will be a multiple of 480 samples: 480 or 960 samples,
   * depending on the framesize (30 or 60 ms).
   *
   * Input:
   *      - ISAC_main_inst    : ISAC instance.
   *      - encoded           : encoded ISAC frame(s)
   *      - len               : bytes in encoded vector
   *
   * Output:
   *      - decoded           : The decoded vector
   *
   * Return value             : >0 - number of samples in decoded vector
   *                            -1 - Error
   */

  WebRtc_Word16 WebRtcIsacfix_Decode(ISACFIX_MainStruct *ISAC_main_inst,
                                     const WebRtc_UWord16 *encoded,
                                     WebRtc_Word16 len,
                                     WebRtc_Word16 *decoded,
                                     WebRtc_Word16 *speechType);


  /****************************************************************************
   * WebRtcIsacfix_DecodeNb(...)
   *
   * This function decodes a ISAC frame in narrow-band (8 kHz sampling).
   * Output speech length will be a multiple of 240 samples: 240 or 480 samples,
   * depending on the framesize (30 or 60 ms).
   *
   * The function is enabled if WEBRTC_ISAC_FIX_NB_CALLS_ENABLED is defined
   *
   * Input:
   *      - ISAC_main_inst    : ISAC instance.
   *      - encoded           : encoded ISAC frame(s)
   *      - len               : bytes in encoded vector
   *
   * Output:
   *      - decoded           : The decoded vector
   *
   * Return value             : >0 - number of samples in decoded vector
   *                            -1 - Error
   */

#ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED
  WebRtc_Word16 WebRtcIsacfix_DecodeNb(ISACFIX_MainStruct *ISAC_main_inst,
                                       const WebRtc_UWord16 *encoded,
                                       WebRtc_Word16 len,
                                       WebRtc_Word16 *decoded,
                                       WebRtc_Word16 *speechType);
#endif //  WEBRTC_ISAC_FIX_NB_CALLS_ENABLED


  /****************************************************************************
   * WebRtcIsacfix_DecodePlcNb(...)
   *
   * This function conducts PLC for ISAC frame(s) in narrow-band (8kHz sampling).
   * Output speech length  will be "240*noOfLostFrames" samples
   * that equevalent of "30*noOfLostFrames" millisecond.
   *
   * The function is enabled if WEBRTC_ISAC_FIX_NB_CALLS_ENABLED is defined
   *
   * Input:
   *      - ISAC_main_inst    : ISAC instance.
   *      - noOfLostFrames    : Number of PLC frames (240 sample=30ms) to produce
   *                            NOTE! Maximum number is 2 (480 samples = 60ms)
   *
   * Output:
   *      - decoded           : The decoded vector
   *
   * Return value             : >0 - number of samples in decoded PLC vector
   *                            -1 - Error
   */

#ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED
  WebRtc_Word16 WebRtcIsacfix_DecodePlcNb(ISACFIX_MainStruct *ISAC_main_inst,
                                          WebRtc_Word16 *decoded,
                                          WebRtc_Word16 noOfLostFrames );
#endif // WEBRTC_ISAC_FIX_NB_CALLS_ENABLED




  /****************************************************************************
   * WebRtcIsacfix_DecodePlc(...)
   *
   * This function conducts PLC for ISAC frame(s) in wide-band (16kHz sampling).
   * Output speech length  will be "480*noOfLostFrames" samples
   * that is equevalent of "30*noOfLostFrames" millisecond.
   *
   * Input:
   *      - ISAC_main_inst    : ISAC instance.
   *      - noOfLostFrames    : Number of PLC frames (480sample = 30ms)
   *                            to produce
   *                            NOTE! Maximum number is 2 (960 samples = 60ms)
   *
   * Output:
   *      - decoded           : The decoded vector
   *
   * Return value             : >0 - number of samples in decoded PLC vector
   *                            -1 - Error
   */

  WebRtc_Word16 WebRtcIsacfix_DecodePlc(ISACFIX_MainStruct *ISAC_main_inst,
                                        WebRtc_Word16 *decoded,
                                        WebRtc_Word16 noOfLostFrames );


  /****************************************************************************
   * WebRtcIsacfix_ReadFrameLen(...)
   *
   * This function returns the length of the frame represented in the packet.
   *
   * Input:
   *      - encoded           : Encoded bitstream
   *
   * Output:
   *      - frameLength       : Length of frame in packet (in samples)
   *
   */

  WebRtc_Word16 WebRtcIsacfix_ReadFrameLen(const WebRtc_Word16* encoded,
                                           WebRtc_Word16* frameLength);

  /****************************************************************************
   * WebRtcIsacfix_Control(...)
   *
   * This function sets the limit on the short-term average bit rate and the
   * frame length. Should be used only in Instantaneous mode.
   *
   * Input:
   *      - ISAC_main_inst    : ISAC instance.
   *      - rate              : limit on the short-term average bit rate,
   *                            in bits/second (between 10000 and 32000)
   *      - framesize         : number of milliseconds per frame (30 or 60)
   *
   * Return value             : 0  - ok
   *                           -1 - Error
   */

  WebRtc_Word16 WebRtcIsacfix_Control(ISACFIX_MainStruct *ISAC_main_inst,
                                      WebRtc_Word16          rate,
                                      WebRtc_Word16          framesize);



  /****************************************************************************
   * WebRtcIsacfix_ControlBwe(...)
   *
   * This function sets the initial values of bottleneck and frame-size if
   * iSAC is used in channel-adaptive mode. Through this API, users can
   * enforce a frame-size for all values of bottleneck. Then iSAC will not
   * automatically change the frame-size.
   *
   *
   * Input:
   *      - ISAC_main_inst    : ISAC instance.
   *      - rateBPS           : initial value of bottleneck in bits/second
   *                            10000 <= rateBPS <= 32000 is accepted
   *      - frameSizeMs       : number of milliseconds per frame (30 or 60)
   *      - enforceFrameSize  : 1 to enforce the given frame-size through out
   *                            the adaptation process, 0 to let iSAC change
   *                            the frame-size if required.
   *
   * Return value             : 0  - ok
   *                           -1 - Error
   */

  WebRtc_Word16 WebRtcIsacfix_ControlBwe(ISACFIX_MainStruct *ISAC_main_inst,
                                         WebRtc_Word16 rateBPS,
                                         WebRtc_Word16 frameSizeMs,
                                         WebRtc_Word16 enforceFrameSize);



  /****************************************************************************
   * WebRtcIsacfix_version(...)
   *
   * This function returns the version number.
   *
   * Output:
   *      - version      : Pointer to character string
   *
   */

  void WebRtcIsacfix_version(char *version);


  /****************************************************************************
   * WebRtcIsacfix_GetErrorCode(...)
   *
   * This function can be used to check the error code of an iSAC instance. When
   * a function returns -1 a error code will be set for that instance. The
   * function below extract the code of the last error that occured in the
   * specified instance.
   *
   * Input:
   *  - ISAC_main_inst        : ISAC instance
   *
   * Return value             : Error code
   */

  WebRtc_Word16 WebRtcIsacfix_GetErrorCode(ISACFIX_MainStruct *ISAC_main_inst);


  /****************************************************************************
   * WebRtcIsacfix_GetUplinkBw(...)
   *
   * This function return iSAC send bitrate
   *
   * Input:
   *      - ISAC_main_inst    : iSAC instance
   *
   * Return value             : <0 Error code
   *                            else bitrate
   */

  WebRtc_Word32 WebRtcIsacfix_GetUplinkBw(ISACFIX_MainStruct *ISAC_main_inst);


  /****************************************************************************
   * WebRtcIsacfix_SetMaxPayloadSize(...)
   *
   * This function sets a limit for the maximum payload size of iSAC. The same
   * value is used both for 30 and 60 msec packets.
   * The absolute max will be valid until next time the function is called.
   * NOTE! This function may override the function WebRtcIsacfix_SetMaxRate()
   *
   * Input:
   *      - ISAC_main_inst    : iSAC instance
   *      - maxPayloadBytes   : maximum size of the payload in bytes
   *                            valid values are between 100 and 400 bytes
   *
   *
   * Return value             : 0 if sucessful
   *                           -1 if error happens
   */

  WebRtc_Word16 WebRtcIsacfix_SetMaxPayloadSize(ISACFIX_MainStruct *ISAC_main_inst,
                                                WebRtc_Word16 maxPayloadBytes);


  /****************************************************************************
   * WebRtcIsacfix_SetMaxRate(...)
   *
   * This function sets the maximum rate which the codec may not exceed for a
   * singel packet. The maximum rate is set in bits per second.
   * The codec has an absolute maximum rate of 53400 bits per second (200 bytes
   * per 30 msec).
   * It is possible to set a maximum rate between 32000 and 53400 bits per second.
   *
   * The rate limit is valid until next time the function is called.
   *
   * NOTE! Packet size will never go above the value set if calling
   * WebRtcIsacfix_SetMaxPayloadSize() (default max packet size is 400 bytes).
   *
   * Input:
   *      - ISAC_main_inst    : iSAC instance
   *      - maxRateInBytes    : maximum rate in bits per second,
   *                            valid values are 32000 to 53400 bits
   *
   * Return value             : 0 if sucessful
   *                           -1 if error happens
   */

  WebRtc_Word16 WebRtcIsacfix_SetMaxRate(ISACFIX_MainStruct *ISAC_main_inst,
                                         WebRtc_Word32 maxRate);

  /****************************************************************************
   * WebRtcIsacfix_CreateInternal(...)
   *
   * This function creates the memory that is used to store data in the encoder
   *
   * Input:
   *      - *ISAC_main_inst   : a pointer to the coder instance.
   *
   * Return value             : 0 - Ok
   *                           -1 - Error
   */

  WebRtc_Word16 WebRtcIsacfix_CreateInternal(ISACFIX_MainStruct *ISAC_main_inst);


  /****************************************************************************
   * WebRtcIsacfix_FreeInternal(...)
   *
   * This function frees the internal memory for storing encoder data.
   *
   * Input:
   *      - ISAC_main_inst        : an ISAC instance.
   *
   * Return value                 :  0 - Ok
   *                                -1 - Error
   */

  WebRtc_Word16 WebRtcIsacfix_FreeInternal(ISACFIX_MainStruct *ISAC_main_inst);


  /****************************************************************************
   * WebRtcIsacfix_GetNewBitStream(...)
   *
   * This function returns encoded data, with the recieved bwe-index in the
   * stream. It should always return a complete packet, i.e. only called once
   * even for 60 msec frames
   *
   * Input:
   *      - ISAC_main_inst    : ISAC instance.
   *      - bweIndex          : index of bandwidth estimate to put in new bitstream
   *      - scale             : factor for rate change (0.4 ~=> half the rate, 1 no change).
   *
   * Output:
   *      - encoded           : the encoded data vector
   *
   * Return value             : >0 - Length (in bytes) of coded data
   *                            -1 - Error
   */

  WebRtc_Word16 WebRtcIsacfix_GetNewBitStream(ISACFIX_MainStruct *ISAC_main_inst,
                                              WebRtc_Word16          bweIndex,
                                              float              scale,
                                              WebRtc_Word16        *encoded);


  /****************************************************************************
   * WebRtcIsacfix_GetDownLinkBwIndex(...)
   *
   * This function returns index representing the Bandwidth estimate from
   * other side to this side.
   *
   * Input:
   *      - ISAC_main_inst    : iSAC struct
   *
   * Output:
   *      - rateIndex         : Bandwidth estimate to transmit to other side.
   *
   */

  WebRtc_Word16 WebRtcIsacfix_GetDownLinkBwIndex(ISACFIX_MainStruct* ISAC_main_inst,
                                                 WebRtc_Word16*     rateIndex);


  /****************************************************************************
   * WebRtcIsacfix_UpdateUplinkBw(...)
   *
   * This function takes an index representing the Bandwidth estimate from
   * this side to other side and updates BWE.
   *
   * Input:
   *      - ISAC_main_inst    : iSAC struct
   *      - rateIndex         : Bandwidth estimate from other side.
   *
   */

  WebRtc_Word16 WebRtcIsacfix_UpdateUplinkBw(ISACFIX_MainStruct* ISAC_main_inst,
                                             WebRtc_Word16     rateIndex);


  /****************************************************************************
   * WebRtcIsacfix_ReadBwIndex(...)
   *
   * This function returns the index of the Bandwidth estimate from the bitstream.
   *
   * Input:
   *      - encoded           : Encoded bitstream
   *
   * Output:
   *      - rateIndex         : Bandwidth estimate in bitstream
   *
   */

  WebRtc_Word16 WebRtcIsacfix_ReadBwIndex(const WebRtc_Word16* encoded,
                                          WebRtc_Word16* rateIndex);


  /****************************************************************************
   * WebRtcIsacfix_GetNewFrameLen(...)
   *
   * This function return the next frame length (in samples) of iSAC.
   *
   * Input:
   *      -ISAC_main_inst     : iSAC instance
   *
   * Return value             : frame lenght in samples
   */

  WebRtc_Word16 WebRtcIsacfix_GetNewFrameLen(ISACFIX_MainStruct *ISAC_main_inst);


#if defined(__cplusplus)
}
#endif



#endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_FIX_INTERFACE_ISACFIX_H_ */