steel support

This commit is contained in:
Neale Pickett 2013-04-12 11:18:58 -06:00
parent 96957e8305
commit dcaa85e4bb
3 changed files with 76 additions and 102 deletions

View File

@ -6,4 +6,8 @@ hdjd: LDFLAGS += $(shell pkg-config --libs libusb-1.0)
aac123: CFLAGS += $(shell pkg-config --cflags alsa) aac123: CFLAGS += $(shell pkg-config --cflags alsa)
aac123: LDLIBS += $(shell pkg-config --libs alsa) aac123: LDLIBS += $(shell pkg-config --libs alsa)
aac123: LDLIBS += -lfaad -lmp4ff aac123: LDLIBS += -lfaad -lmp4v2
aactest: CFLAGS += $(shell pkg-config --cflags alsa)
aactest: LDLIBS += $(shell pkg-config --libs alsa)
aactest: LDLIBS += -lfaad -lmp4v2

View File

@ -3,7 +3,7 @@
#include <alsa/asoundlib.h> #include <alsa/asoundlib.h>
#include <neaacdec.h> #include <neaacdec.h>
#include <mp4ff.h> #include <mp4v2/mp4v2.h>
/* Some things I use for debugging */ /* Some things I use for debugging */
#ifdef NODUMP #ifdef NODUMP
@ -19,40 +19,35 @@
#define DUMP_p(v) DUMPf("%s = %p", #v, v) #define DUMP_p(v) DUMPf("%s = %p", #v, v)
uint32_t
read_callback(void *user_data, void *buffer, uint32_t length)
{
return fread(buffer, 1, length, (FILE*)user_data);
}
uint32_t
seek_callback(void *user_data, uint64_t position)
{
return fseek((FILE*)user_data, position, SEEK_SET);
}
static int static int
GetAACTrack(mp4ff_t *infile) GetAACTrack(MP4FileHandle *infile)
{ {
/* find AAC track */ /* find AAC track */
int i, rc; int rc;
int numTracks = mp4ff_total_tracks(infile); MP4TrackId numTracks = MP4GetNumberOfTracks(infile, NULL, 0);
MP4TrackId i;
for (i = 0; i < numTracks; i++) for (i = 1; i <= numTracks; i++)
{ {
unsigned char *buff = NULL; uint8_t obj_type;
int buff_size = 0; const char *track_type = MP4GetTrackType(infile, i);
mp4AudioSpecificConfig mp4ASC;
mp4ff_get_decoder_config(infile, i, &buff, &buff_size); if (! track_type) continue;
if (buff) if (!MP4_IS_AUDIO_TRACK_TYPE(track_type)) continue;
{
rc = NeAACDecAudioSpecificConfig(buff, buff_size, &mp4ASC);
free(buff);
if (rc < 0) /* MP4GetTrackAudioType */
obj_type = MP4GetTrackEsdsObjectTypeId(infile, i);
if (obj_type == MP4_INVALID_AUDIO_TYPE)
continue; continue;
if (obj_type == MP4_MPEG4_AUDIO_TYPE) {
obj_type = MP4GetTrackAudioMpeg4Type(infile, i);
if (MP4_IS_MPEG4_AAC_AUDIO_TYPE(obj_type))
return i;
} else {
if (MP4_IS_AAC_AUDIO_TYPE(obj_type))
return i; return i;
} }
} }
@ -62,13 +57,12 @@ GetAACTrack(mp4ff_t *infile)
} }
int int
play_file(snd_pcm_t *snd, FILE *f) play_file(snd_pcm_t *snd, char *fn)
{ {
int track; int track;
mp4ff_t *infile; MP4FileHandle infile;
mp4ff_callback_t mp4cb;
NeAACDecHandle hDecoder; NeAACDecHandle hDecoder;
NeAACDecConfigurationPtr config; NeAACDecConfigurationPtr config;
@ -82,11 +76,7 @@ play_file(snd_pcm_t *snd, FILE *f)
long sampleId, numSamples; long sampleId, numSamples;
void *sample_buffer; void *sample_buffer;
mp4cb.read = read_callback; infile = MP4Read(fn);
mp4cb.seek = seek_callback;
mp4cb.user_data = f;
infile = mp4ff_open_read(&mp4cb);
if (! infile) { if (! infile) {
fprintf(stderr, "Unable to open stream\n"); fprintf(stderr, "Unable to open stream\n");
return 1; return 1;
@ -100,11 +90,13 @@ play_file(snd_pcm_t *snd, FILE *f)
hDecoder = NeAACDecOpen(); hDecoder = NeAACDecOpen();
config = NeAACDecGetCurrentConfiguration(hDecoder); config = NeAACDecGetCurrentConfiguration(hDecoder);
config->outputFormat = FAAD_FMT_16BIT; config->outputFormat = FAAD_FMT_16BIT;
config->downMatrix = 1;
config->defObjectType = LC;
NeAACDecSetConfiguration(hDecoder, config); NeAACDecSetConfiguration(hDecoder, config);
buffer = NULL; buffer = NULL;
buffer_size = 0; buffer_size = 0;
mp4ff_get_decoder_config(infile, track, &buffer, &buffer_size); MP4GetTrackESConfiguration(infile, track, &buffer, &buffer_size);
if (NeAACDecInit2(hDecoder, buffer, buffer_size, &samplerate, &channels) < 0) { if (NeAACDecInit2(hDecoder, buffer, buffer_size, &samplerate, &channels) < 0) {
fprintf(stderr, "Initializing decoder\n"); fprintf(stderr, "Initializing decoder\n");
@ -125,9 +117,12 @@ play_file(snd_pcm_t *snd, FILE *f)
free(buffer); free(buffer);
} }
numSamples = mp4ff_num_samples(infile, track); DUMP_d(MP4GetTrackMaxSampleSize(infile, track));
for (sampleId = 0; sampleId < numSamples; sampleId++) { numSamples = MP4GetTrackNumberOfSamples(infile, track);
DUMP_d(numSamples);
for (sampleId = 1; sampleId <= numSamples; sampleId++) {
int rc; int rc;
long dur; long dur;
unsigned int sample_count; unsigned int sample_count;
@ -137,8 +132,7 @@ play_file(snd_pcm_t *snd, FILE *f)
buffer = NULL; buffer = NULL;
buffer_size = 0; buffer_size = 0;
dur = mp4ff_get_sample_duration(infile, track, sampleId); rc = MP4ReadSample(infile, track, sampleId, &buffer, &buffer_size, NULL, NULL, NULL, NULL);
rc = mp4ff_read_sample(infile, track, sampleId, &buffer, &buffer_size);
if (rc == 0) { if (rc == 0) {
fprintf(stderr, "Read failed\n"); fprintf(stderr, "Read failed\n");
return 1; return 1;
@ -164,28 +158,12 @@ main(int argc, char *argv[])
return 1; return 1;
} }
if (argc == 1) {
return play_file(snd, stdin);
}
for (i = 1; i < argc; i += 1) { for (i = 1; i < argc; i += 1) {
char *fn = argv[i]; char *fn = argv[i];
FILE *f = fopen(fn, "r");
if ((fn[0] == '-') && (fn[1] == 0)) {
f = stdin;
fn = "[stdin]";
}
if (! f) {
fprintf(stderr, "Opening %s: %m\n", fn);
continue;
}
printf("%s\n", fn); printf("%s\n", fn);
play_file(snd, f); play_file(snd, fn);
fclose(f);
} }
return 0; return 0;

28
hdjd.c
View File

@ -17,6 +17,10 @@
#define DUMP_c(v) DUMPf("%s = '%c' (0x%02x)", #v, v, v) #define DUMP_c(v) DUMPf("%s = '%c' (0x%02x)", #v, v, v)
#define DUMP_p(v) DUMPf("%s = %p", #v, v) #define DUMP_p(v) DUMPf("%s = %p", #v, v)
// Steel: 0xb102, 0x83, 0x03
// MP3e2: 0x0b105, 0x82,
// 4set: 0xb10c, 0x84, 0x02
int int
main(int argc, char **argv) main(int argc, char **argv)
@ -28,28 +32,18 @@ main(int argc, char **argv)
return 69; return 69;
} }
handle = libusb_open_device_with_vid_pid(NULL, 0x06f8, 0xb105); // MP3e2 handle = libusb_open_device_with_vid_pid(NULL, 0x06f8, 0xb102);
if (!handle) { if (!handle) {
printf("Couldn't find an MP3e2\n"); printf("Couldn't find a controller\n");
return 69; return 69;
} }
/* Make Deck A cue button flash. */
{
int transferred;
uint8_t cmd[] = { 0x90, 0x3e, 0x7f };
libusb_bulk_transfer(handle, 0x03, cmd, 3, &transferred, 0);
}
while (1) { while (1) {
uint8_t data[80]; uint8_t data[80];
int transferred; int transferred;
int i; int i;
if ((ret = libusb_bulk_transfer(handle, 0x82, if ((ret = libusb_bulk_transfer(handle, 0x83, data, sizeof data, &transferred, 0))) {
data, sizeof data,
&transferred, 0))) {
break; break;
} }
@ -58,13 +52,11 @@ main(int argc, char **argv)
} }
printf("\n"); printf("\n");
/* Cram it right back out */ // Cram it back out, to turn that light on
if ((ret = libusb_bulk_transfer(handle, 0x04, data, transferred, &transferred, 0))) {
if ((ret = libusb_bulk_transfer(handle, 0x03,
data, transferred,
&transferred, 0))) {
break; break;
} }
} }
if (ret < 0) { if (ret < 0) {