1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
/* ambix_test - test ambix -*- c -*-
Copyright © 2012 IOhannes m zmölnig <zmoelnig@iem.at>.
Institute of Electronic Music and Acoustics (IEM),
University of Music and Dramatic Arts, Graz
This file is part of libambix
libambix is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
libambix is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */
#include "ambix/ambix.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void print_usage(const char*name);
void print_version(const char*name);
void createfile_basic(const char*path, uint32_t ambichannels, uint32_t extrachannels, uint64_t frames) {
ambix_info_t info;
ambix_t*ambix;
extrachannels=0;
memset(&info, 0, sizeof(info));
info.frames=frames;
info.samplerate=44100;
info.sampleformat=AMBIX_SAMPLEFORMAT_FLOAT32;
info.fileformat=AMBIX_BASIC;
info.ambichannels=ambichannels;
info.extrachannels=extrachannels;
printf("Open file '%s': ", path);
ambix=ambix_open(path, AMBIX_WRITE, &info);
if(!ambix) {
printf("failed\n");
return;
} else
printf("OK\n");
printf("Frames\t: %d\n", (int)info.frames);
printf("Samplerate\t: %f\n", info.samplerate);
printf("Sampleformat\t: %d (", info.sampleformat);
switch(info.sampleformat) {
case(AMBIX_SAMPLEFORMAT_NONE): printf("NONE"); break;
case(AMBIX_SAMPLEFORMAT_PCM16): printf("PCM16"); break;
case(AMBIX_SAMPLEFORMAT_PCM24): printf("PCM24"); break;
case(AMBIX_SAMPLEFORMAT_PCM32): printf("PCM32"); break;
case(AMBIX_SAMPLEFORMAT_FLOAT32): printf("FLOAT32"); break;
default: printf("**unknown**");
}
printf(")\n");
printf("ambiXformat\t: %d (", info.fileformat);
switch(info.fileformat) {
case(AMBIX_NONE): printf("NONE"); break;
case(AMBIX_BASIC): printf("BASIC"); break;
case(AMBIX_EXTENDED): printf("EXTENDED"); break;
default: printf("**unknown** 0x%04X", info.fileformat);
}
printf(")\n");
printf("Ambisonics channels\t: %d\n", info.ambichannels);
printf("Non-Ambisonics channels\t: %d\n", info.extrachannels);
/* now write some data... */
do {
uint64_t res;
float32_t*ambidata =(float32_t*)malloc(sizeof(float32_t)*64*ambichannels);
float32_t*otherdata=(float32_t*)malloc(sizeof(float32_t)*64*extrachannels);
while(frames>64) {
res=ambix_writef_float32(ambix, ambidata, otherdata, 64);
frames-=res;
}
if(frames>0)
res=ambix_writef_float32(ambix, ambidata, otherdata, frames);
free(ambidata);ambidata=NULL;
free(otherdata);otherdata=NULL;
} while(0);
printf("Close file '%s': ", path);
if(AMBIX_ERR_SUCCESS!=ambix_close(ambix))
printf("failed\n");
else
printf("OK\n");
}
void createfile_extended(const char*path, uint32_t ambichannels, uint32_t extrachannels, uint64_t frames) {
ambix_info_t info;
ambix_t*ambix;
ambix_matrix_t adaptmatrix;
ambix_err_t err;
memset(&info, 0, sizeof(info));
info.frames=frames;
info.samplerate=44100;
info.sampleformat=AMBIX_SAMPLEFORMAT_FLOAT32;
info.fileformat=AMBIX_EXTENDED;
info.ambichannels=ambichannels;
info.extrachannels=extrachannels;
printf("Open file '%s': ", path);
ambix=ambix_open(path, AMBIX_WRITE, &info);
if(!ambix) {
printf("failed\n");
return;
} else
printf("OK\n");
printf("Frames\t: %d\n", (int)info.frames);
printf("Samplerate\t: %f\n", info.samplerate);
printf("Sampleformat\t: %d (", info.sampleformat);
switch(info.sampleformat) {
case(AMBIX_SAMPLEFORMAT_NONE): printf("NONE"); break;
case(AMBIX_SAMPLEFORMAT_PCM16): printf("PCM16"); break;
case(AMBIX_SAMPLEFORMAT_PCM24): printf("PCM24"); break;
case(AMBIX_SAMPLEFORMAT_PCM32): printf("PCM32"); break;
case(AMBIX_SAMPLEFORMAT_FLOAT32): printf("FLOAT32"); break;
default: printf("**unknown**");
}
printf(")\n");
printf("ambiXformat\t: %d (", info.fileformat);
switch(info.fileformat) {
case(AMBIX_NONE): printf("NONE"); break;
case(AMBIX_BASIC): printf("BASIC"); break;
case(AMBIX_EXTENDED): printf("EXTENDED"); break;
default: printf("**unknown** 0x%04X", info.fileformat);
}
printf(")\n");
printf("Ambisonics channels\t: %d\n", info.ambichannels);
printf("Non-Ambisonics channels\t: %d\n", info.extrachannels);
memset(&adaptmatrix, 0, sizeof(adaptmatrix));
ambix_matrix_init(25, ambichannels,&adaptmatrix);
do {
uint32_t r, c, rows=adaptmatrix.rows, cols=adaptmatrix.cols;
float32_t**data=adaptmatrix.data;
for(r=0; r<rows; r++) {
for(c=0; c<cols; c++) {
data[r][c]=(float32_t)r+((float32_t)c)/25.f;
}
}
} while(0);
err=ambix_set_adaptormatrix(ambix, &adaptmatrix);
if(err!=AMBIX_ERR_SUCCESS) {
printf("failed setting adaptor matrix\n");
}
/* no write some data... */
printf("Writing %d frames\n", (int)frames);
do {
const unsigned int blocksize=64;
uint64_t res;
float32_t*ambidata=(float32_t*)malloc(sizeof(float32_t)*blocksize*ambichannels);
float32_t*otherdata=(float32_t*)malloc(sizeof(float32_t)*blocksize*extrachannels);
while(frames>blocksize) {
res=ambix_writef_float32(ambix, ambidata, otherdata, blocksize);
if(res!=blocksize)
printf("write returned %d!=%d\n", (int)res, blocksize);
frames-=blocksize;
}
if(frames>0) {
res=ambix_writef_float32(ambix, ambidata, otherdata, frames);
if(res!=frames)
printf("write returned %d!=%d\n", (int)res, (int)frames);
}
free(ambidata);ambidata=NULL;
free(otherdata);otherdata=NULL;
} while(0);
printf("Close file '%s': ", path);
if(AMBIX_ERR_SUCCESS!=ambix_close(ambix))
printf("failed\n");
else
printf("OK\n");
ambix_matrix_deinit(&adaptmatrix);
}
int main(int argc, char**argv) {
if(argc>1) {
if((!strcmp(argv[1], "-V")) || (!strcmp(argv[1], "--version")))
print_version(argv[0]);
if((!strcmp(argv[1], "-h")) || (!strcmp(argv[1], "--help")))
print_usage(argv[0]);
createfile_basic(argv[1], 9, 3, 44100);
if(argc>2)
createfile_extended(argv[2], 9, 3, 44100);
}
else {
print_usage(argv[0]);
}
return 0;
}
void print_usage(const char*name) {
printf("\n");
printf("Usage: %s outfile_basic [outfile_extended]\n", name);
printf("Create ambix test-files\n");
printf("(this may be of limited use when not debugging libambix).\n");
printf("\n");
printf("Options:\n");
printf(" -h, --help Print this help\n");
printf(" -V, --version Version information\n");
printf("\n");
#ifdef PACKAGE_BUGREPORT
printf("Report bugs to: %s\n\n", PACKAGE_BUGREPORT);
#endif
#ifdef PACKAGE_URL
printf("Home page: %s\n", PACKAGE_URL);
#endif
exit(1);
}
void print_version(const char*name) {
#ifdef PACKAGE_VERSION
printf("%s %s\n", name, PACKAGE_VERSION);
#endif
printf("\n");
printf("Copyright (C) 2012 Institute of Electronic Music and Acoustics (IEM), University of Music and Dramatic Arts (KUG), Graz, Austria.\n");
printf("\n");
printf("License LGPLv2.1: GNU Lesser GPL version 2.1 or later <http://gnu.org/licenses/lgpl.html>\n");
printf("This is free software: you are free to change and redistribute it.\n");
printf("There is NO WARRANTY, to the extent permitted by law.\n");
printf("\n");
printf("Written by IOhannes m zmoelnig <zmoelnig@iem.at>\n");
exit(1);
}
|