librfn
An ad-hoc utility library
wavheadertest.c
Go to the documentation of this file.
1 /*
2  * wavheadertest.c
3  *
4  * Part of librfn (a general utility library from redfelineninja.org.uk)
5  *
6  * Copyright (C) 2012 Daniel Thompson <daniel@redfelineninja.org.uk>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published
10  * by the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  */
13 
14 #undef NDEBUG
15 
16 #include <assert.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 
21 #include <librfn.h>
22 
23 int main()
24 {
25  rf_wavheader_t in, out;
26  int insz, outsz;
27  char *s;
28  uint8_t header[128];
29 
30  memset(&in, 0, sizeof(in));
31  verify(0 != rf_wavheader_validate(&in));
32 
33  rf_wavheader_init(&in, 44100, 1, RF_WAVHEADER_FLOAT);
34  verify(0 == rf_wavheader_validate(&in));
35 
36  s = rf_wavheader_tostring(&in);
37  //printf("%s\n", s);
38  free(s);
39 
40  insz = rf_wavheader_encode(&in, header, sizeof(header));
41  verify(insz < sizeof(header));
42 
43  outsz = rf_wavheader_decode(header, insz, &out);
44  verify(insz == outsz);
45  verify(0 == memcmp(&in, &out, sizeof(in)));
46 
47  return 0;
48 }
int rf_wavheader_decode(const uint8_t *p, unsigned int sz, rf_wavheader_t *wh)
Definition: wavheader.c:29
char * rf_wavheader_tostring(rf_wavheader_t *wh)
Definition: wavheader.c:211
void rf_wavheader_init(rf_wavheader_t *wh, int sfreq, int num_channels, rf_wavheader_format_t format)
Definition: wavheader.c:154
#define verify(x)
Definition: util.h:55
struct usb_cdc_header_descriptor header
int rf_wavheader_encode(rf_wavheader_t *wh, uint8_t *p, unsigned int sz)
Definition: wavheader.c:90
int main()
Definition: wavheadertest.c:23
int rf_wavheader_validate(rf_wavheader_t *wh)
Definition: wavheader.c:220