1 // SPDX-License-Identifier: BSD-3-Clause 2 // 3 // Copyright(c) 2021 Google LLC. 4 // 5 // Author: Lionel Koenig <lionelk@google.com> 6 #ifndef GOOGLE_RTC_AUDIO_PROCESSING_H 7 #define GOOGLE_RTC_AUDIO_PROCESSING_H 8 9 #include <stdint.h> 10 11 #ifdef __cplusplus 12 extern "C" { 13 #endif 14 15 // This define ensure that the linked library matches the header file. 16 // LINT.IfChange(api_version) 17 #define GoogleRtcAudioProcessingCreate GoogleRtcAudioProcessingCreate_v1 18 // LINT.ThenChange() 19 20 typedef struct GoogleRtcAudioProcessingState GoogleRtcAudioProcessingState; 21 22 // LINT.IfChange() 23 24 // Attaches `buffer` to use for memory allocations. The ownership of `buffer` 25 // remains within the caller. 26 void GoogleRtcAudioProcessingAttachMemoryBuffer(uint8_t *const buffer, 27 int buffer_size); 28 29 // Detaches any attached memory buffer used for memory allocations. Returns 0 if 30 // success and non zero if failure. 31 void GoogleRtcAudioProcessingDetachMemoryBuffer(void); 32 33 // Creates an instance of GoogleRtcAudioProcessing with the tuning embedded in 34 // the library. If creation fails, NULL is returned. 35 GoogleRtcAudioProcessingState *GoogleRtcAudioProcessingCreate(void); 36 37 // Creates an instance of GoogleRtcAudioProcessing based on `config` and stream 38 // formats, where the content of config overrides any embedded parameters and 39 // the stream formats overrides any content in the config. Setting `config` to 40 // NULL means that no config is specified. If creation fails, NULL is returned. 41 GoogleRtcAudioProcessingState *GoogleRtcAudioProcessingCreateWithConfig( 42 int capture_sample_rate_hz, int num_capture_input_channels, 43 int num_capture_output_channels, int render_sample_rate_hz, 44 int num_render_channels, const uint8_t *const config, int config_size); 45 46 // Frees all allocated resources in `state`. 47 void GoogleRtcAudioProcessingFree(GoogleRtcAudioProcessingState *state); 48 49 // Specifies the stream formats to use. Returns 0 if success and non zero if 50 // failure. 51 int GoogleRtcAudioProcessingSetStreamFormats( 52 GoogleRtcAudioProcessingState *const state, int capture_sample_rate_hz, 53 int num_capture_input_channels, int num_capture_output_channels, 54 int render_sample_rate_hz, int num_render_channels); 55 56 // Specifies setup-specific parameters. Returns 0 if success and non zero if 57 // failure. Parameters which are NULL are ignored. 58 int GoogleRtcAudioProcessingParameters( 59 GoogleRtcAudioProcessingState *const state, float *capture_headroom_linear, 60 float *echo_path_delay_ms); 61 62 // Returns the framesize used for processing. 63 int GoogleRtcAudioProcessingGetFramesizeInMs( 64 GoogleRtcAudioProcessingState *const state); 65 66 // Reconfigure the audio processing. 67 // Returns 0 if success and non zero if failure. 68 int GoogleRtcAudioProcessingReconfigure( 69 GoogleRtcAudioProcessingState *const state, const uint8_t *const config, 70 int config_size); 71 72 // Processes the microphone stream. 73 // Accepts deinterleaved float audio with the range [-1, 1]. Each element of 74 // |src| points to an array of samples for the channel. At output, the channels 75 // will be in |dest|. 76 // Returns 0 if success and non zero if failure. 77 int GoogleRtcAudioProcessingProcessCapture_float32( 78 GoogleRtcAudioProcessingState *const state, const float *const *src, 79 float *const *dest); 80 81 // Accepts and and produces a frame of interleaved 16 bit integer audio. `src` 82 // and `dest` may use the same memory, if desired. 83 // Returns 0 if success and non zero if failure. 84 int GoogleRtcAudioProcessingProcessCapture_int16( 85 GoogleRtcAudioProcessingState *const state, const int16_t *const src, 86 int16_t *const dest); 87 88 // Analyzes the playback stream. 89 // Accepts deinterleaved float audio with the range [-1, 1]. Each element 90 // of |src| points to an array of samples for the channel. 91 // Returns 0 if success and non zero if failure. 92 int GoogleRtcAudioProcessingAnalyzeRender_float32( 93 GoogleRtcAudioProcessingState *const state, const float *const *src); 94 95 // Accepts interleaved int16 audio. 96 // Returns 0 if success and non zero if failure. 97 int GoogleRtcAudioProcessingAnalyzeRender_int16( 98 GoogleRtcAudioProcessingState *const state, const int16_t *const src); 99 100 // LINT.ThenChange(:api_version) 101 102 #ifdef __cplusplus 103 } 104 #endif 105 106 #endif // GOOGLE_RTC_AUDIO_PROCESSING_H 107