Close

how to load audio stream data into LTCreader code

A project log for Arduino TIMECODE smpte LTC reader generator SHIELD

Using libltc to make a SMPTE Time Code Receiver/Generator for Arduino !

ben bilesben biles 10/28/2015 at 03:140 Comments

<EDIT>

OK., go everytihng wrong in this log !!!

I should have just

#defined 'ltc.h'

and called the various void commands ,..,,.

</EDIT>

I think all I need to do to read timecide from input is buffer incoming audio and end the frames to the LTC library. The example code below decodes timecode from an audio file with the manchester encoded timecode. The question is how do I load the data from incoming audio source. I think I can get away with 8bit 16khz or so audio input so maybe I can just do this through the arduino PWM pins !! anyway , heres the example code that loads from file.. any ideas would be great , i'm NOT great at C. I think the audio data from file gets loaded into library in this line.

n = fread(sound, sizeof(ltcsnd_sample_t), BUFFER_SIZE, f);

f being the file data? and somehow its broken into frames ?

// anayway heres the example code..

#include <stdio.h>

#include <math.h>

#include <ltc.h>

#define BUFFER_SIZE (1024)

int main(int argc, char **argv) {

int apv = 1920;

ltcsnd_sample_t sound[BUFFER_SIZE];

size_t n;

long int total;

FILE* f;

char* filename;

LTCDecoder *decoder;

LTCFrameExt frame;

// fIXME

if (argc > 1) {

filename = argv[1];

if (argc > 2) {

sscanf(argv[2], "%i", &apv);

}

} else {

printf("Usage: %s <filename> [audio-frames-per-video-frame]\n", argv[0]);

return -1;

}

f = fopen(filename, "r");

if (!f) {

fprintf(stderr, "error opening '%s'\n", filename);

return -1;

}

fprintf(stderr, "* reading from: %s\n", filename);

total = 0;

decoder = ltc_decoder_create(apv, 32);

do {

n = fread(sound, sizeof(ltcsnd_sample_t), BUFFER_SIZE, f);

ltc_decoder_write(decoder, sound, n, total);

while (ltc_decoder_read(decoder, &frame)) {

SMPTETimecode stime;

ltc_frame_to_time(&stime, &frame.ltc, 1);

printf("%04d-%02d-%02d %s ",

((stime.years < 67) ? 2000+stime.years : 1900+stime.years),

stime.months,

stime.days,

stime.timezone

);

printf("%02d:%02d:%02d%c%02d | %8lld %8lld%s\n",

stime.hours,

stime.mins,

stime.secs,

(frame.ltc.dfbit) ? '.' : ':',

stime.frame,

frame.off_start,

frame.off_end,

frame.reverse ? " R" : ""

);

}

total += n;

} while (n);

fclose(f);

ltc_decoder_free(decoder);

return 0;

}

Discussions