float _af_format_frame_size (const AudioFormat *fmt, bool stretch3to4) { const CompressionUnit *unit = _af_compression_unit_from_id(fmt->compressionType); float squishFactor = unit->squishFactor; return _af_format_frame_size_uncompressed(fmt, stretch3to4) / squishFactor; }
void _af_print_audioformat (AudioFormat *fmt) { /* sampleRate, channelCount */ printf("{ %7.2f Hz %d ch ", fmt->sampleRate, fmt->channelCount); /* sampleFormat, sampleWidth */ switch (fmt->sampleFormat) { case AF_SAMPFMT_TWOSCOMP: printf("%db 2 ", fmt->sampleWidth); break; case AF_SAMPFMT_UNSIGNED: printf("%db u ", fmt->sampleWidth); break; case AF_SAMPFMT_FLOAT: printf("flt "); break; case AF_SAMPFMT_DOUBLE: printf("dbl "); break; default: printf("%dsampfmt? ", fmt->sampleFormat); } /* pcm */ printf("(%.30g+-%.30g [%.30g,%.30g]) ", fmt->pcm.intercept, fmt->pcm.slope, fmt->pcm.minClip, fmt->pcm.maxClip); /* byteOrder */ switch (fmt->byteOrder) { case AF_BYTEORDER_BIGENDIAN: printf("big "); break; case AF_BYTEORDER_LITTLEENDIAN: printf("little "); break; default: printf("%dbyteorder? ", fmt->byteOrder); break; } /* compression */ { const CompressionUnit *unit = _af_compression_unit_from_id(fmt->compressionType); if (!unit) printf("%dcompression?", fmt->compressionType); else if (fmt->compressionType == AF_COMPRESSION_NONE) printf("pcm"); else printf("%s", unit->label); } printf(" }"); }
status ModuleState::initFileModule(AFfilehandle file, Track *track) { const CompressionUnit *unit = _af_compression_unit_from_id(track->f.compressionType); if (!unit) return AF_FAIL; // Validate compression format and parameters. if (!unit->fmtok(&track->f)) return AF_FAIL; if (file->m_seekok && file->m_fh->seek(track->fpos_first_frame, File::SeekFromBeginning) != track->fpos_first_frame) { _af_error(AF_BAD_LSEEK, "unable to position file handle at beginning of sound data"); return AF_FAIL; } AFframecount chunkFrames; if (file->m_access == _AF_READ_ACCESS) m_fileModule = unit->initdecompress(track, file->m_fh, file->m_seekok, file->m_fileFormat == AF_FILE_RAWDATA, &chunkFrames); else m_fileModule = unit->initcompress(track, file->m_fh, file->m_seekok, file->m_fileFormat == AF_FILE_RAWDATA, &chunkFrames); if (unit->needsRebuffer) { assert(unit->nativeSampleFormat == AF_SAMPFMT_TWOSCOMP); RebufferModule::Direction direction = file->m_access == _AF_WRITE_ACCESS ? RebufferModule::VariableToFixed : RebufferModule::FixedToVariable; m_fileRebufferModule = new RebufferModule(direction, track->f.bytesPerFrame(false), chunkFrames, unit->multiple_of); } track->filemodhappy = true; return AF_SUCCEED; }
/* ARGSUSED0 */ AUpvlist _afQueryCompression (int arg1, int arg2, int arg3, int arg4) { const CompressionUnit *unit = NULL; switch (arg1) { case AF_QUERY_ID_COUNT: { int count = 0; for (int i = 0; i < _AF_NUM_COMPRESSION; i++) if (_af_compression[i].implemented) count++; return _af_pv_long(count); } case AF_QUERY_IDS: { int *buf = (int *) _af_calloc(_AF_NUM_COMPRESSION, sizeof (int)); if (!buf) return AU_NULL_PVLIST; int count = 0; for (int i = 0; i < _AF_NUM_COMPRESSION; i++) { if (_af_compression[i].implemented) buf[count++] = _af_compression[i].compressionID; } return _af_pv_pointer(buf); } case AF_QUERY_IMPLEMENTED: unit = _af_compression_unit_from_id(arg2); if (!unit) return _af_pv_long(0); return _af_pv_long(unit->implemented); case AF_QUERY_NATIVE_SAMPFMT: unit = _af_compression_unit_from_id(arg2); if (!unit) return AU_NULL_PVLIST; return _af_pv_long(unit->nativeSampleFormat); case AF_QUERY_NATIVE_SAMPWIDTH: unit = _af_compression_unit_from_id(arg2); if (!unit) return AU_NULL_PVLIST; return _af_pv_long(unit->nativeSampleWidth); case AF_QUERY_LABEL: unit = _af_compression_unit_from_id(arg2); if (!unit) return AU_NULL_PVLIST; return _af_pv_pointer(const_cast<char *>(unit->label)); case AF_QUERY_NAME: unit = _af_compression_unit_from_id(arg2); if (!unit) return AU_NULL_PVLIST; return _af_pv_pointer(const_cast<char *>(unit->shortname)); case AF_QUERY_DESC: unit = _af_compression_unit_from_id(arg2); if (!unit) return AU_NULL_PVLIST; return _af_pv_pointer(const_cast<char *>(unit->name)); } _af_error(AF_BAD_QUERY, "unrecognized query selector %d\n", arg1); return AU_NULL_PVLIST; }