Skip to content

Commit

Permalink
ci: 🎨 GitHub actions + improving readme
Browse files Browse the repository at this point in the history
  • Loading branch information
krthr committed Apr 12, 2024
1 parent 8ded27a commit d1c1827
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 50 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
# opus-cr
# Opus


TODO: Write a description here

## Installation

1. Add the dependency to your `shard.yml`:

```yaml
dependencies:
opus-cr:
github: your-github-user/opus-cr
opus:
github: krthr/opus
```
2. Run `shards install`

## 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 (<https://github.com/your-github-user/opus-cr/fork>)
1. Fork it (<https://github.com/krthr/opus/fork>)
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`)
5. Create a new Pull Request

## Contributors

- [Wilson](https://github.com/your-github-user) - creator and maintainer
- [Wilson](https://github.com/krthr) - creator and maintainer
9 changes: 9 additions & 0 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions spec/opus-cr_spec.cr
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.cr
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require "spec"
require "../src/opus-cr"
require "../src/opus"
34 changes: 0 additions & 34 deletions src/opus.cr
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/opus/encoder.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d1c1827

Please sign in to comment.