btstack_audio.h (7b3465d4a21892caa7288e50d11463deaaa33ae5) btstack_audio.h (e39d945b26cebddb2e28a3ae932371da73f658f1)
1/*
2 * Copyright (C) 2017 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 38 unchanged lines hidden (view full) ---

47/*
48 * btstack_audio.h
49 *
50 * Abstraction layer for 16-bit audio playback and recording within BTstack
51 */
52
53typedef struct {
54
1/*
2 * Copyright (C) 2017 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 38 unchanged lines hidden (view full) ---

47/*
48 * btstack_audio.h
49 *
50 * Abstraction layer for 16-bit audio playback and recording within BTstack
51 */
52
53typedef struct {
54
55 /**
55 /**
56 * @brief Setup audio codec for specified samplerate and number of channels
57 * @param Channels (1=mono, 2=stereo)
58 * @param Sample rate
59 * @param Playback callback
56 * @brief Setup audio codec for specified samplerate and number of channels
57 * @param Channels (1=mono, 2=stereo)
58 * @param Sample rate
59 * @param Playback callback
60 * @param Recording callback
61 * @return 1 on success
62 */
63 int (*init)(uint8_t channels,
64 uint32_t samplerate,
60 * @return 1 on success
61 */
62 int (*init)(uint8_t channels,
63 uint32_t samplerate,
65 void (*playback) ( int16_t * buffer, uint16_t num_samples),
66 void (*recording)(const int16_t * buffer, uint16_t num_samples));
64 void (*playback) ( int16_t * buffer, uint16_t num_samples));
67
65
68 /**
66 /**
69 * @brief Start stream
70 */
71 void (*start_stream)(void);
72
67 * @brief Start stream
68 */
69 void (*start_stream)(void);
70
73 /**
71 /**
72 * @brief Stop stream
73 */
74 void (*stop_stream)(void);
75
76 /**
74 * @brief Close audio codec
75 */
76 void (*close)(void);
77
77 * @brief Close audio codec
78 */
79 void (*close)(void);
80
78} btstack_audio_t;
81} btstack_audio_sink_t;
79
82
83
84typedef struct {
85
86 /**
87 * @brief Setup audio codec for specified samplerate and number of channels
88 * @param Channels (1=mono, 2=stereo)
89 * @param Sample rate
90 * @param Recording callback
91 * @return 1 on success
92 */
93 int (*init)(uint8_t channels,
94 uint32_t samplerate,
95 void (*recording)(const int16_t * buffer, uint16_t num_samples));
96
97 /**
98 * @brief Start stream
99 */
100 void (*start_stream)(void);
101
102 /**
103 * @brief Stop stream
104 */
105 void (*stop_stream)(void);
106
107 /**
108 * @brief Close audio codec
109 */
110 void (*close)(void);
111
112} btstack_audio_source_t;
113
114
80/**
115/**
81 * @brief Get BTstack Audio Instance
82 * @returns btstack_audio implementation
116 * @brief Get BTstack Audio Sink Instance
117 * @returns btstack_audio_sink implementation
83 */
118 */
84const btstack_audio_t * btstack_audio_get_instance(void);
119const btstack_audio_sink_t * btstack_audio_sink_get_instance(void);
85
86/**
120
121/**
87 * @brief Get BTstack Audio Instance
88 * @param btstack_audio implementation
122 * @brief Get BTstack Audio Source Instance
123 * @returns btstack_audio_source implementation
89 */
124 */
90void btstack_audio_set_instance(const btstack_audio_t * audio_impl);
125const btstack_audio_source_t * btstack_audio_source_get_instance(void);
91
92
126
127
128/**
129 * @brief Get BTstack Audio Sink Instance
130 * @param btstack_audio_sink implementation
131 */
132void btstack_audio_sink_set_instance(const btstack_audio_sink_t * audio_sink_impl);
133
134/**
135 * @brief Get BTstack Audio Source Instance
136 * @param btstack_audio_source implementation
137 */
138void btstack_audio_source_set_instance(const btstack_audio_source_t * audio_source_impl);
139
140
93// common implementations
141// common implementations
94const btstack_audio_t * btstack_audio_portaudio_get_instance(void);
95const btstack_audio_t * btstack_audio_embedded_get_instance(void);
96const btstack_audio_t * btstack_audio_esp32_get_instance(void);
142const btstack_audio_sink_t * btstack_audio_portaudio_sink_get_instance(void);
143const btstack_audio_source_t * btstack_audio_portaudio_source_get_instance(void);
97
144
145//const btstack_audio_t * btstack_audio_embedded_get_instance(void);
146//const btstack_audio_t * btstack_audio_esp32_get_instance(void);
147
98#if defined __cplusplus
99}
100#endif
101
102#endif
148#if defined __cplusplus
149}
150#endif
151
152#endif