ref: 0048a15cd919c3cc83b2e87468385fd9c3137d11
parent: 4ddca9e4a811be15806a53bbfea28a80d45c4f20
parent: b51f4bd77afd492962925e5d890accbca0c3f4d1
author: Christopher Snowhill <kode54@gmail.com>
date: Sun Dec 13 20:10:55 EST 2015
Merge pull request #19 from katajakasa/ttv-examples-patches2 dumbout: Implement delay switch + cleanups
--- a/dumb/cmake/CMakeLists.txt
+++ b/dumb/cmake/CMakeLists.txt
@@ -119,7 +119,7 @@
if(BUILD_EXAMPLES)
add_executable(dumbout ../examples/dumbout.c)
- target_link_libraries(dumbout ${ARGTABLE2_LIBRARY} dumb)
+ target_link_libraries(dumbout ${ARGTABLE2_LIBRARY} m dumb)
include_directories(${ARGTABLE2_INCLUDE_DIR} "../examples/")
set(EXAMPLE_TARGETS ${EXAMPLE_TARGETS} "dumbout")
endif()
--- a/dumb/cmake/readme.txt
+++ b/dumb/cmake/readme.txt
@@ -27,4 +27,5 @@
* CMAKE_INSTALL_PREFIX sets the installation path prefix
* CMAKE_BUILD_TYPE sets the build type (eg. Release, Debug, RelWithDebInfo, MinSizeRel). Debug libraries will be named libdumbd, release libraries libdumb.
* BUILD_SHARED_LIBS selects whether cmake should build dynamic or static library (On=shared, OFF=static)
+* BUILD_EXAMPLES selects example binaries. Note that example binaries require libargtable2 library. Enabled by default.
* You may also need to tell cmake what kind of makefiles to create with the "-G" flag. Eg. for MSYS one would say something like `cmake -G "MSYS Makefiles" .`.
--- a/dumb/examples/dumbout.c
+++ b/dumb/examples/dumbout.c
@@ -3,6 +3,7 @@
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
+#include <math.h>
static const int endian_test = 1;
#define is_bigendian() ((*(char*)&endian_test) == 0)
@@ -177,7 +178,6 @@
}
}
- // Loop as long as we have data to play
bool run = true;
char *buffer = malloc(streamer.bufsize);
int read_samples;
@@ -185,8 +185,45 @@
// If output endianness is different than machine endianness, and output is 16 bits, reorder bytes.
int switch_endianness = ((is_bigendian() && settings.endianness == LITTLE_ENDIAN) ||
- (!is_bigendian() && settings.endianness == BIG_ENDIAN)) && settings.bits == 16;
+ (!is_bigendian() && settings.endianness == BIG_ENDIAN));
+ // Write the initial delay to the file if one was requested.
+ long d = ((long)floor(settings.delay * settings.freq + 0.5f)) * settings.n_channels * (settings.bits / 8);
+ if(d) {
+ // Fill the buffer with silence. Remember to take into account endianness
+ if(settings.is_unsigned) {
+ if(settings.bits == 16) {
+ if(settings.endianness == BIG_ENDIAN) {
+ // Unsigned 16bits big endian
+ for(int i = 0; i < streamer.bufsize; i += 2) {
+ buffer[i ] = (char)0x80;
+ buffer[i+1] = (char)0x00;
+ }
+ } else {
+ // Unsigned 16bits little endian
+ for(int i = 0; i < streamer.bufsize; i += 2) {
+ buffer[i ] = (char)0x00;
+ buffer[i+1] = (char)0x80;
+ }
+ }
+ } else {
+ // Unsigned 8 bits
+ memset(buffer, 0x80, streamer.bufsize);
+ }
+ } else {
+ // Signed
+ memset(buffer, 0, streamer.bufsize);
+ }
+
+ while(d >= streamer.bufsize) {
+ fwrite(buffer, 1, streamer.bufsize, streamer.dst);
+ d -= streamer.bufsize;
+ }
+ if(d) {
+ fwrite(buffer, 1, d, streamer.dst);
+ }
+ }
+
// Loop until we have nothing to loop through. Dumb will stop giving out bytes when the file is done.
while(run) {
read_samples = duh_render(streamer.renderer,
@@ -198,7 +235,7 @@
read_bytes = read_samples * (settings.bits / 8) * settings.n_channels;
// switch endianness if required
- if(switch_endianness) {
+ if(switch_endianness && settings.bits == 16) {
char tmp;
for(int i = 0; i < read_bytes / 2; i++) {
tmp = buffer[i*2+0];