void printinstparams (int format) { int i, *iarray; long instParamCount; instParamCount = afQueryLong(AF_QUERYTYPE_INSTPARAM, AF_QUERY_ID_COUNT, format, 0, 0); DEBG("instrument parameter query: id count: %ld\n", instParamCount); iarray = afQueryPointer(AF_QUERYTYPE_INSTPARAM, AF_QUERY_IDS, format, 0, 0); if (iarray == NULL) printf("AF_QUERYTYPE_INSTPARAM failed for format %d\n", format); for (i=0; i<instParamCount; i++) { int paramType; AUpvlist defaultValue; DEBG("instrument parameter query: id: %d\n", iarray[i]); paramType = afQueryLong(AF_QUERYTYPE_INSTPARAM, AF_QUERY_TYPE, format, iarray[i], 0); DEBG("\ttype of parameter: %s\n", paramtypename(paramType)); DEBG("\tname of parameter: %s\n", (char *) afQueryPointer(AF_QUERYTYPE_INSTPARAM, AF_QUERY_NAME, format, iarray[i], 0)); defaultValue = afQuery(AF_QUERYTYPE_INSTPARAM, AF_QUERY_DEFAULT, format, iarray[i], 0); if (paramType == AU_PVTYPE_LONG) { long ldefault; AUpvgetval(defaultValue, 0, &ldefault); DEBG("\tdefault value: %ld\n", ldefault); } else if (paramType == AU_PVTYPE_DOUBLE) { double ddefault; AUpvgetval(defaultValue, 0, &ddefault); DEBG("\tdefault value: %f\n", ddefault); } else if (paramType == AU_PVTYPE_PTR) { void *vdefault; AUpvgetval(defaultValue, 0, &vdefault); DEBG("\tdefault value: %p\n", vdefault); } } free(iarray); }
TEST(Query, CompressionFormats) { IgnoreErrors ignoreErrors; int compressionFormats[] = { AF_COMPRESSION_NONE, AF_COMPRESSION_G711_ULAW, AF_COMPRESSION_G711_ALAW, AF_COMPRESSION_IMA, AF_COMPRESSION_MS_ADPCM, AF_COMPRESSION_G722, AF_COMPRESSION_APPLE_ACE2, AF_COMPRESSION_APPLE_ACE8, AF_COMPRESSION_APPLE_MAC3, AF_COMPRESSION_APPLE_MAC6 }; int numCompressionFormats = sizeof (compressionFormats) / sizeof (int); for (int i=0; i<numCompressionFormats; i++) { long implemented = afQueryLong(AF_QUERYTYPE_COMPRESSION, AF_QUERY_IMPLEMENTED, compressionFormats[i], 0, 0); long nativeSampleFormat = afQueryLong(AF_QUERYTYPE_COMPRESSION, AF_QUERY_NATIVE_SAMPFMT, compressionFormats[i], 0, 0); if (implemented) EXPECT_TRUE(nativeSampleFormat == AF_SAMPFMT_TWOSCOMP || nativeSampleFormat == AF_SAMPFMT_UNSIGNED || nativeSampleFormat == AF_SAMPFMT_FLOAT || nativeSampleFormat == AF_SAMPFMT_DOUBLE); long nativeSampleWidth = afQueryLong(AF_QUERYTYPE_COMPRESSION, AF_QUERY_NATIVE_SAMPWIDTH, compressionFormats[i], 0, 0); if (implemented) { EXPECT_GE(nativeSampleWidth, 1); EXPECT_LE(nativeSampleWidth, 64); } const char *label = static_cast<const char *>(afQueryPointer(AF_QUERYTYPE_COMPRESSION, AF_QUERY_LABEL, compressionFormats[i], 0, 0)); if (implemented) EXPECT_TRUE(label); const char *name = static_cast<const char *>(afQueryPointer(AF_QUERYTYPE_COMPRESSION, AF_QUERY_NAME, compressionFormats[i], 0, 0)); if (implemented) EXPECT_TRUE(name); const char *description = static_cast<const char *>(afQueryPointer(AF_QUERYTYPE_COMPRESSION, AF_QUERY_DESC, compressionFormats[i], 0, 0)); if (implemented) EXPECT_TRUE(description); } }
TEST(Query, FileFormats) { IgnoreErrors ignoreErrors; int fileFormats[] = { AF_FILE_UNKNOWN, AF_FILE_RAWDATA, AF_FILE_AIFFC, AF_FILE_AIFF, AF_FILE_NEXTSND, AF_FILE_WAVE, AF_FILE_BICSF, AF_FILE_MPEG1BITSTREAM, AF_FILE_SOUNDDESIGNER1, AF_FILE_SOUNDDESIGNER2, AF_FILE_AVR, AF_FILE_IFF_8SVX, AF_FILE_SAMPLEVISION, AF_FILE_VOC, AF_FILE_NIST_SPHERE, AF_FILE_SOUNDFONT2, AF_FILE_CAF }; int numFileFormats = sizeof (fileFormats) / sizeof (int); for (int i=0; i<numFileFormats; i++) { long implemented = afQueryLong(AF_QUERYTYPE_FILEFMT, AF_QUERY_IMPLEMENTED, fileFormats[i], 0, 0); const char *label = static_cast<const char *>(afQueryPointer(AF_QUERYTYPE_FILEFMT, AF_QUERY_LABEL, fileFormats[i], 0, 0)); if (implemented) EXPECT_TRUE(label); const char *name = static_cast<const char *>(afQueryPointer(AF_QUERYTYPE_FILEFMT, AF_QUERY_NAME, fileFormats[i], 0, 0)); if (implemented) EXPECT_TRUE(name); const char *description = static_cast<const char *>(afQueryPointer(AF_QUERYTYPE_FILEFMT, AF_QUERY_DESC, fileFormats[i], 0, 0)); if (implemented) EXPECT_TRUE(description); } }
/* 0.73s 44100.00 aiff 1ch 16b -- flute.aif */ bool printshortinfo (const char *filename) { AFfilehandle file = afOpenFile(filename, "r", NULL);; if (!file) return false; int fileFormat = afGetFileFormat(file, NULL); double sampleRate = afGetRate(file, AF_DEFAULT_TRACK); double duration = afGetFrameCount(file, AF_DEFAULT_TRACK) / sampleRate; const char *labelString = (const char *) afQueryPointer(AF_QUERYTYPE_FILEFMT, AF_QUERY_LABEL, fileFormat, 0, 0); int channels = afGetChannels(file, AF_DEFAULT_TRACK); int sampleFormat, sampleWidth; afGetSampleFormat(file, AF_DEFAULT_TRACK, &sampleFormat, &sampleWidth); int compressionType = afGetCompression(file, AF_DEFAULT_TRACK); const char *compressionName = "--"; if (compressionType != AF_COMPRESSION_NONE) { compressionName = (const char *) afQueryPointer(AF_QUERYTYPE_COMPRESSION, AF_QUERY_NAME, compressionType, 0, 0); if (!compressionName) compressionName = "unk"; } printf("%8.2fs %8.2f %4s %2dch %2db %s %s\n", duration, sampleRate, labelString, channels, sampleWidth, compressionName, filename); afCloseFile(file); return true; }
int main (int ac, char **av) { AUpvlist formatlist; int *flist; long lvalue; int i, formatcount; formatlist = afQuery(AF_QUERYTYPE_FILEFMT, AF_QUERY_IDS, 0, 0, 0); formatcount = afQueryLong(AF_QUERYTYPE_FILEFMT, AF_QUERY_ID_COUNT, 0, 0, 0); DEBG("formatcount = %d\n", formatcount); AUpvgetval(formatlist, 0, &flist); AUpvfree(formatlist); for (i=0; i<formatcount; i++) { int format; char *formatstring; format = flist[i]; DEBG("format = %d\n", format); formatstring = afQueryPointer(AF_QUERYTYPE_FILEFMT, AF_QUERY_NAME, format, 0, 0); DEBG("format = %s\n", formatstring); lvalue = afQueryLong(AF_QUERYTYPE_INST, AF_QUERY_SUPPORTED, format, 0, 0); DEBG("instrument query: supported: %ld\n", lvalue); lvalue = afQueryLong(AF_QUERYTYPE_INST, AF_QUERY_MAX_NUMBER, format, 0, 0); DEBG("instrument query: maximum number: %ld\n", lvalue); lvalue = afQueryLong(AF_QUERYTYPE_INSTPARAM, AF_QUERY_SUPPORTED, format, 0, 0); DEBG("instrument parameter query: supported: %ld\n", lvalue); /* Print instrument parameter information only if instrument parameters are supported. */ if (lvalue) printinstparams(format); } free(flist); return 0; }
int main (int argc, char **argv) { /* These file formats support double-precision floating-point audio data. */ const int fileFormats[] = { AF_FILE_AIFFC, AF_FILE_WAVE, AF_FILE_NEXTSND }; const int fileFormatCount = sizeof (fileFormats) / sizeof (fileFormats[0]); int i; for (i=0; i<fileFormatCount; i++) { printf("testdouble: testing %s\n", (char *) afQueryPointer(AF_QUERYTYPE_FILEFMT, AF_QUERY_NAME, fileFormats[i], 0, 0)); testdouble(fileFormats[i]); } printf("testdouble passed\n"); exit(EXIT_SUCCESS); }
//*************************************************************************** QList<Kwave::Compression::Type> Kwave::audiofileCompressionTypes() { QList<Kwave::Compression::Type> list; const long int numCompressionTypes = afQueryLong( AF_QUERYTYPE_COMPRESSION, AF_QUERY_ID_COUNT, 0, 0, 0); if (numCompressionTypes != 0) { int *compressions = static_cast<int *>(afQueryPointer( AF_QUERYTYPE_COMPRESSION, AF_QUERY_IDS, 0, 0, 0)); if (compressions) { for (long int index = 0; index < numCompressionTypes; index++) { Kwave::Compression::Type compression_type = Kwave::Compression::fromAudiofile(compressions[index]); if (!list.contains(compression_type)) list.append(compression_type); } free(compressions); } } return list; }
bool printfileinfo (const char *filename) { AFfilehandle file = afOpenFile(filename, "r", NULL); if (!file) return false; int fileFormat = afGetFileFormat(file, NULL); const char *formatstring = (const char *) afQueryPointer(AF_QUERYTYPE_FILEFMT, AF_QUERY_DESC, fileFormat, 0, 0); const char *labelstring = (const char *) afQueryPointer(AF_QUERYTYPE_FILEFMT, AF_QUERY_LABEL, fileFormat, 0, 0); if (!formatstring || !labelstring) return false; printf("File Name %s\n", filename); printf("File Format %s (%s)\n", formatstring, labelstring); int sampleFormat, sampleWidth; afGetSampleFormat(file, AF_DEFAULT_TRACK, &sampleFormat, &sampleWidth); int byteOrder = afGetByteOrder(file, AF_DEFAULT_TRACK); printf("Data Format "); int compressionType = afGetCompression(file, AF_DEFAULT_TRACK); if (compressionType == AF_COMPRESSION_NONE) { switch (sampleFormat) { case AF_SAMPFMT_TWOSCOMP: printf("%d-bit integer (2's complement, %s)", sampleWidth, byteOrder == AF_BYTEORDER_BIGENDIAN ? "big endian" : "little endian"); break; case AF_SAMPFMT_UNSIGNED: printf("%d-bit integer (unsigned, %s)", sampleWidth, byteOrder == AF_BYTEORDER_BIGENDIAN ? "big endian" : "little endian"); break; case AF_SAMPFMT_FLOAT: printf("single-precision (32-bit) floating point, %s", byteOrder == AF_BYTEORDER_BIGENDIAN ? "big endian" : "little endian"); break; case AF_SAMPFMT_DOUBLE: printf("double-precision (64-bit) floating point, %s", byteOrder == AF_BYTEORDER_BIGENDIAN ? "big endian" : "little endian"); break; default: printf("unknown"); break; } } else { const char *compressionName = (const char *) afQueryPointer(AF_QUERYTYPE_COMPRESSION, AF_QUERY_NAME, compressionType, 0, 0); if (!compressionName) printf("unknown compression"); else printf("%s compression", compressionName); } printf("\n"); printf("Audio Data %jd bytes begins at offset %jd (%jx hex)\n", (intmax_t) afGetTrackBytes(file, AF_DEFAULT_TRACK), (intmax_t) afGetDataOffset(file, AF_DEFAULT_TRACK), (uintmax_t) afGetDataOffset(file, AF_DEFAULT_TRACK)); printf(" %d channel%s, %jd frames\n", afGetChannels(file, AF_DEFAULT_TRACK), afGetChannels(file, AF_DEFAULT_TRACK) > 1 ? "s" : "", (intmax_t) afGetFrameCount(file, AF_DEFAULT_TRACK)); printf("Sampling Rate %.2f Hz\n", afGetRate(file, AF_DEFAULT_TRACK)); printf("Duration %.3f seconds\n", afGetFrameCount(file, AF_DEFAULT_TRACK) / afGetRate(file, AF_DEFAULT_TRACK)); char *copyright = copyrightstring(file); if (copyright) { printf("Copyright %s\n", copyright); free(copyright); } afCloseFile(file); return true; }
Result process() { if (const YAML::Node *n = m_entry.FindValue(kSkip)) return kSkipped; if (const YAML::Node *n = m_entry.FindValue(kPath)) { n->GetScalar(m_path); } else { logerr("no path specified, line %d", n->GetMark().line); return kManifestError; } if (const YAML::Node *n = m_entry.FindValue(kMD5Sum)) { std::string md5 = md5sum(m_path); std::string expectedMD5; n->GetScalar(expectedMD5); if (md5 != expectedMD5) { logerr("md5 checksum differs from expected value"); return kFailure; } } AFfilehandle file = afOpenFile(m_path.c_str(), "r", NULL); if (const YAML::Node *n = m_entry.FindValue(kInvalid)) { if (!file) return kSuccess; logerr("opening invalid file did not fail as expected"); return kFailure; } if (!file) { logerr("could not open file"); return kFailure; } for (YAML::Iterator i = m_entry.begin(); i != m_entry.end(); ++i) { std::string key = i.first().to<std::string>(); std::string value = i.second().to<std::string>(); if (key == kFileFormat) { const char *fileFormat = (const char *) afQueryPointer(AF_QUERYTYPE_FILEFMT, AF_QUERY_LABEL, afGetFileFormat(file, NULL), 0, 0); assert(fileFormat); expect(key, std::string(fileFormat), value); } else if (key == kChannels) { int expectedChannels = atoi(value.c_str()); expect(key, expectedChannels, afGetChannels(file, AF_DEFAULT_TRACK)); } else if (key == kByteOrder) { int expectedByteOrder; if (value == kByteOrder_Big) expectedByteOrder = AF_BYTEORDER_BIGENDIAN; else if (value == kByteOrder_Little) expectedByteOrder = AF_BYTEORDER_LITTLEENDIAN; else { logerr("bad value for byte order: %s, line %d", value.c_str(), i.second().GetMark().line); return kManifestError; } expect(key, expectedByteOrder, afGetByteOrder(file, AF_DEFAULT_TRACK)); } else if (key == kSampleRate) { double expectedSampleRate = atof(value.c_str()); expect(key, expectedSampleRate, afGetRate(file, AF_DEFAULT_TRACK)); } else if (key == kSampleFormat) { std::string width = value.substr(1, value.length() - 1); char format = value[0]; int expectedSampleWidth = atoi(width.c_str()); bool isValidSampleWidth = (expectedSampleWidth >= 1 && expectedSampleWidth <= 32) || expectedSampleWidth == 64; if (!isValidSampleWidth) { logerr("bad value for sample format: %s, line %d", value.c_str(), i.second().GetMark().line); return kManifestError; } int expectedSampleFormat = -1; switch (format) { case 's': expectedSampleFormat = AF_SAMPFMT_TWOSCOMP; break; case 'u': expectedSampleFormat = AF_SAMPFMT_UNSIGNED; break; case 'f': if (expectedSampleWidth == 32) expectedSampleFormat = AF_SAMPFMT_FLOAT; else if (expectedSampleWidth == 64) expectedSampleFormat = AF_SAMPFMT_DOUBLE; break; default: logerr("bad value for sample format: %s, line %d", value.c_str(), i.second().GetMark().line); return kManifestError; } int sampleFormat, sampleWidth; afGetSampleFormat(file, AF_DEFAULT_TRACK, &sampleFormat, &sampleWidth); expect(key, expectedSampleFormat, sampleFormat); expect(key, expectedSampleWidth, sampleWidth); } else if (key == kCompression) { int expectedCompression; if (value == kCompression_None) expectedCompression = AF_COMPRESSION_NONE; else if (value == kCompression_IMA_ADPCM) expectedCompression = AF_COMPRESSION_IMA; else if (value == kCompression_MS_ADPCM) expectedCompression = AF_COMPRESSION_MS_ADPCM; else if (value == kCompression_ulaw) expectedCompression = AF_COMPRESSION_G711_ULAW; else if (value == kCompression_alaw) expectedCompression = AF_COMPRESSION_G711_ALAW; else if (value == kCompression_FLAC) expectedCompression = AF_COMPRESSION_FLAC; else if (value == kCompression_ALAC) expectedCompression = AF_COMPRESSION_ALAC; else { logerr("bad value for compression: %s, line %d", value.c_str(), i.second().GetMark().line); return kManifestError; } expect(key, expectedCompression, afGetCompression(file, AF_DEFAULT_TRACK)); } else if (key == kFrames) { AFframecount expectedFrameCount = atoll(value.c_str()); expect(key, expectedFrameCount, afGetFrameCount(file, AF_DEFAULT_TRACK)); int bufferFrameCount = 1024; int channels = afGetChannels(file, AF_DEFAULT_TRACK); int maxBytesPerFrame = 8; char *buffer = new char[channels * bufferFrameCount * maxBytesPerFrame]; AFframecount framesRead = 0; while (framesRead < expectedFrameCount) { AFframecount framesToRead = std::min<AFframecount>(bufferFrameCount, expectedFrameCount - framesRead); AFframecount result = afReadFrames(file, AF_DEFAULT_TRACK, buffer, framesToRead); if (result != framesToRead) { m_failures++; break; } framesRead += result; } delete [] buffer; } else if (key == kBytes) { AFfileoffset expectedTrackBytes = atoll(value.c_str()); expect(key, expectedTrackBytes, afGetTrackBytes(file, AF_DEFAULT_TRACK)); } } afCloseFile(file); return m_failures == 0 ? kSuccess : kFailure; }