Skip to content

Commit d12b59f

Browse files
[#37] [#38] [#39] DSF: DoP 64/128/256 metadata
1 parent 61fe4d0 commit d12b59f

8 files changed

Lines changed: 395 additions & 350 deletions

File tree

src/CMakeLists.txt

Lines changed: 30 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,38 @@
11
#
2-
# Add files for libpgexporter
2+
# Add files for hrmp
33
#
44
FILE(GLOB SOURCE_FILES "libhrmp/*.c")
55
FILE(GLOB HEADER_FILES "include/*.h")
66

77
set(SOURCES ${SOURCE_FILES} ${HEADER_FILES})
88

9-
#
10-
# OS
11-
#
12-
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
9+
add_compile_options(-DHAVE_LINUX)
10+
add_compile_options(-D_POSIX_C_SOURCE=200809L)
1311

14-
add_compile_options(-DHAVE_LINUX)
15-
add_compile_options(-D_POSIX_C_SOURCE=200809L)
16-
17-
check_include_file("execinfo.h" HAVE_EXECINFO_H)
18-
if (HAVE_EXECINFO_H)
19-
add_compile_options(-DHAVE_EXECINFO_H)
20-
endif()
21-
#
22-
# Include directories
23-
#
24-
include_directories(
25-
${CMAKE_CURRENT_SOURCE_DIR}/include
26-
${LIBASOUND_INCLUDE_DIRS}
27-
${LIBSNDFILE_INCLUDE_DIR}
28-
)
29-
30-
#
31-
# Library directories
32-
#
33-
link_libraries(
34-
${LIBATOMIC_LIBRARY}
35-
${LIBASOUND_LIBRARIES}
36-
${LIBSNDFILE_LIBRARY}
37-
)
38-
39-
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
12+
check_include_file("execinfo.h" HAVE_EXECINFO_H)
13+
if (HAVE_EXECINFO_H)
14+
add_compile_options(-DHAVE_EXECINFO_H)
15+
endif()
4016

41-
else()
17+
#
18+
# Include directories
19+
#
20+
include_directories(
21+
${CMAKE_CURRENT_SOURCE_DIR}/include
22+
${LIBASOUND_INCLUDE_DIRS}
23+
${LIBSNDFILE_INCLUDE_DIR}
24+
)
4225

43-
add_compile_options(-D_XOPEN_SOURCE=700)
44-
add_compile_options(-D_BSD_SOURCE)
45-
add_compile_options(-D_DEFAULT_SOURCE)
46-
add_compile_options(-D__BSD_VISIBLE)
47-
48-
#
49-
# Include directories
50-
#
51-
include_directories(
52-
${CMAKE_CURRENT_SOURCE_DIR}/include
53-
${LIBASOUND_INCLUDE_DIRS}
54-
${LIBSNDFILE_INCLUDE_DIR}
55-
)
56-
57-
#
58-
# Library directories
59-
#
60-
link_libraries(
61-
${LIBASOUND_LIBRARIES}
62-
${LIBSNDFILE_LIBRARY}
63-
)
64-
65-
if (${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
66-
add_compile_options(-DHAVE_OPENBSD)
67-
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
68-
add_compile_options(-DHAVE_FREEBSD)
69-
endif()
26+
#
27+
# Library directories
28+
#
29+
link_libraries(
30+
${LIBATOMIC_LIBRARY}
31+
${LIBASOUND_LIBRARIES}
32+
${LIBSNDFILE_LIBRARY}
33+
)
7034

71-
endif()
35+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
7236

7337
#
7438
# Compile options
@@ -92,12 +56,10 @@ if (CMAKE_BUILD_TYPE MATCHES Debug)
9256
add_compile_options(-DDEBUG)
9357

9458
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
95-
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
96-
add_compile_options(-fsanitize=address)
59+
add_compile_options(-fsanitize=address)
9760

98-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS_DEBUG} -fsanitize=address")
99-
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address")
100-
endif()
61+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS_DEBUG} -fsanitize=address")
62+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address")
10163
endif()
10264

10365
check_c_compiler_flag(-fno-omit-frame-pointer HAS_NO_OMIT_FRAME_POINTER)
@@ -141,12 +103,11 @@ endif()
141103
check_c_compiler_flag(-fPIC HAS_PIC)
142104
if (HAS_PIC)
143105
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
106+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_C_FLAGS} -fPIC")
144107
endif()
145108

146-
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
147-
include(CheckPIESupported)
148-
check_pie_supported()
149-
endif()
109+
include(CheckPIESupported)
110+
check_pie_supported()
150111

151112
check_c_compiler_flag(-Wl,-z,relro HAS_RELRO)
152113
if (HAS_RELRO)

src/include/files.h

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ extern "C" {
4545
#define TYPE_WAV 1
4646
#define TYPE_FLAC 2
4747
#define TYPE_MP3 3
48+
#define TYPE_DSF 4
49+
50+
#define FORMAT_UNKNOWN 0
51+
#define FORMAT_16 1
52+
#define FORMAT_24 2
53+
#define FORMAT_32 3
54+
#define FORMAT_1 4
4855

4956
/** @struct file_metadata
5057
* Defines a file metadata
@@ -53,7 +60,7 @@ struct file_metadata
5360
{
5461
int type; /**< The type of file */
5562
char name[MAX_PATH]; /**< The name of the file */
56-
int format; /**< The format */
63+
int format; /**< The format of the file */
5764
size_t file_size; /**< The file size */
5865
unsigned int sample_rate; /**< The sample rate */
5966
unsigned int channels; /**< The number of channels */
@@ -62,31 +69,15 @@ struct file_metadata
6269
double duration; /**< The number of seconds */
6370
};
6471

65-
/**
66-
* Is the file supported
67-
* @param f The file
68-
* @return The result type
69-
*/
70-
int
71-
hrmp_is_file_supported(char* f);
72-
7372
/**
7473
* Get the file metadata
74+
* @param device The device
7575
* @param f The file
7676
* @param fm The file metadata
77-
* @return The result
77+
* @return The result or NULL if not supported
7878
*/
7979
int
80-
hrmp_file_metadata(char* f, struct file_metadata** fm);
81-
82-
/**
83-
* Is the file metadata supported
84-
* @param device The device
85-
* @param fm The file metadata
86-
* @return The result
87-
*/
88-
bool
89-
hrmp_is_file_metadata_supported(int device, struct file_metadata* fm);
80+
hrmp_file_metadata(int device, char* f, struct file_metadata** fm);
9081

9182
/**
9283
* Print the file metadata

src/include/utils.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#ifndef HRMP_UTILS_H
3232
#define HRMP_UTILS_H
3333

34+
#include <stdint.h>
3435
#ifdef __cplusplus
3536
extern "C" {
3637
#endif
@@ -39,8 +40,25 @@ extern "C" {
3940
#include <deque.h>
4041

4142
#include <stdbool.h>
43+
#include <stdio.h>
4244
#include <stdlib.h>
4345

46+
/**
47+
* Read an unit64_t in little-engine format
48+
* @param f The file
49+
* @return The result
50+
*/
51+
uint64_t
52+
hrmp_read_le_u64(FILE *f);
53+
54+
/**
55+
* Read an unit32_t in little-engine format
56+
* @param f The file
57+
* @return The result
58+
*/
59+
uint32_t
60+
hrmp_read_le_u32(FILE *f);
61+
4462
/**
4563
* Get the home directory of the user
4664
* @return The result

src/libhrmp/alsa.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
/* hrmp */
3232
#include <hrmp.h>
3333
#include <alsa.h>
34+
#include <files.h>
3435
#include <logging.h>
3536

3637
#include <alsa/pcm.h>
@@ -46,24 +47,26 @@ hrmp_alsa_init_handle(char* device, int format, int rate, snd_pcm_t** handle, in
4647
snd_pcm_uframes_t buffer_size = 0;
4748
snd_pcm_uframes_t period_size = 0;
4849
unsigned int r = (unsigned int)rate;
50+
int fmt = 0;
4951

5052
*handle = NULL;
5153

52-
if (format == SND_PCM_FORMAT_S16_LE)
54+
if (format == FORMAT_16)
5355
{
5456
*container = 16;
57+
fmt = SND_PCM_FORMAT_S16_LE;
5558
}
56-
else if (format == SND_PCM_FORMAT_S24_3LE)
59+
else if (format == FORMAT_24)
5760
{
5861
*container = 24;
62+
fmt = SND_PCM_FORMAT_S24_3LE;
5963
}
6064
else
6165
{
62-
format = SND_PCM_FORMAT_S32_LE;
66+
fmt = SND_PCM_FORMAT_S32_LE;
6367
*container = 32;
6468
}
6569

66-
// TODO: flags - SND_PCM_NONBLOCK ?
6770
if ((err = snd_pcm_open(&h, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0)
6871
{
6972
hrmp_log_error("snd_pcm_open %s/%s", device, snd_strerror(err));
@@ -125,13 +128,13 @@ hrmp_alsa_init_handle(char* device, int format, int rate, snd_pcm_t** handle, in
125128
goto error;
126129
}
127130

128-
if ((err = snd_pcm_hw_params_set_format(h, hw_params, format)) < 0)
131+
if ((err = snd_pcm_hw_params_set_format(h, hw_params, fmt)) < 0)
129132
{
130-
if (format == SND_PCM_FORMAT_S24_3LE)
133+
if (fmt == SND_PCM_FORMAT_S24_3LE)
131134
{
132-
format = SND_PCM_FORMAT_S32_LE;
135+
fmt = SND_PCM_FORMAT_S32_LE;
133136
*container = 32;
134-
if ((err = snd_pcm_hw_params_set_format(h, hw_params, format)) < 0)
137+
if ((err = snd_pcm_hw_params_set_format(h, hw_params, fmt)) < 0)
135138
{
136139
hrmp_log_error("snd_pcm_hw_params_set_format %s/%s", device, snd_strerror(err));
137140
goto error;
@@ -169,6 +172,9 @@ hrmp_alsa_init_handle(char* device, int format, int rate, snd_pcm_t** handle, in
169172
snd_pcm_close(h);
170173
}
171174

175+
*handle = NULL;
176+
*container = 0;
177+
172178
return 1;
173179
}
174180

0 commit comments

Comments
 (0)