summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2011-05-20 19:07:41 +0200
committerGravatar waker <wakeroid@gmail.com>2011-05-20 19:07:41 +0200
commitdd7349a00b84b73058b84cb3fc6cfc77d5a9090f (patch)
tree4eb498d4ddc4866566d1a6cda5be0568bd5efb9a
parent0f32609233bf3952221e583367291f0b6ba11c39 (diff)
sndfile: added new metadata field for libsndfile format;
fixed playback of all format where sf_read_raw is unsuitable
-rw-r--r--plugins/sndfile/sndfile.c103
1 files changed, 90 insertions, 13 deletions
diff --git a/plugins/sndfile/sndfile.c b/plugins/sndfile/sndfile.c
index a84486fb..ba4e6993 100644
--- a/plugins/sndfile/sndfile.c
+++ b/plugins/sndfile/sndfile.c
@@ -43,6 +43,7 @@ typedef struct {
int currentsample;
int bitrate;
int sf_format;
+ int read_as_short;
} sndfile_info_t;
// vfs wrapper for sf
@@ -189,14 +190,11 @@ sndfile_init (DB_fileinfo_t *_info, DB_playItem_t *it) {
case SF_FORMAT_PCM_32:
_info->fmt.bps = 32;
break;
- case SF_FORMAT_DOUBLE:
- fprintf (stderr, "[sndfile] 64 bit float input format is not supported (yet)\n");
- return -1;
-// _info->fmt.bps = 64;
- break;
default:
+ info->read_as_short = 1;
+ _info->fmt.bps = 16;
fprintf (stderr, "[sndfile] unidentified input format: 0x%X\n", inf.format&0x000f);
- return -1;
+ break;
}
_info->fmt.channels = inf.channels;
@@ -266,15 +264,20 @@ sndfile_read (DB_fileinfo_t *_info, char *bytes, int size) {
}
int n = 0;
- n = sf_read_raw (info->ctx, (short *)bytes, size);
+ if (info->read_as_short) {
+ n = sf_read_short(info->ctx, (short *)bytes, size/samplesize);
+ }
+ else {
+ n = sf_read_raw (info->ctx, (short *)bytes, size);
- if (info->sf_format == SF_FORMAT_PCM_U8) {
- for (int i = 0; i < n; i++) {
- int sample = ((uint8_t *)bytes)[i];
- ((int8_t *)bytes)[i] = sample-0x80;
+ if (info->sf_format == SF_FORMAT_PCM_U8) {
+ for (int i = 0; i < n; i++) {
+ int sample = ((uint8_t *)bytes)[i];
+ ((int8_t *)bytes)[i] = sample-0x80;
+ }
}
+ n /= samplesize;
}
- n /= samplesize;
info->currentsample += n;
@@ -354,7 +357,12 @@ sndfile_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname) {
break;
}
- snprintf (s, sizeof (s), "%d", bps);
+ if (bps == -1) {
+ snprintf (s, sizeof (s), "unknown");
+ }
+ else {
+ snprintf (s, sizeof (s), "%d", bps);
+ }
deadbeef->pl_add_meta (it, ":BPS", s);
snprintf (s, sizeof (s), "%d", inf.channels);
deadbeef->pl_add_meta (it, ":CHANNELS", s);
@@ -364,6 +372,75 @@ sndfile_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname) {
snprintf (s, sizeof (s), "%d", br);
deadbeef->pl_add_meta (it, ":BITRATE", s);
+ // sndfile subformats
+ const char *subformats[] = {
+ "",
+ "PCM_S8",
+ "PCM_16",
+ "PCM_24",
+ "PCM_32",
+ "PCM_U8",
+ "FLOAT",
+ "DOUBLE",
+ "",
+ "",
+ "ULAW",
+ "ALAW",
+ "IMA_ADPCM",
+ "MS_ADPCM",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "GSM610",
+ "VOX_ADPCM",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "G721_32",
+ "G723_24",
+ "G723_40",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "DWVW_12",
+ "DWVW_16",
+ "DWVW_24",
+ "DWVW_N",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "DPCM_8",
+ "DPCM_16",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "VORBIS",
+ };
+
+ if (inf.format&0x000f <= SF_FORMAT_VORBIS) {
+ deadbeef->pl_add_meta (it, "SF_FORMAT", subformats[inf.format&0x000f]);
+ }
DB_playItem_t *cue_after = deadbeef->plt_insert_cue (plt, after, it, totalsamples, samplerate);
if (cue_after) {