From 53f573b4fdeb15d8cef5deb3fff29c389302f16f Mon Sep 17 00:00:00 2001 From: Brandon Skari Date: Fri, 16 Jun 2017 14:22:56 -0600 Subject: [PATCH] Improve some documentation, bump version # --- setup.py | 2 +- src/python/_rpitxmodule.c | 73 ++++++++++++++++++------------------- src/python/rpitx/_hidden.py | 11 ++++-- 3 files changed, 44 insertions(+), 42 deletions(-) diff --git a/setup.py b/setup.py index 5a14204..151612f 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup, Extension setup( name='rpitx', - version='0.1', + version='0.2', description='Raspyberry Pi radio transmitter', author='Brandon Skari', author_email='brandon@skari.org', diff --git a/src/python/_rpitxmodule.c b/src/python/_rpitxmodule.c index 6959cdd..d023aac 100644 --- a/src/python/_rpitxmodule.c +++ b/src/python/_rpitxmodule.c @@ -107,75 +107,75 @@ _rpitx_broadcast_fm(PyObject* self, PyObject* args) { RETURN_ERROR("Invalid arguments"); } - union { - char char4[4]; - uint32_t uint32; - uint16_t uint16; - } buffer; - size_t byteCount = read(streamFileNo, buffer.char4, 4); - if (byteCount != 4 || strncmp(buffer.char4, "RIFF", 4) != 0) { + char char4[4]; + uint32_t uint32; + uint16_t uint16; + char letter; + + size_t byteCount = read(streamFileNo, char4, sizeof(char4)); + if (byteCount != sizeof(char4) || strncmp(char4, "RIFF", 4) != 0) { RETURN_ERROR("Not a WAV file"); } // Skip chunk size - byteCount = read(streamFileNo, buffer.char4, 4); - if (byteCount != 4) { + byteCount = read(streamFileNo, char4, sizeof(char4)); + if (byteCount != sizeof(char4)) { RETURN_ERROR("Not a WAV file"); } - byteCount = read(streamFileNo, buffer.char4, 4); - if (byteCount != 4 || strncmp(buffer.char4, "WAVE", 4) != 0) { + byteCount = read(streamFileNo, char4, sizeof(char4)); + if (byteCount != sizeof(char4) || strncmp(char4, "WAVE", 4) != 0) { RETURN_ERROR("Not a WAV file"); } - byteCount = read(streamFileNo, buffer.char4, 4); - if (byteCount != 4 || strncmp(buffer.char4, "fmt ", 4) != 0) { + byteCount = read(streamFileNo, char4, sizeof(char4)); + if (byteCount != sizeof(char4) || strncmp(char4, "fmt ", 4) != 0) { RETURN_ERROR("Not a WAV file"); } - byteCount = read(streamFileNo, &buffer.uint32, 4); - buffer.uint32 = le32toh(buffer.uint32); + byteCount = read(streamFileNo, &uint32, sizeof(uint32)); + uint32 = le32toh(uint32); // TODO: This value is coming out as 18 and I don't know why, so I'm // skipping this check for now /* - if (byteCount != 4 || buffer.uint32 != 16) { + if (byteCount != sizeof(uint32) || uint32 != 16) { RETURN_ERROR("Not a PCM WAV file"); } */ - byteCount = read(streamFileNo, &buffer.uint16, 2); - buffer.uint16 = le16toh(buffer.uint16); - if (byteCount != 2 || buffer.uint16 != 1) { + byteCount = read(streamFileNo, &uint16, sizeof(uint16)); + uint16 = le16toh(uint16); + if (byteCount != sizeof(uint16) || uint16 != 1) { RETURN_ERROR("Not an uncompressed WAV file"); } - byteCount = read(streamFileNo, &buffer.uint16, 2); - buffer.uint16 = le16toh(buffer.uint16); - if (byteCount != 2 || buffer.uint16 != 1) { + byteCount = read(streamFileNo, &uint16, sizeof(uint16)); + uint16 = le16toh(uint16); + if (byteCount != sizeof(uint16) || uint16 != 1) { RETURN_ERROR("Not a mono WAV file"); } - byteCount = read(streamFileNo, &buffer.uint32, 4); - sampleRate = le32toh(buffer.uint32); - if (byteCount != 4 || sampleRate != 48000) { + byteCount = read(streamFileNo, &uint32, sizeof(uint32)); + sampleRate = le32toh(uint32); + if (byteCount != sizeof(uint32) || sampleRate != 48000) { RETURN_ERROR("Not a WAV file"); } // Skip byte rate - byteCount = read(streamFileNo, &buffer.uint32, 4); - if (byteCount != 4) { + byteCount = read(streamFileNo, &uint32, sizeof(uint32)); + if (byteCount != sizeof(uint32)) { RETURN_ERROR("Not a WAV file"); } // Skip block align - byteCount = read(streamFileNo, &buffer.uint16, 2); - if (byteCount != 2) { + byteCount = read(streamFileNo, &uint16, sizeof(uint16)); + if (byteCount != sizeof(uint16)) { RETURN_ERROR("Not a WAV file"); } - byteCount = read(streamFileNo, &buffer.uint16, 2); - buffer.uint16 = le16toh(buffer.uint16); - if (byteCount != 2 || buffer.uint16 != 16) { + byteCount = read(streamFileNo, &uint16, sizeof(uint16)); + uint16 = le16toh(uint16); + if (byteCount != sizeof(uint16) || uint16 != 16) { RETURN_ERROR("Not a 16 bit WAV file"); } @@ -183,10 +183,9 @@ _rpitx_broadcast_fm(PyObject* self, PyObject* args) { // parameters, starting with "LIST" and including the encoder I think. However, // the marker "data" is still there where the data starts, so let's just skip // to that. - byteCount = read(streamFileNo, buffer.char4, 1); + byteCount = read(streamFileNo, &letter, sizeof(letter)); int dataLettersCount = 0; while (byteCount == 1) { - const char letter = buffer.char4[0]; switch (letter) { case 'd': dataLettersCount = 1; @@ -211,7 +210,7 @@ _rpitx_broadcast_fm(PyObject* self, PyObject* args) { default: dataLettersCount = 0; } - byteCount = read(streamFileNo, buffer.char4, 1); + byteCount = read(streamFileNo, &letter, sizeof(letter)); } if (dataLettersCount != 4) { RETURN_ERROR("Not a WAV file"); @@ -219,8 +218,8 @@ _rpitx_broadcast_fm(PyObject* self, PyObject* args) { foundDataMarker: // Skip subchunk2 size - byteCount = read(streamFileNo, &buffer.uint32, 4); - if (byteCount != 4) { + byteCount = read(streamFileNo, &uint32, sizeof(uint32)); + if (byteCount != sizeof(uint32)) { RETURN_ERROR("Not a WAV file"); } diff --git a/src/python/rpitx/_hidden.py b/src/python/rpitx/_hidden.py index ab6dd8e..e85a458 100644 --- a/src/python/rpitx/_hidden.py +++ b/src/python/rpitx/_hidden.py @@ -1,20 +1,23 @@ """Hides imports and other irrelevant things so that ipython works nicely.""" -import _rpitx -import ffmpegwrapper -import libavwrapper import logging import os import subprocess import sys import threading +import _rpitx +import ffmpegwrapper +import libavwrapper PIPE = 'pipe:1' DUMMY_FILE = 'dummy-file.wav' def broadcast_fm(media_file_name, frequency): - """Play a media file's audio over FM.""" + """Broadcast a media file's audio over FM. +Args: + media_file_name (str): The file to broadcast. + frequency (float): The frequency, in MHz, to broadcast on.""" logging.basicConfig() logger = logging.getLogger('rpitx')