Esempio n. 1
0
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;
}
Esempio n. 2
0
void readMiscellaneous(const std::string &testFileName)
{
	AFfilehandle file = afOpenFile(testFileName.c_str(), "r", NULL);
	ASSERT_TRUE(file);
	int count = afGetMiscIDs(file, NULL);
	EXPECT_EQ(count, kNumMiscellaneous);
	int miscIDs[kNumMiscellaneous];
	afGetMiscIDs(file, miscIDs);
	for (int i=0; i<kNumMiscellaneous; i++)
		EXPECT_EQ(miscIDs[i], kMiscellaneous[i].id);
	for (int i=0; i<kNumMiscellaneous; i++)
	{
		int misctype = afGetMiscType(file, miscIDs[i]);
		EXPECT_EQ(misctype, kMiscellaneous[i].type);

		int datasize = afGetMiscSize(file, miscIDs[i]);
		EXPECT_EQ(datasize, strlen(kMiscellaneous[i].data));

		char *data = new char[datasize];
		EXPECT_EQ(datasize, afReadMisc(file, miscIDs[i], data, datasize));

		EXPECT_TRUE(!memcmp(data, kMiscellaneous[i].data, datasize));

		delete [] data;
	}
	ASSERT_EQ(0, afCloseFile(file));
}
Esempio n. 3
0
static char *copyrightstring (AFfilehandle file)
{
	char	*copyright = NULL;
	int		*miscids;
	int		i, misccount;

	misccount = afGetMiscIDs(file, NULL);
	miscids = (int *) malloc(sizeof (int) * misccount);
	afGetMiscIDs(file, miscids);

	for (i=0; i<misccount; i++)
	{
		if (afGetMiscType(file, miscids[i]) != AF_MISC_COPY)
			continue;

		/*
			If this code executes, the miscellaneous chunk is a
			copyright chunk.
		*/
		int datasize = afGetMiscSize(file, miscids[i]);
		char *data = (char *) malloc(datasize);
		afReadMisc(file, miscids[i], data, datasize);
		copyright = data;
		break;
	}

	free(miscids);

	return copyright;
}
Esempio n. 4
0
int main (int argc, char **argv)
{
	AFfilehandle	file;
	int				*miscids;
	int				i, misccount;

	if (argc < 2)
	{
		fprintf(stderr, "usage: %s <audio file>\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	file = afOpenFile(argv[1], "r", NULL);
	if (file == NULL)
	{
		fprintf(stderr, "could not open file %s for reading\n", argv[1]);
		exit(EXIT_FAILURE);
	}
	misccount = afGetMiscIDs(file, NULL);
	miscids = malloc(sizeof (int) * misccount);
	afGetMiscIDs(file, miscids);

	for (i=0; i<misccount; i++)
	{
		char	*data;
		int	datasize;

		datasize = afGetMiscSize(file, miscids[i]);
		printf("Miscellaneous %d, %d bytes:\n",
			afGetMiscType(file, miscids[i]), datasize);

		/*
			We know that the data in this test is a string,
			so make the buffer large enough for a null terminator.
		*/
		data = malloc(datasize+1);
		afReadMisc(file, miscids[i], data, datasize);
		data[datasize] = '\0';

		puts(data);
		free(data);
	}

	afCloseFile(file);

	return 0;
}