diff --git a/.github/workflows/cmakebuild.yaml b/.github/workflows/cmakebuild.yaml new file mode 100644 index 0000000..3e68572 --- /dev/null +++ b/.github/workflows/cmakebuild.yaml @@ -0,0 +1,46 @@ +name: CI - Build and Test +on: + push: + pull_request: + branches: [ master ] +jobs: + build: + strategy: + matrix: + build-type: [ Debug, Release ] + port-audio: [ ENABLE_PORTAUDIO=ON, ENABLE_PORTAUDIO=OFF ] + fail-fast: false + runs-on: ubuntu-latest + steps: + - name: Install Dependencies + run: | + sudo apt update + sudo apt install --yes --quiet --no-install-recommends \ + libasound2-dev \ + libmp3lame-dev \ + libogg-dev \ + libsndfile1-dev \ + libvorbis-dev \ + portaudio19-dev + - uses: actions/checkout@v2 + - name: Create Build Environment + run: cmake -E make_directory ${{ github.workspace }}/build + - name: Configure CMake + working-directory: ${{ github.workspace }}/build + # Note the current convention is to use the -S and -B options here to + # specify source and build directories, but this is only available with + # CMake 3.13 and higher. The CMake binaries on the Github Actions + # machines are (as of this writing) 3.12 + run: > + cmake $GITHUB_WORKSPACE + -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} + -D${{ matrix.port-audio }} + -DENABLE_MP3LAME=ON + -DENABLE_SNDFILE=ON + -DENABLE_VORBIS=ON + - name: Build + working-directory: ${{ github.workspace }}/build + run: cmake --build . --config ${{ matrix.build-type }} + - name: Test + working-directory: ${{ github.workspace }}/build + run: ctest -C ${{ matrix.build-type }} diff --git a/.github/workflows/codeql-analysis.yaml b/.github/workflows/codeql-analysis.yaml new file mode 100644 index 0000000..5f7ac88 --- /dev/null +++ b/.github/workflows/codeql-analysis.yaml @@ -0,0 +1,54 @@ +name: CodeQL Analysis +on: + push: + pull_request: + branches: [ master ] +jobs: + analyze: + permissions: + actions: read + contents: read + security-events: write + strategy: + matrix: + build-type: [ Release ] + language: [ cpp ] + fail-fast: false + runs-on: ubuntu-latest + steps: + - name: Install Dependencies + run: | + sudo apt update + sudo apt install --yes --quiet --no-install-recommends \ + libasound2-dev \ + libmp3lame-dev \ + libogg-dev \ + libsndfile1-dev \ + libvorbis-dev \ + portaudio19-dev + - uses: actions/checkout@v2 + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + queries: security-and-quality + - name: Create Build Environment + run: cmake -E make_directory ${{ github.workspace }}/build + - name: Configure CMake + working-directory: ${{ github.workspace }}/build + # Note the current convention is to use the -S and -B options here to + # specify source and build directories, but this is only available with + # CMake 3.13 and higher. The CMake binaries on the Github Actions + # machines are (as of this writing) 3.12 + run: > + cmake $GITHUB_WORKSPACE + -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} + -DENABLE_PORTAUDIO=ON + -DENABLE_MP3LAME=ON + -DENABLE_SNDFILE=ON + -DENABLE_VORBIS=ON + - name: Build + working-directory: ${{ github.workspace }}/build + run: cmake --build . --config ${{ matrix.build-type }} + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6e3e61e..0000000 --- a/.travis.yml +++ /dev/null @@ -1,23 +0,0 @@ -sudo: false -dist: xenial - -language: c - -addons: - apt: - packages: - - libasound2-dev - - libmp3lame-dev - - libsndfile1-dev - - libvorbis-dev - - portaudio19-dev - -before_script: - - mkdir build && cd build - -script: - - cmake .. && make - - cmake .. -DCMAKE_BUILD_TYPE=Debug && make - - cmake .. -DCMAKE_BUILD_TYPE=Release && make - - cmake .. -DENABLE_SNDFILE=ON -DENABLE_MP3LAME=ON -DENABLE_VORBIS=ON && make - - cmake .. -DENABLE_PORTAUDIO=ON && make diff --git a/LICENSE.txt b/LICENSE.txt index 918a3bc..eff4560 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License -Copyright (c) 2010-2020 Arkadiusz Bokowy +Copyright (c) 2010-2021 Arkadiusz Bokowy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index c586054..238364b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ -SVAR - Simple Voice Activated Recorder -====================================== +# SVAR - Simple Voice Activated Recorder + +[![Build Status](https://github.com/Arkq/svar/actions/workflows/cmakebuild.yaml/badge.svg)](https://github.com/Arkq/svar/actions/workflows/cmakebuild.yaml) It is a simple console application (low memory footprint and CPU usage) designed for recording audio when a specified signal level is exceeded. It is commonly known solution called Voice @@ -12,6 +13,7 @@ Alternatively, it is possible to force PortAudio back-end on Linux systems by ad `-DENABLE_PORTAUDIO=ON` to the CMake configuration step. Currently this application supports four output formats: + - RAW (PCM 16bit interleaved) - WAV ([libsndfile](http://www.mega-nerd.com/libsndfile/)) - MP3 ([mp3lame](http://lame.sourceforge.net/)) @@ -30,9 +32,10 @@ For the fine adjustment of the activation condition (the signal level), one can the RMS is displayed. Activation threshold is based on the maximal peak value in the signal packed (time of tenth of the second). -Installation ------------- +## Installation - $ mkdir build && cd build - $ cmake .. -DENABLE_SNDFILE=ON -DENABLE_MP3LAME=ON -DENABLE_VORBIS=ON - $ make && make install +```sh +mkdir build && cd build +cmake .. -DENABLE_SNDFILE=ON -DENABLE_MP3LAME=ON -DENABLE_VORBIS=ON +make && make install +``` diff --git a/src/main.c b/src/main.c index e714b43..748cd6b 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,6 @@ /* * SVAR - main.c - * Copyright (c) 2010-2020 Arkadiusz Bokowy + * Copyright (c) 2010-2021 Arkadiusz Bokowy * * This file is a part of SVAR. * @@ -49,9 +49,15 @@ enum output_format { FORMAT_RAW = 0, +#if ENABLE_SNDFILE FORMAT_WAV, +#endif +#if ENABLE_MP3LAME FORMAT_MP3, +#endif +#if ENABLE_VORBIS FORMAT_OGG, +#endif }; /* available output formats */ @@ -225,15 +231,19 @@ static void print_audio_info(void) { if (!appconfig.signal_meter) printf("Output file format: %s\n", get_output_format_name(appconfig.output_format)); +#if ENABLE_MP3LAME if (appconfig.output_format == FORMAT_MP3) printf("Output bit rate [min, max]: %d, %d kbit/s\n", appconfig.bitrate_min / 1000, appconfig.bitrate_max / 1000); +#endif +#if ENABLE_VORBIS if (appconfig.output_format == FORMAT_OGG) printf("Output bit rate [min, nominal, max]: %d, %d, %d kbit/s\n", appconfig.bitrate_min / 1000, appconfig.bitrate_nom / 1000, appconfig.bitrate_max / 1000); +#endif } #if ENABLE_PORTAUDIO @@ -272,7 +282,7 @@ static void peak_check_S16_LE(const int16_t *buffer, size_t frames, int channels sum2 += abslvl * abslvl; } - *rms = sqrt((double)sum2 / frames); + *rms = ceil(sqrt((double)sum2 / frames)); } /* Process incoming audio frames. */