diff options
author | Aaron Giles <aaron@aarongiles.com> | 2012-02-20 07:26:05 +0000 |
---|---|---|
committer | Aaron Giles <aaron@aarongiles.com> | 2012-02-20 07:26:05 +0000 |
commit | 29b32d229b0b496b47ac3182513ba63329efd7a8 (patch) | |
tree | 91e1c4cf60d3b652ad256df85cdace4d3beceb3d /src/tools | |
parent | 1db879e23206c9a2d941c26ca66dc8845a1c105e (diff) |
Fix ld tool compilation.
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/chdman.c | 11 | ||||
-rw-r--r-- | src/tools/ldresample.c | 645 | ||||
-rw-r--r-- | src/tools/ldverify.c | 764 | ||||
-rw-r--r-- | src/tools/tools.mak | 4 |
4 files changed, 684 insertions, 740 deletions
diff --git a/src/tools/chdman.c b/src/tools/chdman.c index 594bff3a519..bcb9cdc4cc8 100644 --- a/src/tools/chdman.c +++ b/src/tools/chdman.c @@ -431,12 +431,15 @@ public: } // assemble the data into final form - avhuff_error averr = avhuff_encoder::assemble_data(m_rawdata, m_rawdata.count(), subbitmap, channels, samples, samplesptr); + avhuff_error averr = avhuff_encoder::assemble_data(m_rawdata, subbitmap, channels, samples, samplesptr); if (averr != AVHERR_NONE) report_error(1, "Error assembling data for frame %d", framenum); - UINT32 rawsize = avhuff_encoder::raw_data_size(m_rawdata); - if (rawsize < m_rawdata.count()) - memset(&m_rawdata[rawsize], 0, m_rawdata.count() - rawsize); + if (m_rawdata.count() < m_info.bytes_per_frame) + { + UINT32 delta = m_info.bytes_per_frame - m_rawdata.count(); + m_rawdata.resize(m_info.bytes_per_frame, true); + memset(&m_rawdata[m_info.bytes_per_frame - delta], 0, delta); + } // copy to the destination UINT64 start_offset = UINT64(framenum) * UINT64(m_info.bytes_per_frame); diff --git a/src/tools/ldresample.c b/src/tools/ldresample.c index 5c3dc932f9f..fe85423748e 100644 --- a/src/tools/ldresample.c +++ b/src/tools/ldresample.c @@ -44,90 +44,126 @@ #include <new> #include "bitmap.h" #include "chd.h" +#include "avhuff.h" #include "vbiparse.h" -/*************************************************************************** - CONSTANTS -***************************************************************************/ +//************************************************************************** +// CONSTANTS +//************************************************************************** -/* size of window where we scan ahead to find maximum; this should be large enough to - catch peaks of even slow waves */ -#define MAXIMUM_WINDOW_SIZE 40 +// size of window where we scan ahead to find maximum; this should be large enough to +// catch peaks of even slow waves +const UINT32 MAXIMUM_WINDOW_SIZE = 40; -/* number of standard deviations away from silence that we consider a real signal */ -#define SIGNAL_DEVIATIONS 100 +// number of standard deviations away from silence that we consider a real signal +const UINT32 SIGNAL_DEVIATIONS = 100; -/* number of standard deviations away from silence that we consider the start of a signal */ -#define SIGNAL_START_DEVIATIONS 5 +// number of standard deviations away from silence that we consider the start of a signal +const UINT32 SIGNAL_START_DEVIATIONS = 5; -/* number of consecutive entries of signal before we consider that we found it */ -#define MINIMUM_SIGNAL_COUNT 20 +// number of consecutive entries of signal before we consider that we found it +const UINT32 MINIMUM_SIGNAL_COUNT = 20; -/*************************************************************************** - TYPE DEFINITIONS -***************************************************************************/ +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** -typedef struct _movie_info movie_info; -struct _movie_info +struct movie_info { - double framerate; - int iframerate; - int numfields; - int width; - int height; - int samplerate; - int channels; - int interlaced; - bitmap_yuy16 bitmap; + double framerate; + int iframerate; + int numfields; + int width; + int height; + int samplerate; + int channels; + int interlaced; + bitmap_yuy16 bitmap; dynamic_array<INT16> lsound; dynamic_array<INT16> rsound; - UINT32 samples; + UINT32 samples; }; +// ======================> chd_resample_compressor -/*************************************************************************** - GLOBAL VARIABLES -***************************************************************************/ +class chd_resample_compressor : public chd_file_compressor +{ +public: + // construction/destruction + chd_resample_compressor(chd_file &source, movie_info &info, INT64 ioffset, INT64 islope) + : m_source(source), + m_info(info), + m_ioffset(ioffset), + m_islope(islope) { } + + // read interface + virtual UINT32 read_data(void *_dest, UINT64 offset, UINT32 length) + { + assert(offset % m_source.hunk_bytes() == 0); + assert(length % m_source.hunk_bytes() == 0); + + UINT32 startfield = offset / m_source.hunk_bytes(); + UINT32 endfield = startfield + length / m_source.hunk_bytes(); + UINT8 *dest = reinterpret_cast<UINT8 *>(_dest); + + for (UINT32 fieldnum = startfield; fieldnum < endfield; fieldnum++) + { + generate_one_frame(dest, m_source.hunk_bytes(), fieldnum); + dest += m_source.hunk_bytes(); + } + return length; + } +private: + // internal helpers + void generate_one_frame(UINT8 *dest, UINT32 datasize, UINT32 fieldnum); + // internal state + chd_file & m_source; + movie_info & m_info; + INT64 m_ioffset; + INT64 m_islope; +}; -/*************************************************************************** - INLINE FUNCTIONS -***************************************************************************/ -/*------------------------------------------------- - field_to_sample_number - given a field number - compute the absolute sample number for the - first sample of that field --------------------------------------------------*/ -INLINE UINT32 field_to_sample_number(const movie_info *info, UINT32 field) +//************************************************************************** +// INLINE FUNCTIONS +//************************************************************************** + +//------------------------------------------------- +// field_to_sample_number - given a field number +// compute the absolute sample number for the +// first sample of that field +//------------------------------------------------- + +inline UINT32 field_to_sample_number(const movie_info &info, UINT32 field) { - return ((UINT64)info->samplerate * (UINT64)field * (UINT64)1000000 + info->iframerate - 1) / (UINT64)info->iframerate; + return (UINT64(info.samplerate) * UINT64(field) * UINT64(1000000) + info.iframerate - 1) / UINT64(info.iframerate); } -/*------------------------------------------------- - sample_number_to_field - given a sample number - compute the field where it is located and - the offset within the field --------------------------------------------------*/ +//------------------------------------------------- +// sample_number_to_field - given a sample number +// compute the field where it is located and +// the offset within the field +//------------------------------------------------- -INLINE UINT32 sample_number_to_field(const movie_info *info, UINT32 samplenum, UINT32 *offset) +inline UINT32 sample_number_to_field(const movie_info &info, UINT32 samplenum, UINT32 &offset) { - UINT32 guess = ((UINT64)samplenum * (UINT64)info->iframerate + ((UINT64)info->samplerate * (UINT64)1000000 - 1)) / ((UINT64)info->samplerate * (UINT64)1000000); + UINT32 guess = (UINT64(samplenum) * UINT64(info.iframerate) + (UINT64(info.samplerate) * UINT64(1000000) - 1)) / (UINT64(info.samplerate) * UINT64(1000000)); while (1) { UINT32 fieldstart = field_to_sample_number(info, guess); UINT32 fieldend = field_to_sample_number(info, guess + 1); if (samplenum >= fieldstart && samplenum < fieldend) { - *offset = samplenum - fieldstart; + offset = samplenum - fieldstart; return guess; } else if (samplenum < fieldstart) @@ -139,35 +175,35 @@ INLINE UINT32 sample_number_to_field(const movie_info *info, UINT32 samplenum, U -/*************************************************************************** - CHD HANDLING -***************************************************************************/ +//************************************************************************** +// CHD HANDLING +//************************************************************************** -/*------------------------------------------------- - open_chd - open a CHD file and return - information about it --------------------------------------------------*/ +//------------------------------------------------- +// open_chd - open a CHD file and return +// information about it +//------------------------------------------------- static chd_error open_chd(chd_file &file, const char *filename, movie_info &info) { - /* open the file */ + // open the file chd_error chderr = file.open(filename); if (chderr != CHDERR_NONE) { - fprintf(stderr, "Error opening CHD file: %s\n", chd_error_string(chderr)); + fprintf(stderr, "Error opening CHD file: %s\n", chd_file::error_string(chderr)); return chderr; } - /* get the metadata */ + // get the metadata astring metadata; - chderr = chd.read_metadata(chd, AV_METADATA_TAG, 0, metadata); + chderr = file.read_metadata(AV_METADATA_TAG, 0, metadata); if (chderr != CHDERR_NONE) { - fprintf(stderr, "Error getting A/V metadata: %s\n", chd_error_string(chderr)); + fprintf(stderr, "Error getting A/V metadata: %s\n", chd_file::error_string(chderr)); return chderr; } - /* extract the info */ + // extract the info int fps, fpsfrac, width, height, interlaced, channels, rate; if (sscanf(metadata, AV_METADATA_FORMAT, &fps, &fpsfrac, &width, &height, &interlaced, &channels, &rate) != 7) { @@ -175,17 +211,17 @@ static chd_error open_chd(chd_file &file, const char *filename, movie_info &info return CHDERR_INVALID_DATA; } - /* extract movie info */ + // extract movie info info.iframerate = fps * 1000000 + fpsfrac; info.framerate = info.iframerate / 1000000.0; - info.numfields = file->hunk_count(); + info.numfields = file.hunk_count(); info.width = width; info.height = height; info.interlaced = interlaced; info.samplerate = rate; info.channels = channels; - /* allocate buffers */ + // allocate buffers info.bitmap.resize(info.width, info.height); info.lsound.resize(info.samplerate); info.rsound.resize(info.samplerate); @@ -193,279 +229,289 @@ static chd_error open_chd(chd_file &file, const char *filename, movie_info &info } -/*------------------------------------------------- - create_chd - create a new CHD file --------------------------------------------------*/ +//------------------------------------------------- +// create_chd - create a new CHD file +//------------------------------------------------- -static chd_error create_chd(chd_compressor &file, const char *filename, chd_file &source, const movie_info &info) +static chd_error create_chd(chd_file_compressor &file, const char *filename, chd_file &source, const movie_info &info) { - /* create the file */ - chd_codec_type compression = { CHD_CODEC_AVHUFF }; + // create the file + chd_codec_type compression[4] = { CHD_CODEC_AVHUFF }; chd_error chderr = file.create(filename, source.logical_bytes(), source.hunk_bytes(), source.unit_bytes(), compression); if (chderr != CHDERR_NONE) { - fprintf(stderr, "Error creating new CHD file: %s\n", chd_error_string(chderr)); + fprintf(stderr, "Error creating new CHD file: %s\n", chd_file::error_string(chderr)); return chderr; } - /* clone the metadata */ + // clone the metadata chderr = file.clone_all_metadata(source); if (chderr != CHDERR_NONE) { - fprintf(stderr, "Error cloning metadata: %s\n", chd_error_string(chderr)); - return chderr; - } - - /* begin compressing */ - chderr = file.compress_begin(); - if (chderr != CHDERR_NONE) - { - fprintf(stderr, "Error beginning compression: %s\n", chd_error_string(chderr)); + fprintf(stderr, "Error cloning metadata: %s\n", chd_file::error_string(chderr)); return chderr; } + // begin compressing + file.compress_begin(); return CHDERR_NONE; } -/*------------------------------------------------- - read_chd - read a field from a CHD file --------------------------------------------------*/ - -static int read_chd(chd_file *file, UINT32 field, movie_info *info, UINT32 soundoffs) -{ - av_codec_decompress_config avconfig; - chd_error chderr; - - /* configure the codec */ - avconfig.video.wrap(*info->bitmap, info->bitmap->cliprect()); - avconfig.maxsamples = 48000; - avconfig.actsamples = &info->samples; - avconfig.audio[0] = info->lsound + soundoffs; - avconfig.audio[1] = info->rsound + soundoffs; - - /* configure the decompressor for this field */ - chd_codec_config(file, AV_CODEC_DECOMPRESS_CONFIG, &avconfig); - - /* read the field */ - chderr = chd_read(file, field, NULL); - if (chderr != CHDERR_NONE) - return FALSE; - - return TRUE; -} - - -/*------------------------------------------------- - write_chd - write a field to a CHD file --------------------------------------------------*/ +//------------------------------------------------- +// read_chd - read a field from a CHD file +//------------------------------------------------- -static int write_chd(chd_file *file, UINT32 field, movie_info *info) +static bool read_chd(chd_file &file, UINT32 field, movie_info &info, UINT32 soundoffs) { - av_codec_compress_config avconfig; - chd_error chderr; - - /* configure the codec */ - avconfig.video.wrap(*info->bitmap, info->bitmap->cliprect()); - avconfig.channels = 2; - avconfig.samples = info->samples; - avconfig.audio[0] = info->lsound; - avconfig.audio[1] = info->rsound; - - /* configure the decompressor for this field */ - chd_codec_config(file, AV_CODEC_COMPRESS_CONFIG, &avconfig); - - /* read the field */ - chderr = chd_compress_hunk(file, NULL, NULL); - if (chderr != CHDERR_NONE) - return FALSE; - - return TRUE; + // configure the codec + avhuff_decompress_config avconfig; + avconfig.video.wrap(info.bitmap, info.bitmap.cliprect()); + avconfig.maxsamples = info.lsound.count(); + avconfig.actsamples = &info.samples; + avconfig.audio[0] = info.lsound + soundoffs; + avconfig.audio[1] = info.rsound + soundoffs; + + // configure the decompressor for this field + file.codec_configure(CHD_CODEC_AVHUFF, AVHUFF_CODEC_DECOMPRESS_CONFIG, &avconfig); + + // read the field + chd_error chderr = file.read_hunk(field, NULL); + return (chderr == CHDERR_NONE); } -/*------------------------------------------------- - create_close_chd - close a CHD file --------------------------------------------------*/ - -static void create_close_chd(chd_file *file) -{ - chd_error err; - - err = chd_compress_finish(file, TRUE); - if (err != CHDERR_NONE) - fprintf(stderr, "Error finishing compression: %s\n", chd_error_string(err)); - chd_close(file); -} +//************************************************************************** +// CORE IMPLEMENTATION +//************************************************************************** +//------------------------------------------------- +// find_edge_near_field - given a field number, +// load +/- 1/2 second on either side and find +// an audio edge +//------------------------------------------------- -/*------------------------------------------------- - close_chd - close a CHD file --------------------------------------------------*/ - -static void close_chd(chd_file *file, movie_info *info) +static bool find_edge_near_field(chd_file &srcfile, UINT32 fieldnum, movie_info &info, bool report_best_field, INT32 &delta) { - if (info != NULL) - chd_free_buffers(info); - chd_close(file); -} - - - -/*************************************************************************** - CORE IMPLEMENTATION -***************************************************************************/ + // clear the sound buffers + memset(info.lsound, 0, info.lsound.count() * 2); + memset(info.rsound, 0, info.rsound.count() * 2); -/*------------------------------------------------- - find_edge_near_field - given a field number, - load +/- 1/2 second on either side and find - an audio edge --------------------------------------------------*/ - -static int find_edge_near_field(chd_file *srcfile, UINT32 fieldnum, movie_info *info, int report_best_field, INT32 *delta) -{ - int fields_to_read = info->iframerate / 1000000; - UINT32 firstlavg = 0, firstravg = 0; - UINT32 firstldev = 0, firstrdev = 0; - UINT32 lcount = 0, rcount = 0; + // read 1 second around the target area + int fields_to_read = info.iframerate / 1000000; + INT32 firstfield = fieldnum - (fields_to_read / 2); UINT32 targetsoundstart = 0; UINT32 firstfieldend = 0; - INT32 firstfield, curfield; UINT32 fieldstart[100]; UINT32 soundend = 0; - UINT32 sampnum; - - /* clear the sound buffers */ - memset(info->lsound, 0, info->samplerate * sizeof(*info->lsound)); - memset(info->rsound, 0, info->samplerate * sizeof(*info->rsound)); - - /* read 1 second around the target area */ - firstfield = fieldnum - (fields_to_read / 2); - for (curfield = 0; curfield < fields_to_read; curfield++) + for (INT32 curfield = 0; curfield < fields_to_read; curfield++) { - /* remember the start of each field */ + // remember the start of each field fieldstart[curfield] = soundend; - /* remember the sound offset where the initial fieldnum is */ + // remember the sound offset where the initial fieldnum is if (firstfield + curfield == fieldnum) targetsoundstart = soundend; - /* read the frame and samples */ + // read the frame and samples if (firstfield + curfield >= 0) { read_chd(srcfile, firstfield + curfield, info, soundend); - soundend += info->samples; + soundend += info.samples; - /* also remember the offset at the end of the first field */ + // also remember the offset at the end of the first field if (firstfieldend == 0) firstfieldend = soundend; } } - /* compute absolute deltas across the samples */ - for (sampnum = 0; sampnum < soundend; sampnum++) + // compute absolute deltas across the samples + for (UINT32 sampnum = 0; sampnum < soundend; sampnum++) { - info->lsound[sampnum] = labs(info->lsound[sampnum + 1] - info->lsound[sampnum]); - info->rsound[sampnum] = labs(info->rsound[sampnum + 1] - info->rsound[sampnum]); + info.lsound[sampnum] = labs(info.lsound[sampnum + 1] - info.lsound[sampnum]); + info.rsound[sampnum] = labs(info.rsound[sampnum + 1] - info.rsound[sampnum]); } - /* for each sample in the collection, find the highest deltas over the - next few samples, and take the nth highest value (to remove outliers) */ - for (sampnum = 0; sampnum < soundend - MAXIMUM_WINDOW_SIZE; sampnum++) + // for each sample in the collection, find the highest deltas over the + // next few samples, and take the nth highest value (to remove outliers) + for (UINT32 sampnum = 0; sampnum < soundend - MAXIMUM_WINDOW_SIZE; sampnum++) { + // scan forward over the maximum window UINT32 lmax = 0, rmax = 0; - UINT32 scannum; - - /* scan forward over the maximum window */ - for (scannum = 0; scannum < MAXIMUM_WINDOW_SIZE; scannum++) + for (UINT32 scannum = 0; scannum < MAXIMUM_WINDOW_SIZE; scannum++) { - if (info->lsound[sampnum + scannum] > lmax) - lmax = info->lsound[sampnum + scannum]; - if (info->rsound[sampnum + scannum] > rmax) - rmax = info->rsound[sampnum + scannum]; + if (info.lsound[sampnum + scannum] > lmax) + lmax = info.lsound[sampnum + scannum]; + if (info.rsound[sampnum + scannum] > rmax) + rmax = info.rsound[sampnum + scannum]; } - /* replace this sample with the maximum value found */ - info->lsound[sampnum] = lmax; - info->rsound[sampnum] = rmax; + // replace this sample with the maximum value found + info.lsound[sampnum] = lmax; + info.rsound[sampnum] = rmax; } - /* now compute the average over the first field, which is assumed to be silence */ - for (sampnum = 0; sampnum < firstfieldend; sampnum++) + // now compute the average over the first field, which is assumed to be silence + UINT32 firstlavg = 0; + UINT32 firstravg = 0; + for (UINT32 sampnum = 0; sampnum < firstfieldend; sampnum++) { - firstlavg += info->lsound[sampnum]; - firstravg += info->rsound[sampnum]; + firstlavg += info.lsound[sampnum]; + firstravg += info.rsound[sampnum]; } firstlavg /= firstfieldend; firstravg /= firstfieldend; - /* then compute the standard deviation over the first field */ - for (sampnum = 0; sampnum < firstfieldend; sampnum++) + // then compute the standard deviation over the first field + UINT32 firstldev = 0; + UINT32 firstrdev = 0; + for (UINT32 sampnum = 0; sampnum < firstfieldend; sampnum++) { - firstldev += (info->lsound[sampnum] - firstlavg) * (info->lsound[sampnum] - firstlavg); - firstrdev += (info->rsound[sampnum] - firstravg) * (info->rsound[sampnum] - firstravg); + firstldev += (info.lsound[sampnum] - firstlavg) * (info.lsound[sampnum] - firstlavg); + firstrdev += (info.rsound[sampnum] - firstravg) * (info.rsound[sampnum] - firstravg); } - firstldev = sqrt((double)firstldev / firstfieldend); - firstrdev = sqrt((double)firstrdev / firstfieldend); - - /* scan forward through the samples, counting consecutive samples more than - SIGNAL_DEVIATIONS standard deviations away from silence */ + firstldev = sqrt(double(firstldev) / firstfieldend); + firstrdev = sqrt(double(firstrdev) / firstfieldend); + + // scan forward through the samples, counting consecutive samples more than + // SIGNAL_DEVIATIONS standard deviations away from silence + UINT32 lcount = 0; + UINT32 rcount = 0; + UINT32 sampnum = 0; for (sampnum = 0; sampnum < soundend; sampnum++) { - /* left speaker */ - if (info->lsound[sampnum] > firstlavg + SIGNAL_DEVIATIONS * firstldev) + // left speaker + if (info.lsound[sampnum] > firstlavg + SIGNAL_DEVIATIONS * firstldev) lcount++; else lcount = 0; - /* right speaker */ - if (info->rsound[sampnum] > firstravg + SIGNAL_DEVIATIONS * firstrdev) + // right speaker + if (info.rsound[sampnum] > firstravg + SIGNAL_DEVIATIONS * firstrdev) rcount++; else rcount = 0; - /* stop if we find enough */ + // stop if we find enough if (lcount > MINIMUM_SIGNAL_COUNT || rcount > MINIMUM_SIGNAL_COUNT) break; } - /* if we didn't find any, return failure */ + // if we didn't find any, return failure if (sampnum >= soundend) { if (!report_best_field) printf("Field %5d: Unable to find edge\n", fieldnum); - return FALSE; + return false; } - /* scan backwards to find the start of the signal */ + // scan backwards to find the start of the signal for ( ; sampnum > 0; sampnum--) - if (info->lsound[sampnum - 1] < firstlavg + SIGNAL_START_DEVIATIONS * firstldev || - info->rsound[sampnum - 1] < firstravg + SIGNAL_START_DEVIATIONS * firstrdev) + if (info.lsound[sampnum - 1] < firstlavg + SIGNAL_START_DEVIATIONS * firstldev || + info.rsound[sampnum - 1] < firstravg + SIGNAL_START_DEVIATIONS * firstrdev) break; - /* if we're to report the best field, figure out which field we are in */ + // if we're to report the best field, figure out which field we are in if (report_best_field) { + INT32 curfield; for (curfield = 0; curfield < fields_to_read - 1; curfield++) if (sampnum < fieldstart[curfield + 1]) break; printf("Field %5d: Edge found at offset %d (frame %.1f)\n", firstfield + curfield, sampnum - fieldstart[curfield], (double)(firstfield + curfield) * 0.5); } - /* otherwise, compute the delta from the provided field number */ + // otherwise, compute the delta from the provided field number else { printf("Field %5d: Edge at offset %d from expected (found at %d, expected %d)\n", fieldnum, sampnum - targetsoundstart, sampnum, targetsoundstart); - *delta = sampnum - targetsoundstart; + delta = sampnum - targetsoundstart; + } + return true; +} + + +//------------------------------------------------- +// generate_one_frame - generate a single +// resampled frame +//------------------------------------------------- + +void chd_resample_compressor::generate_one_frame(UINT8 *dest, UINT32 datasize, UINT32 fieldnum) +{ + // determine the first field needed to cover this range of samples + UINT32 srcbegin = field_to_sample_number(m_info, fieldnum); + INT64 dstbegin = (INT64(srcbegin) << 24) + m_ioffset + m_islope * fieldnum; + UINT32 dstbeginoffset; + INT32 dstbeginfield; + if (dstbegin >= 0) + dstbeginfield = sample_number_to_field(m_info, dstbegin >> 24, dstbeginoffset); + else + { + dstbeginfield = -1 - sample_number_to_field(m_info, -dstbegin >> 24, dstbeginoffset); + dstbeginoffset = (field_to_sample_number(m_info, -dstbeginfield) - field_to_sample_number(m_info, -dstbeginfield - 1)) - dstbeginoffset; + } + + // determine the last field needed to cover this range of samples + UINT32 srcend = field_to_sample_number(m_info, fieldnum + 1); + INT64 dstend = (INT64(srcend) << 24) + m_ioffset + m_islope * (fieldnum + 1); + UINT32 dstendoffset; + INT32 dstendfield; + if (dstend >= 0) + dstendfield = sample_number_to_field(m_info, dstend >> 24, dstendoffset); + else + { + dstendfield = -1 - -sample_number_to_field(m_info, -dstend >> 24, dstendoffset); + dstendoffset = (field_to_sample_number(m_info, -dstendfield) - field_to_sample_number(m_info, -dstendfield - 1)) - dstendoffset; + } +/* +printf("%5d: start=%10d (%5d.%03d) end=%10d (%5d.%03d)\n", + fieldnum, + (INT32)(dstbegin >> 24), dstbeginfield, dstbeginoffset, + (INT32)(dstend >> 24), dstendfield, dstendoffset); +*/ + // read all samples required into the end of the sound buffers + UINT32 dstoffset = srcend - srcbegin; + for (INT32 dstfield = dstbeginfield; dstfield <= dstendfield; dstfield++) + { + if (dstfield >= 0) + read_chd(m_source, dstfield, m_info, dstoffset); + else + { + m_info.samples = field_to_sample_number(m_info, -dstfield) - field_to_sample_number(m_info, -dstfield - 1); + memset(&m_info.lsound[dstoffset], 0, m_info.samples * sizeof(m_info.lsound[0])); + memset(&m_info.rsound[dstoffset], 0, m_info.samples * sizeof(m_info.rsound[0])); + } + dstoffset += m_info.samples; + } + + // resample the destination samples to the source + dstoffset = srcend - srcbegin; + INT64 dstpos = dstbegin; + INT64 dststep = (dstend - dstbegin) / INT64(srcend - srcbegin); + for (UINT32 srcoffset = 0; srcoffset < srcend - srcbegin; srcoffset++) + { + m_info.lsound[srcoffset] = m_info.lsound[dstoffset + dstbeginoffset + (dstpos >> 24) - (dstbegin >> 24)]; + m_info.rsound[srcoffset] = m_info.rsound[dstoffset + dstbeginoffset + (dstpos >> 24) - (dstbegin >> 24)]; + dstpos += dststep; } - return TRUE; + + // read the original frame, pointing the sound buffer past where we've calculated + read_chd(m_source, fieldnum, m_info, srcend - srcbegin); + + // assemble the final frame + dynamic_buffer buffer; + INT16 *sampledata[2] = { m_info.lsound, m_info.rsound }; + avhuff_encoder::assemble_data(buffer, m_info.bitmap, m_info.channels, m_info.samples, sampledata); + memcpy(dest, buffer, MIN(buffer.count(), datasize)); + if (buffer.count() < datasize) + memset(&dest[buffer.count()], 0, datasize - buffer.count()); } -/*------------------------------------------------- - usage - display program usage --------------------------------------------------*/ +//------------------------------------------------- +// usage - display program usage +//------------------------------------------------- static int usage(void) { @@ -480,27 +526,21 @@ static int usage(void) } -/*------------------------------------------------- - main - main entry point --------------------------------------------------*/ +//------------------------------------------------- +// main - main entry point +//------------------------------------------------- int main(int argc, char *argv[]) { - movie_info info = { 0 }; - const char *srcfilename; - const char *dstfilename; - double offset, slope; - chd_file *dstfile; - - /* verify arguments */ + // verify arguments if (argc < 2) return usage(); - srcfilename = argv[1]; - dstfilename = (argc < 3) ? NULL : argv[2]; - offset = (argc < 4) ? 0.0 : atof(argv[3]); - slope = (argc < 5) ? 1.0 : atof(argv[4]); + const char *srcfilename = argv[1]; + const char *dstfilename = (argc < 3) ? NULL : argv[2]; + double offset = (argc < 4) ? 0.0 : atof(argv[3]); + double slope = (argc < 5) ? 1.0 : atof(argv[4]); - /* print basic information */ + // print basic information printf("Input file: %s\n", srcfilename); if (dstfilename != NULL) { @@ -509,8 +549,9 @@ int main(int argc, char *argv[]) printf("Slope: %f\n", slope); } - /* open the source file */ + // open the source file chd_file srcfile; + movie_info info; chd_error err = open_chd(srcfile, srcfilename, info); if (err != CHDERR_NONE) { @@ -518,33 +559,28 @@ int main(int argc, char *argv[]) return 1; } - /* output some basics */ + // output some basics printf("Video dimensions: %dx%d\n", info.width, info.height); printf("Video frame rate: %.2fHz\n", info.framerate); printf("Sample rate: %dHz\n", info.samplerate); printf("Total fields: %d\n", info.numfields); - /* if we don't have a destination file, scan for edges */ + // if we don't have a destination file, scan for edges if (dstfilename == NULL) { - UINT32 fieldnum; - INT32 delta; - - for (fieldnum = 60; fieldnum < info.numfields - 60; fieldnum += 30) + for (UINT32 fieldnum = 60; fieldnum < info.numfields - 60; fieldnum += 30) { fprintf(stderr, "Field %5d\r", fieldnum); - find_edge_near_field(srcfile, fieldnum, &info, TRUE, &delta); + INT32 delta; + find_edge_near_field(srcfile, fieldnum, info, true, delta); } } - /* otherwise, resample the source to the destination */ + // otherwise, resample the source to the destination else { - INT64 ioffset = (INT64)(offset * 65536.0 * 256.0); - INT64 islope = (INT64)(slope * 65536.0 * 256.0); - UINT32 fieldnum; - - /* open the destination file */ + // open the destination file + chd_resample_compressor dstfile(srcfile, info, INT64(offset * 65536.0 * 256.0), INT64(slope * 65536.0 * 256.0)); err = create_chd(dstfile, dstfilename, srcfile, info); if (dstfile == NULL) { @@ -552,82 +588,15 @@ int main(int argc, char *argv[]) return 1; } - /* loop over all the fields in the source file */ - for (fieldnum = 0; fieldnum < info.numfields; fieldnum++) - { - UINT32 srcbegin = field_to_sample_number(&info, fieldnum); - UINT32 srcend = field_to_sample_number(&info, fieldnum + 1); - INT64 dstbegin = ((INT64)srcbegin << 24) + ioffset + islope * fieldnum; - INT64 dstend = ((INT64)srcend << 24) + ioffset + islope * (fieldnum + 1); - UINT32 dstbeginoffset, dstendoffset, dstoffset; - INT32 dstbeginfield, dstendfield, dstfield; - INT64 dstpos, dststep; - UINT32 srcoffset; - - /* update progress (this ain't fast!) */ - if (fieldnum % 10 == 0) - fprintf(stderr, "Field %d\r", fieldnum); - - /* determine the first and last fields needed to cover this range of samples */ - if (dstbegin >= 0) - dstbeginfield = sample_number_to_field(&info, dstbegin >> 24, &dstbeginoffset); - else + // loop over all the fields in the source file + double progress, ratio; + osd_ticks_t last_update = 0; + while (dstfile.compress_continue(progress, ratio) == CHDERR_COMPRESSING) + if (osd_ticks() - last_update > osd_ticks_per_second() / 4) { - dstbeginfield = -1 - sample_number_to_field(&info, -dstbegin >> 24, &dstbeginoffset); - dstbeginoffset = (field_to_sample_number(&info, -dstbeginfield) - field_to_sample_number(&info, -dstbeginfield - 1)) - dstbeginoffset; + last_update = osd_ticks(); + printf("Processing, %.1f%% complete....\r", progress * 100.0); } - if (dstend >= 0) - dstendfield = sample_number_to_field(&info, dstend >> 24, &dstendoffset); - else - { - dstendfield = -1 - -sample_number_to_field(&info, -dstend >> 24, &dstendoffset); - dstendoffset = (field_to_sample_number(&info, -dstendfield) - field_to_sample_number(&info, -dstendfield - 1)) - dstendoffset; - } -/* -printf("%5d: start=%10d (%5d.%03d) end=%10d (%5d.%03d)\n", - fieldnum, - (INT32)(dstbegin >> 24), dstbeginfield, dstbeginoffset, - (INT32)(dstend >> 24), dstendfield, dstendoffset); -*/ - /* read all samples required into the end of the sound buffers */ - dstoffset = srcend - srcbegin; - for (dstfield = dstbeginfield; dstfield <= dstendfield; dstfield++) - { - if (dstfield >= 0) - read_chd(srcfile, dstfield, &info, dstoffset); - else - { - info.samples = field_to_sample_number(&info, -dstfield) - field_to_sample_number(&info, -dstfield - 1); - memset(&info.lsound[dstoffset], 0, info.samples * sizeof(info.lsound[0])); - memset(&info.rsound[dstoffset], 0, info.samples * sizeof(info.rsound[0])); - } - dstoffset += info.samples; - } - - /* resample the destination samples to the source */ - dstoffset = srcend - srcbegin; - dstpos = dstbegin; - dststep = (dstend - dstbegin) / (INT64)(srcend - srcbegin); - for (srcoffset = 0; srcoffset < srcend - srcbegin; srcoffset++) - { - info.lsound[srcoffset] = info.lsound[dstoffset + dstbeginoffset + (dstpos >> 24) - (dstbegin >> 24)]; - info.rsound[srcoffset] = info.rsound[dstoffset + dstbeginoffset + (dstpos >> 24) - (dstbegin >> 24)]; - dstpos += dststep; - } - - /* read the original frame, pointing the sound buffer past where we've calculated */ - read_chd(srcfile, fieldnum, &info, srcend - srcbegin); - - /* write it to the destination */ - write_chd(dstfile, fieldnum, &info); - } - - /* close the destination file */ - create_close_chd(dstfile); } - - /* close the source file */ - close_chd(srcfile, &info); - return 0; } diff --git a/src/tools/ldverify.c b/src/tools/ldverify.c index 45fe9f4dbf5..e974be533c3 100644 --- a/src/tools/ldverify.c +++ b/src/tools/ldverify.c @@ -41,27 +41,28 @@ #include <stdlib.h> #include <ctype.h> #include <new> +#include "coretmpl.h" #include "aviio.h" +#include "avhuff.h" #include "bitmap.h" #include "chd.h" #include "vbiparse.h" -/*************************************************************************** - CONSTANTS -***************************************************************************/ +//************************************************************************** +// CONSTANTS +//************************************************************************** -#define REPORT_BLANKS_THRESHOLD 50 +const int REPORT_BLANKS_THRESHOLD = 50; -/*************************************************************************** - TYPE DEFINITIONS -***************************************************************************/ +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** -typedef struct _movie_info movie_info; -struct _movie_info +struct movie_info { double framerate; int numframes; @@ -71,12 +72,11 @@ struct _movie_info int channels; }; -typedef struct _video_info video_info; -struct _video_info +struct video_info { int first_whitefield; - int saw_leadin; - int saw_leadout; + bool saw_leadin; + bool saw_leadout; int last_frame; int last_chapter; int cadence; @@ -95,8 +95,7 @@ struct _video_info int num_high_fields; }; -typedef struct _audio_info audio_info; -struct _audio_info +struct audio_info { int min_lsample; int min_rsample; @@ -111,315 +110,301 @@ struct _audio_info -/*************************************************************************** - GLOBAL VARIABLES -***************************************************************************/ +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** -static UINT8 chdinterlaced; +static bool chdinterlaced; -/*************************************************************************** - AVI HANDLING -***************************************************************************/ +//************************************************************************** +// AVI HANDLING +//************************************************************************** -/*------------------------------------------------- - open_avi - open an AVI file and return - information about it --------------------------------------------------*/ +//------------------------------------------------- +// open_avi - open an AVI file and return +// information about it +//------------------------------------------------- -static void *open_avi(const char *filename, movie_info *info) +static void *open_avi(const char *filename, movie_info &info) { - const avi_movie_info *aviinfo; - avi_error avierr; + // open the file avi_file *avi; - - /* open the file */ - avierr = avi_open(filename, &avi); + avi_error avierr = avi_open(filename, &avi); if (avierr != AVIERR_NONE) { fprintf(stderr, "Error opening AVI file: %s\n", avi_error_string(avierr)); return NULL; } - /* extract movie info */ - aviinfo = avi_get_movie_info(avi); - info->framerate = (double)aviinfo->video_timescale / (double)aviinfo->video_sampletime; - info->numframes = aviinfo->video_numsamples; - info->width = aviinfo->video_width; - info->height = aviinfo->video_height; - info->samplerate = aviinfo->audio_samplerate; - info->channels = aviinfo->audio_channels; - + // extract movie info + const avi_movie_info *aviinfo = avi_get_movie_info(avi); + info.framerate = (double)aviinfo->video_timescale / (double)aviinfo->video_sampletime; + info.numframes = aviinfo->video_numsamples; + info.width = aviinfo->video_width; + info.height = aviinfo->video_height; + info.samplerate = aviinfo->audio_samplerate; + info.channels = aviinfo->audio_channels; return avi; } -/*------------------------------------------------- - read_avi - read a frame from an AVI file --------------------------------------------------*/ +//------------------------------------------------- +// read_avi - read a frame from an AVI file +//------------------------------------------------- -static int read_avi(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, INT16 *rsound, int *samples) +static bool read_avi(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, INT16 *rsound, int &samples) { - const avi_movie_info *aviinfo = avi_get_movie_info((avi_file *)file); - UINT32 firstsample = ((UINT64)aviinfo->audio_samplerate * (UINT64)frame * (UINT64)aviinfo->video_sampletime + aviinfo->video_timescale - 1) / (UINT64)aviinfo->video_timescale; - UINT32 lastsample = ((UINT64)aviinfo->audio_samplerate * (UINT64)(frame + 1) * (UINT64)aviinfo->video_sampletime + aviinfo->video_timescale - 1) / (UINT64)aviinfo->video_timescale; - avi_error avierr; + avi_file *avifile = reinterpret_cast<avi_file *>(file); - /* read the frame */ - avierr = avi_read_video_frame((avi_file *)file, frame, bitmap); + // read the frame + avi_error avierr = avi_read_video_frame(avifile, frame, bitmap); if (avierr != AVIERR_NONE) return FALSE; - /* read the samples */ - avierr = avi_read_sound_samples((avi_file *)file, 0, firstsample, lastsample - firstsample, lsound); - avierr = avi_read_sound_samples((avi_file *)file, 1, firstsample, lastsample - firstsample, rsound); + // read the samples + const avi_movie_info *aviinfo = avi_get_movie_info(avifile); + UINT32 firstsample = (UINT64(aviinfo->audio_samplerate) * UINT64(frame) * UINT64(aviinfo->video_sampletime) + aviinfo->video_timescale - 1) / UINT64(aviinfo->video_timescale); + UINT32 lastsample = (UINT64(aviinfo->audio_samplerate) * UINT64(frame + 1) * UINT64(aviinfo->video_sampletime) + aviinfo->video_timescale - 1) / UINT64(aviinfo->video_timescale); + avierr = avi_read_sound_samples(avifile, 0, firstsample, lastsample - firstsample, lsound); + avierr = avi_read_sound_samples(avifile, 1, firstsample, lastsample - firstsample, rsound); if (avierr != AVIERR_NONE) - return FALSE; - *samples = lastsample - firstsample; - return TRUE; + return false; + samples = lastsample - firstsample; + return true; } -/*------------------------------------------------- - close_avi - close an AVI file --------------------------------------------------*/ +//------------------------------------------------- +// close_avi - close an AVI file +//------------------------------------------------- static void close_avi(void *file) { - avi_close((avi_file *)file); + avi_file *avifile = reinterpret_cast<avi_file *>(file); + avi_close(avifile); } -/*************************************************************************** - CHD HANDLING -***************************************************************************/ +//************************************************************************** +// CHD HANDLING +//************************************************************************** -/*------------------------------------------------- - open_chd - open a CHD file and return - information about it --------------------------------------------------*/ +//------------------------------------------------- +// open_chd - open a CHD file and return +// information about it +//------------------------------------------------- -static void *open_chd(const char *filename, movie_info *info) +static void *open_chd(const char *filename, movie_info &info) { - int fps, fpsfrac, width, height, interlaced, channels, rate; - char metadata[256]; - chd_error chderr; - chd_file *chd; + chd_file *chd = new chd_file; - /* open the file */ - chderr = chd_open(filename, CHD_OPEN_READ, NULL, &chd); + // open the file + chd_error chderr = chd->open(filename); if (chderr != CHDERR_NONE) { - fprintf(stderr, "Error opening CHD file: %s\n", chd_error_string(chderr)); + fprintf(stderr, "Error opening CHD file: %s\n", chd_file::error_string(chderr)); + delete chd; return NULL; } - /* get the metadata */ - chderr = chd_get_metadata(chd, AV_METADATA_TAG, 0, metadata, sizeof(metadata), NULL, NULL, NULL); + // get the metadata + astring metadata; + chderr = chd->read_metadata(AV_METADATA_TAG, 0, metadata); if (chderr != CHDERR_NONE) { - fprintf(stderr, "Error getting A/V metadata: %s\n", chd_error_string(chderr)); - chd_close(chd); + fprintf(stderr, "Error getting A/V metadata: %s\n", chd_file::error_string(chderr)); + delete chd; return NULL; } - /* extract the info */ + // extract the info + int fps, fpsfrac, width, height, interlaced, channels, rate; if (sscanf(metadata, AV_METADATA_FORMAT, &fps, &fpsfrac, &width, &height, &interlaced, &channels, &rate) != 7) { fprintf(stderr, "Improperly formatted metadata\n"); - chd_close(chd); + delete chd; return NULL; } - /* extract movie info */ - info->framerate = (fps * 1000000 + fpsfrac) / 1000000.0; - info->numframes = chd_get_header(chd)->totalhunks; - info->width = width; - info->height = height; - info->samplerate = rate; - info->channels = channels; + // extract movie info + info.framerate = (fps * 1000000 + fpsfrac) / 1000000.0; + info.numframes = chd->hunk_count(); + info.width = width; + info.height = height; + info.samplerate = rate; + info.channels = channels; - /* convert to an interlaced frame */ + // convert to an interlaced frame chdinterlaced = interlaced; if (interlaced) { - info->framerate /= 2; - info->numframes = (info->numframes + 1) / 2; - info->height *= 2; + info.framerate /= 2; + info.numframes = (info.numframes + 1) / 2; + info.height *= 2; } - return chd; } -/*------------------------------------------------- - read_chd - read a frame from a CHD file --------------------------------------------------*/ +//------------------------------------------------- +// read_chd - read a frame from a CHD file +//------------------------------------------------- -static int read_chd(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, INT16 *rsound, int *samples) +static int read_chd(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, INT16 *rsound, int &samples) { - av_codec_decompress_config avconfig; + chd_file *chdfile = reinterpret_cast<chd_file *>(file); + + // loop over fields int interlace_factor = chdinterlaced ? 2 : 1; - bitmap_yuy16 fakebitmap; - UINT32 numsamples; - chd_error chderr; - int fieldnum; - - /* loop over fields */ - *samples = 0; - for (fieldnum = 0; fieldnum < interlace_factor; fieldnum++) + samples = 0; + for (int fieldnum = 0; fieldnum < interlace_factor; fieldnum++) { - /* make a fake bitmap for this field */ + // make a fake bitmap for this field + avhuff_decompress_config avconfig; avconfig.video.wrap(&bitmap.pix16(fieldnum), bitmap.width(), bitmap.height() / interlace_factor, bitmap.rowpixels() * interlace_factor); - /* configure the codec */ + // configure the codec + UINT32 numsamples; avconfig.maxsamples = 48000; avconfig.actsamples = &numsamples; - avconfig.audio[0] = &lsound[*samples]; - avconfig.audio[1] = &rsound[*samples]; + avconfig.audio[0] = &lsound[samples]; + avconfig.audio[1] = &rsound[samples]; - /* configure the decompressor for this frame */ - chd_codec_config((chd_file *)file, AV_CODEC_DECOMPRESS_CONFIG, &avconfig); + // configure the decompressor for this frame + chdfile->codec_configure(CHD_CODEC_AVHUFF, AVHUFF_CODEC_DECOMPRESS_CONFIG, &avconfig); - /* read the frame */ - chderr = chd_read((chd_file *)file, frame * interlace_factor + fieldnum, NULL); + // read the frame + chd_error chderr = chdfile->read_hunk(frame * interlace_factor + fieldnum, NULL); if (chderr != CHDERR_NONE) - return FALSE; + return false; - /* account for samples read */ - *samples += numsamples; + // account for samples read + samples += numsamples; } - return TRUE; + return true; } -/*------------------------------------------------- - close_chd - close a CHD file --------------------------------------------------*/ +//------------------------------------------------- +// close_chd - close a CHD file +//------------------------------------------------- static void close_chd(void *file) { - chd_close((chd_file *)file); + chd_file *chdfile = reinterpret_cast<chd_file *>(file); + delete chdfile; } -/*************************************************************************** - CORE IMPLEMENTATION -***************************************************************************/ +//************************************************************************** +// CORE IMPLEMENTATION +//************************************************************************** -/*------------------------------------------------- - init_video - init video info structure --------------------------------------------------*/ +//------------------------------------------------- +// init_video - init video info structure +//------------------------------------------------- -static void init_video(video_info *video) +static void init_video(video_info &video) { - video->first_whitefield = -1; - video->saw_leadin = FALSE; - video->saw_leadout = FALSE; - video->last_frame = -1; - video->last_chapter = -1; - video->cadence = -1; - video->cadence_history = 0; - video->prev_whitefield = -1; - video->min_overall = 255; - video->max_overall = 0; - video->first_blank_frame = -1; - video->first_blank_field = -1; - video->num_blank_fields = -1; - video->first_low_frame = -1; - video->first_low_field = -1; - video->num_low_fields = -1; - video->first_high_frame = -1; - video->first_high_field = -1; - video->num_high_fields = -1; + video.first_whitefield = -1; + video.saw_leadin = false; + video.saw_leadout = false; + video.last_frame = -1; + video.last_chapter = -1; + video.cadence = -1; + video.cadence_history = 0; + video.prev_whitefield = -1; + video.min_overall = 255; + video.max_overall = 0; + video.first_blank_frame = -1; + video.first_blank_field = -1; + video.num_blank_fields = -1; + video.first_low_frame = -1; + video.first_low_field = -1; + video.num_low_fields = -1; + video.first_high_frame = -1; + video.first_high_field = -1; + video.num_high_fields = -1; } -/*------------------------------------------------- - verify_video - verify video frame --------------------------------------------------*/ +//------------------------------------------------- +// verify_video - verify video frame +//------------------------------------------------- -static void verify_video(video_info *video, int frame, bitmap_yuy16 &bitmap) +static void verify_video(video_info &video, int frame, bitmap_yuy16 &bitmap) { + // loop over fields const int fields_per_frame = 2; - int fieldnum; - - /* loop over fields */ - for (fieldnum = 0; fieldnum < fields_per_frame; fieldnum++) + for (int fieldnum = 0; fieldnum < fields_per_frame; fieldnum++) { - int yminval, ymaxval, cbminval, cbmaxval, crminval, crmaxval; - int field = frame * fields_per_frame + fieldnum; - int x, y, pixels, remaining; - UINT32 yhisto[256] = { 0 }; - UINT32 crhisto[256] = { 0 }; - UINT32 cbhisto[256] = { 0 }; - vbi_metadata metadata; - - /* output status */ + // output status if (frame % 10 == 0 && fieldnum == 0) fprintf(stderr, "%6d.%d...\r", frame, fieldnum); - /* parse the VBI data */ + // parse the VBI data + vbi_metadata metadata; vbi_parse_all(&bitmap.pix16(fieldnum), bitmap.rowpixels() * 2, bitmap.width(), 8, &metadata); - /* if we have data in both 17 and 18, it should match */ + // if we have data in both 17 and 18, it should match if (metadata.line17 != 0 && metadata.line18 != 0 && metadata.line17 != metadata.line18) { printf("%6d.%d: line 17 and 18 data does not match (17=%06X 18=%06X) (WARNING)\n", frame, fieldnum, metadata.line17, metadata.line18); printf("%6d.%d: selected %06X based on bit confidence\n", frame, fieldnum, metadata.line1718); } - /* is this a lead-in code? */ + // is this a lead-in code? if (metadata.line1718 == VBI_CODE_LEADIN) { - /* if we haven't seen lead-in yet, detect it */ - if (!video->saw_leadin) + // if we haven't seen lead-in yet, detect it + if (!video.saw_leadin) { - video->saw_leadin = TRUE; + video.saw_leadin = TRUE; printf("%6d.%d: lead-in code detected\n", frame, fieldnum); } - /* if we've previously seen chapters/frames, that's weird */ - if (video->last_frame != -1 || video->last_chapter != -1) + // if we've previously seen chapters/frames, that's weird + if (video.last_frame != -1 || video.last_chapter != -1) printf("%6d.%d: lead-in code detected after frame/chapter data (WARNING)\n", frame, fieldnum); } - /* is this a lead-out code? */ + // is this a lead-out code? if (metadata.line1718 == VBI_CODE_LEADOUT) { - /* if we haven't seen lead-in yet, detect it */ - if (!video->saw_leadout) + // if we haven't seen lead-in yet, detect it + if (!video.saw_leadout) { - video->saw_leadout = TRUE; + video.saw_leadout = TRUE; printf("%6d.%d: lead-out code detected\n", frame, fieldnum); - if (video->last_frame != -1) - printf("%6d.%d: final frame number was %d\n", frame, fieldnum, video->last_frame); + if (video.last_frame != -1) + printf("%6d.%d: final frame number was %d\n", frame, fieldnum, video.last_frame); else printf("%6d.%d: never detected any frame numbers (ERROR)\n", frame, fieldnum); } - /* if we've previously seen chapters/frames, that's weird */ - if (video->last_frame == -1) + // if we've previously seen chapters/frames, that's weird + if (video.last_frame == -1) printf("%6d.%d: lead-out code detected with no frames detected beforehand (WARNING)\n", frame, fieldnum); } - /* is this a frame code? */ + // is this a frame code? if ((metadata.line1718 & VBI_MASK_CAV_PICTURE) == VBI_CODE_CAV_PICTURE) { int framenum = VBI_CAV_PICTURE(metadata.line1718); - /* did we see any leadin? */ - if (!video->saw_leadin) + // did we see any leadin? + if (!video.saw_leadin) { printf("%6d.%d: detected frame number but never saw any lead-in (WARNING)\n", frame, fieldnum); - video->saw_leadin = TRUE; + video.saw_leadin = TRUE; } - /* if this is the first frame, make sure it's 1 */ - if (video->last_frame == -1) + // if this is the first frame, make sure it's 1 + if (video.last_frame == -1) { if (framenum == 0) printf("%6d.%d: detected frame 0\n", frame, fieldnum); @@ -429,99 +414,103 @@ static void verify_video(video_info *video, int frame, bitmap_yuy16 &bitmap) printf("%6d.%d: first frame number is not 0 or 1 (%d) (ERROR)\n", frame, fieldnum, framenum); } - /* print an update every 10000 frames */ + // print an update every 10000 frames if (framenum != 0 && framenum % 10000 == 0) printf("%6d.%d: detected frame %d\n", frame, fieldnum, framenum); - /* if this frame is not consecutive, it's an error */ - if (video->last_frame != -1 && framenum != video->last_frame + 1) - printf("%6d.%d: gap in frame number sequence (%d->%d) (ERROR)\n", frame, fieldnum, video->last_frame, framenum); + // if this frame is not consecutive, it's an error + if (video.last_frame != -1 && framenum != video.last_frame + 1) + printf("%6d.%d: gap in frame number sequence (%d->%d) (ERROR)\n", frame, fieldnum, video.last_frame, framenum); - /* remember the frame number */ - video->last_frame = framenum; + // remember the frame number + video.last_frame = framenum; - /* if we've seen a white flag before, but it's not here, warn */ - if (video->first_whitefield != -1 && !metadata.white) + // if we've seen a white flag before, but it's not here, warn + if (video.first_whitefield != -1 && !metadata.white) printf("%6d.%d: detected frame number but no white flag (WARNING)\n", frame, fieldnum); } - /* is the whiteflag set? */ + // is the whiteflag set? + int field = frame * fields_per_frame + fieldnum; if (metadata.white) { - /* if this is the first white flag we see, count it */ - if (video->first_whitefield == -1) + // if this is the first white flag we see, count it + if (video.first_whitefield == -1) { - video->first_whitefield = field; + video.first_whitefield = field; printf("%6d.%d: first white flag seen\n", frame, fieldnum); } - /* if we've seen frame numbers before, but not here, warn */ - if (video->last_frame != -1 && (metadata.line1718 & VBI_MASK_CAV_PICTURE) != VBI_CODE_CAV_PICTURE) + // if we've seen frame numbers before, but not here, warn + if (video.last_frame != -1 && (metadata.line1718 & VBI_MASK_CAV_PICTURE) != VBI_CODE_CAV_PICTURE) printf("%6d.%d: detected white flag but no frame number (WARNING)\n", frame, fieldnum); } - /* if this is the start of a frame, handle cadence */ + // if this is the start of a frame, handle cadence if (metadata.white || (metadata.line1718 & VBI_MASK_CAV_PICTURE) == VBI_CODE_CAV_PICTURE) { - /* if we've seen frames, but we're not yet to the lead-out, check the cadence */ - if (video->last_frame != -1 && !video->saw_leadout) + // if we've seen frames, but we're not yet to the lead-out, check the cadence + if (video.last_frame != -1 && !video.saw_leadout) { - /* make sure we have a proper history */ - if (video->prev_whitefield != -1) - video->cadence_history = (video->cadence_history << 4) | ((field - video->prev_whitefield) & 0x0f); - video->prev_whitefield = field; + // make sure we have a proper history + if (video.prev_whitefield != -1) + video.cadence_history = (video.cadence_history << 4) | ((field - video.prev_whitefield) & 0x0f); + video.prev_whitefield = field; - /* if we don't know our cadence yet, determine it */ - if (video->cadence == -1 && (video->cadence_history & 0xf00) != 0) + // if we don't know our cadence yet, determine it + if (video.cadence == -1 && (video.cadence_history & 0xf00) != 0) { - if ((video->cadence_history & 0xfff) == 0x222) + if ((video.cadence_history & 0xfff) == 0x222) { printf("%6d.%d: detected 2:2 cadence\n", frame, fieldnum); - video->cadence = 4; + video.cadence = 4; } - else if ((video->cadence_history & 0xfff) == 0x323) + else if ((video.cadence_history & 0xfff) == 0x323) { printf("%6d.%d: detected 3:2 cadence\n", frame, fieldnum); - video->cadence = 5; + video.cadence = 5; } - else if ((video->cadence_history & 0xfff) == 0x232) + else if ((video.cadence_history & 0xfff) == 0x232) { printf("%6d.%d: detected 2:3 cadence\n", frame, fieldnum); - video->cadence = 5; + video.cadence = 5; } else { printf("%6d.%d: unknown cadence (history %d:%d:%d) (WARNING)\n", frame, fieldnum, - (video->cadence_history >> 8) & 15, (video->cadence_history >> 4) & 15, video->cadence_history & 15); + (video.cadence_history >> 8) & 15, (video.cadence_history >> 4) & 15, video.cadence_history & 15); } } - /* if we know our cadence, make sure we stick to it */ - if (video->cadence != -1) + // if we know our cadence, make sure we stick to it + if (video.cadence != -1) { - if (video->cadence == 4 && (video->cadence_history & 0xfff) != 0x222) + if (video.cadence == 4 && (video.cadence_history & 0xfff) != 0x222) { printf("%6d.%d: missed cadence (history %d:%d:%d) (WARNING)\n", frame, fieldnum, - (video->cadence_history >> 8) & 15, (video->cadence_history >> 4) & 15, video->cadence_history & 15); - video->cadence = -1; - video->cadence_history = 0; + (video.cadence_history >> 8) & 15, (video.cadence_history >> 4) & 15, video.cadence_history & 15); + video.cadence = -1; + video.cadence_history = 0; } - else if (video->cadence == 5 && (video->cadence_history & 0xfff) != 0x323 && (video->cadence_history & 0xfff) != 0x232) + else if (video.cadence == 5 && (video.cadence_history & 0xfff) != 0x323 && (video.cadence_history & 0xfff) != 0x232) { printf("%6d.%d: missed cadence (history %d:%d:%d) (WARNING)\n", frame, fieldnum, - (video->cadence_history >> 8) & 15, (video->cadence_history >> 4) & 15, video->cadence_history & 15); - video->cadence = -1; - video->cadence_history = 0; + (video.cadence_history >> 8) & 15, (video.cadence_history >> 4) & 15, video.cadence_history & 15); + video.cadence = -1; + video.cadence_history = 0; } } } } - /* now examine the active video signal */ - pixels = 0; - for (y = 22*2 + fieldnum; y < bitmap.height(); y += 2) + // now examine the active video signal + UINT32 yhisto[256] = { 0 }; + UINT32 crhisto[256] = { 0 }; + UINT32 cbhisto[256] = { 0 }; + int pixels = 0; + for (int y = 22*2 + fieldnum; y < bitmap.height(); y += 2) { - for (x = 16; x < 720 - 16; x++) + for (int x = 16; x < 720 - 16; x++) { yhisto[bitmap.pix16(y, x) >> 8]++; if (x % 2 == 0) @@ -532,200 +521,204 @@ static void verify_video(video_info *video, int frame, bitmap_yuy16 &bitmap) pixels += 720 - 16 - 16; } - /* remove the top/bottom 0.1% of Y */ - remaining = pixels / 1000; + // remove the top/bottom 0.1% of Y + int remaining = pixels / 1000; + int yminval; for (yminval = 0; (remaining -= yhisto[yminval]) >= 0; yminval++) ; remaining = pixels / 1000; + int ymaxval; for (ymaxval = 255; (remaining -= yhisto[ymaxval]) >= 0; ymaxval--) ; - /* remove the top/bottom 0.1% of Cb */ + // remove the top/bottom 0.1% of Cb remaining = pixels / 500; + int cbminval; for (cbminval = 0; (remaining -= cbhisto[cbminval]) >= 0; cbminval++) ; remaining = pixels / 500; + int cbmaxval; for (cbmaxval = 255; (remaining -= cbhisto[cbmaxval]) >= 0; cbmaxval--) ; - /* remove the top/bottom 0.1% of Cr */ + // remove the top/bottom 0.1% of Cr remaining = pixels / 500; + int crminval; for (crminval = 0; (remaining -= crhisto[crminval]) >= 0; crminval++) ; remaining = pixels / 500; + int crmaxval; for (crmaxval = 255; (remaining -= crhisto[crmaxval]) >= 0; crmaxval--) ; - /* track blank frames */ + // track blank frames if (ymaxval - yminval < 10 && cbmaxval - cbminval < 10 && crmaxval - cbmaxval < 10) { - if (video->first_blank_frame == -1) + if (video.first_blank_frame == -1) { - video->first_blank_frame = frame; - video->first_blank_field = fieldnum; - video->num_blank_fields = 0; + video.first_blank_frame = frame; + video.first_blank_field = fieldnum; + video.num_blank_fields = 0; } - video->num_blank_fields++; + video.num_blank_fields++; } - else if (video->num_blank_fields > 0) + else if (video.num_blank_fields > 0) { - if (video->num_blank_fields >= REPORT_BLANKS_THRESHOLD) - printf("%6d.%d-%6d.%d: blank frames for %d fields (INFO)\n", video->first_blank_frame, video->first_blank_field, frame, fieldnum, video->num_blank_fields); - video->first_blank_frame = video->first_blank_field = video->num_blank_fields = -1; + if (video.num_blank_fields >= REPORT_BLANKS_THRESHOLD) + printf("%6d.%d-%6d.%d: blank frames for %d fields (INFO)\n", video.first_blank_frame, video.first_blank_field, frame, fieldnum, video.num_blank_fields); + video.first_blank_frame = video.first_blank_field = video.num_blank_fields = -1; } - /* update the overall min/max */ - video->min_overall = MIN(yminval, video->min_overall); - video->max_overall = MAX(ymaxval, video->max_overall); + // update the overall min/max + video.min_overall = MIN(yminval, video.min_overall); + video.max_overall = MAX(ymaxval, video.max_overall); - /* track low fields */ + // track low fields if (yminval <= 0) { - if (video->first_low_frame == -1) + if (video.first_low_frame == -1) { - video->first_low_frame = frame; - video->first_low_field = fieldnum; - video->num_low_fields = 0; + video.first_low_frame = frame; + video.first_low_field = fieldnum; + video.num_low_fields = 0; } - video->num_low_fields++; + video.num_low_fields++; } - else if (video->num_low_fields > 0) + else if (video.num_low_fields > 0) { - printf("%6d.%d-%6d.%d: active video signal level low for %d fields (WARNING)\n", video->first_low_frame, video->first_low_field, frame, fieldnum, video->num_low_fields); - video->first_low_frame = video->first_low_field = video->num_low_fields = -1; + printf("%6d.%d-%6d.%d: active video signal level low for %d fields (WARNING)\n", video.first_low_frame, video.first_low_field, frame, fieldnum, video.num_low_fields); + video.first_low_frame = video.first_low_field = video.num_low_fields = -1; } - /* track high fields */ + // track high fields if (ymaxval >= 255) { - if (video->first_high_frame == -1) + if (video.first_high_frame == -1) { - video->first_high_frame = frame; - video->first_high_field = fieldnum; - video->num_high_fields = 0; + video.first_high_frame = frame; + video.first_high_field = fieldnum; + video.num_high_fields = 0; } - video->num_high_fields++; + video.num_high_fields++; } - else if (video->num_high_fields > 0) + else if (video.num_high_fields > 0) { - printf("%6d.%d-%6d.%d: active video signal level high for %d fields (WARNING)\n", video->first_high_frame, video->first_high_field, frame, fieldnum, video->num_high_fields); - video->first_high_frame = video->first_high_field = video->num_high_fields = -1; + printf("%6d.%d-%6d.%d: active video signal level high for %d fields (WARNING)\n", video.first_high_frame, video.first_high_field, frame, fieldnum, video.num_high_fields); + video.first_high_frame = video.first_high_field = video.num_high_fields = -1; } } } -/*------------------------------------------------- - verify_video_final - final verification --------------------------------------------------*/ +//------------------------------------------------- +// verify_video_final - final verification +//------------------------------------------------- -static void verify_video_final(video_info *video, int frame, bitmap_yuy16 &bitmap) +static void verify_video_final(video_info &video, int frame, bitmap_yuy16 &bitmap) { int fields_per_frame = (bitmap.height() >= 288) ? 2 : 1; int field = frame * fields_per_frame; - /* did we ever see any white flags? */ - if (video->first_whitefield == -1) + // did we ever see any white flags? + if (video.first_whitefield == -1) printf("Track %6d.%d: never saw any white flags (WARNING)\n", field / fields_per_frame, 0); - /* did we ever see any lead-out? */ - if (!video->saw_leadout) + // did we ever see any lead-out? + if (!video.saw_leadout) printf("Track %6d.%d: never saw any lead-out (WARNING)\n", field / fields_per_frame, 0); - /* any remaining high/low reports? */ - if (video->num_blank_fields >= REPORT_BLANKS_THRESHOLD) - printf("%6d.%d-%6d.%d: blank frames for %d fields (INFO)\n", video->first_blank_frame, video->first_blank_field, frame, 0, video->num_blank_fields); - if (video->num_low_fields > 0) - printf("%6d.%d-%6d.%d: active video signal level low for %d fields (WARNING)\n", video->first_low_frame, video->first_low_field, frame, 0, video->num_low_fields); - if (video->num_high_fields > 0) - printf("%6d.%d-%6d.%d: active video signal level high for %d fields (WARNING)\n", video->first_high_frame, video->first_high_field, frame, 0, video->num_high_fields); + // any remaining high/low reports? + if (video.num_blank_fields >= REPORT_BLANKS_THRESHOLD) + printf("%6d.%d-%6d.%d: blank frames for %d fields (INFO)\n", video.first_blank_frame, video.first_blank_field, frame, 0, video.num_blank_fields); + if (video.num_low_fields > 0) + printf("%6d.%d-%6d.%d: active video signal level low for %d fields (WARNING)\n", video.first_low_frame, video.first_low_field, frame, 0, video.num_low_fields); + if (video.num_high_fields > 0) + printf("%6d.%d-%6d.%d: active video signal level high for %d fields (WARNING)\n", video.first_high_frame, video.first_high_field, frame, 0, video.num_high_fields); - /* summary info */ + // summary info printf("\nVideo summary:\n"); - printf(" Overall video range: %d-%d (%02X-%02X)\n", video->min_overall, video->max_overall, video->min_overall, video->max_overall); + printf(" Overall video range: %d-%d (%02X-%02X)\n", video.min_overall, video.max_overall, video.min_overall, video.max_overall); } -/*------------------------------------------------- - init_audio - init audio info structure --------------------------------------------------*/ +//------------------------------------------------- +// init_audio - init audio info structure +//------------------------------------------------- -static void init_audio(audio_info *audio) +static void init_audio(audio_info &audio) { - audio->min_lsample = 32767; - audio->min_rsample = 32767; - audio->max_lsample = -32768; - audio->max_rsample = -32768; - audio->min_lsample_count = 0; - audio->min_rsample_count = 0; - audio->max_lsample_count = 0; - audio->max_rsample_count = 0; - audio->sample_count = 0; + audio.min_lsample = 32767; + audio.min_rsample = 32767; + audio.max_lsample = -32768; + audio.max_rsample = -32768; + audio.min_lsample_count = 0; + audio.min_rsample_count = 0; + audio.max_lsample_count = 0; + audio.max_rsample_count = 0; + audio.sample_count = 0; } -/*------------------------------------------------- - verify_audio - verify audio data --------------------------------------------------*/ +//------------------------------------------------- +// verify_audio - verify audio data +//------------------------------------------------- -static void verify_audio(audio_info *audio, const INT16 *lsound, const INT16 *rsound, int samples) +static void verify_audio(audio_info &audio, const INT16 *lsound, const INT16 *rsound, int samples) { - int sampnum; + // count the overall samples + audio.sample_count += samples; - /* count the overall samples */ - audio->sample_count += samples; - - /* iterate over samples, tracking min/max */ - for (sampnum = 0; sampnum < samples; sampnum++) + // iterate over samples, tracking min/max + for (int sampnum = 0; sampnum < samples; sampnum++) { - /* did we hit a minimum on the left? */ - if (lsound[sampnum] < audio->min_lsample) + // did we hit a minimum on the left? + if (lsound[sampnum] < audio.min_lsample) { - audio->min_lsample = lsound[sampnum]; - audio->min_lsample_count = 1; + audio.min_lsample = lsound[sampnum]; + audio.min_lsample_count = 1; } - else if (lsound[sampnum] == audio->min_lsample) - audio->min_lsample_count++; + else if (lsound[sampnum] == audio.min_lsample) + audio.min_lsample_count++; - /* did we hit a maximum on the left? */ - if (lsound[sampnum] > audio->max_lsample) + // did we hit a maximum on the left? + if (lsound[sampnum] > audio.max_lsample) { - audio->max_lsample = lsound[sampnum]; - audio->max_lsample_count = 1; + audio.max_lsample = lsound[sampnum]; + audio.max_lsample_count = 1; } - else if (lsound[sampnum] == audio->max_lsample) - audio->max_lsample_count++; + else if (lsound[sampnum] == audio.max_lsample) + audio.max_lsample_count++; - /* did we hit a minimum on the right? */ - if (rsound[sampnum] < audio->min_rsample) + // did we hit a minimum on the right? + if (rsound[sampnum] < audio.min_rsample) { - audio->min_rsample = rsound[sampnum]; - audio->min_rsample_count = 1; + audio.min_rsample = rsound[sampnum]; + audio.min_rsample_count = 1; } - else if (rsound[sampnum] == audio->min_rsample) - audio->min_rsample_count++; + else if (rsound[sampnum] == audio.min_rsample) + audio.min_rsample_count++; - /* did we hit a maximum on the right? */ - if (rsound[sampnum] > audio->max_rsample) + // did we hit a maximum on the right? + if (rsound[sampnum] > audio.max_rsample) { - audio->max_rsample = rsound[sampnum]; - audio->max_rsample_count = 1; + audio.max_rsample = rsound[sampnum]; + audio.max_rsample_count = 1; } - else if (rsound[sampnum] == audio->max_rsample) - audio->max_rsample_count++; + else if (rsound[sampnum] == audio.max_rsample) + audio.max_rsample_count++; } } -/*------------------------------------------------- - verify_audio_final - final verification --------------------------------------------------*/ +//------------------------------------------------- +// verify_audio_final - final verification +//------------------------------------------------- -static void verify_audio_final(audio_info *audio) +static void verify_audio_final(audio_info &audio) { printf("\nAudio summary:\n"); - printf(" Overall channel 0 range: %d-%d (%04X-%04X)\n", audio->min_lsample, audio->max_lsample, (UINT16)audio->min_lsample, (UINT16)audio->max_lsample); - printf(" Overall channel 1 range: %d-%d (%04X-%04X)\n", audio->min_rsample, audio->max_rsample, (UINT16)audio->min_rsample, (UINT16)audio->max_rsample); + printf(" Overall channel 0 range: %d-%d (%04X-%04X)\n", audio.min_lsample, audio.max_lsample, UINT16(audio.min_lsample), UINT16(audio.max_lsample)); + printf(" Overall channel 1 range: %d-%d (%04X-%04X)\n", audio.min_rsample, audio.max_rsample, UINT16(audio.min_rsample), UINT16(audio.max_rsample)); } -/*------------------------------------------------- - usage - display program usage --------------------------------------------------*/ +//------------------------------------------------- +// usage - display program usage +//------------------------------------------------- static int usage(void) { @@ -735,108 +728,87 @@ static int usage(void) } -/*------------------------------------------------- - main - main entry point --------------------------------------------------*/ +//------------------------------------------------- +// main - main entry point +//------------------------------------------------- int main(int argc, char *argv[]) { try { - movie_info info = { 0 }; - INT16 *lsound, *rsound; - const char *srcfile; - bitmap_yuy16 bitmap; - int srcfilelen; - int samples = 0; - void *file; - int isavi; - int frame; + // init globals audio_info audio; + init_audio(audio); video_info video; + init_video(video); - /* init globals */ - init_audio(&audio); - init_video(&video); - - /* verify arguments */ + // verify arguments if (argc < 2) return usage(); - srcfile = argv[1]; + const char *srcfile = argv[1]; - /* check extension of file */ - srcfilelen = strlen(srcfile); + // check extension of file + int srcfilelen = strlen(srcfile); if (srcfilelen < 4) return usage(); + bool isavi; if (tolower((UINT8)srcfile[srcfilelen-3]) == 'a' && tolower((UINT8)srcfile[srcfilelen-2]) == 'v' && tolower((UINT8)srcfile[srcfilelen-1]) == 'i') - isavi = TRUE; + isavi = true; else if (tolower((UINT8)srcfile[srcfilelen-3]) == 'c' && tolower((UINT8)srcfile[srcfilelen-2]) == 'h' && tolower((UINT8)srcfile[srcfilelen-1]) == 'd') - isavi = FALSE; + isavi = false; else return usage(); - /* open the file */ + // open the file printf("Processing file: %s\n", srcfile); - file = isavi ? open_avi(srcfile, &info) : open_chd(srcfile, &info); + movie_info info = { 0 }; + void *file = isavi ? open_avi(srcfile, info) : open_chd(srcfile, info); if (file == NULL) { fprintf(stderr, "Unable to open file '%s'\n", srcfile); return 1; } - /* comment on the video dimensions */ + // comment on the video dimensions printf("Video dimensions: %dx%d\n", info.width, info.height); if (info.width != 720) printf("WARNING: Unexpected video width (should be 720)\n"); if (info.height != 524) printf("WARNING: Unexpected video height (should be 262 or 524)\n"); - /* comment on the video frame rate */ + // comment on the video frame rate printf("Video frame rate: %.2fHz\n", info.framerate); - if ((int)(info.framerate * 100.0 + 0.5) != 2997) + if (int(info.framerate * 100.0 + 0.5) != 2997) printf("WARNING: Unexpected frame rate (should be 29.97Hz)\n"); - /* comment on the sample rate */ + // comment on the sample rate printf("Sample rate: %dHz\n", info.samplerate); if (info.samplerate != 48000) printf("WARNING: Unexpected sampele rate (should be 48000Hz)\n"); - /* allocate a bitmap */ - bitmap.allocate(info.width, info.height); + // allocate a bitmap + bitmap_yuy16 bitmap(info.width, info.height); - /* allocate sound buffers */ - lsound = (INT16 *)malloc(info.samplerate * sizeof(*lsound)); - rsound = (INT16 *)malloc(info.samplerate * sizeof(*rsound)); - if (lsound == NULL || rsound == NULL) - { - isavi ? close_avi(file) : close_chd(file); - if (rsound != NULL) - free(rsound); - if (lsound != NULL) - free(lsound); - fprintf(stderr, "Out of memory allocating sound buffers of %d bytes\n", (INT32)(info.samplerate * sizeof(*rsound))); - return 1; - } + // allocate sound buffers + dynamic_array<INT16> lsound(info.samplerate); + dynamic_array<INT16> rsound(info.samplerate); - /* loop over frames */ - frame = 0; - while (isavi ? read_avi(file, frame, bitmap, lsound, rsound, &samples) : read_chd(file, frame, bitmap, lsound, rsound, &samples)) + // loop over frames + int frame = 0; + int samples = 0; + while (isavi ? read_avi(file, frame, bitmap, lsound, rsound, samples) : read_chd(file, frame, bitmap, lsound, rsound, samples)) { - verify_video(&video, frame, bitmap); - verify_audio(&audio, lsound, rsound, samples); + verify_video(video, frame, bitmap); + verify_audio(audio, lsound, rsound, samples); frame++; } - /* close the files */ + // close the files isavi ? close_avi(file) : close_chd(file); - /* final output */ - verify_video_final(&video, frame, bitmap); - verify_audio_final(&audio); - - /* free memory */ - free(lsound); - free(rsound); + // final output + verify_video_final(video, frame, bitmap); + verify_audio_final(audio); } catch (std::bad_alloc &) { diff --git a/src/tools/tools.mak b/src/tools/tools.mak index 5625c01d2a8..a8504e78e8a 100644 --- a/src/tools/tools.mak +++ b/src/tools/tools.mak @@ -124,7 +124,7 @@ unidasm$(EXE): $(UNIDASMOBJS) $(LIBDASM) $(LIBEMU) $(LIBUTIL) $(LIBOCORE) $(ZLIB LDRESAMPLEOBJS = \ $(TOOLSOBJ)/ldresample.o \ -ldresample$(EXE): $(LDRESAMPLEOBJS) $(LIBUTIL) $(LIBOCORE) $(ZLIB) $(FLAC_LIB) $(EXPAT) +ldresample$(EXE): $(LDRESAMPLEOBJS) $(LIBUTIL) $(LIBOCORE) $(ZLIB) $(FLAC_LIB) $(7Z_LIB) $(EXPAT) @echo Linking $@... $(LD) $(LDFLAGS) $^ $(LIBS) $(FLAC_LIB) -o $@ @@ -137,7 +137,7 @@ ldresample$(EXE): $(LDRESAMPLEOBJS) $(LIBUTIL) $(LIBOCORE) $(ZLIB) $(FLAC_LIB) $ LDVERIFYOBJS = \ $(TOOLSOBJ)/ldverify.o \ -ldverify$(EXE): $(LDVERIFYOBJS) $(LIBUTIL) $(LIBOCORE) $(ZLIB) $(FLAC_LIB) $(EXPAT) +ldverify$(EXE): $(LDVERIFYOBJS) $(LIBUTIL) $(LIBOCORE) $(ZLIB) $(FLAC_LIB) $(7Z_LIB) $(EXPAT) @echo Linking $@... $(LD) $(LDFLAGS) $^ $(LIBS) $(FLAC_LIB) -o $@ |