1 /* SPDX-License-Identifier: BSD-3-Clause 2 * 3 * Copyright(c) 2022 Google LLC. 4 * 5 * Author: Kehuang Li <kehuangli@google.com> 6 */ 7 8 #ifndef GOOGLE_AUDIO_POST_PROCESSING_H 9 #define GOOGLE_AUDIO_POST_PROCESSING_H 10 11 #include <stdint.h> 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 // This define ensure that the linked library matches the header file. 18 #define GoogleAudioPostProcessingCreate GoogleAudioPostProcessingCreate_v1 19 20 typedef struct GoogleAudioPostProcessingState GoogleAudioPostProcessingState; 21 22 struct GoogleAudioPostProcessingBuffer { 23 uint16_t sample_size; // Bytes per sample, s16=>2, s32=>4. 24 uint16_t channels; // Number of interleaved channels. 25 uint32_t frames; // Total available frames. 26 void *base_addr; // Start address of the circular buffer. 27 void *head_ptr; // Current read/write position of the circular buffer. 28 void *end_addr; // End address of the circular buffer. 29 }; 30 31 // Creates an instance of GoogleAudioPostProcessing with the tuning embedded in 32 // the library. 33 GoogleAudioPostProcessingState *GoogleAudioPostProcessingCreate(void); 34 35 // Frees all allocated resources in `state` and deletes `state`. 36 void GoogleAudioPostProcessingDelete(GoogleAudioPostProcessingState *state); 37 38 // Setup or reconfigure the audio processing. 39 // Returns 0 if success and non zero if failure. 40 int GoogleAudioPostProcessingSetup(GoogleAudioPostProcessingState *const state, 41 int channels, int frames, int volume, 42 const uint8_t *const config, 43 int config_size); 44 45 // Pulls the current config (serialized) of the audio processing pipeline. 46 // If the config size is greater than `max_config_size`, following calls with 47 // `msg_index` > 0 can happen, and the implementation will maintain that internally. 48 // Returns config size if success and negative if failure. 49 int GoogleAudioPostProcessingGetConfig( 50 GoogleAudioPostProcessingState *const state, int code, int msg_index, 51 uint8_t *const config, int max_config_size); 52 53 // Accepts and produces a frame of interleaved 32 bit integer audio. `src` and 54 // `dest` may use the same memory, if desired. 55 // Returns 0 if success and non zero if failure. 56 int GoogleAudioPostProcessingProcess( 57 GoogleAudioPostProcessingState *const state, 58 const struct GoogleAudioPostProcessingBuffer *const src, 59 struct GoogleAudioPostProcessingBuffer *const dest); 60 61 // Sets system volume. 62 // Returns volume if success and negative if failure. 63 int GoogleAudioPostProcessingSetVol(GoogleAudioPostProcessingState *const state, 64 const int *const volume, int num_channels); 65 66 // Gets current volume. 67 // Returns 0 if success and non zero if failure. 68 int GoogleAudioPostProcessingGetVol(GoogleAudioPostProcessingState *const state, 69 int *const volume, int num_channels); 70 71 #ifdef __cplusplus 72 } 73 #endif 74 75 #endif // GOOGLE_AUDIO_POST_PROCESSING_H 76