| 87 | } |
| 88 | |
| 89 | static int init(struct sr_input *in, const char *filename) |
| 90 | { |
| 91 | struct sr_channel *probe; |
| 92 | struct context *ctx; |
| 93 | char buf[40], probename[15]; |
| 94 | int i; |
| 95 | |
| 96 | if (get_wav_header(filename, buf) != SR_OK) |
| 97 | return SR_ERR; |
| 98 | |
| 99 | if (!(ctx = malloc(sizeof(struct context)))){ |
| 100 | sr_err("%s,ERROR:failed to alloc memory.", __func__); |
| 101 | return SR_ERR_MALLOC; |
| 102 | } |
| 103 | memset(ctx, 0, sizeof(struct context)); |
| 104 | |
| 105 | /* Create a virtual device. */ |
| 106 | in->sdi = sr_dev_inst_new(LOGIC, SR_ST_ACTIVE, NULL, NULL, NULL); |
| 107 | in->sdi->priv = ctx; |
| 108 | |
| 109 | ctx->samplerate = GUINT32_FROM_LE(*(uint32_t *)(buf + 24)); |
| 110 | ctx->samplesize = GUINT16_FROM_LE(*(uint16_t *)(buf + 34)) / 8; |
| 111 | if (ctx->samplesize != 1 && ctx->samplesize != 2 && ctx->samplesize != 4) { |
| 112 | sr_err("only 8, 16 or 32 bits per sample supported."); |
| 113 | return SR_ERR; |
| 114 | } |
| 115 | |
| 116 | if ((ctx->num_channels = GUINT16_FROM_LE(*(uint16_t *)(buf + 22))) > 20) { |
| 117 | sr_err("%d channels seems crazy.", ctx->num_channels); |
| 118 | return SR_ERR; |
| 119 | } |
| 120 | |
| 121 | for (i = 0; i < ctx->num_channels; i++) { |
| 122 | sprintf(probename,"CH%d", i + 1); |
| 123 | if (!(probe = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, probename))) |
| 124 | return SR_ERR; |
| 125 | in->sdi->channels = g_slist_append(in->sdi->channels, probe); |
| 126 | } |
| 127 | |
| 128 | return SR_OK; |
| 129 | } |
| 130 | |
| 131 | static int loadfile(struct sr_input *in, const char *filename) |
| 132 | { |
nothing calls this directly
no test coverage detected