Remove libsndfile dep and code our own savewav

This commit is contained in:
Philippe Teuwen 2020-01-13 13:49:32 +01:00
parent fe5b3b0911
commit 5cdc6aab48
6 changed files with 45 additions and 21 deletions

View file

@ -22,7 +22,7 @@ vpath %.dic dictionaries
OBJDIR = obj
LDLIBS ?= -L/usr/local/lib
LDLIBS += -lreadline -lsndfile -lpthread -lm
LDLIBS += -lreadline -lpthread -lm
# RPi Zero gcc requires -latomic
# but MacOSX /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld

View file

@ -41,7 +41,6 @@
#include <dirent.h>
#include <ctype.h>
#include <sndfile.h>
#include "pm3_cmd.h"
#include "commonutil.h"
@ -405,30 +404,55 @@ int saveFileWAVE(const char *preferredName, int *data, size_t datalen) {
if (data == NULL) return PM3_EINVARG;
char *fileName = newfilenamemcopy(preferredName, ".wav");
if (fileName == NULL) return PM3_EMALLOC;
int retval = PM3_SUCCESS;
SF_INFO wave_info;
// TODO update for other tag types
wave_info.samplerate = 125000;
wave_info.channels = 1;
wave_info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_U8;
SNDFILE *wave_file = sf_open(fileName, SFM_WRITE, &wave_info);
struct wave_info_t {
char signature[4];
uint32_t filesize;
char type[4];
struct {
char tag[4];
uint32_t size;
uint16_t codec;
uint16_t nb_channel;
uint32_t sample_per_sec;
uint32_t byte_per_sec;
uint16_t block_align;
uint16_t bit_per_sample;
} PACKED format;
struct {
char tag[4];
uint32_t size;
} PACKED audio_data;
} PACKED wave_info = {
.signature = "RIFF",
.filesize = sizeof(wave_info) - sizeof(wave_info.signature) - sizeof(wave_info.filesize) + datalen,
.type = "WAVE",
.format.tag = "fmt ",
.format.size = sizeof(wave_info.format) - sizeof(wave_info.format.tag) - sizeof(wave_info.format.size),
.format.codec = 1, // PCM
.format.nb_channel = 1,
.format.sample_per_sec = 125000, // TODO update for other tag types
.format.byte_per_sec = 125000, // TODO update for other tag types
.format.block_align = 1,
.format.bit_per_sample = 8,
.audio_data.tag = "data",
.audio_data.size = datalen,
};
FILE *wave_file = fopen(fileName, "wb");
if (!wave_file) {
PrintAndLogEx(WARNING, "file not found or locked. "_YELLOW_("'%s'"), fileName);
retval = PM3_EFILE;
goto out;
}
// unfortunately need to upconvert to 16-bit samples because libsndfile doesn't do 8-bit(?)
fwrite(&wave_info, sizeof(wave_info), 1, wave_file);
for (int i = 0; i < datalen; i++) {
short sample = data[i] * 256;
sf_write_short(wave_file, &sample, 1);
uint8_t sample = data[i] + 128;
fwrite(&sample, 1, 1, wave_file);
}
fclose(wave_file);
sf_close(wave_file);
PrintAndLogEx(SUCCESS, "saved " _YELLOW_("%zu")" bytes to wave file " _YELLOW_("'%s'"), 2 * datalen, fileName);
out:

View file

@ -25,7 +25,7 @@ Install the requirements
```sh
sudo apt-get install --no-install-recommends git ca-certificates build-essential pkg-config \
libreadline-dev gcc-arm-none-eabi libnewlib-dev qtbase5-dev libsndfile1-dev
libreadline-dev gcc-arm-none-eabi libnewlib-dev qtbase5-dev
```
If you don't need the graphical components of the Proxmark3 client, you can skip the installation of `qtbase5-dev`.
@ -35,7 +35,7 @@ If you get some (non blocking) error at runtime such as _Gtk-Message: Failed to
## On ArchLinux
```sh
sudo pacman -Sy base-devel readline arm-none-eabi-gcc arm-none-eabi-newlib libsndfile git --needed
sudo pacman -Sy base-devel readline arm-none-eabi-gcc arm-none-eabi-newlib git --needed
```
If you want graphical output (such as in `hw tune`):
```sh
@ -45,7 +45,7 @@ sudo pacman -Su qt5-base
## On Fedora
```sh
sudo dnf install git make gcc gcc-c++ arm-none-eabi-gcc-cs arm-none-eabi-newlib readline-devel qt5-qtbase-devel libatomic libsndfile
sudo dnf install git make gcc gcc-c++ arm-none-eabi-gcc-cs arm-none-eabi-newlib readline-devel qt5-qtbase-devel libatomic
```
If you don't need the graphical components of the Proxmark3 client, you can skip the installation of `qt5-qtbase-devel`.

View file

@ -82,7 +82,7 @@ These instructions will show how to setup the environment on OSX to the point wh
2. Install dependencies:
```
brew install readline qt5 pkgconfig libsndfile
brew install readline qt5 pkgconfig
brew install RfidResearchGroup/proxmark3/arm-none-eabi-gcc
```

View file

@ -77,7 +77,7 @@ Enter WSL prompt (`wsl`) and from there, follow the [Linux Installation Instruct
```sh
sudo apt-get update
sudo apt-get install --no-install-recommends git ca-certificates build-essential pkg-config \
libreadline-dev gcc-arm-none-eabi libnewlib-dev qtbase5-dev libsndfile1-dev
libreadline-dev gcc-arm-none-eabi libnewlib-dev qtbase5-dev
```
If you don't need the graphical components of the Proxmark3 client, you can skip the installation of `qtbase5-dev`.

View file

@ -33,7 +33,7 @@ ref : https://github.com/Proxmark/proxmark3/wiki/android
1. Install [Termux](https://play.google.com/store/apps/details?id=com.termux) and start it
2. Run the following commands:
```
pkg install make clang clang++ readline libc++ git tsu libsndfile
pkg install make clang clang++ readline libc++ git tsu
git clone https://github.com/RfidResearchGroup/proxmark3.git
```
### Building Proxmark3 client