Use libsndfile for wav file input

This commit is contained in:
balr0g 2013-07-07 15:47:30 -04:00
parent 260ec82ea1
commit e3bafe96e9
4 changed files with 180 additions and 138 deletions

View File

@ -7,7 +7,7 @@ INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}" "${CMAKE_INSTALL_PREFIX}/include")
LINK_DIRECTORIES("${CMAKE_INSTALL_PREFIX}/lib")
ADD_EXECUTABLE(dsd ${SRCS})
TARGET_LINK_LIBRARIES(dsd mbe)
TARGET_LINK_LIBRARIES(dsd mbe sndfile)
install(TARGETS dsd DESTINATION bin)

8
dsd.h
View File

@ -36,7 +36,7 @@
#endif
#include <math.h>
#include <mbelib.h>
#include <sndfile.h>
/*
* global variables
*/
@ -59,8 +59,14 @@ typedef struct
int scoperate;
char audio_in_dev[1024];
int audio_in_fd;
SNDFILE *audio_in_file;
SF_INFO *audio_in_file_info;
int audio_in_type; // 0 for device, 1 for file
char audio_out_dev[1024];
int audio_out_fd;
SNDFILE *audio_out_file;
SF_INFO *audio_out_file_info;
int audio_out_type; // 0 for device, 1 for file
int split;
int playoffset;
char mbe_out_dir[1024];

View File

@ -207,6 +207,21 @@ playSynthesizedVoice (dsd_opts * opts, dsd_state * state)
void
openAudioOutDevice (dsd_opts * opts, int speed)
{
// get info of device/file
struct stat stat_buf;
stat(opts->audio_out_dev, &stat_buf);
if(S_ISREG(stat_buf.st_mode)) { // is this a regular file? then process with libsndfile.
opts->audio_out_type = 1;
opts->audio_out_file_info = calloc(1, sizeof(SF_INFO));
opts->audio_out_file_info->samplerate = 48000;
opts->audio_out_file_info->channels = 1;
opts->audio_out_file_info->format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
opts->audio_out_file = sf_open(opts->audio_out_dev, SFM_READ, opts->audio_out_file_info);
if(opts->audio_out_file == NULL) {
printf ("Error, couldn't open file %s\n", opts->audio_in_dev);
}
}
else { // this is a device, use old handling
#ifdef SOLARIS
sample_info_t aset, aget;
@ -270,14 +285,27 @@ openAudioOutDevice (dsd_opts * opts, int speed)
}
#endif
}
printf ("Audio Out Device: %s\n", opts->audio_out_dev);
}
void
openAudioInDevice (dsd_opts * opts)
{
// get info of device/file
struct stat stat_buf;
stat(opts->audio_in_dev, &stat_buf);
if(S_ISREG(stat_buf.st_mode)) { // is this a regular file? then process with libsndfile.
opts->audio_in_type = 1;
opts->audio_in_file_info = calloc(1, sizeof(SF_INFO));
opts->audio_in_file_info->channels = 1;
opts->audio_in_file = sf_open(opts->audio_in_dev, SFM_READ, opts->audio_in_file_info);
if(opts->audio_in_file == NULL) {
printf ("Error, couldn't open file %s\n", opts->audio_in_dev);
}
}
else { // this is a device, use old handling
opts->audio_in_type = 0;
#ifdef SOLARIS
sample_info_t aset, aget;
int rgain;
@ -357,7 +385,7 @@ openAudioInDevice (dsd_opts * opts)
printf ("ioctl setfmt error \n");
}
#endif
}
if (opts->split == 1)
{
printf ("Audio In Device: %s\n", opts->audio_in_dev);

View File

@ -78,8 +78,16 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync)
}
state->jitter = -1;
}
if(opts->audio_in_type == 0) {
result = read (opts->audio_in_fd, &sample, 2);
}
else {
result = sf_read_short(opts->audio_in_file, &sample, 1);
if(result == 0) {
exit(0);
}
}
// printf("res: %zd\n, offset: %lld", result, sf_seek(opts->audio_in_file, 0, SEEK_CUR));
{
#define NZEROS 60
#define GAIN 7.423339364e+00