1
0

In an audio module: 1) removed a commented out block of code; 2) uint8_t -> unsigned char; 3) size_t -> int; 4) make audio_read() return a number of encoded bytes or -1 on an error.

This commit is contained in:
Alexander Andreev 2024-03-23 04:17:19 +04:00
parent 0c7995d5fc
commit b5d92489b8
Signed by: Arav
GPG Key ID: 25969B23DCB5CA34
2 changed files with 6 additions and 13 deletions

View File

@ -74,14 +74,7 @@ int audio_destroy(audio_t *aud) {
return 0; return 0;
} }
/* int audio_read(audio_t *aud, unsigned char *output, int output_len) {
int encLen = opus_encode_float(aud->opus_enc, (float *)input, frameCount, aud->opusBuf, aud->opusBufSz);
(void)encLen;
int frame_size = opus_decode_float(aud->opus_dec, aud->opusBuf, aud->opusBufSz, (float *)output, frameCount, 0);
(void)frame_size;
*/
int audio_read(audio_t *aud, uint8_t *output, size_t output_len) {
PaError pa_err; PaError pa_err;
if ((pa_err = Pa_ReadStream(aud->stream, aud->buffer, aud->buffer_size)) != paNoError) { if ((pa_err = Pa_ReadStream(aud->stream, aud->buffer, aud->buffer_size)) != paNoError) {
@ -95,10 +88,10 @@ int audio_read(audio_t *aud, uint8_t *output, size_t output_len) {
return -1; return -1;
} }
return 0; return encodedLen;
} }
int audio_write(audio_t *aud, const uint8_t *input, size_t input_len) { int audio_write(audio_t *aud, const unsigned char *input, int input_len) {
PaError pa_err; PaError pa_err;
int frame_size = opus_decode_float(aud->opus_dec, input, input_len, aud->buffer, aud->buffer_size, 0); int frame_size = opus_decode_float(aud->opus_dec, input, input_len, aud->buffer, aud->buffer_size, 0);

View File

@ -16,13 +16,13 @@ typedef struct audio_t {
OpusDecoder *opus_dec; OpusDecoder *opus_dec;
audio_sample_t *buffer; audio_sample_t *buffer;
size_t buffer_size; int buffer_size;
} audio_t; } audio_t;
int audio_init(audio_t *aud, int channels, int sample_rate, int frame_size); int audio_init(audio_t *aud, int channels, int sample_rate, int frame_size);
int audio_destroy(audio_t *aud); int audio_destroy(audio_t *aud);
int audio_read(audio_t *aud, uint8_t *output, size_t output_len); int audio_read(audio_t *aud, unsigned char *output, int output_len);
int audio_write(audio_t *aud, const uint8_t *input, size_t input_len); int audio_write(audio_t *aud, const unsigned char *input, int input_len);
#endif /* _AUDIO_H_ */ #endif /* _AUDIO_H_ */