kopia lustrzana https://github.com/F5OEO/rpitx
Improve some documentation, bump version #
rodzic
cc0d5e2baf
commit
53f573b4fd
2
setup.py
2
setup.py
|
@ -4,7 +4,7 @@ from setuptools import setup, Extension
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='rpitx',
|
name='rpitx',
|
||||||
version='0.1',
|
version='0.2',
|
||||||
description='Raspyberry Pi radio transmitter',
|
description='Raspyberry Pi radio transmitter',
|
||||||
author='Brandon Skari',
|
author='Brandon Skari',
|
||||||
author_email='brandon@skari.org',
|
author_email='brandon@skari.org',
|
||||||
|
|
|
@ -107,75 +107,75 @@ _rpitx_broadcast_fm(PyObject* self, PyObject* args) {
|
||||||
RETURN_ERROR("Invalid arguments");
|
RETURN_ERROR("Invalid arguments");
|
||||||
}
|
}
|
||||||
|
|
||||||
union {
|
char char4[4];
|
||||||
char char4[4];
|
uint32_t uint32;
|
||||||
uint32_t uint32;
|
uint16_t uint16;
|
||||||
uint16_t uint16;
|
char letter;
|
||||||
} buffer;
|
|
||||||
size_t byteCount = read(streamFileNo, buffer.char4, 4);
|
size_t byteCount = read(streamFileNo, char4, sizeof(char4));
|
||||||
if (byteCount != 4 || strncmp(buffer.char4, "RIFF", 4) != 0) {
|
if (byteCount != sizeof(char4) || strncmp(char4, "RIFF", 4) != 0) {
|
||||||
RETURN_ERROR("Not a WAV file");
|
RETURN_ERROR("Not a WAV file");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip chunk size
|
// Skip chunk size
|
||||||
byteCount = read(streamFileNo, buffer.char4, 4);
|
byteCount = read(streamFileNo, char4, sizeof(char4));
|
||||||
if (byteCount != 4) {
|
if (byteCount != sizeof(char4)) {
|
||||||
RETURN_ERROR("Not a WAV file");
|
RETURN_ERROR("Not a WAV file");
|
||||||
}
|
}
|
||||||
|
|
||||||
byteCount = read(streamFileNo, buffer.char4, 4);
|
byteCount = read(streamFileNo, char4, sizeof(char4));
|
||||||
if (byteCount != 4 || strncmp(buffer.char4, "WAVE", 4) != 0) {
|
if (byteCount != sizeof(char4) || strncmp(char4, "WAVE", 4) != 0) {
|
||||||
RETURN_ERROR("Not a WAV file");
|
RETURN_ERROR("Not a WAV file");
|
||||||
}
|
}
|
||||||
|
|
||||||
byteCount = read(streamFileNo, buffer.char4, 4);
|
byteCount = read(streamFileNo, char4, sizeof(char4));
|
||||||
if (byteCount != 4 || strncmp(buffer.char4, "fmt ", 4) != 0) {
|
if (byteCount != sizeof(char4) || strncmp(char4, "fmt ", 4) != 0) {
|
||||||
RETURN_ERROR("Not a WAV file");
|
RETURN_ERROR("Not a WAV file");
|
||||||
}
|
}
|
||||||
|
|
||||||
byteCount = read(streamFileNo, &buffer.uint32, 4);
|
byteCount = read(streamFileNo, &uint32, sizeof(uint32));
|
||||||
buffer.uint32 = le32toh(buffer.uint32);
|
uint32 = le32toh(uint32);
|
||||||
// TODO: This value is coming out as 18 and I don't know why, so I'm
|
// TODO: This value is coming out as 18 and I don't know why, so I'm
|
||||||
// skipping this check for now
|
// skipping this check for now
|
||||||
/*
|
/*
|
||||||
if (byteCount != 4 || buffer.uint32 != 16) {
|
if (byteCount != sizeof(uint32) || uint32 != 16) {
|
||||||
RETURN_ERROR("Not a PCM WAV file");
|
RETURN_ERROR("Not a PCM WAV file");
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
byteCount = read(streamFileNo, &buffer.uint16, 2);
|
byteCount = read(streamFileNo, &uint16, sizeof(uint16));
|
||||||
buffer.uint16 = le16toh(buffer.uint16);
|
uint16 = le16toh(uint16);
|
||||||
if (byteCount != 2 || buffer.uint16 != 1) {
|
if (byteCount != sizeof(uint16) || uint16 != 1) {
|
||||||
RETURN_ERROR("Not an uncompressed WAV file");
|
RETURN_ERROR("Not an uncompressed WAV file");
|
||||||
}
|
}
|
||||||
|
|
||||||
byteCount = read(streamFileNo, &buffer.uint16, 2);
|
byteCount = read(streamFileNo, &uint16, sizeof(uint16));
|
||||||
buffer.uint16 = le16toh(buffer.uint16);
|
uint16 = le16toh(uint16);
|
||||||
if (byteCount != 2 || buffer.uint16 != 1) {
|
if (byteCount != sizeof(uint16) || uint16 != 1) {
|
||||||
RETURN_ERROR("Not a mono WAV file");
|
RETURN_ERROR("Not a mono WAV file");
|
||||||
}
|
}
|
||||||
|
|
||||||
byteCount = read(streamFileNo, &buffer.uint32, 4);
|
byteCount = read(streamFileNo, &uint32, sizeof(uint32));
|
||||||
sampleRate = le32toh(buffer.uint32);
|
sampleRate = le32toh(uint32);
|
||||||
if (byteCount != 4 || sampleRate != 48000) {
|
if (byteCount != sizeof(uint32) || sampleRate != 48000) {
|
||||||
RETURN_ERROR("Not a WAV file");
|
RETURN_ERROR("Not a WAV file");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip byte rate
|
// Skip byte rate
|
||||||
byteCount = read(streamFileNo, &buffer.uint32, 4);
|
byteCount = read(streamFileNo, &uint32, sizeof(uint32));
|
||||||
if (byteCount != 4) {
|
if (byteCount != sizeof(uint32)) {
|
||||||
RETURN_ERROR("Not a WAV file");
|
RETURN_ERROR("Not a WAV file");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip block align
|
// Skip block align
|
||||||
byteCount = read(streamFileNo, &buffer.uint16, 2);
|
byteCount = read(streamFileNo, &uint16, sizeof(uint16));
|
||||||
if (byteCount != 2) {
|
if (byteCount != sizeof(uint16)) {
|
||||||
RETURN_ERROR("Not a WAV file");
|
RETURN_ERROR("Not a WAV file");
|
||||||
}
|
}
|
||||||
|
|
||||||
byteCount = read(streamFileNo, &buffer.uint16, 2);
|
byteCount = read(streamFileNo, &uint16, sizeof(uint16));
|
||||||
buffer.uint16 = le16toh(buffer.uint16);
|
uint16 = le16toh(uint16);
|
||||||
if (byteCount != 2 || buffer.uint16 != 16) {
|
if (byteCount != sizeof(uint16) || uint16 != 16) {
|
||||||
RETURN_ERROR("Not a 16 bit WAV file");
|
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,
|
// 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
|
// the marker "data" is still there where the data starts, so let's just skip
|
||||||
// to that.
|
// to that.
|
||||||
byteCount = read(streamFileNo, buffer.char4, 1);
|
byteCount = read(streamFileNo, &letter, sizeof(letter));
|
||||||
int dataLettersCount = 0;
|
int dataLettersCount = 0;
|
||||||
while (byteCount == 1) {
|
while (byteCount == 1) {
|
||||||
const char letter = buffer.char4[0];
|
|
||||||
switch (letter) {
|
switch (letter) {
|
||||||
case 'd':
|
case 'd':
|
||||||
dataLettersCount = 1;
|
dataLettersCount = 1;
|
||||||
|
@ -211,7 +210,7 @@ _rpitx_broadcast_fm(PyObject* self, PyObject* args) {
|
||||||
default:
|
default:
|
||||||
dataLettersCount = 0;
|
dataLettersCount = 0;
|
||||||
}
|
}
|
||||||
byteCount = read(streamFileNo, buffer.char4, 1);
|
byteCount = read(streamFileNo, &letter, sizeof(letter));
|
||||||
}
|
}
|
||||||
if (dataLettersCount != 4) {
|
if (dataLettersCount != 4) {
|
||||||
RETURN_ERROR("Not a WAV file");
|
RETURN_ERROR("Not a WAV file");
|
||||||
|
@ -219,8 +218,8 @@ _rpitx_broadcast_fm(PyObject* self, PyObject* args) {
|
||||||
foundDataMarker:
|
foundDataMarker:
|
||||||
|
|
||||||
// Skip subchunk2 size
|
// Skip subchunk2 size
|
||||||
byteCount = read(streamFileNo, &buffer.uint32, 4);
|
byteCount = read(streamFileNo, &uint32, sizeof(uint32));
|
||||||
if (byteCount != 4) {
|
if (byteCount != sizeof(uint32)) {
|
||||||
RETURN_ERROR("Not a WAV file");
|
RETURN_ERROR("Not a WAV file");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,23 @@
|
||||||
"""Hides imports and other irrelevant things so that ipython works nicely."""
|
"""Hides imports and other irrelevant things so that ipython works nicely."""
|
||||||
|
|
||||||
import _rpitx
|
|
||||||
import ffmpegwrapper
|
|
||||||
import libavwrapper
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
import _rpitx
|
||||||
|
import ffmpegwrapper
|
||||||
|
import libavwrapper
|
||||||
|
|
||||||
PIPE = 'pipe:1'
|
PIPE = 'pipe:1'
|
||||||
DUMMY_FILE = 'dummy-file.wav'
|
DUMMY_FILE = 'dummy-file.wav'
|
||||||
|
|
||||||
|
|
||||||
def broadcast_fm(media_file_name, frequency):
|
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()
|
logging.basicConfig()
|
||||||
logger = logging.getLogger('rpitx')
|
logger = logging.getLogger('rpitx')
|
||||||
|
|
Ładowanie…
Reference in New Issue