Skip to content

Commit 80f7423

Browse files
committed
Configure audio support at runtime - fixes #372
Signed-off-by: Benn Snyder <[email protected]>
1 parent fb2b056 commit 80f7423

11 files changed

+44
-124
lines changed

CMakeLists.txt

+2-9
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ set (PROJECT_VER
5454
set (PROJECT_APIVER
5555
"${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}")
5656

57-
OPTION(BUILD_AUDIO "Build audio support" OFF)
58-
OPTION(BUILD_REDIST_PACKAGE "Build libfreenect in a legally-redistributable manner (only affects audio)" OFF)
57+
OPTION(BUILD_REDIST_PACKAGE "Build libfreenect in a legally-redistributable manner (only affects audio)" ON)
5958
OPTION(BUILD_EXAMPLES "Build example programs" ON)
6059
OPTION(BUILD_FAKENECT "Build fakenect mock library" ON)
6160
OPTION(BUILD_C_SYNC "Build c synchronous library" ON)
@@ -84,10 +83,6 @@ if(BIG_ENDIAN)
8483
add_definitions(-DFN_BIGENDIAN)
8584
endif()
8685

87-
if(BUILD_AUDIO)
88-
add_definitions(-DBUILD_AUDIO)
89-
endif()
90-
9186
if (WIN32)
9287
set(MATH_LIB "")
9388
else(WIN32)
@@ -217,11 +212,9 @@ IF ( BUILD_CPACK_TGZ OR BUILD_CPACK_DEB OR BUILD_CPACK_RPM )
217212
include(CPack)
218213

219214
INSTALL(FILES "${CMAKE_BINARY_DIR}/lib/libfreenect.a" DESTINATION ${PROJECT_LIBRARY_INSTALL_DIR})
220-
if (BUILD_AUDIO)
221-
INSTALL(FILES "include/libfreenect_audio.h" DESTINATION ${PROJECT_INCLUDE_INSTALL_DIR})
222-
endif()
223215
INSTALL(FILES "include/libfreenect.h" DESTINATION ${PROJECT_INCLUDE_INSTALL_DIR})
224216
INSTALL(FILES "include/libfreenect_registration.h" DESTINATION ${PROJECT_INCLUDE_INSTALL_DIR})
217+
INSTALL(FILES "include/libfreenect_audio.h" DESTINATION ${PROJECT_INCLUDE_INSTALL_DIR})
225218
INSTALL(FILES "APACHE20" DESTINATION "share/doc/${CPACK_PACKAGE_NAME}")
226219
INSTALL(FILES "GPL2" DESTINATION "share/doc/${CPACK_PACKAGE_NAME}")
227220
INSTALL(FILES "README.md" DESTINATION "share/doc/${CPACK_PACKAGE_NAME}")

README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ It runs on Linux, OSX, and Windows and supports
88
- Motors
99
- Accelerometer
1010
- LED
11-
12-
Audio is a work in progress.
11+
- Audio
1312

1413

1514
# Build Instructions
@@ -18,14 +17,20 @@ To build libfreenect, you'll need
1817

1918
- [libusb](http://libusb.info) >= 1.0.18
2019
- [CMake](http://cmake.org) >= 2.6
21-
- [python](http://python.org) == 2.* (only if BUILD_AUDIO or BUILD_PYTHON)
20+
- [python](http://python.org) == 2.* (only if BUILD_PYTHON=ON or BUILD_REDIST_PACKAGE=OFF)
2221

2322
For the examples, you'll need
2423

2524
- OpenGL (included with OSX)
2625
- glut (included with OSX)
2726
- [pthreads-win32](http://sourceforge.net/projects/pthreads4w/) (Windows)
2827

28+
For audio support, you must have firmware to upload to the Kinect.
29+
If you specify a non-redistributable package, firmware will be downloaded automatically:
30+
31+
cmake -L .. -DBUILD_REDIST_PACKAGE=OFF
32+
33+
Note that the downloaded firmware may not be legal to redistribute!
2934

3035
## <a name="fetch-build"></a>Fetch & Build
3136

@@ -39,10 +44,6 @@ For the examples, you'll need
3944
# if you don't have `make` or don't want color output
4045
# cmake --build .
4146

42-
For some newer Kinect models, audio must be enabled for tilt and LED control:
43-
44-
cmake -L .. -DBUILD_AUDIO=ON
45-
4647
You can specify a build with debug symbols:
4748

4849
cmake -L .. -DCMAKE_BUILD_TYPE=debug

examples/CMakeLists.txt

+7-19
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ add_executable(freenect-glview glview.c)
1919
add_executable(freenect-regview regview.c)
2020
add_executable(freenect-hiview hiview.c)
2121
add_executable(freenect-chunkview chunkview.c)
22-
23-
if(BUILD_AUDIO)
24-
add_executable(freenect-wavrecord wavrecord.c)
25-
add_executable(freenect-micview micview.c)
26-
endif()
22+
add_executable(freenect-wavrecord wavrecord.c)
23+
add_executable(freenect-micview micview.c)
2724

2825
if (BUILD_C_SYNC)
2926
add_executable(freenect-glpclview glpclview.c)
@@ -44,10 +41,8 @@ if(APPLE)
4441
target_link_libraries(freenect-regview freenect)
4542
target_link_libraries(freenect-hiview freenect)
4643
target_link_libraries(freenect-chunkview freenect)
47-
if (BUILD_AUDIO)
48-
target_link_libraries(freenect-wavrecord freenect)
49-
target_link_libraries(freenect-micview freenect)
50-
endif()
44+
target_link_libraries(freenect-wavrecord freenect)
45+
target_link_libraries(freenect-micview freenect)
5146
if (BUILD_C_SYNC)
5247
target_link_libraries(freenect-glpclview freenect_sync)
5348
target_link_libraries(freenect-tiltdemo freenect_sync)
@@ -66,10 +61,8 @@ else()
6661
target_link_libraries(freenect-regview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
6762
target_link_libraries(freenect-hiview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
6863
target_link_libraries(freenect-chunkview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
69-
if (BUILD_AUDIO)
70-
target_link_libraries(freenect-wavrecord freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
71-
target_link_libraries(freenect-micview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
72-
endif()
64+
target_link_libraries(freenect-wavrecord freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
65+
target_link_libraries(freenect-micview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
7366
if (BUILD_C_SYNC)
7467
target_link_libraries(freenect-glpclview freenect_sync ${OPENGL_LIBRARIES} ${GLUT_LIBRARY}
7568
${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
@@ -78,15 +71,10 @@ else()
7871
endif()
7972
endif()
8073

81-
install (TARGETS freenect-glview freenect-regview freenect-hiview freenect-chunkview
74+
install (TARGETS freenect-glview freenect-regview freenect-hiview freenect-chunkview freenect-wavrecord freenect-micview
8275
DESTINATION bin)
8376

8477
if (BUILD_C_SYNC)
8578
install (TARGETS freenect-glpclview freenect-tiltdemo
8679
DESTINATION bin)
8780
endif()
88-
89-
if (BUILD_AUDIO)
90-
install (TARGETS freenect-wavrecord DESTINATION bin)
91-
install (TARGETS freenect-micview DESTINATION bin)
92-
endif()

src/CMakeLists.txt

+14-19
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@ IF(WIN32)
1010
set_source_files_properties(${SRC} PROPERTIES LANGUAGE CXX)
1111
ENDIF(WIN32)
1212

13-
IF(BUILD_AUDIO)
14-
include(FindPythonInterp)
15-
LIST(APPEND SRC audio.c loader.c)
16-
IF(BUILD_REDIST_PACKAGE)
17-
# If this build is intended for a redistributable package, we can't include audios.bin, so we should include fwfetcher.py
18-
# and the package should run "python fwfetcher.py $INSTALL_PREFIX/share" as a postinst hook
19-
install (FILES "fwfetcher.py" DESTINATION "${CMAKE_INSTALL_PREFIX}/share")
20-
ELSE(BUILD_REDIST_PACKAGE)
21-
# If the install is local only, we can just run fwfetcher.py and install the audios.bin firmware to the system folder
22-
add_custom_target(firmware ALL
23-
COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/fwfetcher.py" "../audios.bin"
24-
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/fwfetcher.py")
25-
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/../audios.bin" DESTINATION "${CMAKE_INSTALL_PREFIX}/share/libfreenect")
26-
ENDIF()
13+
# Audio
14+
include(FindPythonInterp)
15+
LIST(APPEND SRC audio.c loader.c)
16+
IF(BUILD_REDIST_PACKAGE)
17+
# If this build is intended for a redistributable package, we can't include audios.bin, so we should include fwfetcher.py
18+
# and the package should run "python fwfetcher.py $INSTALL_PREFIX/share" as a postinst hook
19+
install (FILES "fwfetcher.py" DESTINATION "${CMAKE_INSTALL_PREFIX}/share")
20+
ELSE(BUILD_REDIST_PACKAGE)
21+
# If the install is local only, we can just run fwfetcher.py and install the audios.bin firmware to the system folder
22+
add_custom_target(firmware ALL
23+
COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/fwfetcher.py" "../audios.bin"
24+
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/fwfetcher.py")
25+
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/../audios.bin" DESTINATION "${CMAKE_INSTALL_PREFIX}/share/libfreenect")
2726
ENDIF()
2827

2928
add_library (freenect SHARED ${SRC})
@@ -45,12 +44,8 @@ target_link_libraries (freenect ${LIBUSB_1_LIBRARIES})
4544
target_link_libraries (freenectstatic ${LIBUSB_1_LIBRARIES})
4645

4746
# Install the header files
48-
install (FILES "../include/libfreenect.h" "../include/libfreenect_registration.h"
47+
install (FILES "../include/libfreenect.h" "../include/libfreenect_registration.h" "../include/libfreenect_audio.h"
4948
DESTINATION ${PROJECT_INCLUDE_INSTALL_DIR})
50-
if(BUILD_AUDIO)
51-
install (FILES "../include/libfreenect_audio.h"
52-
DESTINATION ${PROJECT_INCLUDE_INSTALL_DIR})
53-
endif()
5449

5550
IF(UNIX AND NOT APPLE)
5651
# Produce a pkg-config file for linking against the shared lib

src/audio.c

-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <string.h>
3131
#include <stdlib.h>
3232

33-
#ifdef BUILD_AUDIO
3433

3534
static void prepare_iso_out_data(freenect_device* dev, uint8_t* buffer) {
3635
audio_stream* stream = &dev->audio;
@@ -239,5 +238,3 @@ int freenect_stop_audio(freenect_device* dev) {
239238

240239
return ret;
241240
}
242-
243-
#endif

src/core.c

+9-21
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@
3434
#include "freenect_internal.h"
3535
#include "registration.h"
3636
#include "cameras.h"
37-
#ifdef BUILD_AUDIO
3837
#include "loader.h"
39-
#endif
38+
4039

4140
FREENECTAPI int freenect_init(freenect_context **ctx, freenect_usb_context *usb_ctx)
4241
{
@@ -49,11 +48,7 @@ FREENECTAPI int freenect_init(freenect_context **ctx, freenect_usb_context *usb_
4948
memset(*ctx, 0, sizeof(freenect_context));
5049

5150
(*ctx)->log_level = LL_WARNING;
52-
(*ctx)->enabled_subdevices = (freenect_device_flags)(FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA
53-
#ifdef BUILD_AUDIO
54-
| FREENECT_DEVICE_AUDIO
55-
#endif
56-
);
51+
(*ctx)->enabled_subdevices = (freenect_device_flags)(FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA | FREENECT_DEVICE_AUDIO);
5752
res = fnusb_init(&(*ctx)->usb, usb_ctx);
5853
if (res < 0) {
5954
free(*ctx);
@@ -94,13 +89,11 @@ FREENECTAPI int freenect_process_events_timeout(freenect_context *ctx, struct ti
9489
freenect_stop_video(dev);
9590
freenect_stop_depth(dev);
9691
}
97-
#ifdef BUILD_AUDIO
9892
if (dev->usb_audio.device_dead) {
9993
FN_ERROR("USB audio marked dead, stopping streams\n");
10094
res = -1; // Or something else to tell the user that the device just vanished.
10195
freenect_stop_audio(dev);
10296
}
103-
#endif
10497
dev = dev->next;
10598
}
10699
return res;
@@ -132,23 +125,18 @@ FREENECTAPI void freenect_free_device_attributes(struct freenect_device_attribut
132125
return;
133126
}
134127

135-
FREENECTAPI int freenect_supported_subdevices(void) {
136-
#ifdef BUILD_AUDIO
128+
FREENECTAPI int freenect_supported_subdevices(void)
129+
{
137130
return FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA | FREENECT_DEVICE_AUDIO;
138-
#else
139-
return FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA;
140-
#endif
141131
}
142132

143-
FREENECTAPI void freenect_select_subdevices(freenect_context *ctx, freenect_device_flags subdevs) {
144-
ctx->enabled_subdevices = (freenect_device_flags)(subdevs & (FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA
145-
#ifdef BUILD_AUDIO
146-
| FREENECT_DEVICE_AUDIO
147-
#endif
148-
));
133+
FREENECTAPI void freenect_select_subdevices(freenect_context *ctx, freenect_device_flags subdevs)
134+
{
135+
ctx->enabled_subdevices = (freenect_device_flags)(subdevs & (FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA | FREENECT_DEVICE_AUDIO));
149136
}
150137

151-
FREENECTAPI freenect_device_flags freenect_enabled_subdevices(freenect_context *ctx) {
138+
FREENECTAPI freenect_device_flags freenect_enabled_subdevices(freenect_context *ctx)
139+
{
152140
return ctx->enabled_subdevices;
153141
}
154142

src/freenect_internal.h

+2-9
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@
2929

3030
#include "libfreenect.h"
3131
#include "libfreenect_registration.h"
32-
33-
#ifdef BUILD_AUDIO
34-
#include "libfreenect_audio.h"
35-
#endif
32+
#include "libfreenect_audio.h"
3633

3734
#ifdef __ELF__
3835
#define FN_INTERNAL __attribute__ ((visibility ("hidden")))
@@ -174,7 +171,6 @@ typedef struct {
174171
void *proc_buf;
175172
} packet_stream;
176173

177-
#ifdef BUILD_AUDIO
178174
typedef struct {
179175
int running;
180176

@@ -214,8 +210,6 @@ typedef struct {
214210
freenect_sample_51 samples[6]; // Audio samples - 6 samples per transfer
215211
} audio_out_block;
216212

217-
#endif
218-
219213
struct _freenect_device {
220214
freenect_context *parent;
221215
freenect_device *next;
@@ -244,7 +238,6 @@ struct _freenect_device {
244238
// Registration
245239
freenect_registration registration;
246240

247-
#ifdef BUILD_AUDIO
248241
// Audio
249242
fnusb_dev usb_audio;
250243
fnusb_isoc_stream audio_out_isoc;
@@ -255,7 +248,7 @@ struct _freenect_device {
255248

256249
audio_stream audio;
257250
uint32_t audio_tag;
258-
#endif
251+
259252
// Motor
260253
fnusb_dev usb_motor;
261254
freenect_raw_tilt_state raw_state;

src/loader.c

-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <stdio.h>
3333
#include <stdlib.h>
3434

35-
#ifdef BUILD_AUDIO
3635

3736
static void dump_bl_cmd(freenect_context* ctx, bootloader_command cmd) {
3837
int i;
@@ -418,6 +417,3 @@ FN_INTERNAL int upload_cemd_data(fnusb_dev* dev) {
418417
FN_INFO("CEMD data uploaded successfully.\n");
419418
return 0;
420419
}
421-
422-
#endif
423-

0 commit comments

Comments
 (0)