From 5cdc6aab48fa6c35d51b0f199da96ce0a9ae60ac Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 13 Jan 2020 13:49:32 +0100 Subject: [PATCH 1/2] Remove libsndfile dep and code our own savewav --- client/Makefile | 2 +- client/fileutils.c | 52 ++++++++++++++----- .../Linux-Installation-Instructions.md | 6 +-- ...OS-X-Homebrew-Installation-Instructions.md | 2 +- .../Windows-Installation-Instructions.md | 2 +- doc/termux_notes.md | 2 +- 6 files changed, 45 insertions(+), 21 deletions(-) diff --git a/client/Makefile b/client/Makefile index 483856b8f..6e2ebd001 100644 --- a/client/Makefile +++ b/client/Makefile @@ -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 diff --git a/client/fileutils.c b/client/fileutils.c index 4847d52b8..44f397cda 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -41,7 +41,6 @@ #include #include -#include #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: diff --git a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md index b48b8e9f5..d56d1056c 100644 --- a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md @@ -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`. diff --git a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md index 846383658..76f5ee6f3 100644 --- a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md @@ -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 ``` diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index 4065e0d27..9d94490f5 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -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`. diff --git a/doc/termux_notes.md b/doc/termux_notes.md index 2d2147513..d86ec7f08 100644 --- a/doc/termux_notes.md +++ b/doc/termux_notes.md @@ -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 From f46a01abfa76d958382fac69516bdc376b78ecca Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 13 Jan 2020 14:03:32 +0100 Subject: [PATCH 2/2] Move snd_info struct to top of file --- client/fileutils.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/client/fileutils.c b/client/fileutils.c index 44f397cda..982b0f753 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -52,6 +52,26 @@ #define PATH_MAX_LENGTH 200 +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; + /** * @brief checks if a file exists * @param filename @@ -406,25 +426,7 @@ int saveFileWAVE(const char *preferredName, int *data, size_t datalen) { if (fileName == NULL) return PM3_EMALLOC; int retval = PM3_SUCCESS; - 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 = { + struct wave_info_t wave_info = { .signature = "RIFF", .filesize = sizeof(wave_info) - sizeof(wave_info.signature) - sizeof(wave_info.filesize) + datalen, .type = "WAVE",