<h1 align="center">lwavconv</h1>

![thumb](./readmesrc/00.png)

lwavconv is a conversion helper for loop-set WAV format files. Use FFmpeg or other tools as an external process.

When setting up looping in a WAV file, it is necessary to determine the loop start and end positions within the smpl chunk. To apply these settings to tags such as .ogg, you often need to take multiple steps. This tool completes the loop-related processing internally so that it can be applied to tags, and then uses an external encoder to convert them to various formats while preserving the original metadata.

When converting, the length of the song can be adjusted automatically from the loop settings and the excess length can be cut before conversion. This can be expected to optimize the file capacity when using the file. It is also possible to change the settings file and apply the loop setting to the original file with the song length of the original file for conversion.

Only the OGG format can also generate split files at loop sections, which may be necessary in some environments.

Non -loop format MP3, FLAC, etc. are also targeted for conversion destinations, so they can be used simply as a multi -formal simultaneous conversion tool of WAV files, and also supports TXT output of tag information using templates.

-----

## Cautious

lwavconv is not guaranteed. Use at your own risk.

I am not responsible for any damage or trouble caused by the use of lwavconv.

Not allow sales or redistribution of this except the author.

-----

## Required Files

At a minimum, the following are required for operation. I will not provide detailed instructions on how to download and install the software.

- FFmpeg.exe    https://ffmpeg.org/
    It is used for almost all conversion processes. It supports environment variables, but has not been tested. Recommend the introduction method described below.

-  AtomicParsley.exe    https://github.com/wez/atomicparsley
    Required to set loop tags for M4A files converted with the AAC codec; FFmpeg cannot set loop tags for M4A files.
    <span style="color: red;">The build 20221229.172126.d813aa6 does not set the user tag correctly. Please use the previous version.</span>
    If you do not use the AAC codec, you can omit installing this file, but be sure to do so as unintended errors may occur.

-----

### Optional Files

The following are required when using certain encoders

- qaac (qaac64.exe, refalac64.exe)  https://sites.google.com/site/qaacpage/
- fdkaac.exe   https://www.rarewares.org/aac-encoders.php#fdkaac
- Opus Tools (opusenc.exe)  https://www.rarewares.org/opus.php#opus-tools

Use of OPUSENC is recommended when converting to OPUS format. There is a limited sampling rate when converting with ffmpeg.

-----

## Installation

First, unzip lwavconv.zip into any folder.

After unzip, Place each exe in the file downloaded from the link above in the `exe_files` folder in the same folder as `lwavconv.exe`. For qaac64 and refalac64, install it in the QAAC folder in the exe_files folder.

When all files, including optional files, have been introduced, the exe_files folder will look like this
![01](./readmesrc/01.png)

If FFmpeg does not exist in the exe_files folder, it is set to be referenced from an environment variable, but as mentioned in the required files section, it has not been tested.

-----

## How to Use

Use Wavosaur, Reaper, etc., and prepare a WAV file with the loop settings in the SMPL chunk. If you do not need to create a loop song, prepare a normal WAV file.

Simply drag and drop a WAV file to lwavconv.exe, and a converted audio file in each format will be output in the convert folder. It supports drag and drop of multiple files.

<span style="color: red;">Caution : If a file with the same name exists in the convert folder, it will be overwritten without confirmation. Only WAV files can be used as input.</span>

## lwavconv.ini Advanced Settings
![02](./readmesrc/02.png)

By editing lwavconv.ini, you can customize to some extent the formats to be converted and the command line arguments of the encoder. However, some settings need to be careful because they cause unexpected files overwriting.

### Export

Select here the file format to be converted from the WAV file. The `split_ogg` will only be output if a loop setting exists in the WAV file.

The `metadata_txt` is disabled if output of any file format other than `split_ogg` is not enabled.

### Encoder

For some file formats, you can select the encoder to be used for conversion. The used encoder and the corresponding EXE files are as follows, and all other formats are processed in FFMPEG.

- aac
  - ffmpeg_aac (default, ffmpeg.exe)
  - aac_mf (ffmpeg.exe)
  - qaac64 (qaac64.exe)
  - fdkaac (fdkaac.exe)

- alac
  - ffmpeg_alac (default, ffmpeg.exe)
  - refalac64 (refalac64.exe)

- opus
  - libopus (default, ffmpeg.exe)
  - ffmpeg_opus (ffmpeg.exe)
  - opusenc (opusenc)

For invalid strings, the default format is used.

### Codecs_Option

The command line arguments for conversion can be controlled to some extent in this section. The arguments that can be used are not described here because they depend on each external encoder. If you do not understand how to change this setting, do not change it.

If you set the command line argument yourself, do not set the input -only command or tag -related command. The sampling rate and bit depth can be changed in the setting described later, so do not try to change them here. エラーの原因になります。

When customizing the arguments, please also refer to the corresponding exe in the Encoder column and do so with care. The `split_ogg` setting is shared with `ogg`.

### Other_Option

This section contains all other detailed settings. This section is explained in detail as it concerns the output of the file.

#### sr_bd_change
![03](./readmesrc/03.png)

Only if set to `true` will sampling rate and bit depth changes be enabled during conversion. __But keep in mind that this setting is only optional.__

When this setting is enabled, loop samples are automatically calculated, but it does not guarantee accurate loops after sampling rate conversion. It is better not to use this setting and to adjust everything at the WAV file preparation stage.

The available values are listed below; otherwise, the default values are applied.

- sample_rate
  - 8000
  - 11025
  - 12000
  - 16000
  - 22050
  - 24000
  - 32000
  - 44100
  - 48000 (default)
  - 64000
  - 88200
  - 96000
  - 128000
  - 176400
  - 192000

- bit_depth
  - 8
  - 16
  - 24 (default)
  - 32
  - 32_float
  - 64_float


#### use_both_for_loop_file, always_export_no_loop_folder

![04](./readmesrc/04.png)

This setting is related to `tag_order.txt` and `tag_order_loop.txt` described below, if `metadata_txt = true` in Export.

If `use_both_for_loop_file` is` false`, use either `tag_order.txt`,` tag_order_loop.txt` for the text output of the tag information, based on the presence or absence of the loop information of the WAV file. If `true`, both files are used as the base for output. It can be used to output normal metadata with `tag_order.txt` and only write loops with` tag_order_loop.txt`.

If `always_export_no_loop_folder` is `false`, text based on `tag_order_loop.txt` is output to the same folder as audio files with loop settings. Setting it to `true`, it always outputs it to a non-loop formats storage folder such as MP3.


#### aac_codec_extention, add_alac_file_modifier

![05](./readmesrc/05.png)

It is related to the file extension when converting files in AAC and ALAC codecs.

The extension of AAC and Alac is generally .m4a, but these two may be output to the same folder due to the use of a non -loop WAV file or setting a folder described later. This setting is intended to prevent overwriting when the extension and file name are the same.

Specifying `aac` in `aac_codec_extention` will change the file extension to `.aac` after conversion with the AAC codec. The default is `.m4a`.

If `add_alac_file_modifier` is enabled, the string specified by `alac_file_modifier` is added to the end of the file name to suppress file overwriting.

I recommend not changing this setting.

#### sound_loop_optimization

![06](./readmesrc/06.png)

With `true`, when converting a wav file with a loop setting to a loop-enabled format, it will cut off the unplayable area after the loop portion before converting. This optimizes the file size for loop-enabled formats, and allows batch conversion of non-loop formats that can be played back to the end of the song as usual.

If you need to be able to play a song to the end when the loop flag is disabled, set it to `false` and reflect only the loop settings with the playback time of the original file.

#### loop_sound_individual_folder、no_loop_sound_filename_folder

![07](./readmesrc/07.png)

When converting a wav file with a loop setting, the file format with the loop is compiled in one folder. The output of `split_ogg` enters the` unityLoop` folder in it.If `loop_Sound_individual_folder` is set to` false`, all files in the loop-compatible format are output to the same folder as the non-loop formats. If you set this to `false`, please attention the .m4a extension related settings mentioned above.

Setting `no_loop_sound_filename_folder` to true will also save non-loop format files in the name folder. This can be used in combination with `loop_Sound_individual_folder`.

A folder with the file name is created in the convert folder, a folder with the non-loop sound source and file name is created in the first  file name folder, a folder with the loop sound source and unityloop folder is created in the convert folder, and `split_ogg` is output in the unityloop folder.

If only `loop_sound_individual_folder` is set to `true`, a folder with the file name is created under the convert folder and all output results are stored directly under it.

#### length_add

![08](./readmesrc/08.png)

Change the playback time notation at the time of .txt output of metadata. If both sides are set to `true`, they will be output in the form of hh: mm: ss.xxx.

#### split_ogg_name

![09](./readmesrc/09.png)

Set the file name end modifier when the output of `sprit_ogg` is enabled with` Export`. If you use the same file name, it will be overwritten, so be sure to set a different name.

## For tag_order.txt, tag_order_loop.txt

lwavconv includes tag_order.txt and tag_order_loop.txt as templates for metadata output.

This template is editable and allows for some customization of the layout of the output results.

![10](./readmesrc/10.png)

Above is the default content of tag_order.txt. Using this template, the results of tagging as much as possible with Foobar2000 are as follows.

![11](./readmesrc/11.png)

The output will be replaced with the tag content corresponding to the position specified by `<tag name>`. If the tag specified by `<tag name>` does not exist in the wav file, it will be left blank as shown below.

![12](./readmesrc/12.png)

The included tag_order.txt describes all tags that can be set by default with foobar2000, but if any user tag is set, if you fill it in the form of `<tag name>`. It is possible to replace it with a position and output. In this case, the tag name in the txt side should be in lower case.

Nothing is processed internally except for `<`,`>`, so you can decorate txt to some extent freely.

![13](./readmesrc/13.png)

The above is the default content of tag_order_loop.txt. The result of using this template in a WAV file with a loop setting is as follows.

![14](./readmesrc/14.png)

tag_order_loop.txt has only simple information, but if you add `<title>` or `<artist>`, etc. in the same way as tag_order.txt, the contents will be displayed even if you use this template.

### For tags `<length>`, `<filename>`

In tag_order.txt and tag_order_loop.txt I have added two special tags for my personal convenience.

The `<length>` tag refers to the playback time of the original WAV file, as mentioned briefly in the lwavconv.ini Advanced Settings, and is listed in .txt as a normal tag. Since it only refers to the original WAV file, it cannot contain the playback time after loop optimization.

The `<filename>` tag is simply the name of the original WAV file. The file extension is not shown, but if you need it, you can include it directly in the template. The following is an example of displaying `.ogg` after the file name.

![15](./readmesrc/15.png)
![16](./readmesrc/16.png)

If you write `.ogg` immediately after the `<filename>` tag, it will be output with this description.

Although there are few uses, you can describe any character string not only for `<fileName>` tag but other tag information.

## Update History


2023-07-07 
v1.0.1 Fix split ogg filename.

2023-06-28 
v1.0.0 Release

-----

Copyright© 2023 [doranarasi](https://doranarasi.com/) All rights reserved.

lwavconv.exe is compiled by [Nuitka](https://nuitka.net/)

[Nuitka](https://nuitka.net/) is licensed under the Apache License, Version 2.0

