From e075a99a288b5b23f4cf2cc6cf8e6c81e0fb8e05 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Fri, 22 Mar 2024 03:30:12 +0400 Subject: [PATCH] In audio.c/.h arg/var naming style was changed. --- src/audio.c | 88 ++++++++++++++++++++++++++--------------------------- src/audio.h | 12 ++++---- 2 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/audio.c b/src/audio.c index 535081d..5b50069 100644 --- a/src/audio.c +++ b/src/audio.c @@ -4,38 +4,38 @@ #include #include -int audio_init(audio_t *aud, int channels, int sampleRate, int frameSize) { - PaError paErr; - int opusErr; +int audio_init(audio_t *aud, int channels, int sample_rate, int frame_size) { + PaError pa_err; + int opus_err; - if ((paErr = Pa_Initialize()) != paNoError) { - fprintf(stderr, "Cannot initialise PortAudio: %s\n", Pa_GetErrorText(paErr)); + if ((pa_err = Pa_Initialize()) != paNoError) { + fprintf(stderr, "Cannot initialise PortAudio: %s\n", Pa_GetErrorText(pa_err)); return -1; } - aud->opusEnc = opus_encoder_create(sampleRate, channels, OPUS_APPLICATION_VOIP, &opusErr); - if (opusErr != OPUS_OK) { - fprintf(stderr, "An Opus encoder cannot be created: %s\n", opus_strerror(opusErr)); + aud->opus_enc = opus_encoder_create(sample_rate, channels, OPUS_APPLICATION_VOIP, &opus_err); + if (opus_err != OPUS_OK) { + fprintf(stderr, "An Opus encoder cannot be created: %s\n", opus_strerror(opus_err)); return -1; } - aud->opusDec = opus_decoder_create(sampleRate, channels, &opusErr); - if (opusErr != OPUS_OK) { - fprintf(stderr, "An Opus decoder cannot be created: %s\n", opus_strerror(opusErr)); + aud->opus_dec = opus_decoder_create(sample_rate, channels, &opus_err); + if (opus_err != OPUS_OK) { + fprintf(stderr, "An Opus decoder cannot be created: %s\n", opus_strerror(opus_err)); return -1; } - if ((paErr = Pa_OpenDefaultStream(&aud->stream, channels, channels, AUDIO_SAMPLE_FORMAT, - sampleRate, frameSize, NULL, NULL)) != paNoError) { - fprintf(stderr, "Cannot open a PortAudio stream: %s\n", Pa_GetErrorText(paErr)); + if ((pa_err = Pa_OpenDefaultStream(&aud->stream, channels, channels, AUDIO_SAMPLE_FORMAT, + sample_rate, frame_size, NULL, NULL)) != paNoError) { + fprintf(stderr, "Cannot open a PortAudio stream: %s\n", Pa_GetErrorText(pa_err)); return -1; } - aud->bufferSz = frameSize * channels; - aud->buffer = (audio_sample_t *)malloc(aud->bufferSz * sizeof(audio_sample_t)); + aud->buffer_size = frame_size * channels; + aud->buffer = (audio_sample_t *)malloc(aud->buffer_size * sizeof(audio_sample_t)); - if ((paErr = Pa_StartStream(aud->stream)) != paNoError) { - fprintf(stderr, "Cannot start a PortAudio stream: %s\n", Pa_GetErrorText(paErr)); + if ((pa_err = Pa_StartStream(aud->stream)) != paNoError) { + fprintf(stderr, "Cannot start a PortAudio stream: %s\n", Pa_GetErrorText(pa_err)); return -1; } @@ -43,53 +43,53 @@ int audio_init(audio_t *aud, int channels, int sampleRate, int frameSize) { } int audio_destroy(audio_t *aud) { - PaError paErr; + PaError pa_err; if (aud->stream) { - if ((paErr = Pa_StopStream(aud->stream)) != paNoError) { - fprintf(stderr, "Cannot stop a PortAudio stream: %s\n", Pa_GetErrorText(paErr)); + if ((pa_err = Pa_StopStream(aud->stream)) != paNoError) { + fprintf(stderr, "Cannot stop a PortAudio stream: %s\n", Pa_GetErrorText(pa_err)); return -1; } - if ((paErr = Pa_CloseStream(aud->stream)) != paNoError) { - fprintf(stderr, "Cannot close a PortAudio stream: %s\n", Pa_GetErrorText(paErr)); + if ((pa_err = Pa_CloseStream(aud->stream)) != paNoError) { + fprintf(stderr, "Cannot close a PortAudio stream: %s\n", Pa_GetErrorText(pa_err)); return -1; } } - if ((paErr = Pa_Terminate()) != paNoError) { - fprintf(stderr, "Cannot terminate PortAudio: %s\n", Pa_GetErrorText(paErr)); + if ((pa_err = Pa_Terminate()) != paNoError) { + fprintf(stderr, "Cannot terminate PortAudio: %s\n", Pa_GetErrorText(pa_err)); return -1; } if (aud->buffer) free(aud->buffer); - if (aud->opusEnc) - opus_encoder_destroy(aud->opusEnc); + if (aud->opus_enc) + opus_encoder_destroy(aud->opus_enc); - if (aud->opusDec) - opus_decoder_destroy(aud->opusDec); + if (aud->opus_dec) + opus_decoder_destroy(aud->opus_dec); return 0; } /* -int encLen = opus_encode_float(aud->opusEnc, (float *)input, frameCount, aud->opusBuf, aud->opusBufSz); +int encLen = opus_encode_float(aud->opus_enc, (float *)input, frameCount, aud->opusBuf, aud->opusBufSz); (void)encLen; - int frameSize = opus_decode_float(aud->opusDec, aud->opusBuf, aud->opusBufSz, (float *)output, frameCount, 0); - (void)frameSize; + 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 *outputData, size_t outputLen) { - PaError paErr; +int audio_read(audio_t *aud, uint8_t *output, size_t output_len) { + PaError pa_err; - if ((paErr = Pa_ReadStream(aud->stream, aud->buffer, aud->bufferSz)) != paNoError) { - fprintf(stderr, "Cannot read from a PortAudio stream: %s\n", Pa_GetErrorText(paErr)); + if ((pa_err = Pa_ReadStream(aud->stream, aud->buffer, aud->buffer_size)) != paNoError) { + fprintf(stderr, "Cannot read from a PortAudio stream: %s\n", Pa_GetErrorText(pa_err)); return -1; } - int encodedLen = opus_encode_float(aud->opusEnc, aud->buffer, aud->bufferSz, outputData, outputLen); + int encodedLen = opus_encode_float(aud->opus_enc, aud->buffer, aud->buffer_size, output, output_len); if (encodedLen < 0) { fprintf(stderr, "Opus failed to encode: %s\n", opus_strerror(encodedLen)); return -1; @@ -98,17 +98,17 @@ int audio_read(audio_t *aud, uint8_t *outputData, size_t outputLen) { return 0; } -int audio_write(audio_t *aud, const uint8_t *inputData, size_t inputLen) { - PaError paErr; +int audio_write(audio_t *aud, const uint8_t *input, size_t input_len) { + PaError pa_err; - int frameSize = opus_decode_float(aud->opusDec, inputData, inputLen, aud->buffer, aud->bufferSz, 0); - if (frameSize < 0) { - fprintf(stderr, "Opus failed to decode: %s\n", opus_strerror(frameSize)); + int frame_size = opus_decode_float(aud->opus_dec, input, input_len, aud->buffer, aud->buffer_size, 0); + if (frame_size < 0) { + fprintf(stderr, "Opus failed to decode: %s\n", opus_strerror(frame_size)); return -1; } - if ((paErr = Pa_WriteStream(aud->stream, aud->buffer, aud->bufferSz)) != paNoError) { - fprintf(stderr, "Cannot write to a PortAudio stream: %s\n", Pa_GetErrorText(paErr)); + if ((pa_err = Pa_WriteStream(aud->stream, aud->buffer, aud->buffer_size)) != paNoError) { + fprintf(stderr, "Cannot write to a PortAudio stream: %s\n", Pa_GetErrorText(pa_err)); return -1; } diff --git a/src/audio.h b/src/audio.h index 4d12482..bc954c8 100644 --- a/src/audio.h +++ b/src/audio.h @@ -12,17 +12,17 @@ typedef float audio_sample_t; typedef struct audio_t { PaStream *stream; - OpusEncoder *opusEnc; - OpusDecoder *opusDec; + OpusEncoder *opus_enc; + OpusDecoder *opus_dec; audio_sample_t *buffer; - size_t bufferSz; + size_t buffer_size; } audio_t; -int audio_init(audio_t *aud, int channels, int sampleRate, int frameSize); +int audio_init(audio_t *aud, int channels, int sample_rate, int frame_size); int audio_destroy(audio_t *aud); -int audio_read(audio_t *aud, uint8_t *outputData, size_t outputLen); -int audio_write(audio_t *aud, const uint8_t *inputData, size_t inputLen); +int audio_read(audio_t *aud, uint8_t *output, size_t output_len); +int audio_write(audio_t *aud, const uint8_t *input, size_t input_len); #endif /* _AUDIO_H_ */ \ No newline at end of file