int main (int argc, char **argv) { int filefmt; AFfilehandle file; AFfilesetup setup; int miscids[] = {1, 2}; int result; if (argc < 3) { fprintf(stderr, "usage: %s <file format> <audio file>\n", argv[0]); exit(EXIT_FAILURE); } if (strcmp(argv[1], "aiff") == 0) filefmt = AF_FILE_AIFF; else if (strcmp(argv[1], "aifc") == 0) filefmt = AF_FILE_AIFFC; else if (strcmp(argv[1], "wave") == 0) filefmt = AF_FILE_WAVE; else { fprintf(stderr, "unrecognized file format '%s'\n", argv[1]); exit(EXIT_FAILURE); } setup = afNewFileSetup(); afInitFileFormat(setup, filefmt); afInitMiscIDs(setup, miscids, 2); afInitMiscType(setup, 1, AF_MISC_COPY); afInitMiscType(setup, 2, AF_MISC_NAME); afInitMiscSize(setup, 1, strlen(copyright)); afInitMiscSize(setup, 2, strlen(name)); file = afOpenFile(argv[2], "w", setup); if (file == NULL) { fprintf(stderr, "could not open file '%s' for writing\n", argv[2]); exit(EXIT_FAILURE); } result = afWriteMisc(file, 1, copyright, strlen(copyright)); DEBG("wrote miscellaneous data of type %d with length = %d\n", afGetMiscType(file, 1), result); result = afWriteMisc(file, 2, name, strlen(name)); DEBG("wrote miscellaneous data of type %d with length = %d\n", afGetMiscType(file, 2), result); /* Write out two token frames of sample data. */ afWriteFrames(file, AF_DEFAULT_TRACK, data, 2); afCloseFile(file); afFreeFileSetup(setup); return 0; }
void writeMiscellaneous(int fileFormat, const std::string &testFileName) { AFfilesetup setup = afNewFileSetup(); afInitChannels(setup, AF_DEFAULT_TRACK, 1); afInitFileFormat(setup, fileFormat); int *miscIDs = new int[kNumMiscellaneous]; for (int i=0; i<kNumMiscellaneous; i++) miscIDs[i] = kMiscellaneous[i].id; afInitMiscIDs(setup, miscIDs, kNumMiscellaneous); delete [] miscIDs; for (int i=0; i<kNumMiscellaneous; i++) { afInitMiscType(setup, kMiscellaneous[i].id, kMiscellaneous[i].type); afInitMiscSize(setup, kMiscellaneous[i].id, strlen(kMiscellaneous[i].data)); } AFfilehandle file = afOpenFile(testFileName.c_str(), "w", setup); ASSERT_TRUE(file); afFreeFileSetup(setup); for (int i=0; i<kNumMiscellaneous; i++) { int result = afWriteMisc(file, kMiscellaneous[i].id, kMiscellaneous[i].data, strlen(kMiscellaneous[i].data)); EXPECT_EQ(strlen(kMiscellaneous[i].data), result); } const int16_t samples[] = { 1, 2, 3, 4 }; const int sampleCount = sizeof (samples) / sizeof (samples[0]); EXPECT_EQ(sampleCount, afWriteFrames(file, AF_DEFAULT_TRACK, samples, sampleCount)); ASSERT_EQ(0, afCloseFile(file)); }