Hi Aurelien, Le Fri, 25 Jul 2014 21:38:11 +0200, Aurelien Jacobs <[email protected]> a écrit :
> On Fri, Jul 25, 2014 at 06:25:16PM +0200, Matthieu CASTET wrote: > > Le Thu, 24 Jul 2014 19:23:53 +0200, > > Bert Vermeulen <[email protected]> a écrit : > > > > > On 07/24/2014 12:01 PM, Matthieu CASTET wrote: > > > > Hi, > > > > > > > > I have something that is working for logic signal, but the analog part > > > > is weird. > > > > > > Excellent! Do you have some code we can look at, on github or some place? > > > > > I attached the current version of the code. Code need cleaning. > > I see the code needs some cleaning, but still, I have at least one > important comment: > > > [...] > > + > > + /* goto waveform header */ > > + data += 12; > > + for (i = 0; i < ctx->num_channels; i++) { > > + struct WaveformHeader *whdr = (struct WaveformHeader *)data; > > You can't map raw data from the file to a struct like this for at least > 2 reasons: > - the compiler is free to add some alignment padding between the struct > fields which would prevent them to map to the data you expect > - the data stored in the file may not match the endianness of the host > trying to read it For int I was planning to use GUINTxx_FROM_LE, and expecting g_mapped_file_new return aligned memory. But I forgot to pack the stuct to make sure compiler don't add padding. > > To solve this issue, you should use the RL16() and RL32() macro to read > directly from raw data. (you may need to add a RL64() version of the > macro) > Do you have suggestion how to read float/double in a portable way ? Is RL32/RL64 is enough ? Thanks, Matthieu PS : speaking of alignment problem, there is a candidate in wav format_match [1]. buf is a char and may be not aligned on 16 bits. And "*(uint16_t *)(buf + 20)" will do an unaligned access. [1] static int format_match(const char *filename) { char buf[40]; if (get_wav_header(filename, buf) != SR_OK) return FALSE; if (strncmp(buf, "RIFF", 4)) return FALSE; if (strncmp(buf + 8, "WAVE", 4)) return FALSE; if (strncmp(buf + 12, "fmt ", 4)) return FALSE; if (GUINT16_FROM_LE(*(uint16_t *)(buf + 20)) != 1) /* Not PCM. */ return FALSE; if (strncmp(buf + 36, "data", 4)) return FALSE; return TRUE; } ------------------------------------------------------------------------------ Infragistics Professional Build stunning WinForms apps today! Reboot your WinForms applications with our WinForms controls. Build a bridge from your legacy apps to the future. http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk _______________________________________________ sigrok-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sigrok-devel

