diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ee68ad6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,42 @@ +name: CI + +on: + push: + pull_request: + +jobs: + test: + strategy: + fail-fast: false + runs-on: ubuntu-latest + + steps: + - name: Install Crystal + uses: oprypin/install-crystal@v1 + with: + crystal: latest + + - name: Install linux dependencies + run: | + sudo apt install libopus-dev + + - name: Download source + uses: actions/checkout@v2 + + - name: Install dependencies + run: shards install + + # - name: Run specs + # run: | + # crystal spec + # crystal spec --release --no-debug + + - name: Check formatting + run: crystal tool format --check + + - name: Run ameba linter + run: bin/ameba + + - name: Build + run: | + crystal build --progress --time --stats src/opus.cr diff --git a/README.md b/README.md index f58ad10..f6c65e5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# opus-cr +# Opus + -TODO: Write a description here ## Installation @@ -8,8 +8,8 @@ TODO: Write a description here ```yaml dependencies: - opus-cr: - github: your-github-user/opus-cr + opus: + github: krthr/opus ``` 2. Run `shards install` @@ -17,18 +17,26 @@ TODO: Write a description here ## Usage ```crystal -require "opus-cr" -``` +require "opus" -TODO: Write usage instructions here +sample_rate = 48_000 +frame_size = 960 +channels = 2 -## Development +encoder = Opus::Encoder.new(sample_rate, frame_size, channels) -TODO: Write development instructions here +buffer = Bytes.new(encoder.input_length, 0) + +while real_length = audio_data.read(buffer) + break if real_length.zero? + opus_encoded_data = encoder.encode(buffer) + # Use the encoded data +end +``` ## Contributing -1. Fork it () +1. Fork it () 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) @@ -36,4 +44,4 @@ TODO: Write development instructions here ## Contributors -- [Wilson](https://github.com/your-github-user) - creator and maintainer +- [Wilson](https://github.com/krthr) - creator and maintainer diff --git a/shard.yml b/shard.yml index f1ce9d0..3cceaf2 100644 --- a/shard.yml +++ b/shard.yml @@ -6,4 +6,13 @@ authors: crystal: ">= 1.12.0" +documentation: https://crystaldoc.info/github/krthr/opus + +libraries: + libopus: "*" + license: MIT + +development_dependencies: + ameba: + github: crystal-ameba/ameba diff --git a/spec/opus-cr_spec.cr b/spec/opus-cr_spec.cr index 30873dd..b9ff6fd 100644 --- a/spec/opus-cr_spec.cr +++ b/spec/opus-cr_spec.cr @@ -1,8 +1,6 @@ require "./spec_helper" -describe Opus::Cr do - # TODO: Write tests - +describe Opus do it "works" do false.should eq(true) end diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 5b527d5..15a1557 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -1,2 +1,2 @@ require "spec" -require "../src/opus-cr" +require "../src/opus" diff --git a/src/opus.cr b/src/opus.cr index 0d36e1d..f9f7ff8 100644 --- a/src/opus.cr +++ b/src/opus.cr @@ -1,39 +1,5 @@ -require "log" require "./opus/encoder" module Opus VERSION = "0.1.0" end - -# sample_rate = 48_000 -# channels = 2 - -# encoder = Opus::Encoder.new(sample_rate, 960, channels) - -# input = File.open("/Users/krthr/Projects/discord-music/output.mp3", "r") -# output = File.open("output.opus", "w") - -# audio_data = IO::Memory.new - -# process = Process.run("ffmpeg", ["-i", "pipe:0", -# "-loglevel", "0", -# "-f", "s16le", -# "-c:a", "pcm_s16le", -# "-ar", sample_rate.to_s, -# "-ac", channels.to_s, -# "pipe:1", -# ], shell: true, input: input, output: audio_data, error: STDOUT) - -# audio_data.rewind - -# Log.info { "Audio data size in bytes: #{audio_data.size}" } -# Log.info { "Encoder input length: #{encoder.input_length}" } - -# buffer = Bytes.new(encoder.input_length, 0) - -# while real_length = audio_data.read(buffer) -# break if real_length.zero? -# opus_encoded_data = encoder.encode(buffer) -# output.write_bytes(opus_encoded_data.size.to_i16, IO::ByteFormat::LittleEndian) -# output.write(opus_encoded_data) -# end diff --git a/src/opus/encoder.cr b/src/opus/encoder.cr index 25149e7..a789a07 100644 --- a/src/opus/encoder.cr +++ b/src/opus/encoder.cr @@ -16,7 +16,7 @@ module Opus LibOpus.opus_encoder_destroy(@encoder) end - def reset : Nil + def reset : Void LibOpus.encoder_ctl(@encoder, LibOpus::CTL::RESET_STATE) end