Skip to content

Commit

Permalink
initial commit for SRLA.
Browse files Browse the repository at this point in the history
  • Loading branch information
aikiriao committed Jan 28, 2023
0 parents commit f75044c
Show file tree
Hide file tree
Showing 99 changed files with 13,001 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.yml]
indent_size = 2
trim_trailing_whitespace = false

[*.rb]
indent_size = 2
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
build
tmp
data
*.o
*.swp
*.swo
*~
46 changes: 46 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.15)

# コーデックライブラリ
project(SRLACodecLibrary C)
set(CODEC_LIB_NAME srlacodec)
add_library(${CODEC_LIB_NAME}
STATIC
$<TARGET_OBJECTS:srla_encoder>
$<TARGET_OBJECTS:srla_decoder>
$<TARGET_OBJECTS:srla_coder>
$<TARGET_OBJECTS:srla_internal>
$<TARGET_OBJECTS:bit_stream>
$<TARGET_OBJECTS:lpc>
)

# デコーダライブラリ
project(SRLADecoderLibrary C)
set(DECODER_LIB_NAME srladec)
add_library(${DECODER_LIB_NAME}
STATIC
$<TARGET_OBJECTS:srla_decoder>
$<TARGET_OBJECTS:srla_coder>
$<TARGET_OBJECTS:srla_internal>
$<TARGET_OBJECTS:bit_stream>
)

# 依存するプロジェクト
add_subdirectory(libs)

# テスト
if(NOT without-test)
enable_testing()
# C++環境でないとgtestがビルドできないので、CXXプロジェクトを作る
# -> Cとの挙動で差異が生じるかもしれない...
project(SRLATest CXX)
if(MSVC)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
else()
set(CMAKE_CXX_FLAGS "-std=gnu++11") # gtestがGNU独自拡張を使用しているため
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -DDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
endif()
include(cmake/gtest.cmake)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
add_subdirectory(test)
endif()
21 changes: 21 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 aikiriao <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# SRLA

aka Soleil Rising Lossless Audio codec

# How to build

## Requirement

* [CMake](https://cmake.org) >= 3.15

## Build SRLA Codec

```bash
git clone https://github.com/ShounoLab/SRLA.git
cd SRLA/tools/srla_codec
cmake -B build
cmake --build build
```

# Usage

## SRLA Codec

### Encode

```bash
./srla -e INPUT.wav OUTPUT.srl
```

you can change compression mode by `-m` option.
Following example encoding in maximum compression (but slow) option.

```bash
./srla -e -m 5 INPUT.wav OUTPUT.srl
```

### Decode

```bash
./srla -d INPUT.srl OUTPUT.wav
```

## License

MIT
51 changes: 51 additions & 0 deletions cmake/gtest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
cmake_minimum_required(VERSION 3.15)

# Google Test settings
include(ExternalProject)

# gtest追加
ExternalProject_Add(GoogleTest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.0
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
)

# インクルードパス追加
ExternalProject_Get_Property(GoogleTest source_dir)
include_directories(${source_dir}/googletest/include)

# 成果物のディレクトリ取得
ExternalProject_Get_Property(GoogleTest binary_dir)

# ライブラリ追加
add_library(gtest STATIC IMPORTED)
if(MSVC)
set_target_properties(gtest
PROPERTIES
IMPORTED_LOCATION "${binary_dir}/lib/Debug/gtest.lib"
IMPORTED_LOCATION_DEBUG "${binary_dir}/lib/Debug/gtest.lib"
IMPORTED_LOCATION_RELEASE "${binary_dir}/lib/Release/gtest.lib"
)
else()
set_target_properties(gtest
PROPERTIES
IMPORTED_LOCATION ${binary_dir}/lib/libgtest.a
)
endif()

# メインエントリ追加
add_library(gtest_main STATIC IMPORTED)
if(MSVC)
set_target_properties(gtest_main
PROPERTIES
IMPORTED_LOCATION "${binary_dir}/lib/Debug/gtest_main.lib"
IMPORTED_LOCATION_DEBUG "${binary_dir}/lib/Debug/gtest_main.lib"
IMPORTED_LOCATION_RELEASE "${binary_dir}/lib/Release/gtest_main.lib"
)
else()
set_target_properties(gtest_main
PROPERTIES
IMPORTED_LOCATION ${binary_dir}/lib/libgtest_main.a
)
endif()
19 changes: 19 additions & 0 deletions evaluation/codec_comparison_summery.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
,SFLA -m 0,SFLA -m 1,SFLA -m 2,SFLA -m 3,SFLA -m 4,SFLA -m 5
classic mean encode time,2.1463422375623296,10.07418304959943,1.9410030808785546,8.168703015165022,4.3587425386216365,9.224339659192657
genre mean encode time,2.12240976190562,9.805849101835305,2.0300083861255915,8.048654987900365,4.000971228283839,8.903252905958409
jazz mean encode time,2.0901955034801376,10.233647398591351,2.0885893799250352,7.59833719809332,4.047462738277384,9.084297794282588
popular mean encode time,2.1062993339775824,9.244210549952072,2.073766501603843,8.228736590277194,4.097600123214178,11.380466953318077
right mean encode time,2.151912552638434,8.792490786101663,2.072541237903354,7.527640951489073,4.104422125150039,9.849197809848953
total mean encode time,2.115843248752311,9.708067239300949,2.045844317304964,7.978871838339197,4.106302094538328,9.816523363852014
classic mean decode time,0.23532411995210242,0.24146054144651874,0.18582631588974155,0.18499188976473074,0.1870066425538413,0.19813029993712092
genre mean decode time,0.23754737758750252,0.2290321044232394,0.1965400700104293,0.18355494589056645,0.18623609007395378,0.18703174084555974
jazz mean decode time,0.2310707603696749,0.22479188782559598,0.20146217343942385,0.19309912088540826,0.19099264815075956,0.1848804252351176
popular mean decode time,0.2389101940810997,0.21725211364323724,0.20352851668634508,0.1972963818041787,0.20378588269988956,0.1858582672682349
right mean decode time,0.24353698084874226,0.21764401628896637,0.2045213652897606,0.19755539783229734,0.21591995601500277,0.19682529757174275
total mean decode time,0.23649355144538797,0.22564734279752893,0.19866716739334367,0.1912114554595751,0.1949207886774234,0.18865063312297645
classic mean compression rate,43.94922828916623,43.94465295981446,43.85064224764169,43.84544940647651,43.846626459795914,43.84130142245651
genre mean compression rate,58.406170090094484,58.35404773195658,58.318265983580794,58.26165970999139,58.30614357904465,58.25151775676188
jazz mean compression rate,47.93229431056631,47.87342167392149,47.827005209736136,47.76487209475472,47.81897521735741,47.759679420383236
popular mean compression rate,67.83985786295364,67.77027270365582,67.76775650884096,67.69427274648717,67.75300388322596,67.68276755961523
right mean compression rate,60.85819586164452,60.806215550493555,60.768906383799134,60.714754945215724,60.75667699000537,60.70506580834179
total mean compression rate,56.63037195657916,56.57902493722776,56.541321689295316,56.48674564261108,56.53066993209297,56.478361055202626
19 changes: 19 additions & 0 deletions evaluation/codec_comparison_summery_sse41.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
,SFLA -m 0,SFLA -m 1,SFLA -m 2,SFLA -m 3,SFLA -m 4,SFLA -m 5
classic mean encode time,1.853644518349601,9.033031663315231,1.9307104294040605,6.774597894822078,3.771602566031967,8.52801475610579
genre mean encode time,1.8938096272300136,9.380883281063456,1.9619670765323722,6.804070612250814,3.759008462857397,8.591708777157196
jazz mean encode time,1.8868362771708331,9.543943597586129,1.9369440208780122,6.789060641169558,3.7530082732126586,8.611576517030251
popular mean encode time,1.9083161670041597,9.28966216323793,1.9433015347541789,7.178663163399555,3.803710867246452,8.738973062562122
right mean encode time,1.911434825229543,8.939300392415419,1.9494931226247207,6.885123601205838,3.8300126380047117,8.747879459326832
total mean encode time,1.891338135811271,9.304410133917198,1.9444524662598615,6.915147139081168,3.7782227118327882,8.641923302163663
classic mean decode time,0.16280584641137985,0.17383497498923337,0.161880264897766,0.16271098867523728,0.16140331657731016,0.16097628480396278
genre mean decode time,0.16874013178574807,0.17292584458932456,0.16505980603675505,0.1630915347196641,0.1644649594814271,0.16233090020728527
jazz mean decode time,0.16927131369020393,0.17662810854192657,0.16299880741136044,0.1616782013793746,0.1610726422144156,0.16376791265650223
popular mean decode time,0.17225964085808726,0.1761409472513793,0.16542970807898155,0.17004469355453866,0.1643255223900824,0.16423267325594415
right mean decode time,0.1741159126920204,0.17134420686599539,0.17055075810779607,0.1689573280641753,0.17340951382687358,0.17215079964422333
total mean decode time,0.16935946205455407,0.1748124115833936,0.1645616244337823,0.16522131591907002,0.1637613226058114,0.1637280834557029
classic mean compression rate,43.94922828916623,43.94465295981446,43.85064224764169,43.84544940647651,43.846626459795914,43.84130142245651
genre mean compression rate,58.406170090094484,58.35404773195658,58.318265983580794,58.26165970999139,58.30614357904465,58.25151775676188
jazz mean compression rate,47.93229431056631,47.87342167392149,47.827005209736136,47.76487209475472,47.81897521735741,47.759679420383236
popular mean compression rate,67.83985786295364,67.77027270365582,67.76775650884096,67.69427274648717,67.75300388322596,67.68276755961523
right mean compression rate,60.85819586164452,60.806215550493555,60.768906383799134,60.714754945215724,60.75667699000537,60.70506580834179
total mean compression rate,56.63037195657916,56.57902493722776,56.541321689295316,56.48674564261108,56.53066993209297,56.478361055202626
49 changes: 49 additions & 0 deletions include/srla.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef SRLA_H_INCLUDED
#define SRLA_H_INCLUDED

#include "srla_stdint.h"

/* フォーマットバージョン */
#define SRLA_FORMAT_VERSION 1

/* コーデックバージョン */
#define SRLA_CODEC_VERSION 1

/* ヘッダサイズ */
#define SRLA_HEADER_SIZE 29

/* 処理可能な最大チャンネル数 */
#define SRLA_MAX_NUM_CHANNELS 8

/* 最大係数サイズ */
#define SRLA_MAX_COEFFICIENT_ORDER 32

/* パラメータプリセット数 */
#define SRLA_NUM_PARAMETER_PRESETS 6


/* API結果型 */
typedef enum SRLAApiResultTag {
SRLA_APIRESULT_OK = 0, /* 成功 */
SRLA_APIRESULT_INVALID_ARGUMENT, /* 無効な引数 */
SRLA_APIRESULT_INVALID_FORMAT, /* 不正なフォーマット */
SRLA_APIRESULT_INSUFFICIENT_BUFFER, /* バッファサイズが足りない */
SRLA_APIRESULT_INSUFFICIENT_DATA, /* データが足りない */
SRLA_APIRESULT_PARAMETER_NOT_SET, /* パラメータがセットされてない */
SRLA_APIRESULT_DETECT_DATA_CORRUPTION, /* データ破損を検知した */
SRLA_APIRESULT_NG /* 分類不能な失敗 */
} SRLAApiResult;

/* ヘッダ情報 */
struct SRLAHeader {
uint32_t format_version; /* フォーマットバージョン */
uint32_t codec_version; /* エンコーダバージョン */
uint16_t num_channels; /* チャンネル数 */
uint32_t num_samples; /* 1チャンネルあたり総サンプル数 */
uint32_t sampling_rate; /* サンプリングレート */
uint16_t bits_per_sample; /* サンプルあたりビット数 */
uint32_t num_samples_per_block; /* ブロックあたりサンプル数 */
uint8_t preset; /* パラメータプリセット */
};

#endif /* SRLA_H_INCLUDED */
55 changes: 55 additions & 0 deletions include/srla_decoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef SRLA_DECODER_H_INCLUDED
#define SRLA_DECODER_H_INCLUDED

#include "srla.h"
#include "srla_stdint.h"

/* デコーダコンフィグ */
struct SRLADecoderConfig {
uint32_t max_num_channels; /* 最大チャンネル数 */
uint32_t max_num_parameters; /* 最大パラメータ数 */
uint8_t check_checksum; /* チェックサムによるデータ破損検査を行うか? 1:ON それ以外:OFF */
};

/* デコーダハンドル */
struct SRLADecoder;

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* ヘッダデコード */
SRLAApiResult SRLADecoder_DecodeHeader(
const uint8_t *data, uint32_t data_size, struct SRLAHeader *header);

/* デコーダハンドルの作成に必要なワークサイズの計算 */
int32_t SRLADecoder_CalculateWorkSize(const struct SRLADecoderConfig *condig);

/* デコーダハンドルの作成 */
struct SRLADecoder* SRLADecoder_Create(const struct SRLADecoderConfig *condig, void *work, int32_t work_size);

/* デコーダハンドルの破棄 */
void SRLADecoder_Destroy(struct SRLADecoder *decoder);

/* デコーダにヘッダをセット */
SRLAApiResult SRLADecoder_SetHeader(
struct SRLADecoder *decoder, const struct SRLAHeader *header);

/* 単一データブロックデコード */
SRLAApiResult SRLADecoder_DecodeBlock(
struct SRLADecoder *decoder,
const uint8_t *data, uint32_t data_size,
int32_t **buffer, uint32_t buffer_num_channels, uint32_t buffer_num_samples,
uint32_t *decode_size, uint32_t *num_decode_samples);

/* ヘッダを含めて全ブロックデコード */
SRLAApiResult SRLADecoder_DecodeWhole(
struct SRLADecoder *decoder,
const uint8_t *data, uint32_t data_size,
int32_t **buffer, uint32_t buffer_num_channels, uint32_t buffer_num_samples);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* SRLA_DECODER_H_INCLUDED */
Loading

0 comments on commit f75044c

Please sign in to comment.