LTC-Reader - Compiler Error

Hello Folks,

I’m a almost newbie with arduino and with C/C++.

I want to write a LTC (LinearTimeCode)-Reader, to use it with my 7seg-Displays.

I already found a project by Robin Gareus (the maker of the libltc-Library) here:
http://gareus.org/gitweb/?p=arduino.git;a=tree;f=ltcsmpte
This code has almost the same approach then my project, except the output, as he used other hardware.

Now I was trying to understand what he did, for later on adapting it to my hardware.
For this goal I changed all the outputs to serial.print.

Now my problem is, that I get many Compiler-Errors and I can’t handle these myself, especially as the code is working with the dereference-pointer, which throws me out completely :o
The main problem I see is the errors with converting between formats.
The buffer-resizing could be ok, but I can’t try, as it doens’t compile right…

Arduino: 1.6.12 (Windows 7), Board: “Arduino/Genuino Uno”

C:\Users\video\Produktionen\LTC-Reader\LTC-Reader-Variante2-201611224\ltcsmpte\ltcsmpte.ino:211:0: warning: “BUFSIZ” redefined

#define BUFSIZ 64

^

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:24:0,

from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Stream.h:26,

from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:29,

from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:232,

from sketch\ltcsmpte.ino.cpp:1:

c:\program files (x86)\arduino\hardware\tools\avr\avr\include\stdio.h:948:0: note: this is the location of the previous definition

#define BUFSIZ 1024

^

C:\Users\video\Produktionen\LTC-Reader\LTC-Reader-Variante2-201611224\ltcsmpte\ltcsmpte.ino: In function ‘int process_audio_buffer(unsigned char*, int)’:

ltcsmpte:263: error: cannot convert ‘unsigned char*’ to ‘boolean* {aka bool*}’ in initialization

boolean *bits= buf; //re-use snd buffer

^
C:\Users\video\Produktionen\LTC-Reader\LTC-Reader-Variante2-201611224\ltcsmpte\ltcsmpte.ino:266:44: warning: left shift count >= width of type

if (mode==10) { Serial.print((buf[2]<<16)|(buf[1]<<8)|buf[0]); }

^
ltcsmpte:269: error: cannot convert ‘boolean* {aka bool*}’ to ‘byte* {aka unsigned char*}’ for argument ‘3’ to ‘int biphase_decode(SMPTEDecoder*, boolean*, byte*, int)’

size = biphase_decode(d, code, bits, size);

^
ltcsmpte:292: error: cannot convert ‘boolean* {aka bool*}’ to ‘byte* {aka unsigned char*}’ for argument ‘2’ to ‘int ltc_decode(SMPTEDecoder*, byte*, int)’

return ltc_decode(d, bits, size);

^
exit status 1
cannot convert ‘unsigned char*’ to ‘boolean* {aka bool*}’ in initialization

Here is the part of the code with the converting problems:

int process_audio_buffer(unsigned char *buf, int size) {
  struct SMPTEDecoder *d = &ltcdec;
  boolean code[BUFSIZ]; 
  boolean *bits=  buf; //re-use snd buffer
  size = audio_to_biphase(d, buf, code, size);
#ifdef DEBUG
 if (mode==10)     { Serial.print((buf[2]<<16)|(buf[1]<<8)|buf[0]); }
 else if (mode==7) { Serial.print(size); Serial.print(1,'S'); }
#endif
  size = biphase_decode(d, code, bits, size);

You find the complete code as attachment.

I will be thankfull for every hint, as I couldn’t get further until now by myself.

Greetings,

Wolfgang

ltcsmpte.ino (11.8 KB)

Well, this one is pretty simple:

C:\Users\video\Produktionen\LTC-Reader\LTC-Reader-Variante2-201611224\ltcsmpte\ltcsmpte.ino:211:0: warning: “BUFSIZ” redefined

#define BUFSIZ 64

^

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:24:0,

from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Stream.h:26,

from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:29,

from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:232,

from sketch\ltcsmpte.ino.cpp:1:

c:\program files (x86)\arduino\hardware\tools\avr\avr\include\stdio.h:948:0: note: this is the location of the previous definition

#define BUFSIZ 1024

^

The code you posted, on line 211, has:

#define BUFSIZ 64

The solution is simple. Do NOT try to reuse a common name. Make up your own.

This one is fairly obvious, too:

C:\Users\video\Produktionen\LTC-Reader\LTC-Reader-Variante2-201611224\ltcsmpte\ltcsmpte.ino: In function ‘int process_audio_buffer(unsigned char*, int)’:

ltcsmpte:263: error: cannot convert ‘unsigned char*’ to ‘boolean* {aka bool*}’ in initialization

boolean *bits= buf; //re-use snd buffer

You code has:

int process_audio_buffer(unsigned char *buf, int size) {
  struct SMPTEDecoder *d = &ltcdec;
  boolean code[BUFSIZ]; 
  boolean *bits=  buf; //re-use snd buffer

buf is of a specific type. Any pointer to that memory location should be the same type. bits is not a pointer of the same type that buf points to.

This one is pretty simple, too:

C:\Users\video\Produktionen\LTC-Reader\LTC-Reader-Variante2-201611224\ltcsmpte\ltcsmpte.ino:266:44: warning: left shift count >= width of type

if (mode==10) { Serial.print((buf[2]<<16)|(buf[1]<<8)|buf[0]); }

^

buf is treated as though it is an array of bytes. Shifting the 8 bits in a byte 16 positions will force all the data way out of position. Since the apparent goal is to print a 32 bit value for 3 8 bit values, you need to cast buf[ n] to a 32 bit type, so that a 32 bit register is used to hold the value being shifted, to prevents bits falling off the Arduino.

The rest of the messages refer to similar attempts to move data from one type of variable to another of a different (and not necessarily compatible) type.