src/mame/drivers/segas16b.c
| r14546 | r14547 | |
| 3711 | 3711 | CPU: 68000 + i8751 (317-0076) |
| 3712 | 3712 | ROM Board: 171-5521 |
| 3713 | 3713 | */ |
| 3714 | | ROM_START( altbeast5 ) |
| 3714 | ROM_START( altbeast6 ) |
| 3715 | 3715 | ROM_REGION( 0xc0000, "maincpu", 0 ) /* 68000 code */ |
| 3716 | 3716 | ROM_LOAD16_BYTE( "epr-11883.a7", 0x000000, 0x20000, CRC(c5b3e8f7) SHA1(06c59d38093330b74f685cb02f8c7311e4a7b38c) ) |
| 3717 | 3717 | ROM_LOAD16_BYTE( "epr-11882.a5", 0x000001, 0x20000, CRC(9c01170b) SHA1(7651f791e5488ce1143eeb4ad01eb924d1460170) ) |
| r14546 | r14547 | |
| 3751 | 3751 | |
| 3752 | 3752 | /************************************************************************************************************************** |
| 3753 | 3753 | Altered Beast, Sega System 16B |
| 3754 | CPU: FD1094 (317-0069) |
| 3755 | ROM Board: 171-5521 |
| 3756 | Sega ID# for ROM board: 834-6661-07 |
| 3757 | */ |
| 3758 | ROM_START( altbeast5 ) |
| 3759 | ROM_REGION( 0x040000, "maincpu", 0 ) /* 68000 code */ |
| 3760 | ROM_LOAD16_BYTE( "epr-11742.a7", 0x000000, 0x20000, CRC(61839534) SHA1(0246985ec642fb44d33acbbbec9f6a1936afb302) ) |
| 3761 | ROM_LOAD16_BYTE( "epr-11741.a5", 0x000001, 0x20000, CRC(9b2159cb) SHA1(dba53afcbb42be3e2611d00324bca6544faec071) ) |
| 3762 | |
| 3763 | ROM_REGION( 0x2000, "user1", 0 ) /* decryption key */ |
| 3764 | ROM_LOAD( "317-0069.key", 0x0000, 0x2000, CRC(959e256a) SHA1(392832620ddbe549b3a807ef226dadbf861a16ee) ) /* The "9" was printed over a "3" */ |
| 3765 | |
| 3766 | ROM_REGION( 0xc0000, "gfx1", 0 ) /* tiles */ |
| 3767 | ROM_LOAD( "epr-11722.a14", 0x00000, 0x10000, CRC(adaa8db5) SHA1(3262c98d13d08c333d16052cac841f44d2f99743) ) /* plane 1 */ |
| 3768 | ROM_LOAD( "epr-11736.b14", 0x20000, 0x10000, CRC(e9ad5e89) SHA1(769628eee6e194a84aa8a3729f4e7d07dd3ba25c) ) |
| 3769 | ROM_LOAD( "epr-11723.a15", 0x40000, 0x10000, CRC(131a3f9a) SHA1(8182c3b8ce7a2f02b226cfa2081187593c9d0d0b) ) /* plane 2 */ |
| 3770 | ROM_LOAD( "epr-11737.b15", 0x60000, 0x10000, CRC(2e420023) SHA1(3aa2c3b6fccafb4d53b6ab99b95181d3eed7c77f) ) |
| 3771 | ROM_LOAD( "epr-11724.a16", 0x80000, 0x10000, CRC(6f2ed50a) SHA1(55d0c4299e7240b0ef5316b48db7a158145c76ab) ) /* plane 3 */ |
| 3772 | ROM_LOAD( "epr-11738.b16", 0xa0000, 0x10000, CRC(de3d6d02) SHA1(428811f21c68761022521a17fc4716f6e7214b20) ) |
| 3773 | |
| 3774 | ROM_REGION16_BE( 0x200000, "gfx2", 0 ) /* sprites */ |
| 3775 | ROM_LOAD16_BYTE( "epr-11725.b1", 0x000001, 0x010000, CRC(f8b3684e) SHA1(3de2685cae5fb3c954b8440fafce313072747469) ) |
| 3776 | ROM_LOAD16_BYTE( "epr-11729.b5", 0x000000, 0x010000, CRC(ae3c2793) SHA1(c4f46861ea63ffa3c038a1ef931479b94e5382df) ) |
| 3777 | ROM_LOAD16_BYTE( "epr-11726.b2", 0x040001, 0x010000, CRC(3cce5419) SHA1(fccdbd6d05f5927272e7d6e5f997418d4fa2baf5) ) |
| 3778 | ROM_LOAD16_BYTE( "epr-11730.b6", 0x040000, 0x010000, CRC(3af62b55) SHA1(9f079af88aaf2447948c9ac01c6cbd1e79539704) ) |
| 3779 | ROM_LOAD16_BYTE( "epr-11727.b3", 0x080001, 0x010000, CRC(b0390078) SHA1(9035d9f45c67bdc802710018722943f5b63e8b5d) ) |
| 3780 | ROM_LOAD16_BYTE( "epr-11731.b7", 0x080000, 0x010000, CRC(2a87744a) SHA1(421b3926de046ddeddad05f65fc6b5078af28dbd) ) |
| 3781 | ROM_LOAD16_BYTE( "epr-11728.b4", 0x0c0001, 0x010000, CRC(f3a43fd8) SHA1(d42833ecd0c1920f1a6904d32c096f12d8622141) ) |
| 3782 | ROM_LOAD16_BYTE( "epr-11732.b8", 0x0c0000, 0x010000, CRC(2fb3e355) SHA1(960e0a66b23f79833b011ea35a5a412dffb47083) ) |
| 3783 | ROM_LOAD16_BYTE( "epr-11717.a1", 0x100001, 0x010000, CRC(676be0cb) SHA1(1e7d4c5f231992f111cc7885e97bc5a7267a5e89) ) |
| 3784 | ROM_LOAD16_BYTE( "epr-11733.b10", 0x100000, 0x010000, CRC(802cac94) SHA1(24e5aa74ce8b6c53c78cc33a41a473df3fbce639) ) |
| 3785 | ROM_LOAD16_BYTE( "epr-11718.a2", 0x140001, 0x010000, CRC(882864c2) SHA1(bd44bbdc13e5fd1b5c31c343da00a75b9dd90478) ) |
| 3786 | ROM_LOAD16_BYTE( "epr-11734.b11", 0x140000, 0x010000, CRC(76c704d2) SHA1(35b393071e29b8d122d3f904b923689a7dddc808) ) |
| 3787 | ROM_LOAD16_BYTE( "epr-11719.a3", 0x180001, 0x010000, CRC(339987f7) SHA1(b5650f8bdbd44510e84686b20daf70bc4a564f28) ) |
| 3788 | ROM_LOAD16_BYTE( "epr-11735.b12", 0x180000, 0x010000, CRC(4fe406aa) SHA1(7f068b81f35be4cc4785824ed524d28f201ff0a5) ) |
| 3789 | |
| 3790 | ROM_REGION( 0x50000, "soundcpu", 0 ) /* sound CPU */ |
| 3791 | ROM_LOAD( "epr-11671.a10", 0x00000, 0x08000, CRC(2b71343b) SHA1(8a657f787de2b9d5161ed2c109642a148348af09) ) |
| 3792 | ROM_LOAD( "opr-11672.a11", 0x10000, 0x20000, CRC(bbd7f460) SHA1(bbc5c2219cb3a827d84062b19affd9780da2a3cf) ) |
| 3793 | ROM_LOAD( "opr-11673.a12", 0x30000, 0x20000, CRC(400c4a36) SHA1(de4bdfa91734410e0a7f6a16bf8336db172f458a) ) |
| 3794 | ROM_END |
| 3795 | |
| 3796 | /************************************************************************************************************************** |
| 3797 | Altered Beast, Sega System 16B |
| 3754 | 3798 | CPU: 68000 + MC-8123B 317-0066 |
| 3755 | 3799 | ROM Board: 171-5521 |
| 3756 | 3800 | Sega ID# for ROM board: 834-6661-06 |
| r14546 | r14547 | |
| 3873 | 3917 | |
| 3874 | 3918 | /************************************************************************************************************************** |
| 3875 | 3919 | Jyuohki (Altered Beast), Sega System 16B |
| 3876 | | CPU: FD1094 (317-0069) |
| 3877 | | ROM Board: 171-5521 |
| 3878 | | Sega ID# for ROM board: 834-6661-07 |
| 3879 | | */ |
| 3880 | | ROM_START( altbeastj2 ) |
| 3881 | | ROM_REGION( 0x040000, "maincpu", 0 ) /* 68000 code */ |
| 3882 | | ROM_LOAD16_BYTE( "epr-11742.a7", 0x000000, 0x20000, CRC(61839534) SHA1(0246985ec642fb44d33acbbbec9f6a1936afb302) ) |
| 3883 | | ROM_LOAD16_BYTE( "epr-11741.a5", 0x000001, 0x20000, CRC(9b2159cb) SHA1(dba53afcbb42be3e2611d00324bca6544faec071) ) |
| 3884 | | |
| 3885 | | ROM_REGION( 0x2000, "user1", 0 ) /* decryption key */ |
| 3886 | | ROM_LOAD( "317-0069.key", 0x0000, 0x2000, NO_DUMP ) /* The "9" was printed over a "3" */ |
| 3887 | | |
| 3888 | | ROM_REGION( 0xc0000, "gfx1", 0 ) /* tiles */ |
| 3889 | | ROM_LOAD( "epr-11722.a14", 0x00000, 0x10000, CRC(adaa8db5) SHA1(3262c98d13d08c333d16052cac841f44d2f99743) ) /* plane 1 */ |
| 3890 | | ROM_LOAD( "epr-11736.b14", 0x20000, 0x10000, CRC(e9ad5e89) SHA1(769628eee6e194a84aa8a3729f4e7d07dd3ba25c) ) |
| 3891 | | ROM_LOAD( "epr-11723.a15", 0x40000, 0x10000, CRC(131a3f9a) SHA1(8182c3b8ce7a2f02b226cfa2081187593c9d0d0b) ) /* plane 2 */ |
| 3892 | | ROM_LOAD( "epr-11737.b15", 0x60000, 0x10000, CRC(2e420023) SHA1(3aa2c3b6fccafb4d53b6ab99b95181d3eed7c77f) ) |
| 3893 | | ROM_LOAD( "epr-11724.a16", 0x80000, 0x10000, CRC(6f2ed50a) SHA1(55d0c4299e7240b0ef5316b48db7a158145c76ab) ) /* plane 3 */ |
| 3894 | | ROM_LOAD( "epr-11738.b16", 0xa0000, 0x10000, CRC(de3d6d02) SHA1(428811f21c68761022521a17fc4716f6e7214b20) ) |
| 3895 | | |
| 3896 | | ROM_REGION16_BE( 0x200000, "gfx2", 0 ) /* sprites */ |
| 3897 | | ROM_LOAD16_BYTE( "epr-11725.b1", 0x000001, 0x010000, CRC(f8b3684e) SHA1(3de2685cae5fb3c954b8440fafce313072747469) ) |
| 3898 | | ROM_LOAD16_BYTE( "epr-11729.b5", 0x000000, 0x010000, CRC(ae3c2793) SHA1(c4f46861ea63ffa3c038a1ef931479b94e5382df) ) |
| 3899 | | ROM_LOAD16_BYTE( "epr-11726.b2", 0x040001, 0x010000, CRC(3cce5419) SHA1(fccdbd6d05f5927272e7d6e5f997418d4fa2baf5) ) |
| 3900 | | ROM_LOAD16_BYTE( "epr-11730.b6", 0x040000, 0x010000, CRC(3af62b55) SHA1(9f079af88aaf2447948c9ac01c6cbd1e79539704) ) |
| 3901 | | ROM_LOAD16_BYTE( "epr-11727.b3", 0x080001, 0x010000, CRC(b0390078) SHA1(9035d9f45c67bdc802710018722943f5b63e8b5d) ) |
| 3902 | | ROM_LOAD16_BYTE( "epr-11731.b7", 0x080000, 0x010000, CRC(2a87744a) SHA1(421b3926de046ddeddad05f65fc6b5078af28dbd) ) |
| 3903 | | ROM_LOAD16_BYTE( "epr-11728.b4", 0x0c0001, 0x010000, CRC(f3a43fd8) SHA1(d42833ecd0c1920f1a6904d32c096f12d8622141) ) |
| 3904 | | ROM_LOAD16_BYTE( "epr-11732.b8", 0x0c0000, 0x010000, CRC(2fb3e355) SHA1(960e0a66b23f79833b011ea35a5a412dffb47083) ) |
| 3905 | | ROM_LOAD16_BYTE( "epr-11717.a1", 0x100001, 0x010000, CRC(676be0cb) SHA1(1e7d4c5f231992f111cc7885e97bc5a7267a5e89) ) |
| 3906 | | ROM_LOAD16_BYTE( "epr-11733.b10", 0x100000, 0x010000, CRC(802cac94) SHA1(24e5aa74ce8b6c53c78cc33a41a473df3fbce639) ) |
| 3907 | | ROM_LOAD16_BYTE( "epr-11718.a2", 0x140001, 0x010000, CRC(882864c2) SHA1(bd44bbdc13e5fd1b5c31c343da00a75b9dd90478) ) |
| 3908 | | ROM_LOAD16_BYTE( "epr-11734.b11", 0x140000, 0x010000, CRC(76c704d2) SHA1(35b393071e29b8d122d3f904b923689a7dddc808) ) |
| 3909 | | ROM_LOAD16_BYTE( "epr-11719.a3", 0x180001, 0x010000, CRC(339987f7) SHA1(b5650f8bdbd44510e84686b20daf70bc4a564f28) ) |
| 3910 | | ROM_LOAD16_BYTE( "epr-11735.b12", 0x180000, 0x010000, CRC(4fe406aa) SHA1(7f068b81f35be4cc4785824ed524d28f201ff0a5) ) |
| 3911 | | |
| 3912 | | ROM_REGION( 0x50000, "soundcpu", 0 ) /* sound CPU */ |
| 3913 | | ROM_LOAD( "epr-11671.a10", 0x00000, 0x08000, CRC(2b71343b) SHA1(8a657f787de2b9d5161ed2c109642a148348af09) ) |
| 3914 | | ROM_LOAD( "opr-11672.a11", 0x10000, 0x20000, CRC(bbd7f460) SHA1(bbc5c2219cb3a827d84062b19affd9780da2a3cf) ) |
| 3915 | | ROM_LOAD( "opr-11673.a12", 0x30000, 0x20000, CRC(400c4a36) SHA1(de4bdfa91734410e0a7f6a16bf8336db172f458a) ) |
| 3916 | | ROM_END |
| 3917 | | |
| 3918 | | /************************************************************************************************************************** |
| 3919 | | Jyuohki (Altered Beast), Sega System 16B |
| 3920 | 3920 | CPU: FD1094 (317-0065) |
| 3921 | 3921 | ROM Board: 171-5521 |
| 3922 | 3922 | */ |
| r14546 | r14547 | |
| 3932 | 3932 | ROM_LOAD( "opr-11674.a14", 0x00000, 0x20000, CRC(a57a66d5) SHA1(5103583d48997abad12a0c5fee26431c486ced52) ) |
| 3933 | 3933 | ROM_LOAD( "opr-11675.a15", 0x20000, 0x20000, CRC(2ef2f144) SHA1(38d22d609db2d9b6067b5d12f6499436de4605cb) ) |
| 3934 | 3934 | ROM_LOAD( "opr-11676.a16", 0x40000, 0x20000, CRC(0c04acac) SHA1(87fe2a0dd9913f9550e9b4cbc7e7465b61640e07) ) |
| 3935 | | /* If this is truly a Japanese set it should use these roms: |
| 3936 | | ROM_LOAD( "epr-11722.a14", 0x00000, 0x10000, CRC(adaa8db5) SHA1(3262c98d13d08c333d16052cac841f44d2f99743) ) |
| 3937 | | ROM_LOAD( "epr-11736.b14", 0x20000, 0x10000, CRC(e9ad5e89) SHA1(769628eee6e194a84aa8a3729f4e7d07dd3ba25c) ) |
| 3938 | | ROM_LOAD( "epr-11723.a15", 0x40000, 0x10000, CRC(131a3f9a) SHA1(8182c3b8ce7a2f02b226cfa2081187593c9d0d0b) ) |
| 3939 | | ROM_LOAD( "epr-11737.b15", 0x60000, 0x10000, CRC(2e420023) SHA1(3aa2c3b6fccafb4d53b6ab99b95181d3eed7c77f) ) |
| 3940 | | ROM_LOAD( "epr-11724.a16", 0x80000, 0x10000, CRC(6f2ed50a) SHA1(55d0c4299e7240b0ef5316b48db7a158145c76ab) ) |
| 3941 | | ROM_LOAD( "epr-11738.b16", 0xa0000, 0x10000, CRC(de3d6d02) SHA1(428811f21c68761022521a17fc4716f6e7214b20) ) |
| 3942 | | */ |
| 3943 | 3935 | |
| 3944 | 3936 | ROM_REGION16_BE( 0x100000, "gfx2", 0 ) /* sprites */ |
| 3945 | 3937 | ROM_LOAD16_BYTE( "epr-11677.b1", 0x00001, 0x20000, CRC(a01425cd) SHA1(72be5ec29e476601f9bf6aaedef9b73cedeb42f0) ) |
| r14546 | r14547 | |
| 3950 | 3942 | ROM_LOAD16_BYTE( "epr-11683.b7", 0x80000, 0x20000, CRC(f9a60f06) SHA1(0cffcfdb02733feaa869198b7e668c58b47c321a) ) |
| 3951 | 3943 | ROM_LOAD16_BYTE( "epr-11680.b4", 0xc0001, 0x20000, CRC(f43dcdec) SHA1(2941500cf33afca487f19f2329033d5d17aad826) ) |
| 3952 | 3944 | ROM_LOAD16_BYTE( "epr-11684.b8", 0xc0000, 0x20000, CRC(b20c0edb) SHA1(6c8694d05e3adac37c9015037ab800233371db36) ) |
| 3953 | | /* If this is truly a Japanese set it should use these roms: |
| 3954 | | ROM_LOAD16_BYTE( "epr-11725.b1", 0x000001, 0x010000, CRC(f8b3684e) SHA1(3de2685cae5fb3c954b8440fafce313072747469) ) |
| 3955 | | ROM_LOAD16_BYTE( "epr-11729.b5", 0x000000, 0x010000, CRC(ae3c2793) SHA1(c4f46861ea63ffa3c038a1ef931479b94e5382df) ) |
| 3956 | | ROM_LOAD16_BYTE( "epr-11726.b2", 0x040001, 0x010000, CRC(3cce5419) SHA1(fccdbd6d05f5927272e7d6e5f997418d4fa2baf5) ) |
| 3957 | | ROM_LOAD16_BYTE( "epr-11730.b6", 0x040000, 0x010000, CRC(3af62b55) SHA1(9f079af88aaf2447948c9ac01c6cbd1e79539704) ) |
| 3958 | | ROM_LOAD16_BYTE( "epr-11727.b3", 0x080001, 0x010000, CRC(b0390078) SHA1(9035d9f45c67bdc802710018722943f5b63e8b5d) ) |
| 3959 | | ROM_LOAD16_BYTE( "epr-11731.b7", 0x080000, 0x010000, CRC(2a87744a) SHA1(421b3926de046ddeddad05f65fc6b5078af28dbd) ) |
| 3960 | | ROM_LOAD16_BYTE( "epr-11728.b4", 0x0c0001, 0x010000, CRC(f3a43fd8) SHA1(d42833ecd0c1920f1a6904d32c096f12d8622141) ) |
| 3961 | | ROM_LOAD16_BYTE( "epr-11732.b8", 0x0c0000, 0x010000, CRC(2fb3e355) SHA1(960e0a66b23f79833b011ea35a5a412dffb47083) ) |
| 3962 | | ROM_LOAD16_BYTE( "epr-11717.a1", 0x100001, 0x010000, CRC(676be0cb) SHA1(1e7d4c5f231992f111cc7885e97bc5a7267a5e89) ) |
| 3963 | | ROM_LOAD16_BYTE( "epr-11733.b10", 0x100000, 0x010000, CRC(802cac94) SHA1(24e5aa74ce8b6c53c78cc33a41a473df3fbce639) ) |
| 3964 | | ROM_LOAD16_BYTE( "epr-11718.a2", 0x140001, 0x010000, CRC(882864c2) SHA1(bd44bbdc13e5fd1b5c31c343da00a75b9dd90478) ) |
| 3965 | | ROM_LOAD16_BYTE( "epr-11734.b11", 0x140000, 0x010000, CRC(76c704d2) SHA1(35b393071e29b8d122d3f904b923689a7dddc808) ) |
| 3966 | | ROM_LOAD16_BYTE( "epr-11719.a3", 0x180001, 0x010000, CRC(339987f7) SHA1(b5650f8bdbd44510e84686b20daf70bc4a564f28) ) |
| 3967 | | ROM_LOAD16_BYTE( "epr-11735.b12", 0x180000, 0x010000, CRC(4fe406aa) SHA1(7f068b81f35be4cc4785824ed524d28f201ff0a5) ) |
| 3968 | | */ |
| 3969 | 3945 | |
| 3970 | 3946 | ROM_REGION( 0x50000, "soundcpu", 0 ) /* sound CPU */ |
| 3971 | 3947 | ROM_LOAD( "epr-11671.a10", 0x00000, 0x08000, CRC(2b71343b) SHA1(8a657f787de2b9d5161ed2c109642a148348af09) ) |
| r14546 | r14547 | |
| 6682 | 6658 | |
| 6683 | 6659 | GAME( 1988, altbeast, 0, system16b_8751, altbeast, altbeast_5521, ROT0, "Sega", "Altered Beast (set 8, 8751 317-0078)", 0 ) |
| 6684 | 6660 | GAME( 1988, altbeastj, altbeast, system16b_8751, altbeast, altbeasj_5521, ROT0, "Sega", "Juuouki (set 7, Japan, 8751 317-0077)", 0 ) |
| 6685 | | GAME( 1988, altbeast5, altbeast, system16b_8751, altbeast, altbeas5_5521, ROT0, "Sega", "Altered Beast (set 6, 8751 317-0076)", 0 ) |
| 6661 | GAME( 1988, altbeast6, altbeast, system16b_8751, altbeast, altbeas5_5521, ROT0, "Sega", "Altered Beast (set 6, 8751 317-0076)", 0 ) |
| 6662 | GAME( 1988, altbeast5, altbeast, system16b, altbeast, generic_5521, ROT0, "Sega", "Altered Beast (set 5, FD1094 317-0069)", 0 ) |
| 6686 | 6663 | GAME( 1988, altbeast4, altbeast, system16b, altbeast, altbeas4_5521, ROT0, "Sega", "Altered Beast (set 4, MC-8123B 317-0066)", 0 ) |
| 6687 | 6664 | GAME( 1988, altbeastj3, altbeast, system16b, altbeast, generic_5521, ROT0, "Sega", "Juuouki (set 3, Japan, FD1094 317-0068)", 0 ) |
| 6688 | 6665 | GAME( 1988, altbeast2, altbeast, system16b, altbeast, altbeas4_5521, ROT0, "Sega", "Altered Beast (set 2, MC-8123B 317-0066)", 0 ) |
| 6689 | 6666 | GAME( 1988, altbeastj1, altbeast, system16b, altbeast, generic_5521, ROT0, "Sega", "Juuouki (set 1, Japan, FD1094 317-0065)", GAME_NOT_WORKING ) /* No CPU decrypt key */ |
| 6690 | | GAME( 1988, altbeastj2, altbeast, system16b, altbeast, generic_5521, ROT0, "Sega", "Juuouki (set 5, Japan, FD1094 317-0069)", GAME_NOT_WORKING ) /* No CPU decrypt key */ |
| 6691 | 6667 | |
| 6692 | 6668 | GAME( 1990, aurail, 0, system16b, aurail, generic_5704, ROT0, "Sega / Westone", "Aurail (set 3, US, unprotected)", 0 ) |
| 6693 | 6669 | GAME( 1990, aurail1, aurail, system16b, aurail, aurail1_5704, ROT0, "Sega / Westone", "Aurail (set 2, World, FD1089B 317-0168)", 0 ) |
src/tools/ldverify.c
| r14546 | r14547 | |
| 41 | 41 | #include <stdlib.h> |
| 42 | 42 | #include <ctype.h> |
| 43 | 43 | #include <new> |
| 44 | #include "coretmpl.h" |
| 44 | 45 | #include "aviio.h" |
| 46 | #include "avhuff.h" |
| 45 | 47 | #include "bitmap.h" |
| 46 | 48 | #include "chd.h" |
| 47 | 49 | #include "vbiparse.h" |
| 48 | 50 | |
| 49 | 51 | |
| 50 | 52 | |
| 51 | | /*************************************************************************** |
| 52 | | CONSTANTS |
| 53 | | ***************************************************************************/ |
| 53 | //************************************************************************** |
| 54 | // CONSTANTS |
| 55 | //************************************************************************** |
| 54 | 56 | |
| 55 | | #define REPORT_BLANKS_THRESHOLD 50 |
| 57 | const int REPORT_BLANKS_THRESHOLD = 50; |
| 56 | 58 | |
| 57 | 59 | |
| 58 | 60 | |
| 59 | | /*************************************************************************** |
| 60 | | TYPE DEFINITIONS |
| 61 | | ***************************************************************************/ |
| 61 | //************************************************************************** |
| 62 | // TYPE DEFINITIONS |
| 63 | //************************************************************************** |
| 62 | 64 | |
| 63 | | typedef struct _movie_info movie_info; |
| 64 | | struct _movie_info |
| 65 | struct movie_info |
| 65 | 66 | { |
| 66 | 67 | double framerate; |
| 67 | 68 | int numframes; |
| r14546 | r14547 | |
| 71 | 72 | int channels; |
| 72 | 73 | }; |
| 73 | 74 | |
| 74 | | typedef struct _video_info video_info; |
| 75 | | struct _video_info |
| 75 | struct video_info |
| 76 | 76 | { |
| 77 | 77 | int first_whitefield; |
| 78 | | int saw_leadin; |
| 79 | | int saw_leadout; |
| 78 | bool saw_leadin; |
| 79 | bool saw_leadout; |
| 80 | 80 | int last_frame; |
| 81 | 81 | int last_chapter; |
| 82 | 82 | int cadence; |
| r14546 | r14547 | |
| 95 | 95 | int num_high_fields; |
| 96 | 96 | }; |
| 97 | 97 | |
| 98 | | typedef struct _audio_info audio_info; |
| 99 | | struct _audio_info |
| 98 | struct audio_info |
| 100 | 99 | { |
| 101 | 100 | int min_lsample; |
| 102 | 101 | int min_rsample; |
| r14546 | r14547 | |
| 111 | 110 | |
| 112 | 111 | |
| 113 | 112 | |
| 114 | | /*************************************************************************** |
| 115 | | GLOBAL VARIABLES |
| 116 | | ***************************************************************************/ |
| 113 | //************************************************************************** |
| 114 | // GLOBAL VARIABLES |
| 115 | //************************************************************************** |
| 117 | 116 | |
| 118 | | static UINT8 chdinterlaced; |
| 117 | static bool chdinterlaced; |
| 119 | 118 | |
| 120 | 119 | |
| 121 | 120 | |
| 122 | | /*************************************************************************** |
| 123 | | AVI HANDLING |
| 124 | | ***************************************************************************/ |
| 121 | //************************************************************************** |
| 122 | // AVI HANDLING |
| 123 | //************************************************************************** |
| 125 | 124 | |
| 126 | | /*------------------------------------------------- |
| 127 | | open_avi - open an AVI file and return |
| 128 | | information about it |
| 129 | | -------------------------------------------------*/ |
| 125 | //------------------------------------------------- |
| 126 | // open_avi - open an AVI file and return |
| 127 | // information about it |
| 128 | //------------------------------------------------- |
| 130 | 129 | |
| 131 | | static void *open_avi(const char *filename, movie_info *info) |
| 130 | static void *open_avi(const char *filename, movie_info &info) |
| 132 | 131 | { |
| 133 | | const avi_movie_info *aviinfo; |
| 134 | | avi_error avierr; |
| 132 | // open the file |
| 135 | 133 | avi_file *avi; |
| 136 | | |
| 137 | | /* open the file */ |
| 138 | | avierr = avi_open(filename, &avi); |
| 134 | avi_error avierr = avi_open(filename, &avi); |
| 139 | 135 | if (avierr != AVIERR_NONE) |
| 140 | 136 | { |
| 141 | 137 | fprintf(stderr, "Error opening AVI file: %s\n", avi_error_string(avierr)); |
| 142 | 138 | return NULL; |
| 143 | 139 | } |
| 144 | 140 | |
| 145 | | /* extract movie info */ |
| 146 | | aviinfo = avi_get_movie_info(avi); |
| 147 | | info->framerate = (double)aviinfo->video_timescale / (double)aviinfo->video_sampletime; |
| 148 | | info->numframes = aviinfo->video_numsamples; |
| 149 | | info->width = aviinfo->video_width; |
| 150 | | info->height = aviinfo->video_height; |
| 151 | | info->samplerate = aviinfo->audio_samplerate; |
| 152 | | info->channels = aviinfo->audio_channels; |
| 153 | | |
| 141 | // extract movie info |
| 142 | const avi_movie_info *aviinfo = avi_get_movie_info(avi); |
| 143 | info.framerate = (double)aviinfo->video_timescale / (double)aviinfo->video_sampletime; |
| 144 | info.numframes = aviinfo->video_numsamples; |
| 145 | info.width = aviinfo->video_width; |
| 146 | info.height = aviinfo->video_height; |
| 147 | info.samplerate = aviinfo->audio_samplerate; |
| 148 | info.channels = aviinfo->audio_channels; |
| 154 | 149 | return avi; |
| 155 | 150 | } |
| 156 | 151 | |
| 157 | 152 | |
| 158 | | /*------------------------------------------------- |
| 159 | | read_avi - read a frame from an AVI file |
| 160 | | -------------------------------------------------*/ |
| 153 | //------------------------------------------------- |
| 154 | // read_avi - read a frame from an AVI file |
| 155 | //------------------------------------------------- |
| 161 | 156 | |
| 162 | | static int read_avi(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, INT16 *rsound, int *samples) |
| 157 | static bool read_avi(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, INT16 *rsound, int &samples) |
| 163 | 158 | { |
| 164 | | const avi_movie_info *aviinfo = avi_get_movie_info((avi_file *)file); |
| 165 | | UINT32 firstsample = ((UINT64)aviinfo->audio_samplerate * (UINT64)frame * (UINT64)aviinfo->video_sampletime + aviinfo->video_timescale - 1) / (UINT64)aviinfo->video_timescale; |
| 166 | | UINT32 lastsample = ((UINT64)aviinfo->audio_samplerate * (UINT64)(frame + 1) * (UINT64)aviinfo->video_sampletime + aviinfo->video_timescale - 1) / (UINT64)aviinfo->video_timescale; |
| 167 | | avi_error avierr; |
| 159 | avi_file *avifile = reinterpret_cast<avi_file *>(file); |
| 168 | 160 | |
| 169 | | /* read the frame */ |
| 170 | | avierr = avi_read_video_frame((avi_file *)file, frame, bitmap); |
| 161 | // read the frame |
| 162 | avi_error avierr = avi_read_video_frame(avifile, frame, bitmap); |
| 171 | 163 | if (avierr != AVIERR_NONE) |
| 172 | 164 | return FALSE; |
| 173 | 165 | |
| 174 | | /* read the samples */ |
| 175 | | avierr = avi_read_sound_samples((avi_file *)file, 0, firstsample, lastsample - firstsample, lsound); |
| 176 | | avierr = avi_read_sound_samples((avi_file *)file, 1, firstsample, lastsample - firstsample, rsound); |
| 166 | // read the samples |
| 167 | const avi_movie_info *aviinfo = avi_get_movie_info(avifile); |
| 168 | UINT32 firstsample = (UINT64(aviinfo->audio_samplerate) * UINT64(frame) * UINT64(aviinfo->video_sampletime) + aviinfo->video_timescale - 1) / UINT64(aviinfo->video_timescale); |
| 169 | UINT32 lastsample = (UINT64(aviinfo->audio_samplerate) * UINT64(frame + 1) * UINT64(aviinfo->video_sampletime) + aviinfo->video_timescale - 1) / UINT64(aviinfo->video_timescale); |
| 170 | avierr = avi_read_sound_samples(avifile, 0, firstsample, lastsample - firstsample, lsound); |
| 171 | avierr = avi_read_sound_samples(avifile, 1, firstsample, lastsample - firstsample, rsound); |
| 177 | 172 | if (avierr != AVIERR_NONE) |
| 178 | | return FALSE; |
| 179 | | *samples = lastsample - firstsample; |
| 180 | | return TRUE; |
| 173 | return false; |
| 174 | samples = lastsample - firstsample; |
| 175 | return true; |
| 181 | 176 | } |
| 182 | 177 | |
| 183 | 178 | |
| 184 | | /*------------------------------------------------- |
| 185 | | close_avi - close an AVI file |
| 186 | | -------------------------------------------------*/ |
| 179 | //------------------------------------------------- |
| 180 | // close_avi - close an AVI file |
| 181 | //------------------------------------------------- |
| 187 | 182 | |
| 188 | 183 | static void close_avi(void *file) |
| 189 | 184 | { |
| 190 | | avi_close((avi_file *)file); |
| 185 | avi_file *avifile = reinterpret_cast<avi_file *>(file); |
| 186 | avi_close(avifile); |
| 191 | 187 | } |
| 192 | 188 | |
| 193 | 189 | |
| 194 | 190 | |
| 195 | | /*************************************************************************** |
| 196 | | CHD HANDLING |
| 197 | | ***************************************************************************/ |
| 191 | //************************************************************************** |
| 192 | // CHD HANDLING |
| 193 | //************************************************************************** |
| 198 | 194 | |
| 199 | | /*------------------------------------------------- |
| 200 | | open_chd - open a CHD file and return |
| 201 | | information about it |
| 202 | | -------------------------------------------------*/ |
| 195 | //------------------------------------------------- |
| 196 | // open_chd - open a CHD file and return |
| 197 | // information about it |
| 198 | //------------------------------------------------- |
| 203 | 199 | |
| 204 | | static void *open_chd(const char *filename, movie_info *info) |
| 200 | static void *open_chd(const char *filename, movie_info &info) |
| 205 | 201 | { |
| 206 | | int fps, fpsfrac, width, height, interlaced, channels, rate; |
| 207 | | char metadata[256]; |
| 208 | | chd_error chderr; |
| 209 | | chd_file *chd; |
| 202 | chd_file *chd = new chd_file; |
| 210 | 203 | |
| 211 | | /* open the file */ |
| 212 | | chderr = chd_open(filename, CHD_OPEN_READ, NULL, &chd); |
| 204 | // open the file |
| 205 | chd_error chderr = chd->open(filename); |
| 213 | 206 | if (chderr != CHDERR_NONE) |
| 214 | 207 | { |
| 215 | | fprintf(stderr, "Error opening CHD file: %s\n", chd_error_string(chderr)); |
| 208 | fprintf(stderr, "Error opening CHD file: %s\n", chd_file::error_string(chderr)); |
| 209 | delete chd; |
| 216 | 210 | return NULL; |
| 217 | 211 | } |
| 218 | 212 | |
| 219 | | /* get the metadata */ |
| 220 | | chderr = chd_get_metadata(chd, AV_METADATA_TAG, 0, metadata, sizeof(metadata), NULL, NULL, NULL); |
| 213 | // get the metadata |
| 214 | astring metadata; |
| 215 | chderr = chd->read_metadata(AV_METADATA_TAG, 0, metadata); |
| 221 | 216 | if (chderr != CHDERR_NONE) |
| 222 | 217 | { |
| 223 | | fprintf(stderr, "Error getting A/V metadata: %s\n", chd_error_string(chderr)); |
| 224 | | chd_close(chd); |
| 218 | fprintf(stderr, "Error getting A/V metadata: %s\n", chd_file::error_string(chderr)); |
| 219 | delete chd; |
| 225 | 220 | return NULL; |
| 226 | 221 | } |
| 227 | 222 | |
| 228 | | /* extract the info */ |
| 223 | // extract the info |
| 224 | int fps, fpsfrac, width, height, interlaced, channels, rate; |
| 229 | 225 | if (sscanf(metadata, AV_METADATA_FORMAT, &fps, &fpsfrac, &width, &height, &interlaced, &channels, &rate) != 7) |
| 230 | 226 | { |
| 231 | 227 | fprintf(stderr, "Improperly formatted metadata\n"); |
| 232 | | chd_close(chd); |
| 228 | delete chd; |
| 233 | 229 | return NULL; |
| 234 | 230 | } |
| 235 | 231 | |
| 236 | | /* extract movie info */ |
| 237 | | info->framerate = (fps * 1000000 + fpsfrac) / 1000000.0; |
| 238 | | info->numframes = chd_get_header(chd)->totalhunks; |
| 239 | | info->width = width; |
| 240 | | info->height = height; |
| 241 | | info->samplerate = rate; |
| 242 | | info->channels = channels; |
| 232 | // extract movie info |
| 233 | info.framerate = (fps * 1000000 + fpsfrac) / 1000000.0; |
| 234 | info.numframes = chd->hunk_count(); |
| 235 | info.width = width; |
| 236 | info.height = height; |
| 237 | info.samplerate = rate; |
| 238 | info.channels = channels; |
| 243 | 239 | |
| 244 | | /* convert to an interlaced frame */ |
| 240 | // convert to an interlaced frame |
| 245 | 241 | chdinterlaced = interlaced; |
| 246 | 242 | if (interlaced) |
| 247 | 243 | { |
| 248 | | info->framerate /= 2; |
| 249 | | info->numframes = (info->numframes + 1) / 2; |
| 250 | | info->height *= 2; |
| 244 | info.framerate /= 2; |
| 245 | info.numframes = (info.numframes + 1) / 2; |
| 246 | info.height *= 2; |
| 251 | 247 | } |
| 252 | | |
| 253 | 248 | return chd; |
| 254 | 249 | } |
| 255 | 250 | |
| 256 | 251 | |
| 257 | | /*------------------------------------------------- |
| 258 | | read_chd - read a frame from a CHD file |
| 259 | | -------------------------------------------------*/ |
| 252 | //------------------------------------------------- |
| 253 | // read_chd - read a frame from a CHD file |
| 254 | //------------------------------------------------- |
| 260 | 255 | |
| 261 | | static int read_chd(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, INT16 *rsound, int *samples) |
| 256 | static int read_chd(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, INT16 *rsound, int &samples) |
| 262 | 257 | { |
| 263 | | av_codec_decompress_config avconfig; |
| 258 | chd_file *chdfile = reinterpret_cast<chd_file *>(file); |
| 259 | |
| 260 | // loop over fields |
| 264 | 261 | int interlace_factor = chdinterlaced ? 2 : 1; |
| 265 | | bitmap_yuy16 fakebitmap; |
| 266 | | UINT32 numsamples; |
| 267 | | chd_error chderr; |
| 268 | | int fieldnum; |
| 269 | | |
| 270 | | /* loop over fields */ |
| 271 | | *samples = 0; |
| 272 | | for (fieldnum = 0; fieldnum < interlace_factor; fieldnum++) |
| 262 | samples = 0; |
| 263 | for (int fieldnum = 0; fieldnum < interlace_factor; fieldnum++) |
| 273 | 264 | { |
| 274 | | /* make a fake bitmap for this field */ |
| 265 | // make a fake bitmap for this field |
| 266 | avhuff_decompress_config avconfig; |
| 275 | 267 | avconfig.video.wrap(&bitmap.pix16(fieldnum), bitmap.width(), bitmap.height() / interlace_factor, bitmap.rowpixels() * interlace_factor); |
| 276 | 268 | |
| 277 | | /* configure the codec */ |
| 269 | // configure the codec |
| 270 | UINT32 numsamples; |
| 278 | 271 | avconfig.maxsamples = 48000; |
| 279 | 272 | avconfig.actsamples = &numsamples; |
| 280 | | avconfig.audio[0] = &lsound[*samples]; |
| 281 | | avconfig.audio[1] = &rsound[*samples]; |
| 273 | avconfig.audio[0] = &lsound[samples]; |
| 274 | avconfig.audio[1] = &rsound[samples]; |
| 282 | 275 | |
| 283 | | /* configure the decompressor for this frame */ |
| 284 | | chd_codec_config((chd_file *)file, AV_CODEC_DECOMPRESS_CONFIG, &avconfig); |
| 276 | // configure the decompressor for this frame |
| 277 | chdfile->codec_configure(CHD_CODEC_AVHUFF, AVHUFF_CODEC_DECOMPRESS_CONFIG, &avconfig); |
| 285 | 278 | |
| 286 | | /* read the frame */ |
| 287 | | chderr = chd_read((chd_file *)file, frame * interlace_factor + fieldnum, NULL); |
| 279 | // read the frame |
| 280 | chd_error chderr = chdfile->read_hunk(frame * interlace_factor + fieldnum, NULL); |
| 288 | 281 | if (chderr != CHDERR_NONE) |
| 289 | | return FALSE; |
| 282 | return false; |
| 290 | 283 | |
| 291 | | /* account for samples read */ |
| 292 | | *samples += numsamples; |
| 284 | // account for samples read |
| 285 | samples += numsamples; |
| 293 | 286 | } |
| 294 | | return TRUE; |
| 287 | return true; |
| 295 | 288 | } |
| 296 | 289 | |
| 297 | 290 | |
| 298 | | /*------------------------------------------------- |
| 299 | | close_chd - close a CHD file |
| 300 | | -------------------------------------------------*/ |
| 291 | //------------------------------------------------- |
| 292 | // close_chd - close a CHD file |
| 293 | //------------------------------------------------- |
| 301 | 294 | |
| 302 | 295 | static void close_chd(void *file) |
| 303 | 296 | { |
| 304 | | chd_close((chd_file *)file); |
| 297 | chd_file *chdfile = reinterpret_cast<chd_file *>(file); |
| 298 | delete chdfile; |
| 305 | 299 | } |
| 306 | 300 | |
| 307 | 301 | |
| 308 | 302 | |
| 309 | | /*************************************************************************** |
| 310 | | CORE IMPLEMENTATION |
| 311 | | ***************************************************************************/ |
| 303 | //************************************************************************** |
| 304 | // CORE IMPLEMENTATION |
| 305 | //************************************************************************** |
| 312 | 306 | |
| 313 | | /*------------------------------------------------- |
| 314 | | init_video - init video info structure |
| 315 | | -------------------------------------------------*/ |
| 307 | //------------------------------------------------- |
| 308 | // init_video - init video info structure |
| 309 | //------------------------------------------------- |
| 316 | 310 | |
| 317 | | static void init_video(video_info *video) |
| 311 | static void init_video(video_info &video) |
| 318 | 312 | { |
| 319 | | video->first_whitefield = -1; |
| 320 | | video->saw_leadin = FALSE; |
| 321 | | video->saw_leadout = FALSE; |
| 322 | | video->last_frame = -1; |
| 323 | | video->last_chapter = -1; |
| 324 | | video->cadence = -1; |
| 325 | | video->cadence_history = 0; |
| 326 | | video->prev_whitefield = -1; |
| 327 | | video->min_overall = 255; |
| 328 | | video->max_overall = 0; |
| 329 | | video->first_blank_frame = -1; |
| 330 | | video->first_blank_field = -1; |
| 331 | | video->num_blank_fields = -1; |
| 332 | | video->first_low_frame = -1; |
| 333 | | video->first_low_field = -1; |
| 334 | | video->num_low_fields = -1; |
| 335 | | video->first_high_frame = -1; |
| 336 | | video->first_high_field = -1; |
| 337 | | video->num_high_fields = -1; |
| 313 | video.first_whitefield = -1; |
| 314 | video.saw_leadin = false; |
| 315 | video.saw_leadout = false; |
| 316 | video.last_frame = -1; |
| 317 | video.last_chapter = -1; |
| 318 | video.cadence = -1; |
| 319 | video.cadence_history = 0; |
| 320 | video.prev_whitefield = -1; |
| 321 | video.min_overall = 255; |
| 322 | video.max_overall = 0; |
| 323 | video.first_blank_frame = -1; |
| 324 | video.first_blank_field = -1; |
| 325 | video.num_blank_fields = -1; |
| 326 | video.first_low_frame = -1; |
| 327 | video.first_low_field = -1; |
| 328 | video.num_low_fields = -1; |
| 329 | video.first_high_frame = -1; |
| 330 | video.first_high_field = -1; |
| 331 | video.num_high_fields = -1; |
| 338 | 332 | } |
| 339 | 333 | |
| 340 | 334 | |
| 341 | | /*------------------------------------------------- |
| 342 | | verify_video - verify video frame |
| 343 | | -------------------------------------------------*/ |
| 335 | //------------------------------------------------- |
| 336 | // verify_video - verify video frame |
| 337 | //------------------------------------------------- |
| 344 | 338 | |
| 345 | | static void verify_video(video_info *video, int frame, bitmap_yuy16 &bitmap) |
| 339 | static void verify_video(video_info &video, int frame, bitmap_yuy16 &bitmap) |
| 346 | 340 | { |
| 341 | // loop over fields |
| 347 | 342 | const int fields_per_frame = 2; |
| 348 | | int fieldnum; |
| 349 | | |
| 350 | | /* loop over fields */ |
| 351 | | for (fieldnum = 0; fieldnum < fields_per_frame; fieldnum++) |
| 343 | for (int fieldnum = 0; fieldnum < fields_per_frame; fieldnum++) |
| 352 | 344 | { |
| 353 | | int yminval, ymaxval, cbminval, cbmaxval, crminval, crmaxval; |
| 354 | | int field = frame * fields_per_frame + fieldnum; |
| 355 | | int x, y, pixels, remaining; |
| 356 | | UINT32 yhisto[256] = { 0 }; |
| 357 | | UINT32 crhisto[256] = { 0 }; |
| 358 | | UINT32 cbhisto[256] = { 0 }; |
| 359 | | vbi_metadata metadata; |
| 360 | | |
| 361 | | /* output status */ |
| 345 | // output status |
| 362 | 346 | if (frame % 10 == 0 && fieldnum == 0) |
| 363 | 347 | fprintf(stderr, "%6d.%d...\r", frame, fieldnum); |
| 364 | 348 | |
| 365 | | /* parse the VBI data */ |
| 349 | // parse the VBI data |
| 350 | vbi_metadata metadata; |
| 366 | 351 | vbi_parse_all(&bitmap.pix16(fieldnum), bitmap.rowpixels() * 2, bitmap.width(), 8, &metadata); |
| 367 | 352 | |
| 368 | | /* if we have data in both 17 and 18, it should match */ |
| 353 | // if we have data in both 17 and 18, it should match |
| 369 | 354 | if (metadata.line17 != 0 && metadata.line18 != 0 && metadata.line17 != metadata.line18) |
| 370 | 355 | { |
| 371 | 356 | printf("%6d.%d: line 17 and 18 data does not match (17=%06X 18=%06X) (WARNING)\n", frame, fieldnum, metadata.line17, metadata.line18); |
| 372 | 357 | printf("%6d.%d: selected %06X based on bit confidence\n", frame, fieldnum, metadata.line1718); |
| 373 | 358 | } |
| 374 | 359 | |
| 375 | | /* is this a lead-in code? */ |
| 360 | // is this a lead-in code? |
| 376 | 361 | if (metadata.line1718 == VBI_CODE_LEADIN) |
| 377 | 362 | { |
| 378 | | /* if we haven't seen lead-in yet, detect it */ |
| 379 | | if (!video->saw_leadin) |
| 363 | // if we haven't seen lead-in yet, detect it |
| 364 | if (!video.saw_leadin) |
| 380 | 365 | { |
| 381 | | video->saw_leadin = TRUE; |
| 366 | video.saw_leadin = TRUE; |
| 382 | 367 | printf("%6d.%d: lead-in code detected\n", frame, fieldnum); |
| 383 | 368 | } |
| 384 | 369 | |
| 385 | | /* if we've previously seen chapters/frames, that's weird */ |
| 386 | | if (video->last_frame != -1 || video->last_chapter != -1) |
| 370 | // if we've previously seen chapters/frames, that's weird |
| 371 | if (video.last_frame != -1 || video.last_chapter != -1) |
| 387 | 372 | printf("%6d.%d: lead-in code detected after frame/chapter data (WARNING)\n", frame, fieldnum); |
| 388 | 373 | } |
| 389 | 374 | |
| 390 | | /* is this a lead-out code? */ |
| 375 | // is this a lead-out code? |
| 391 | 376 | if (metadata.line1718 == VBI_CODE_LEADOUT) |
| 392 | 377 | { |
| 393 | | /* if we haven't seen lead-in yet, detect it */ |
| 394 | | if (!video->saw_leadout) |
| 378 | // if we haven't seen lead-in yet, detect it |
| 379 | if (!video.saw_leadout) |
| 395 | 380 | { |
| 396 | | video->saw_leadout = TRUE; |
| 381 | video.saw_leadout = TRUE; |
| 397 | 382 | printf("%6d.%d: lead-out code detected\n", frame, fieldnum); |
| 398 | | if (video->last_frame != -1) |
| 399 | | printf("%6d.%d: final frame number was %d\n", frame, fieldnum, video->last_frame); |
| 383 | if (video.last_frame != -1) |
| 384 | printf("%6d.%d: final frame number was %d\n", frame, fieldnum, video.last_frame); |
| 400 | 385 | else |
| 401 | 386 | printf("%6d.%d: never detected any frame numbers (ERROR)\n", frame, fieldnum); |
| 402 | 387 | } |
| 403 | 388 | |
| 404 | | /* if we've previously seen chapters/frames, that's weird */ |
| 405 | | if (video->last_frame == -1) |
| 389 | // if we've previously seen chapters/frames, that's weird |
| 390 | if (video.last_frame == -1) |
| 406 | 391 | printf("%6d.%d: lead-out code detected with no frames detected beforehand (WARNING)\n", frame, fieldnum); |
| 407 | 392 | } |
| 408 | 393 | |
| 409 | | /* is this a frame code? */ |
| 394 | // is this a frame code? |
| 410 | 395 | if ((metadata.line1718 & VBI_MASK_CAV_PICTURE) == VBI_CODE_CAV_PICTURE) |
| 411 | 396 | { |
| 412 | 397 | int framenum = VBI_CAV_PICTURE(metadata.line1718); |
| 413 | 398 | |
| 414 | | /* did we see any leadin? */ |
| 415 | | if (!video->saw_leadin) |
| 399 | // did we see any leadin? |
| 400 | if (!video.saw_leadin) |
| 416 | 401 | { |
| 417 | 402 | printf("%6d.%d: detected frame number but never saw any lead-in (WARNING)\n", frame, fieldnum); |
| 418 | | video->saw_leadin = TRUE; |
| 403 | video.saw_leadin = TRUE; |
| 419 | 404 | } |
| 420 | 405 | |
| 421 | | /* if this is the first frame, make sure it's 1 */ |
| 422 | | if (video->last_frame == -1) |
| 406 | // if this is the first frame, make sure it's 1 |
| 407 | if (video.last_frame == -1) |
| 423 | 408 | { |
| 424 | 409 | if (framenum == 0) |
| 425 | 410 | printf("%6d.%d: detected frame 0\n", frame, fieldnum); |
| r14546 | r14547 | |
| 429 | 414 | printf("%6d.%d: first frame number is not 0 or 1 (%d) (ERROR)\n", frame, fieldnum, framenum); |
| 430 | 415 | } |
| 431 | 416 | |
| 432 | | /* print an update every 10000 frames */ |
| 417 | // print an update every 10000 frames |
| 433 | 418 | if (framenum != 0 && framenum % 10000 == 0) |
| 434 | 419 | printf("%6d.%d: detected frame %d\n", frame, fieldnum, framenum); |
| 435 | 420 | |
| 436 | | /* if this frame is not consecutive, it's an error */ |
| 437 | | if (video->last_frame != -1 && framenum != video->last_frame + 1) |
| 438 | | printf("%6d.%d: gap in frame number sequence (%d->%d) (ERROR)\n", frame, fieldnum, video->last_frame, framenum); |
| 421 | // if this frame is not consecutive, it's an error |
| 422 | if (video.last_frame != -1 && framenum != video.last_frame + 1) |
| 423 | printf("%6d.%d: gap in frame number sequence (%d->%d) (ERROR)\n", frame, fieldnum, video.last_frame, framenum); |
| 439 | 424 | |
| 440 | | /* remember the frame number */ |
| 441 | | video->last_frame = framenum; |
| 425 | // remember the frame number |
| 426 | video.last_frame = framenum; |
| 442 | 427 | |
| 443 | | /* if we've seen a white flag before, but it's not here, warn */ |
| 444 | | if (video->first_whitefield != -1 && !metadata.white) |
| 428 | // if we've seen a white flag before, but it's not here, warn |
| 429 | if (video.first_whitefield != -1 && !metadata.white) |
| 445 | 430 | printf("%6d.%d: detected frame number but no white flag (WARNING)\n", frame, fieldnum); |
| 446 | 431 | } |
| 447 | 432 | |
| 448 | | /* is the whiteflag set? */ |
| 433 | // is the whiteflag set? |
| 434 | int field = frame * fields_per_frame + fieldnum; |
| 449 | 435 | if (metadata.white) |
| 450 | 436 | { |
| 451 | | /* if this is the first white flag we see, count it */ |
| 452 | | if (video->first_whitefield == -1) |
| 437 | // if this is the first white flag we see, count it |
| 438 | if (video.first_whitefield == -1) |
| 453 | 439 | { |
| 454 | | video->first_whitefield = field; |
| 440 | video.first_whitefield = field; |
| 455 | 441 | printf("%6d.%d: first white flag seen\n", frame, fieldnum); |
| 456 | 442 | } |
| 457 | 443 | |
| 458 | | /* if we've seen frame numbers before, but not here, warn */ |
| 459 | | if (video->last_frame != -1 && (metadata.line1718 & VBI_MASK_CAV_PICTURE) != VBI_CODE_CAV_PICTURE) |
| 444 | // if we've seen frame numbers before, but not here, warn |
| 445 | if (video.last_frame != -1 && (metadata.line1718 & VBI_MASK_CAV_PICTURE) != VBI_CODE_CAV_PICTURE) |
| 460 | 446 | printf("%6d.%d: detected white flag but no frame number (WARNING)\n", frame, fieldnum); |
| 461 | 447 | } |
| 462 | 448 | |
| 463 | | /* if this is the start of a frame, handle cadence */ |
| 449 | // if this is the start of a frame, handle cadence |
| 464 | 450 | if (metadata.white || (metadata.line1718 & VBI_MASK_CAV_PICTURE) == VBI_CODE_CAV_PICTURE) |
| 465 | 451 | { |
| 466 | | /* if we've seen frames, but we're not yet to the lead-out, check the cadence */ |
| 467 | | if (video->last_frame != -1 && !video->saw_leadout) |
| 452 | // if we've seen frames, but we're not yet to the lead-out, check the cadence |
| 453 | if (video.last_frame != -1 && !video.saw_leadout) |
| 468 | 454 | { |
| 469 | | /* make sure we have a proper history */ |
| 470 | | if (video->prev_whitefield != -1) |
| 471 | | video->cadence_history = (video->cadence_history << 4) | ((field - video->prev_whitefield) & 0x0f); |
| 472 | | video->prev_whitefield = field; |
| 455 | // make sure we have a proper history |
| 456 | if (video.prev_whitefield != -1) |
| 457 | video.cadence_history = (video.cadence_history << 4) | ((field - video.prev_whitefield) & 0x0f); |
| 458 | video.prev_whitefield = field; |
| 473 | 459 | |
| 474 | | /* if we don't know our cadence yet, determine it */ |
| 475 | | if (video->cadence == -1 && (video->cadence_history & 0xf00) != 0) |
| 460 | // if we don't know our cadence yet, determine it |
| 461 | if (video.cadence == -1 && (video.cadence_history & 0xf00) != 0) |
| 476 | 462 | { |
| 477 | | if ((video->cadence_history & 0xfff) == 0x222) |
| 463 | if ((video.cadence_history & 0xfff) == 0x222) |
| 478 | 464 | { |
| 479 | 465 | printf("%6d.%d: detected 2:2 cadence\n", frame, fieldnum); |
| 480 | | video->cadence = 4; |
| 466 | video.cadence = 4; |
| 481 | 467 | } |
| 482 | | else if ((video->cadence_history & 0xfff) == 0x323) |
| 468 | else if ((video.cadence_history & 0xfff) == 0x323) |
| 483 | 469 | { |
| 484 | 470 | printf("%6d.%d: detected 3:2 cadence\n", frame, fieldnum); |
| 485 | | video->cadence = 5; |
| 471 | video.cadence = 5; |
| 486 | 472 | } |
| 487 | | else if ((video->cadence_history & 0xfff) == 0x232) |
| 473 | else if ((video.cadence_history & 0xfff) == 0x232) |
| 488 | 474 | { |
| 489 | 475 | printf("%6d.%d: detected 2:3 cadence\n", frame, fieldnum); |
| 490 | | video->cadence = 5; |
| 476 | video.cadence = 5; |
| 491 | 477 | } |
| 492 | 478 | else |
| 493 | 479 | { |
| 494 | 480 | printf("%6d.%d: unknown cadence (history %d:%d:%d) (WARNING)\n", frame, fieldnum, |
| 495 | | (video->cadence_history >> 8) & 15, (video->cadence_history >> 4) & 15, video->cadence_history & 15); |
| 481 | (video.cadence_history >> 8) & 15, (video.cadence_history >> 4) & 15, video.cadence_history & 15); |
| 496 | 482 | } |
| 497 | 483 | } |
| 498 | 484 | |
| 499 | | /* if we know our cadence, make sure we stick to it */ |
| 500 | | if (video->cadence != -1) |
| 485 | // if we know our cadence, make sure we stick to it |
| 486 | if (video.cadence != -1) |
| 501 | 487 | { |
| 502 | | if (video->cadence == 4 && (video->cadence_history & 0xfff) != 0x222) |
| 488 | if (video.cadence == 4 && (video.cadence_history & 0xfff) != 0x222) |
| 503 | 489 | { |
| 504 | 490 | printf("%6d.%d: missed cadence (history %d:%d:%d) (WARNING)\n", frame, fieldnum, |
| 505 | | (video->cadence_history >> 8) & 15, (video->cadence_history >> 4) & 15, video->cadence_history & 15); |
| 506 | | video->cadence = -1; |
| 507 | | video->cadence_history = 0; |
| 491 | (video.cadence_history >> 8) & 15, (video.cadence_history >> 4) & 15, video.cadence_history & 15); |
| 492 | video.cadence = -1; |
| 493 | video.cadence_history = 0; |
| 508 | 494 | } |
| 509 | | else if (video->cadence == 5 && (video->cadence_history & 0xfff) != 0x323 && (video->cadence_history & 0xfff) != 0x232) |
| 495 | else if (video.cadence == 5 && (video.cadence_history & 0xfff) != 0x323 && (video.cadence_history & 0xfff) != 0x232) |
| 510 | 496 | { |
| 511 | 497 | printf("%6d.%d: missed cadence (history %d:%d:%d) (WARNING)\n", frame, fieldnum, |
| 512 | | (video->cadence_history >> 8) & 15, (video->cadence_history >> 4) & 15, video->cadence_history & 15); |
| 513 | | video->cadence = -1; |
| 514 | | video->cadence_history = 0; |
| 498 | (video.cadence_history >> 8) & 15, (video.cadence_history >> 4) & 15, video.cadence_history & 15); |
| 499 | video.cadence = -1; |
| 500 | video.cadence_history = 0; |
| 515 | 501 | } |
| 516 | 502 | } |
| 517 | 503 | } |
| 518 | 504 | } |
| 519 | 505 | |
| 520 | | /* now examine the active video signal */ |
| 521 | | pixels = 0; |
| 522 | | for (y = 22*2 + fieldnum; y < bitmap.height(); y += 2) |
| 506 | // now examine the active video signal |
| 507 | UINT32 yhisto[256] = { 0 }; |
| 508 | UINT32 crhisto[256] = { 0 }; |
| 509 | UINT32 cbhisto[256] = { 0 }; |
| 510 | int pixels = 0; |
| 511 | for (int y = 22*2 + fieldnum; y < bitmap.height(); y += 2) |
| 523 | 512 | { |
| 524 | | for (x = 16; x < 720 - 16; x++) |
| 513 | for (int x = 16; x < 720 - 16; x++) |
| 525 | 514 | { |
| 526 | 515 | yhisto[bitmap.pix16(y, x) >> 8]++; |
| 527 | 516 | if (x % 2 == 0) |
| r14546 | r14547 | |
| 532 | 521 | pixels += 720 - 16 - 16; |
| 533 | 522 | } |
| 534 | 523 | |
| 535 | | /* remove the top/bottom 0.1% of Y */ |
| 536 | | remaining = pixels / 1000; |
| 524 | // remove the top/bottom 0.1% of Y |
| 525 | int remaining = pixels / 1000; |
| 526 | int yminval; |
| 537 | 527 | for (yminval = 0; (remaining -= yhisto[yminval]) >= 0; yminval++) ; |
| 538 | 528 | remaining = pixels / 1000; |
| 529 | int ymaxval; |
| 539 | 530 | for (ymaxval = 255; (remaining -= yhisto[ymaxval]) >= 0; ymaxval--) ; |
| 540 | 531 | |
| 541 | | /* remove the top/bottom 0.1% of Cb */ |
| 532 | // remove the top/bottom 0.1% of Cb |
| 542 | 533 | remaining = pixels / 500; |
| 534 | int cbminval; |
| 543 | 535 | for (cbminval = 0; (remaining -= cbhisto[cbminval]) >= 0; cbminval++) ; |
| 544 | 536 | remaining = pixels / 500; |
| 537 | int cbmaxval; |
| 545 | 538 | for (cbmaxval = 255; (remaining -= cbhisto[cbmaxval]) >= 0; cbmaxval--) ; |
| 546 | 539 | |
| 547 | | /* remove the top/bottom 0.1% of Cr */ |
| 540 | // remove the top/bottom 0.1% of Cr |
| 548 | 541 | remaining = pixels / 500; |
| 542 | int crminval; |
| 549 | 543 | for (crminval = 0; (remaining -= crhisto[crminval]) >= 0; crminval++) ; |
| 550 | 544 | remaining = pixels / 500; |
| 545 | int crmaxval; |
| 551 | 546 | for (crmaxval = 255; (remaining -= crhisto[crmaxval]) >= 0; crmaxval--) ; |
| 552 | 547 | |
| 553 | | /* track blank frames */ |
| 548 | // track blank frames |
| 554 | 549 | if (ymaxval - yminval < 10 && cbmaxval - cbminval < 10 && crmaxval - cbmaxval < 10) |
| 555 | 550 | { |
| 556 | | if (video->first_blank_frame == -1) |
| 551 | if (video.first_blank_frame == -1) |
| 557 | 552 | { |
| 558 | | video->first_blank_frame = frame; |
| 559 | | video->first_blank_field = fieldnum; |
| 560 | | video->num_blank_fields = 0; |
| 553 | video.first_blank_frame = frame; |
| 554 | video.first_blank_field = fieldnum; |
| 555 | video.num_blank_fields = 0; |
| 561 | 556 | } |
| 562 | | video->num_blank_fields++; |
| 557 | video.num_blank_fields++; |
| 563 | 558 | } |
| 564 | | else if (video->num_blank_fields > 0) |
| 559 | else if (video.num_blank_fields > 0) |
| 565 | 560 | { |
| 566 | | if (video->num_blank_fields >= REPORT_BLANKS_THRESHOLD) |
| 567 | | 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); |
| 568 | | video->first_blank_frame = video->first_blank_field = video->num_blank_fields = -1; |
| 561 | if (video.num_blank_fields >= REPORT_BLANKS_THRESHOLD) |
| 562 | 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); |
| 563 | video.first_blank_frame = video.first_blank_field = video.num_blank_fields = -1; |
| 569 | 564 | } |
| 570 | 565 | |
| 571 | | /* update the overall min/max */ |
| 572 | | video->min_overall = MIN(yminval, video->min_overall); |
| 573 | | video->max_overall = MAX(ymaxval, video->max_overall); |
| 566 | // update the overall min/max |
| 567 | video.min_overall = MIN(yminval, video.min_overall); |
| 568 | video.max_overall = MAX(ymaxval, video.max_overall); |
| 574 | 569 | |
| 575 | | /* track low fields */ |
| 570 | // track low fields |
| 576 | 571 | if (yminval <= 0) |
| 577 | 572 | { |
| 578 | | if (video->first_low_frame == -1) |
| 573 | if (video.first_low_frame == -1) |
| 579 | 574 | { |
| 580 | | video->first_low_frame = frame; |
| 581 | | video->first_low_field = fieldnum; |
| 582 | | video->num_low_fields = 0; |
| 575 | video.first_low_frame = frame; |
| 576 | video.first_low_field = fieldnum; |
| 577 | video.num_low_fields = 0; |
| 583 | 578 | } |
| 584 | | video->num_low_fields++; |
| 579 | video.num_low_fields++; |
| 585 | 580 | } |
| 586 | | else if (video->num_low_fields > 0) |
| 581 | else if (video.num_low_fields > 0) |
| 587 | 582 | { |
| 588 | | 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); |
| 589 | | video->first_low_frame = video->first_low_field = video->num_low_fields = -1; |
| 583 | 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); |
| 584 | video.first_low_frame = video.first_low_field = video.num_low_fields = -1; |
| 590 | 585 | } |
| 591 | 586 | |
| 592 | | /* track high fields */ |
| 587 | // track high fields |
| 593 | 588 | if (ymaxval >= 255) |
| 594 | 589 | { |
| 595 | | if (video->first_high_frame == -1) |
| 590 | if (video.first_high_frame == -1) |
| 596 | 591 | { |
| 597 | | video->first_high_frame = frame; |
| 598 | | video->first_high_field = fieldnum; |
| 599 | | video->num_high_fields = 0; |
| 592 | video.first_high_frame = frame; |
| 593 | video.first_high_field = fieldnum; |
| 594 | video.num_high_fields = 0; |
| 600 | 595 | } |
| 601 | | video->num_high_fields++; |
| 596 | video.num_high_fields++; |
| 602 | 597 | } |
| 603 | | else if (video->num_high_fields > 0) |
| 598 | else if (video.num_high_fields > 0) |
| 604 | 599 | { |
| 605 | | 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); |
| 606 | | video->first_high_frame = video->first_high_field = video->num_high_fields = -1; |
| 600 | 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); |
| 601 | video.first_high_frame = video.first_high_field = video.num_high_fields = -1; |
| 607 | 602 | } |
| 608 | 603 | } |
| 609 | 604 | } |
| 610 | 605 | |
| 611 | 606 | |
| 612 | | /*------------------------------------------------- |
| 613 | | verify_video_final - final verification |
| 614 | | -------------------------------------------------*/ |
| 607 | //------------------------------------------------- |
| 608 | // verify_video_final - final verification |
| 609 | //------------------------------------------------- |
| 615 | 610 | |
| 616 | | static void verify_video_final(video_info *video, int frame, bitmap_yuy16 &bitmap) |
| 611 | static void verify_video_final(video_info &video, int frame, bitmap_yuy16 &bitmap) |
| 617 | 612 | { |
| 618 | 613 | int fields_per_frame = (bitmap.height() >= 288) ? 2 : 1; |
| 619 | 614 | int field = frame * fields_per_frame; |
| 620 | 615 | |
| 621 | | /* did we ever see any white flags? */ |
| 622 | | if (video->first_whitefield == -1) |
| 616 | // did we ever see any white flags? |
| 617 | if (video.first_whitefield == -1) |
| 623 | 618 | printf("Track %6d.%d: never saw any white flags (WARNING)\n", field / fields_per_frame, 0); |
| 624 | 619 | |
| 625 | | /* did we ever see any lead-out? */ |
| 626 | | if (!video->saw_leadout) |
| 620 | // did we ever see any lead-out? |
| 621 | if (!video.saw_leadout) |
| 627 | 622 | printf("Track %6d.%d: never saw any lead-out (WARNING)\n", field / fields_per_frame, 0); |
| 628 | 623 | |
| 629 | | /* any remaining high/low reports? */ |
| 630 | | if (video->num_blank_fields >= REPORT_BLANKS_THRESHOLD) |
| 631 | | 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); |
| 632 | | if (video->num_low_fields > 0) |
| 633 | | 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); |
| 634 | | if (video->num_high_fields > 0) |
| 635 | | 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); |
| 624 | // any remaining high/low reports? |
| 625 | if (video.num_blank_fields >= REPORT_BLANKS_THRESHOLD) |
| 626 | 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); |
| 627 | if (video.num_low_fields > 0) |
| 628 | 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); |
| 629 | if (video.num_high_fields > 0) |
| 630 | 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); |
| 636 | 631 | |
| 637 | | /* summary info */ |
| 632 | // summary info |
| 638 | 633 | printf("\nVideo summary:\n"); |
| 639 | | printf(" Overall video range: %d-%d (%02X-%02X)\n", video->min_overall, video->max_overall, video->min_overall, video->max_overall); |
| 634 | printf(" Overall video range: %d-%d (%02X-%02X)\n", video.min_overall, video.max_overall, video.min_overall, video.max_overall); |
| 640 | 635 | } |
| 641 | 636 | |
| 642 | 637 | |
| 643 | | /*------------------------------------------------- |
| 644 | | init_audio - init audio info structure |
| 645 | | -------------------------------------------------*/ |
| 638 | //------------------------------------------------- |
| 639 | // init_audio - init audio info structure |
| 640 | //------------------------------------------------- |
| 646 | 641 | |
| 647 | | static void init_audio(audio_info *audio) |
| 642 | static void init_audio(audio_info &audio) |
| 648 | 643 | { |
| 649 | | audio->min_lsample = 32767; |
| 650 | | audio->min_rsample = 32767; |
| 651 | | audio->max_lsample = -32768; |
| 652 | | audio->max_rsample = -32768; |
| 653 | | audio->min_lsample_count = 0; |
| 654 | | audio->min_rsample_count = 0; |
| 655 | | audio->max_lsample_count = 0; |
| 656 | | audio->max_rsample_count = 0; |
| 657 | | audio->sample_count = 0; |
| 644 | audio.min_lsample = 32767; |
| 645 | audio.min_rsample = 32767; |
| 646 | audio.max_lsample = -32768; |
| 647 | audio.max_rsample = -32768; |
| 648 | audio.min_lsample_count = 0; |
| 649 | audio.min_rsample_count = 0; |
| 650 | audio.max_lsample_count = 0; |
| 651 | audio.max_rsample_count = 0; |
| 652 | audio.sample_count = 0; |
| 658 | 653 | } |
| 659 | 654 | |
| 660 | 655 | |
| 661 | | /*------------------------------------------------- |
| 662 | | verify_audio - verify audio data |
| 663 | | -------------------------------------------------*/ |
| 656 | //------------------------------------------------- |
| 657 | // verify_audio - verify audio data |
| 658 | //------------------------------------------------- |
| 664 | 659 | |
| 665 | | static void verify_audio(audio_info *audio, const INT16 *lsound, const INT16 *rsound, int samples) |
| 660 | static void verify_audio(audio_info &audio, const INT16 *lsound, const INT16 *rsound, int samples) |
| 666 | 661 | { |
| 667 | | int sampnum; |
| 662 | // count the overall samples |
| 663 | audio.sample_count += samples; |
| 668 | 664 | |
| 669 | | /* count the overall samples */ |
| 670 | | audio->sample_count += samples; |
| 671 | | |
| 672 | | /* iterate over samples, tracking min/max */ |
| 673 | | for (sampnum = 0; sampnum < samples; sampnum++) |
| 665 | // iterate over samples, tracking min/max |
| 666 | for (int sampnum = 0; sampnum < samples; sampnum++) |
| 674 | 667 | { |
| 675 | | /* did we hit a minimum on the left? */ |
| 676 | | if (lsound[sampnum] < audio->min_lsample) |
| 668 | // did we hit a minimum on the left? |
| 669 | if (lsound[sampnum] < audio.min_lsample) |
| 677 | 670 | { |
| 678 | | audio->min_lsample = lsound[sampnum]; |
| 679 | | audio->min_lsample_count = 1; |
| 671 | audio.min_lsample = lsound[sampnum]; |
| 672 | audio.min_lsample_count = 1; |
| 680 | 673 | } |
| 681 | | else if (lsound[sampnum] == audio->min_lsample) |
| 682 | | audio->min_lsample_count++; |
| 674 | else if (lsound[sampnum] == audio.min_lsample) |
| 675 | audio.min_lsample_count++; |
| 683 | 676 | |
| 684 | | /* did we hit a maximum on the left? */ |
| 685 | | if (lsound[sampnum] > audio->max_lsample) |
| 677 | // did we hit a maximum on the left? |
| 678 | if (lsound[sampnum] > audio.max_lsample) |
| 686 | 679 | { |
| 687 | | audio->max_lsample = lsound[sampnum]; |
| 688 | | audio->max_lsample_count = 1; |
| 680 | audio.max_lsample = lsound[sampnum]; |
| 681 | audio.max_lsample_count = 1; |
| 689 | 682 | } |
| 690 | | else if (lsound[sampnum] == audio->max_lsample) |
| 691 | | audio->max_lsample_count++; |
| 683 | else if (lsound[sampnum] == audio.max_lsample) |
| 684 | audio.max_lsample_count++; |
| 692 | 685 | |
| 693 | | /* did we hit a minimum on the right? */ |
| 694 | | if (rsound[sampnum] < audio->min_rsample) |
| 686 | // did we hit a minimum on the right? |
| 687 | if (rsound[sampnum] < audio.min_rsample) |
| 695 | 688 | { |
| 696 | | audio->min_rsample = rsound[sampnum]; |
| 697 | | audio->min_rsample_count = 1; |
| 689 | audio.min_rsample = rsound[sampnum]; |
| 690 | audio.min_rsample_count = 1; |
| 698 | 691 | } |
| 699 | | else if (rsound[sampnum] == audio->min_rsample) |
| 700 | | audio->min_rsample_count++; |
| 692 | else if (rsound[sampnum] == audio.min_rsample) |
| 693 | audio.min_rsample_count++; |
| 701 | 694 | |
| 702 | | /* did we hit a maximum on the right? */ |
| 703 | | if (rsound[sampnum] > audio->max_rsample) |
| 695 | // did we hit a maximum on the right? |
| 696 | if (rsound[sampnum] > audio.max_rsample) |
| 704 | 697 | { |
| 705 | | audio->max_rsample = rsound[sampnum]; |
| 706 | | audio->max_rsample_count = 1; |
| 698 | audio.max_rsample = rsound[sampnum]; |
| 699 | audio.max_rsample_count = 1; |
| 707 | 700 | } |
| 708 | | else if (rsound[sampnum] == audio->max_rsample) |
| 709 | | audio->max_rsample_count++; |
| 701 | else if (rsound[sampnum] == audio.max_rsample) |
| 702 | audio.max_rsample_count++; |
| 710 | 703 | } |
| 711 | 704 | } |
| 712 | 705 | |
| 713 | 706 | |
| 714 | | /*------------------------------------------------- |
| 715 | | verify_audio_final - final verification |
| 716 | | -------------------------------------------------*/ |
| 707 | //------------------------------------------------- |
| 708 | // verify_audio_final - final verification |
| 709 | //------------------------------------------------- |
| 717 | 710 | |
| 718 | | static void verify_audio_final(audio_info *audio) |
| 711 | static void verify_audio_final(audio_info &audio) |
| 719 | 712 | { |
| 720 | 713 | printf("\nAudio summary:\n"); |
| 721 | | printf(" Overall channel 0 range: %d-%d (%04X-%04X)\n", audio->min_lsample, audio->max_lsample, (UINT16)audio->min_lsample, (UINT16)audio->max_lsample); |
| 722 | | printf(" Overall channel 1 range: %d-%d (%04X-%04X)\n", audio->min_rsample, audio->max_rsample, (UINT16)audio->min_rsample, (UINT16)audio->max_rsample); |
| 714 | printf(" Overall channel 0 range: %d-%d (%04X-%04X)\n", audio.min_lsample, audio.max_lsample, UINT16(audio.min_lsample), UINT16(audio.max_lsample)); |
| 715 | printf(" Overall channel 1 range: %d-%d (%04X-%04X)\n", audio.min_rsample, audio.max_rsample, UINT16(audio.min_rsample), UINT16(audio.max_rsample)); |
| 723 | 716 | } |
| 724 | 717 | |
| 725 | 718 | |
| 726 | | /*------------------------------------------------- |
| 727 | | usage - display program usage |
| 728 | | -------------------------------------------------*/ |
| 719 | //------------------------------------------------- |
| 720 | // usage - display program usage |
| 721 | //------------------------------------------------- |
| 729 | 722 | |
| 730 | 723 | static int usage(void) |
| 731 | 724 | { |
| r14546 | r14547 | |
| 735 | 728 | } |
| 736 | 729 | |
| 737 | 730 | |
| 738 | | /*------------------------------------------------- |
| 739 | | main - main entry point |
| 740 | | -------------------------------------------------*/ |
| 731 | //------------------------------------------------- |
| 732 | // main - main entry point |
| 733 | //------------------------------------------------- |
| 741 | 734 | |
| 742 | 735 | int main(int argc, char *argv[]) |
| 743 | 736 | { |
| 744 | 737 | try |
| 745 | 738 | { |
| 746 | | movie_info info = { 0 }; |
| 747 | | INT16 *lsound, *rsound; |
| 748 | | const char *srcfile; |
| 749 | | bitmap_yuy16 bitmap; |
| 750 | | int srcfilelen; |
| 751 | | int samples = 0; |
| 752 | | void *file; |
| 753 | | int isavi; |
| 754 | | int frame; |
| 739 | // init globals |
| 755 | 740 | audio_info audio; |
| 741 | init_audio(audio); |
| 756 | 742 | video_info video; |
| 743 | init_video(video); |
| 757 | 744 | |
| 758 | | /* init globals */ |
| 759 | | init_audio(&audio); |
| 760 | | init_video(&video); |
| 761 | | |
| 762 | | /* verify arguments */ |
| 745 | // verify arguments |
| 763 | 746 | if (argc < 2) |
| 764 | 747 | return usage(); |
| 765 | | srcfile = argv[1]; |
| 748 | const char *srcfile = argv[1]; |
| 766 | 749 | |
| 767 | | /* check extension of file */ |
| 768 | | srcfilelen = strlen(srcfile); |
| 750 | // check extension of file |
| 751 | int srcfilelen = strlen(srcfile); |
| 769 | 752 | if (srcfilelen < 4) |
| 770 | 753 | return usage(); |
| 754 | bool isavi; |
| 771 | 755 | if (tolower((UINT8)srcfile[srcfilelen-3]) == 'a' && tolower((UINT8)srcfile[srcfilelen-2]) == 'v' && tolower((UINT8)srcfile[srcfilelen-1]) == 'i') |
| 772 | | isavi = TRUE; |
| 756 | isavi = true; |
| 773 | 757 | else if (tolower((UINT8)srcfile[srcfilelen-3]) == 'c' && tolower((UINT8)srcfile[srcfilelen-2]) == 'h' && tolower((UINT8)srcfile[srcfilelen-1]) == 'd') |
| 774 | | isavi = FALSE; |
| 758 | isavi = false; |
| 775 | 759 | else |
| 776 | 760 | return usage(); |
| 777 | 761 | |
| 778 | | /* open the file */ |
| 762 | // open the file |
| 779 | 763 | printf("Processing file: %s\n", srcfile); |
| 780 | | file = isavi ? open_avi(srcfile, &info) : open_chd(srcfile, &info); |
| 764 | movie_info info = { 0 }; |
| 765 | void *file = isavi ? open_avi(srcfile, info) : open_chd(srcfile, info); |
| 781 | 766 | if (file == NULL) |
| 782 | 767 | { |
| 783 | 768 | fprintf(stderr, "Unable to open file '%s'\n", srcfile); |
| 784 | 769 | return 1; |
| 785 | 770 | } |
| 786 | 771 | |
| 787 | | /* comment on the video dimensions */ |
| 772 | // comment on the video dimensions |
| 788 | 773 | printf("Video dimensions: %dx%d\n", info.width, info.height); |
| 789 | 774 | if (info.width != 720) |
| 790 | 775 | printf("WARNING: Unexpected video width (should be 720)\n"); |
| 791 | 776 | if (info.height != 524) |
| 792 | 777 | printf("WARNING: Unexpected video height (should be 262 or 524)\n"); |
| 793 | 778 | |
| 794 | | /* comment on the video frame rate */ |
| 779 | // comment on the video frame rate |
| 795 | 780 | printf("Video frame rate: %.2fHz\n", info.framerate); |
| 796 | | if ((int)(info.framerate * 100.0 + 0.5) != 2997) |
| 781 | if (int(info.framerate * 100.0 + 0.5) != 2997) |
| 797 | 782 | printf("WARNING: Unexpected frame rate (should be 29.97Hz)\n"); |
| 798 | 783 | |
| 799 | | /* comment on the sample rate */ |
| 784 | // comment on the sample rate |
| 800 | 785 | printf("Sample rate: %dHz\n", info.samplerate); |
| 801 | 786 | if (info.samplerate != 48000) |
| 802 | 787 | printf("WARNING: Unexpected sampele rate (should be 48000Hz)\n"); |
| 803 | 788 | |
| 804 | | /* allocate a bitmap */ |
| 805 | | bitmap.allocate(info.width, info.height); |
| 789 | // allocate a bitmap |
| 790 | bitmap_yuy16 bitmap(info.width, info.height); |
| 806 | 791 | |
| 807 | | /* allocate sound buffers */ |
| 808 | | lsound = (INT16 *)malloc(info.samplerate * sizeof(*lsound)); |
| 809 | | rsound = (INT16 *)malloc(info.samplerate * sizeof(*rsound)); |
| 810 | | if (lsound == NULL || rsound == NULL) |
| 811 | | { |
| 812 | | isavi ? close_avi(file) : close_chd(file); |
| 813 | | if (rsound != NULL) |
| 814 | | free(rsound); |
| 815 | | if (lsound != NULL) |
| 816 | | free(lsound); |
| 817 | | fprintf(stderr, "Out of memory allocating sound buffers of %d bytes\n", (INT32)(info.samplerate * sizeof(*rsound))); |
| 818 | | return 1; |
| 819 | | } |
| 792 | // allocate sound buffers |
| 793 | dynamic_array<INT16> lsound(info.samplerate); |
| 794 | dynamic_array<INT16> rsound(info.samplerate); |
| 820 | 795 | |
| 821 | | /* loop over frames */ |
| 822 | | frame = 0; |
| 823 | | while (isavi ? read_avi(file, frame, bitmap, lsound, rsound, &samples) : read_chd(file, frame, bitmap, lsound, rsound, &samples)) |
| 796 | // loop over frames |
| 797 | int frame = 0; |
| 798 | int samples = 0; |
| 799 | while (isavi ? read_avi(file, frame, bitmap, lsound, rsound, samples) : read_chd(file, frame, bitmap, lsound, rsound, samples)) |
| 824 | 800 | { |
| 825 | | verify_video(&video, frame, bitmap); |
| 826 | | verify_audio(&audio, lsound, rsound, samples); |
| 801 | verify_video(video, frame, bitmap); |
| 802 | verify_audio(audio, lsound, rsound, samples); |
| 827 | 803 | frame++; |
| 828 | 804 | } |
| 829 | 805 | |
| 830 | | /* close the files */ |
| 806 | // close the files |
| 831 | 807 | isavi ? close_avi(file) : close_chd(file); |
| 832 | 808 | |
| 833 | | /* final output */ |
| 834 | | verify_video_final(&video, frame, bitmap); |
| 835 | | verify_audio_final(&audio); |
| 836 | | |
| 837 | | /* free memory */ |
| 838 | | free(lsound); |
| 839 | | free(rsound); |
| 809 | // final output |
| 810 | verify_video_final(video, frame, bitmap); |
| 811 | verify_audio_final(audio); |
| 840 | 812 | } |
| 841 | 813 | catch (std::bad_alloc &) |
| 842 | 814 | { |
src/tools/ldresample.c
| r14546 | r14547 | |
| 44 | 44 | #include <new> |
| 45 | 45 | #include "bitmap.h" |
| 46 | 46 | #include "chd.h" |
| 47 | #include "avhuff.h" |
| 47 | 48 | #include "vbiparse.h" |
| 48 | 49 | |
| 49 | 50 | |
| 50 | 51 | |
| 51 | | /*************************************************************************** |
| 52 | | CONSTANTS |
| 53 | | ***************************************************************************/ |
| 52 | //************************************************************************** |
| 53 | // CONSTANTS |
| 54 | //************************************************************************** |
| 54 | 55 | |
| 55 | | /* size of window where we scan ahead to find maximum; this should be large enough to |
| 56 | | catch peaks of even slow waves */ |
| 57 | | #define MAXIMUM_WINDOW_SIZE 40 |
| 56 | // size of window where we scan ahead to find maximum; this should be large enough to |
| 57 | // catch peaks of even slow waves |
| 58 | const UINT32 MAXIMUM_WINDOW_SIZE = 40; |
| 58 | 59 | |
| 59 | | /* number of standard deviations away from silence that we consider a real signal */ |
| 60 | | #define SIGNAL_DEVIATIONS 100 |
| 60 | // number of standard deviations away from silence that we consider a real signal |
| 61 | const UINT32 SIGNAL_DEVIATIONS = 100; |
| 61 | 62 | |
| 62 | | /* number of standard deviations away from silence that we consider the start of a signal */ |
| 63 | | #define SIGNAL_START_DEVIATIONS 5 |
| 63 | // number of standard deviations away from silence that we consider the start of a signal |
| 64 | const UINT32 SIGNAL_START_DEVIATIONS = 5; |
| 64 | 65 | |
| 65 | | /* number of consecutive entries of signal before we consider that we found it */ |
| 66 | | #define MINIMUM_SIGNAL_COUNT 20 |
| 66 | // number of consecutive entries of signal before we consider that we found it |
| 67 | const UINT32 MINIMUM_SIGNAL_COUNT = 20; |
| 67 | 68 | |
| 68 | 69 | |
| 69 | 70 | |
| 70 | | /*************************************************************************** |
| 71 | | TYPE DEFINITIONS |
| 72 | | ***************************************************************************/ |
| 71 | //************************************************************************** |
| 72 | // TYPE DEFINITIONS |
| 73 | //************************************************************************** |
| 73 | 74 | |
| 74 | | typedef struct _movie_info movie_info; |
| 75 | | struct _movie_info |
| 75 | struct movie_info |
| 76 | 76 | { |
| 77 | | double framerate; |
| 78 | | int iframerate; |
| 79 | | int numfields; |
| 80 | | int width; |
| 81 | | int height; |
| 82 | | int samplerate; |
| 83 | | int channels; |
| 84 | | int interlaced; |
| 85 | | bitmap_yuy16 bitmap; |
| 77 | double framerate; |
| 78 | int iframerate; |
| 79 | int numfields; |
| 80 | int width; |
| 81 | int height; |
| 82 | int samplerate; |
| 83 | int channels; |
| 84 | int interlaced; |
| 85 | bitmap_yuy16 bitmap; |
| 86 | 86 | dynamic_array<INT16> lsound; |
| 87 | 87 | dynamic_array<INT16> rsound; |
| 88 | | UINT32 samples; |
| 88 | UINT32 samples; |
| 89 | 89 | }; |
| 90 | 90 | |
| 91 | 91 | |
| 92 | // ======================> chd_resample_compressor |
| 92 | 93 | |
| 93 | | /*************************************************************************** |
| 94 | | GLOBAL VARIABLES |
| 95 | | ***************************************************************************/ |
| 94 | class chd_resample_compressor : public chd_file_compressor |
| 95 | { |
| 96 | public: |
| 97 | // construction/destruction |
| 98 | chd_resample_compressor(chd_file &source, movie_info &info, INT64 ioffset, INT64 islope) |
| 99 | : m_source(source), |
| 100 | m_info(info), |
| 101 | m_ioffset(ioffset), |
| 102 | m_islope(islope) { } |
| 96 | 103 | |
| 104 | // read interface |
| 105 | virtual UINT32 read_data(void *_dest, UINT64 offset, UINT32 length) |
| 106 | { |
| 107 | assert(offset % m_source.hunk_bytes() == 0); |
| 108 | assert(length % m_source.hunk_bytes() == 0); |
| 109 | |
| 110 | UINT32 startfield = offset / m_source.hunk_bytes(); |
| 111 | UINT32 endfield = startfield + length / m_source.hunk_bytes(); |
| 112 | UINT8 *dest = reinterpret_cast<UINT8 *>(_dest); |
| 97 | 113 | |
| 114 | for (UINT32 fieldnum = startfield; fieldnum < endfield; fieldnum++) |
| 115 | { |
| 116 | generate_one_frame(dest, m_source.hunk_bytes(), fieldnum); |
| 117 | dest += m_source.hunk_bytes(); |
| 118 | } |
| 119 | return length; |
| 120 | } |
| 98 | 121 | |
| 99 | | /*************************************************************************** |
| 100 | | INLINE FUNCTIONS |
| 101 | | ***************************************************************************/ |
| 122 | private: |
| 123 | // internal helpers |
| 124 | void generate_one_frame(UINT8 *dest, UINT32 datasize, UINT32 fieldnum); |
| 102 | 125 | |
| 103 | | /*------------------------------------------------- |
| 104 | | field_to_sample_number - given a field number |
| 105 | | compute the absolute sample number for the |
| 106 | | first sample of that field |
| 107 | | -------------------------------------------------*/ |
| 126 | // internal state |
| 127 | chd_file & m_source; |
| 128 | movie_info & m_info; |
| 129 | INT64 m_ioffset; |
| 130 | INT64 m_islope; |
| 131 | }; |
| 108 | 132 | |
| 109 | | INLINE UINT32 field_to_sample_number(const movie_info *info, UINT32 field) |
| 133 | |
| 134 | |
| 135 | //************************************************************************** |
| 136 | // INLINE FUNCTIONS |
| 137 | //************************************************************************** |
| 138 | |
| 139 | //------------------------------------------------- |
| 140 | // field_to_sample_number - given a field number |
| 141 | // compute the absolute sample number for the |
| 142 | // first sample of that field |
| 143 | //------------------------------------------------- |
| 144 | |
| 145 | inline UINT32 field_to_sample_number(const movie_info &info, UINT32 field) |
| 110 | 146 | { |
| 111 | | return ((UINT64)info->samplerate * (UINT64)field * (UINT64)1000000 + info->iframerate - 1) / (UINT64)info->iframerate; |
| 147 | return (UINT64(info.samplerate) * UINT64(field) * UINT64(1000000) + info.iframerate - 1) / UINT64(info.iframerate); |
| 112 | 148 | } |
| 113 | 149 | |
| 114 | 150 | |
| 115 | | /*------------------------------------------------- |
| 116 | | sample_number_to_field - given a sample number |
| 117 | | compute the field where it is located and |
| 118 | | the offset within the field |
| 119 | | -------------------------------------------------*/ |
| 151 | //------------------------------------------------- |
| 152 | // sample_number_to_field - given a sample number |
| 153 | // compute the field where it is located and |
| 154 | // the offset within the field |
| 155 | //------------------------------------------------- |
| 120 | 156 | |
| 121 | | INLINE UINT32 sample_number_to_field(const movie_info *info, UINT32 samplenum, UINT32 *offset) |
| 157 | inline UINT32 sample_number_to_field(const movie_info &info, UINT32 samplenum, UINT32 &offset) |
| 122 | 158 | { |
| 123 | | UINT32 guess = ((UINT64)samplenum * (UINT64)info->iframerate + ((UINT64)info->samplerate * (UINT64)1000000 - 1)) / ((UINT64)info->samplerate * (UINT64)1000000); |
| 159 | UINT32 guess = (UINT64(samplenum) * UINT64(info.iframerate) + (UINT64(info.samplerate) * UINT64(1000000) - 1)) / (UINT64(info.samplerate) * UINT64(1000000)); |
| 124 | 160 | while (1) |
| 125 | 161 | { |
| 126 | 162 | UINT32 fieldstart = field_to_sample_number(info, guess); |
| 127 | 163 | UINT32 fieldend = field_to_sample_number(info, guess + 1); |
| 128 | 164 | if (samplenum >= fieldstart && samplenum < fieldend) |
| 129 | 165 | { |
| 130 | | *offset = samplenum - fieldstart; |
| 166 | offset = samplenum - fieldstart; |
| 131 | 167 | return guess; |
| 132 | 168 | } |
| 133 | 169 | else if (samplenum < fieldstart) |
| r14546 | r14547 | |
| 139 | 175 | |
| 140 | 176 | |
| 141 | 177 | |
| 142 | | /*************************************************************************** |
| 143 | | CHD HANDLING |
| 144 | | ***************************************************************************/ |
| 178 | //************************************************************************** |
| 179 | // CHD HANDLING |
| 180 | //************************************************************************** |
| 145 | 181 | |
| 146 | | /*------------------------------------------------- |
| 147 | | open_chd - open a CHD file and return |
| 148 | | information about it |
| 149 | | -------------------------------------------------*/ |
| 182 | //------------------------------------------------- |
| 183 | // open_chd - open a CHD file and return |
| 184 | // information about it |
| 185 | //------------------------------------------------- |
| 150 | 186 | |
| 151 | 187 | static chd_error open_chd(chd_file &file, const char *filename, movie_info &info) |
| 152 | 188 | { |
| 153 | | /* open the file */ |
| 189 | // open the file |
| 154 | 190 | chd_error chderr = file.open(filename); |
| 155 | 191 | if (chderr != CHDERR_NONE) |
| 156 | 192 | { |
| 157 | | fprintf(stderr, "Error opening CHD file: %s\n", chd_error_string(chderr)); |
| 193 | fprintf(stderr, "Error opening CHD file: %s\n", chd_file::error_string(chderr)); |
| 158 | 194 | return chderr; |
| 159 | 195 | } |
| 160 | 196 | |
| 161 | | /* get the metadata */ |
| 197 | // get the metadata |
| 162 | 198 | astring metadata; |
| 163 | | chderr = chd.read_metadata(chd, AV_METADATA_TAG, 0, metadata); |
| 199 | chderr = file.read_metadata(AV_METADATA_TAG, 0, metadata); |
| 164 | 200 | if (chderr != CHDERR_NONE) |
| 165 | 201 | { |
| 166 | | fprintf(stderr, "Error getting A/V metadata: %s\n", chd_error_string(chderr)); |
| 202 | fprintf(stderr, "Error getting A/V metadata: %s\n", chd_file::error_string(chderr)); |
| 167 | 203 | return chderr; |
| 168 | 204 | } |
| 169 | 205 | |
| 170 | | /* extract the info */ |
| 206 | // extract the info |
| 171 | 207 | int fps, fpsfrac, width, height, interlaced, channels, rate; |
| 172 | 208 | if (sscanf(metadata, AV_METADATA_FORMAT, &fps, &fpsfrac, &width, &height, &interlaced, &channels, &rate) != 7) |
| 173 | 209 | { |
| r14546 | r14547 | |
| 175 | 211 | return CHDERR_INVALID_DATA; |
| 176 | 212 | } |
| 177 | 213 | |
| 178 | | /* extract movie info */ |
| 214 | // extract movie info |
| 179 | 215 | info.iframerate = fps * 1000000 + fpsfrac; |
| 180 | 216 | info.framerate = info.iframerate / 1000000.0; |
| 181 | | info.numfields = file->hunk_count(); |
| 217 | info.numfields = file.hunk_count(); |
| 182 | 218 | info.width = width; |
| 183 | 219 | info.height = height; |
| 184 | 220 | info.interlaced = interlaced; |
| 185 | 221 | info.samplerate = rate; |
| 186 | 222 | info.channels = channels; |
| 187 | 223 | |
| 188 | | /* allocate buffers */ |
| 224 | // allocate buffers |
| 189 | 225 | info.bitmap.resize(info.width, info.height); |
| 190 | 226 | info.lsound.resize(info.samplerate); |
| 191 | 227 | info.rsound.resize(info.samplerate); |
| r14546 | r14547 | |
| 193 | 229 | } |
| 194 | 230 | |
| 195 | 231 | |
| 196 | | /*------------------------------------------------- |
| 197 | | create_chd - create a new CHD file |
| 198 | | -------------------------------------------------*/ |
| 232 | //------------------------------------------------- |
| 233 | // create_chd - create a new CHD file |
| 234 | //------------------------------------------------- |
| 199 | 235 | |
| 200 | | static chd_error create_chd(chd_compressor &file, const char *filename, chd_file &source, const movie_info &info) |
| 236 | static chd_error create_chd(chd_file_compressor &file, const char *filename, chd_file &source, const movie_info &info) |
| 201 | 237 | { |
| 202 | | /* create the file */ |
| 203 | | chd_codec_type compression = { CHD_CODEC_AVHUFF }; |
| 238 | // create the file |
| 239 | chd_codec_type compression[4] = { CHD_CODEC_AVHUFF }; |
| 204 | 240 | chd_error chderr = file.create(filename, source.logical_bytes(), source.hunk_bytes(), source.unit_bytes(), compression); |
| 205 | 241 | if (chderr != CHDERR_NONE) |
| 206 | 242 | { |
| 207 | | fprintf(stderr, "Error creating new CHD file: %s\n", chd_error_string(chderr)); |
| 243 | fprintf(stderr, "Error creating new CHD file: %s\n", chd_file::error_string(chderr)); |
| 208 | 244 | return chderr; |
| 209 | 245 | } |
| 210 | 246 | |
| 211 | | /* clone the metadata */ |
| 247 | // clone the metadata |
| 212 | 248 | chderr = file.clone_all_metadata(source); |
| 213 | 249 | if (chderr != CHDERR_NONE) |
| 214 | 250 | { |
| 215 | | fprintf(stderr, "Error cloning metadata: %s\n", chd_error_string(chderr)); |
| 251 | fprintf(stderr, "Error cloning metadata: %s\n", chd_file::error_string(chderr)); |
| 216 | 252 | return chderr; |
| 217 | 253 | } |
| 218 | 254 | |
| 219 | | /* begin compressing */ |
| 220 | | chderr = file.compress_begin(); |
| 221 | | if (chderr != CHDERR_NONE) |
| 222 | | { |
| 223 | | fprintf(stderr, "Error beginning compression: %s\n", chd_error_string(chderr)); |
| 224 | | return chderr; |
| 225 | | } |
| 226 | | |
| 255 | // begin compressing |
| 256 | file.compress_begin(); |
| 227 | 257 | return CHDERR_NONE; |
| 228 | 258 | } |
| 229 | 259 | |
| 230 | 260 | |
| 231 | | /*------------------------------------------------- |
| 232 | | read_chd - read a field from a CHD file |
| 233 | | -------------------------------------------------*/ |
| 261 | //------------------------------------------------- |
| 262 | // read_chd - read a field from a CHD file |
| 263 | //------------------------------------------------- |
| 234 | 264 | |
| 235 | | static int read_chd(chd_file *file, UINT32 field, movie_info *info, UINT32 soundoffs) |
| 265 | static bool read_chd(chd_file &file, UINT32 field, movie_info &info, UINT32 soundoffs) |
| 236 | 266 | { |
| 237 | | av_codec_decompress_config avconfig; |
| 238 | | chd_error chderr; |
| 267 | // configure the codec |
| 268 | avhuff_decompress_config avconfig; |
| 269 | avconfig.video.wrap(info.bitmap, info.bitmap.cliprect()); |
| 270 | avconfig.maxsamples = info.lsound.count(); |
| 271 | avconfig.actsamples = &info.samples; |
| 272 | avconfig.audio[0] = info.lsound + soundoffs; |
| 273 | avconfig.audio[1] = info.rsound + soundoffs; |
| 239 | 274 | |
| 240 | | /* configure the codec */ |
| 241 | | avconfig.video.wrap(*info->bitmap, info->bitmap->cliprect()); |
| 242 | | avconfig.maxsamples = 48000; |
| 243 | | avconfig.actsamples = &info->samples; |
| 244 | | avconfig.audio[0] = info->lsound + soundoffs; |
| 245 | | avconfig.audio[1] = info->rsound + soundoffs; |
| 275 | // configure the decompressor for this field |
| 276 | file.codec_configure(CHD_CODEC_AVHUFF, AVHUFF_CODEC_DECOMPRESS_CONFIG, &avconfig); |
| 246 | 277 | |
| 247 | | /* configure the decompressor for this field */ |
| 248 | | chd_codec_config(file, AV_CODEC_DECOMPRESS_CONFIG, &avconfig); |
| 249 | | |
| 250 | | /* read the field */ |
| 251 | | chderr = chd_read(file, field, NULL); |
| 252 | | if (chderr != CHDERR_NONE) |
| 253 | | return FALSE; |
| 254 | | |
| 255 | | return TRUE; |
| 278 | // read the field |
| 279 | chd_error chderr = file.read_hunk(field, NULL); |
| 280 | return (chderr == CHDERR_NONE); |
| 256 | 281 | } |
| 257 | 282 | |
| 258 | 283 | |
| 259 | | /*------------------------------------------------- |
| 260 | | write_chd - write a field to a CHD file |
| 261 | | -------------------------------------------------*/ |
| 262 | 284 | |
| 263 | | static int write_chd(chd_file *file, UINT32 field, movie_info *info) |
| 264 | | { |
| 265 | | av_codec_compress_config avconfig; |
| 266 | | chd_error chderr; |
| 285 | //************************************************************************** |
| 286 | // CORE IMPLEMENTATION |
| 287 | //************************************************************************** |
| 267 | 288 | |
| 268 | | /* configure the codec */ |
| 269 | | avconfig.video.wrap(*info->bitmap, info->bitmap->cliprect()); |
| 270 | | avconfig.channels = 2; |
| 271 | | avconfig.samples = info->samples; |
| 272 | | avconfig.audio[0] = info->lsound; |
| 273 | | avconfig.audio[1] = info->rsound; |
| 289 | //------------------------------------------------- |
| 290 | // find_edge_near_field - given a field number, |
| 291 | // load +/- 1/2 second on either side and find |
| 292 | // an audio edge |
| 293 | //------------------------------------------------- |
| 274 | 294 | |
| 275 | | /* configure the decompressor for this field */ |
| 276 | | chd_codec_config(file, AV_CODEC_COMPRESS_CONFIG, &avconfig); |
| 277 | | |
| 278 | | /* read the field */ |
| 279 | | chderr = chd_compress_hunk(file, NULL, NULL); |
| 280 | | if (chderr != CHDERR_NONE) |
| 281 | | return FALSE; |
| 282 | | |
| 283 | | return TRUE; |
| 284 | | } |
| 285 | | |
| 286 | | |
| 287 | | /*------------------------------------------------- |
| 288 | | create_close_chd - close a CHD file |
| 289 | | -------------------------------------------------*/ |
| 290 | | |
| 291 | | static void create_close_chd(chd_file *file) |
| 295 | static bool find_edge_near_field(chd_file &srcfile, UINT32 fieldnum, movie_info &info, bool report_best_field, INT32 &delta) |
| 292 | 296 | { |
| 293 | | chd_error err; |
| 297 | // clear the sound buffers |
| 298 | memset(info.lsound, 0, info.lsound.count() * 2); |
| 299 | memset(info.rsound, 0, info.rsound.count() * 2); |
| 294 | 300 | |
| 295 | | err = chd_compress_finish(file, TRUE); |
| 296 | | if (err != CHDERR_NONE) |
| 297 | | fprintf(stderr, "Error finishing compression: %s\n", chd_error_string(err)); |
| 298 | | |
| 299 | | chd_close(file); |
| 300 | | } |
| 301 | | |
| 302 | | |
| 303 | | /*------------------------------------------------- |
| 304 | | close_chd - close a CHD file |
| 305 | | -------------------------------------------------*/ |
| 306 | | |
| 307 | | static void close_chd(chd_file *file, movie_info *info) |
| 308 | | { |
| 309 | | if (info != NULL) |
| 310 | | chd_free_buffers(info); |
| 311 | | chd_close(file); |
| 312 | | } |
| 313 | | |
| 314 | | |
| 315 | | |
| 316 | | /*************************************************************************** |
| 317 | | CORE IMPLEMENTATION |
| 318 | | ***************************************************************************/ |
| 319 | | |
| 320 | | /*------------------------------------------------- |
| 321 | | find_edge_near_field - given a field number, |
| 322 | | load +/- 1/2 second on either side and find |
| 323 | | an audio edge |
| 324 | | -------------------------------------------------*/ |
| 325 | | |
| 326 | | static int find_edge_near_field(chd_file *srcfile, UINT32 fieldnum, movie_info *info, int report_best_field, INT32 *delta) |
| 327 | | { |
| 328 | | int fields_to_read = info->iframerate / 1000000; |
| 329 | | UINT32 firstlavg = 0, firstravg = 0; |
| 330 | | UINT32 firstldev = 0, firstrdev = 0; |
| 331 | | UINT32 lcount = 0, rcount = 0; |
| 301 | // read 1 second around the target area |
| 302 | int fields_to_read = info.iframerate / 1000000; |
| 303 | INT32 firstfield = fieldnum - (fields_to_read / 2); |
| 332 | 304 | UINT32 targetsoundstart = 0; |
| 333 | 305 | UINT32 firstfieldend = 0; |
| 334 | | INT32 firstfield, curfield; |
| 335 | 306 | UINT32 fieldstart[100]; |
| 336 | 307 | UINT32 soundend = 0; |
| 337 | | UINT32 sampnum; |
| 338 | | |
| 339 | | /* clear the sound buffers */ |
| 340 | | memset(info->lsound, 0, info->samplerate * sizeof(*info->lsound)); |
| 341 | | memset(info->rsound, 0, info->samplerate * sizeof(*info->rsound)); |
| 342 | | |
| 343 | | /* read 1 second around the target area */ |
| 344 | | firstfield = fieldnum - (fields_to_read / 2); |
| 345 | | for (curfield = 0; curfield < fields_to_read; curfield++) |
| 308 | for (INT32 curfield = 0; curfield < fields_to_read; curfield++) |
| 346 | 309 | { |
| 347 | | /* remember the start of each field */ |
| 310 | // remember the start of each field |
| 348 | 311 | fieldstart[curfield] = soundend; |
| 349 | 312 | |
| 350 | | /* remember the sound offset where the initial fieldnum is */ |
| 313 | // remember the sound offset where the initial fieldnum is |
| 351 | 314 | if (firstfield + curfield == fieldnum) |
| 352 | 315 | targetsoundstart = soundend; |
| 353 | 316 | |
| 354 | | /* read the frame and samples */ |
| 317 | // read the frame and samples |
| 355 | 318 | if (firstfield + curfield >= 0) |
| 356 | 319 | { |
| 357 | 320 | read_chd(srcfile, firstfield + curfield, info, soundend); |
| 358 | | soundend += info->samples; |
| 321 | soundend += info.samples; |
| 359 | 322 | |
| 360 | | /* also remember the offset at the end of the first field */ |
| 323 | // also remember the offset at the end of the first field |
| 361 | 324 | if (firstfieldend == 0) |
| 362 | 325 | firstfieldend = soundend; |
| 363 | 326 | } |
| 364 | 327 | } |
| 365 | 328 | |
| 366 | | /* compute absolute deltas across the samples */ |
| 367 | | for (sampnum = 0; sampnum < soundend; sampnum++) |
| 329 | // compute absolute deltas across the samples |
| 330 | for (UINT32 sampnum = 0; sampnum < soundend; sampnum++) |
| 368 | 331 | { |
| 369 | | info->lsound[sampnum] = labs(info->lsound[sampnum + 1] - info->lsound[sampnum]); |
| 370 | | info->rsound[sampnum] = labs(info->rsound[sampnum + 1] - info->rsound[sampnum]); |
| 332 | info.lsound[sampnum] = labs(info.lsound[sampnum + 1] - info.lsound[sampnum]); |
| 333 | info.rsound[sampnum] = labs(info.rsound[sampnum + 1] - info.rsound[sampnum]); |
| 371 | 334 | } |
| 372 | 335 | |
| 373 | | /* for each sample in the collection, find the highest deltas over the |
| 374 | | next few samples, and take the nth highest value (to remove outliers) */ |
| 375 | | for (sampnum = 0; sampnum < soundend - MAXIMUM_WINDOW_SIZE; sampnum++) |
| 336 | // for each sample in the collection, find the highest deltas over the |
| 337 | // next few samples, and take the nth highest value (to remove outliers) |
| 338 | for (UINT32 sampnum = 0; sampnum < soundend - MAXIMUM_WINDOW_SIZE; sampnum++) |
| 376 | 339 | { |
| 340 | // scan forward over the maximum window |
| 377 | 341 | UINT32 lmax = 0, rmax = 0; |
| 378 | | UINT32 scannum; |
| 379 | | |
| 380 | | /* scan forward over the maximum window */ |
| 381 | | for (scannum = 0; scannum < MAXIMUM_WINDOW_SIZE; scannum++) |
| 342 | for (UINT32 scannum = 0; scannum < MAXIMUM_WINDOW_SIZE; scannum++) |
| 382 | 343 | { |
| 383 | | if (info->lsound[sampnum + scannum] > lmax) |
| 384 | | lmax = info->lsound[sampnum + scannum]; |
| 385 | | if (info->rsound[sampnum + scannum] > rmax) |
| 386 | | rmax = info->rsound[sampnum + scannum]; |
| 344 | if (info.lsound[sampnum + scannum] > lmax) |
| 345 | lmax = info.lsound[sampnum + scannum]; |
| 346 | if (info.rsound[sampnum + scannum] > rmax) |
| 347 | rmax = info.rsound[sampnum + scannum]; |
| 387 | 348 | } |
| 388 | 349 | |
| 389 | | /* replace this sample with the maximum value found */ |
| 390 | | info->lsound[sampnum] = lmax; |
| 391 | | info->rsound[sampnum] = rmax; |
| 350 | // replace this sample with the maximum value found |
| 351 | info.lsound[sampnum] = lmax; |
| 352 | info.rsound[sampnum] = rmax; |
| 392 | 353 | } |
| 393 | 354 | |
| 394 | | /* now compute the average over the first field, which is assumed to be silence */ |
| 395 | | for (sampnum = 0; sampnum < firstfieldend; sampnum++) |
| 355 | // now compute the average over the first field, which is assumed to be silence |
| 356 | UINT32 firstlavg = 0; |
| 357 | UINT32 firstravg = 0; |
| 358 | for (UINT32 sampnum = 0; sampnum < firstfieldend; sampnum++) |
| 396 | 359 | { |
| 397 | | firstlavg += info->lsound[sampnum]; |
| 398 | | firstravg += info->rsound[sampnum]; |
| 360 | firstlavg += info.lsound[sampnum]; |
| 361 | firstravg += info.rsound[sampnum]; |
| 399 | 362 | } |
| 400 | 363 | firstlavg /= firstfieldend; |
| 401 | 364 | firstravg /= firstfieldend; |
| 402 | 365 | |
| 403 | | /* then compute the standard deviation over the first field */ |
| 404 | | for (sampnum = 0; sampnum < firstfieldend; sampnum++) |
| 366 | // then compute the standard deviation over the first field |
| 367 | UINT32 firstldev = 0; |
| 368 | UINT32 firstrdev = 0; |
| 369 | for (UINT32 sampnum = 0; sampnum < firstfieldend; sampnum++) |
| 405 | 370 | { |
| 406 | | firstldev += (info->lsound[sampnum] - firstlavg) * (info->lsound[sampnum] - firstlavg); |
| 407 | | firstrdev += (info->rsound[sampnum] - firstravg) * (info->rsound[sampnum] - firstravg); |
| 371 | firstldev += (info.lsound[sampnum] - firstlavg) * (info.lsound[sampnum] - firstlavg); |
| 372 | firstrdev += (info.rsound[sampnum] - firstravg) * (info.rsound[sampnum] - firstravg); |
| 408 | 373 | } |
| 409 | | firstldev = sqrt((double)firstldev / firstfieldend); |
| 410 | | firstrdev = sqrt((double)firstrdev / firstfieldend); |
| 374 | firstldev = sqrt(double(firstldev) / firstfieldend); |
| 375 | firstrdev = sqrt(double(firstrdev) / firstfieldend); |
| 411 | 376 | |
| 412 | | /* scan forward through the samples, counting consecutive samples more than |
| 413 | | SIGNAL_DEVIATIONS standard deviations away from silence */ |
| 377 | // scan forward through the samples, counting consecutive samples more than |
| 378 | // SIGNAL_DEVIATIONS standard deviations away from silence |
| 379 | UINT32 lcount = 0; |
| 380 | UINT32 rcount = 0; |
| 381 | UINT32 sampnum = 0; |
| 414 | 382 | for (sampnum = 0; sampnum < soundend; sampnum++) |
| 415 | 383 | { |
| 416 | | /* left speaker */ |
| 417 | | if (info->lsound[sampnum] > firstlavg + SIGNAL_DEVIATIONS * firstldev) |
| 384 | // left speaker |
| 385 | if (info.lsound[sampnum] > firstlavg + SIGNAL_DEVIATIONS * firstldev) |
| 418 | 386 | lcount++; |
| 419 | 387 | else |
| 420 | 388 | lcount = 0; |
| 421 | 389 | |
| 422 | | /* right speaker */ |
| 423 | | if (info->rsound[sampnum] > firstravg + SIGNAL_DEVIATIONS * firstrdev) |
| 390 | // right speaker |
| 391 | if (info.rsound[sampnum] > firstravg + SIGNAL_DEVIATIONS * firstrdev) |
| 424 | 392 | rcount++; |
| 425 | 393 | else |
| 426 | 394 | rcount = 0; |
| 427 | 395 | |
| 428 | | /* stop if we find enough */ |
| 396 | // stop if we find enough |
| 429 | 397 | if (lcount > MINIMUM_SIGNAL_COUNT || rcount > MINIMUM_SIGNAL_COUNT) |
| 430 | 398 | break; |
| 431 | 399 | } |
| 432 | 400 | |
| 433 | | /* if we didn't find any, return failure */ |
| 401 | // if we didn't find any, return failure |
| 434 | 402 | if (sampnum >= soundend) |
| 435 | 403 | { |
| 436 | 404 | if (!report_best_field) |
| 437 | 405 | printf("Field %5d: Unable to find edge\n", fieldnum); |
| 438 | | return FALSE; |
| 406 | return false; |
| 439 | 407 | } |
| 440 | 408 | |
| 441 | | /* scan backwards to find the start of the signal */ |
| 409 | // scan backwards to find the start of the signal |
| 442 | 410 | for ( ; sampnum > 0; sampnum--) |
| 443 | | if (info->lsound[sampnum - 1] < firstlavg + SIGNAL_START_DEVIATIONS * firstldev || |
| 444 | | info->rsound[sampnum - 1] < firstravg + SIGNAL_START_DEVIATIONS * firstrdev) |
| 411 | if (info.lsound[sampnum - 1] < firstlavg + SIGNAL_START_DEVIATIONS * firstldev || |
| 412 | info.rsound[sampnum - 1] < firstravg + SIGNAL_START_DEVIATIONS * firstrdev) |
| 445 | 413 | break; |
| 446 | 414 | |
| 447 | | /* if we're to report the best field, figure out which field we are in */ |
| 415 | // if we're to report the best field, figure out which field we are in |
| 448 | 416 | if (report_best_field) |
| 449 | 417 | { |
| 418 | INT32 curfield; |
| 450 | 419 | for (curfield = 0; curfield < fields_to_read - 1; curfield++) |
| 451 | 420 | if (sampnum < fieldstart[curfield + 1]) |
| 452 | 421 | break; |
| 453 | 422 | printf("Field %5d: Edge found at offset %d (frame %.1f)\n", firstfield + curfield, sampnum - fieldstart[curfield], (double)(firstfield + curfield) * 0.5); |
| 454 | 423 | } |
| 455 | 424 | |
| 456 | | /* otherwise, compute the delta from the provided field number */ |
| 425 | // otherwise, compute the delta from the provided field number |
| 457 | 426 | else |
| 458 | 427 | { |
| 459 | 428 | printf("Field %5d: Edge at offset %d from expected (found at %d, expected %d)\n", fieldnum, sampnum - targetsoundstart, sampnum, targetsoundstart); |
| 460 | | *delta = sampnum - targetsoundstart; |
| 429 | delta = sampnum - targetsoundstart; |
| 461 | 430 | } |
| 462 | | return TRUE; |
| 431 | return true; |
| 463 | 432 | } |
| 464 | 433 | |
| 465 | 434 | |
| 466 | | /*------------------------------------------------- |
| 467 | | usage - display program usage |
| 468 | | -------------------------------------------------*/ |
| 435 | //------------------------------------------------- |
| 436 | // generate_one_frame - generate a single |
| 437 | // resampled frame |
| 438 | //------------------------------------------------- |
| 469 | 439 | |
| 440 | void chd_resample_compressor::generate_one_frame(UINT8 *dest, UINT32 datasize, UINT32 fieldnum) |
| 441 | { |
| 442 | // determine the first field needed to cover this range of samples |
| 443 | UINT32 srcbegin = field_to_sample_number(m_info, fieldnum); |
| 444 | INT64 dstbegin = (INT64(srcbegin) << 24) + m_ioffset + m_islope * fieldnum; |
| 445 | UINT32 dstbeginoffset; |
| 446 | INT32 dstbeginfield; |
| 447 | if (dstbegin >= 0) |
| 448 | dstbeginfield = sample_number_to_field(m_info, dstbegin >> 24, dstbeginoffset); |
| 449 | else |
| 450 | { |
| 451 | dstbeginfield = -1 - sample_number_to_field(m_info, -dstbegin >> 24, dstbeginoffset); |
| 452 | dstbeginoffset = (field_to_sample_number(m_info, -dstbeginfield) - field_to_sample_number(m_info, -dstbeginfield - 1)) - dstbeginoffset; |
| 453 | } |
| 454 | |
| 455 | // determine the last field needed to cover this range of samples |
| 456 | UINT32 srcend = field_to_sample_number(m_info, fieldnum + 1); |
| 457 | INT64 dstend = (INT64(srcend) << 24) + m_ioffset + m_islope * (fieldnum + 1); |
| 458 | UINT32 dstendoffset; |
| 459 | INT32 dstendfield; |
| 460 | if (dstend >= 0) |
| 461 | dstendfield = sample_number_to_field(m_info, dstend >> 24, dstendoffset); |
| 462 | else |
| 463 | { |
| 464 | dstendfield = -1 - -sample_number_to_field(m_info, -dstend >> 24, dstendoffset); |
| 465 | dstendoffset = (field_to_sample_number(m_info, -dstendfield) - field_to_sample_number(m_info, -dstendfield - 1)) - dstendoffset; |
| 466 | } |
| 467 | /* |
| 468 | printf("%5d: start=%10d (%5d.%03d) end=%10d (%5d.%03d)\n", |
| 469 | fieldnum, |
| 470 | (INT32)(dstbegin >> 24), dstbeginfield, dstbeginoffset, |
| 471 | (INT32)(dstend >> 24), dstendfield, dstendoffset); |
| 472 | */ |
| 473 | // read all samples required into the end of the sound buffers |
| 474 | UINT32 dstoffset = srcend - srcbegin; |
| 475 | for (INT32 dstfield = dstbeginfield; dstfield <= dstendfield; dstfield++) |
| 476 | { |
| 477 | if (dstfield >= 0) |
| 478 | read_chd(m_source, dstfield, m_info, dstoffset); |
| 479 | else |
| 480 | { |
| 481 | m_info.samples = field_to_sample_number(m_info, -dstfield) - field_to_sample_number(m_info, -dstfield - 1); |
| 482 | memset(&m_info.lsound[dstoffset], 0, m_info.samples * sizeof(m_info.lsound[0])); |
| 483 | memset(&m_info.rsound[dstoffset], 0, m_info.samples * sizeof(m_info.rsound[0])); |
| 484 | } |
| 485 | dstoffset += m_info.samples; |
| 486 | } |
| 487 | |
| 488 | // resample the destination samples to the source |
| 489 | dstoffset = srcend - srcbegin; |
| 490 | INT64 dstpos = dstbegin; |
| 491 | INT64 dststep = (dstend - dstbegin) / INT64(srcend - srcbegin); |
| 492 | for (UINT32 srcoffset = 0; srcoffset < srcend - srcbegin; srcoffset++) |
| 493 | { |
| 494 | m_info.lsound[srcoffset] = m_info.lsound[(int)(dstoffset + dstbeginoffset + (dstpos >> 24) - (dstbegin >> 24))]; |
| 495 | m_info.rsound[srcoffset] = m_info.rsound[(int)(dstoffset + dstbeginoffset + (dstpos >> 24) - (dstbegin >> 24))]; |
| 496 | dstpos += dststep; |
| 497 | } |
| 498 | |
| 499 | // read the original frame, pointing the sound buffer past where we've calculated |
| 500 | read_chd(m_source, fieldnum, m_info, srcend - srcbegin); |
| 501 | |
| 502 | // assemble the final frame |
| 503 | dynamic_buffer buffer; |
| 504 | INT16 *sampledata[2] = { m_info.lsound, m_info.rsound }; |
| 505 | avhuff_encoder::assemble_data(buffer, m_info.bitmap, m_info.channels, m_info.samples, sampledata); |
| 506 | memcpy(dest, buffer, MIN(buffer.count(), datasize)); |
| 507 | if (buffer.count() < datasize) |
| 508 | memset(&dest[buffer.count()], 0, datasize - buffer.count()); |
| 509 | } |
| 510 | |
| 511 | |
| 512 | //------------------------------------------------- |
| 513 | // usage - display program usage |
| 514 | //------------------------------------------------- |
| 515 | |
| 470 | 516 | static int usage(void) |
| 471 | 517 | { |
| 472 | 518 | fprintf(stderr, "Usage: \n"); |
| r14546 | r14547 | |
| 480 | 526 | } |
| 481 | 527 | |
| 482 | 528 | |
| 483 | | /*------------------------------------------------- |
| 484 | | main - main entry point |
| 485 | | -------------------------------------------------*/ |
| 529 | //------------------------------------------------- |
| 530 | // main - main entry point |
| 531 | //------------------------------------------------- |
| 486 | 532 | |
| 487 | 533 | int main(int argc, char *argv[]) |
| 488 | 534 | { |
| 489 | | movie_info info = { 0 }; |
| 490 | | const char *srcfilename; |
| 491 | | const char *dstfilename; |
| 492 | | double offset, slope; |
| 493 | | chd_file *dstfile; |
| 494 | | |
| 495 | | /* verify arguments */ |
| 535 | // verify arguments |
| 496 | 536 | if (argc < 2) |
| 497 | 537 | return usage(); |
| 498 | | srcfilename = argv[1]; |
| 499 | | dstfilename = (argc < 3) ? NULL : argv[2]; |
| 500 | | offset = (argc < 4) ? 0.0 : atof(argv[3]); |
| 501 | | slope = (argc < 5) ? 1.0 : atof(argv[4]); |
| 538 | const char *srcfilename = argv[1]; |
| 539 | const char *dstfilename = (argc < 3) ? NULL : argv[2]; |
| 540 | double offset = (argc < 4) ? 0.0 : atof(argv[3]); |
| 541 | double slope = (argc < 5) ? 1.0 : atof(argv[4]); |
| 502 | 542 | |
| 503 | | /* print basic information */ |
| 543 | // print basic information |
| 504 | 544 | printf("Input file: %s\n", srcfilename); |
| 505 | 545 | if (dstfilename != NULL) |
| 506 | 546 | { |
| r14546 | r14547 | |
| 509 | 549 | printf("Slope: %f\n", slope); |
| 510 | 550 | } |
| 511 | 551 | |
| 512 | | /* open the source file */ |
| 552 | // open the source file |
| 513 | 553 | chd_file srcfile; |
| 554 | movie_info info; |
| 514 | 555 | chd_error err = open_chd(srcfile, srcfilename, info); |
| 515 | 556 | if (err != CHDERR_NONE) |
| 516 | 557 | { |
| r14546 | r14547 | |
| 518 | 559 | return 1; |
| 519 | 560 | } |
| 520 | 561 | |
| 521 | | /* output some basics */ |
| 562 | // output some basics |
| 522 | 563 | printf("Video dimensions: %dx%d\n", info.width, info.height); |
| 523 | 564 | printf("Video frame rate: %.2fHz\n", info.framerate); |
| 524 | 565 | printf("Sample rate: %dHz\n", info.samplerate); |
| 525 | 566 | printf("Total fields: %d\n", info.numfields); |
| 526 | 567 | |
| 527 | | /* if we don't have a destination file, scan for edges */ |
| 568 | // if we don't have a destination file, scan for edges |
| 528 | 569 | if (dstfilename == NULL) |
| 529 | 570 | { |
| 530 | | UINT32 fieldnum; |
| 531 | | INT32 delta; |
| 532 | | |
| 533 | | for (fieldnum = 60; fieldnum < info.numfields - 60; fieldnum += 30) |
| 571 | for (UINT32 fieldnum = 60; fieldnum < info.numfields - 60; fieldnum += 30) |
| 534 | 572 | { |
| 535 | 573 | fprintf(stderr, "Field %5d\r", fieldnum); |
| 536 | | find_edge_near_field(srcfile, fieldnum, &info, TRUE, &delta); |
| 574 | INT32 delta; |
| 575 | find_edge_near_field(srcfile, fieldnum, info, true, delta); |
| 537 | 576 | } |
| 538 | 577 | } |
| 539 | 578 | |
| 540 | | /* otherwise, resample the source to the destination */ |
| 579 | // otherwise, resample the source to the destination |
| 541 | 580 | else |
| 542 | 581 | { |
| 543 | | INT64 ioffset = (INT64)(offset * 65536.0 * 256.0); |
| 544 | | INT64 islope = (INT64)(slope * 65536.0 * 256.0); |
| 545 | | UINT32 fieldnum; |
| 546 | | |
| 547 | | /* open the destination file */ |
| 582 | // open the destination file |
| 583 | chd_resample_compressor dstfile(srcfile, info, INT64(offset * 65536.0 * 256.0), INT64(slope * 65536.0 * 256.0)); |
| 548 | 584 | err = create_chd(dstfile, dstfilename, srcfile, info); |
| 549 | 585 | if (dstfile == NULL) |
| 550 | 586 | { |
| r14546 | r14547 | |
| 552 | 588 | return 1; |
| 553 | 589 | } |
| 554 | 590 | |
| 555 | | /* loop over all the fields in the source file */ |
| 556 | | for (fieldnum = 0; fieldnum < info.numfields; fieldnum++) |
| 557 | | { |
| 558 | | UINT32 srcbegin = field_to_sample_number(&info, fieldnum); |
| 559 | | UINT32 srcend = field_to_sample_number(&info, fieldnum + 1); |
| 560 | | INT64 dstbegin = ((INT64)srcbegin << 24) + ioffset + islope * fieldnum; |
| 561 | | INT64 dstend = ((INT64)srcend << 24) + ioffset + islope * (fieldnum + 1); |
| 562 | | UINT32 dstbeginoffset, dstendoffset, dstoffset; |
| 563 | | INT32 dstbeginfield, dstendfield, dstfield; |
| 564 | | INT64 dstpos, dststep; |
| 565 | | UINT32 srcoffset; |
| 566 | | |
| 567 | | /* update progress (this ain't fast!) */ |
| 568 | | if (fieldnum % 10 == 0) |
| 569 | | fprintf(stderr, "Field %d\r", fieldnum); |
| 570 | | |
| 571 | | /* determine the first and last fields needed to cover this range of samples */ |
| 572 | | if (dstbegin >= 0) |
| 573 | | dstbeginfield = sample_number_to_field(&info, dstbegin >> 24, &dstbeginoffset); |
| 574 | | else |
| 591 | // loop over all the fields in the source file |
| 592 | double progress, ratio; |
| 593 | osd_ticks_t last_update = 0; |
| 594 | while (dstfile.compress_continue(progress, ratio) == CHDERR_COMPRESSING) |
| 595 | if (osd_ticks() - last_update > osd_ticks_per_second() / 4) |
| 575 | 596 | { |
| 576 | | dstbeginfield = -1 - sample_number_to_field(&info, -dstbegin >> 24, &dstbeginoffset); |
| 577 | | dstbeginoffset = (field_to_sample_number(&info, -dstbeginfield) - field_to_sample_number(&info, -dstbeginfield - 1)) - dstbeginoffset; |
| 597 | last_update = osd_ticks(); |
| 598 | printf("Processing, %.1f%% complete....\r", progress * 100.0); |
| 578 | 599 | } |
| 579 | | if (dstend >= 0) |
| 580 | | dstendfield = sample_number_to_field(&info, dstend >> 24, &dstendoffset); |
| 581 | | else |
| 582 | | { |
| 583 | | dstendfield = -1 - -sample_number_to_field(&info, -dstend >> 24, &dstendoffset); |
| 584 | | dstendoffset = (field_to_sample_number(&info, -dstendfield) - field_to_sample_number(&info, -dstendfield - 1)) - dstendoffset; |
| 585 | | } |
| 586 | | /* |
| 587 | | printf("%5d: start=%10d (%5d.%03d) end=%10d (%5d.%03d)\n", |
| 588 | | fieldnum, |
| 589 | | (INT32)(dstbegin >> 24), dstbeginfield, dstbeginoffset, |
| 590 | | (INT32)(dstend >> 24), dstendfield, dstendoffset); |
| 591 | | */ |
| 592 | | /* read all samples required into the end of the sound buffers */ |
| 593 | | dstoffset = srcend - srcbegin; |
| 594 | | for (dstfield = dstbeginfield; dstfield <= dstendfield; dstfield++) |
| 595 | | { |
| 596 | | if (dstfield >= 0) |
| 597 | | read_chd(srcfile, dstfield, &info, dstoffset); |
| 598 | | else |
| 599 | | { |
| 600 | | info.samples = field_to_sample_number(&info, -dstfield) - field_to_sample_number(&info, -dstfield - 1); |
| 601 | | memset(&info.lsound[dstoffset], 0, info.samples * sizeof(info.lsound[0])); |
| 602 | | memset(&info.rsound[dstoffset], 0, info.samples * sizeof(info.rsound[0])); |
| 603 | | } |
| 604 | | dstoffset += info.samples; |
| 605 | | } |
| 606 | | |
| 607 | | /* resample the destination samples to the source */ |
| 608 | | dstoffset = srcend - srcbegin; |
| 609 | | dstpos = dstbegin; |
| 610 | | dststep = (dstend - dstbegin) / (INT64)(srcend - srcbegin); |
| 611 | | for (srcoffset = 0; srcoffset < srcend - srcbegin; srcoffset++) |
| 612 | | { |
| 613 | | info.lsound[srcoffset] = info.lsound[dstoffset + dstbeginoffset + (dstpos >> 24) - (dstbegin >> 24)]; |
| 614 | | info.rsound[srcoffset] = info.rsound[dstoffset + dstbeginoffset + (dstpos >> 24) - (dstbegin >> 24)]; |
| 615 | | dstpos += dststep; |
| 616 | | } |
| 617 | | |
| 618 | | /* read the original frame, pointing the sound buffer past where we've calculated */ |
| 619 | | read_chd(srcfile, fieldnum, &info, srcend - srcbegin); |
| 620 | | |
| 621 | | /* write it to the destination */ |
| 622 | | write_chd(dstfile, fieldnum, &info); |
| 623 | | } |
| 624 | | |
| 625 | | /* close the destination file */ |
| 626 | | create_close_chd(dstfile); |
| 627 | 600 | } |
| 628 | | |
| 629 | | /* close the source file */ |
| 630 | | close_chd(srcfile, &info); |
| 631 | | |
| 632 | 601 | return 0; |
| 633 | 602 | } |
src/emu/info.c
| r14546 | r14547 | |
| 239 | 239 | CONFIG_VERSION |
| 240 | 240 | ); |
| 241 | 241 | |
| 242 | | m_device_used = global_alloc_array_clear(UINT8, m_device_count); |
| 242 | m_device_used.resize(m_device_count); |
| 243 | memset(m_device_used, 0, m_device_count); |
| 243 | 244 | |
| 244 | 245 | // iterate through the drivers, outputting one at a time |
| 245 | 246 | while (m_drivlist.next()) |
| r14546 | r14547 | |
| 248 | 249 | // iterate through the devices, and output their roms |
| 249 | 250 | output_devices(); |
| 250 | 251 | |
| 251 | | global_free(m_device_used); |
| 252 | | |
| 253 | 252 | // close the top level tag |
| 254 | 253 | fprintf(m_output, "</%s>\n",emulator_info::get_xml_root()); |
| 255 | 254 | } |
| r14546 | r14547 | |
| 266 | 265 | m_drivlist.next(); |
| 267 | 266 | machine_config &config = m_drivlist.config(); |
| 268 | 267 | device_t &owner = config.root_device(); |
| 268 | |
| 269 | 269 | // check if all are listed, note that empty one is included |
| 270 | | bool display_all = driver_list::total() == (m_drivlist.count()+1); |
| 271 | | for(int i=0;i<m_device_count;i++) { |
| 272 | | if (display_all || (m_device_used[i]!=0)) { |
| 273 | | device_type type = *s_devices_sorted[i]; |
| 270 | bool display_all = (driver_list::total() == m_drivlist.count() + 1); |
| 271 | for (int devnum = 0; devnum < m_device_count; devnum++) |
| 272 | { |
| 273 | if (display_all || m_device_used[devnum]) |
| 274 | { |
| 275 | device_type type = *s_devices_sorted[devnum]; |
| 274 | 276 | device_t *dev = (*type)(config, "dummy", &owner, 0); |
| 275 | 277 | dev->config_complete(); |
| 276 | 278 | |
| 277 | 279 | // print the header and the game name |
| 278 | | fprintf(m_output, "\t<%s",emulator_info::get_xml_top()); |
| 280 | fprintf(m_output, "\t<%s", emulator_info::get_xml_top()); |
| 279 | 281 | fprintf(m_output, " name=\"%s\"", xml_normalize_string(dev->shortname())); |
| 280 | 282 | fprintf(m_output, " isdevice=\"yes\""); |
| 281 | 283 | fprintf(m_output, " runnable=\"no\""); |
| r14546 | r14547 | |
| 285 | 287 | if (dev->name() != NULL) |
| 286 | 288 | fprintf(m_output, "\t\t<description>%s</description>\n", xml_normalize_string(dev->name())); |
| 287 | 289 | |
| 288 | | output_rom(dev); |
| 290 | output_rom(*dev); |
| 289 | 291 | |
| 290 | 292 | // close the topmost tag |
| 291 | | fprintf(m_output, "\t</%s>\n",emulator_info::get_xml_top()); |
| 293 | fprintf(m_output, "\t</%s>\n", emulator_info::get_xml_top()); |
| 292 | 294 | global_free(dev); |
| 293 | 295 | } |
| 294 | 296 | } |
| 295 | 297 | } |
| 296 | 298 | |
| 299 | |
| 297 | 300 | //------------------------------------------------- |
| 298 | 301 | // output_one - print the XML information |
| 299 | 302 | // for one particular game driver |
| r14546 | r14547 | |
| 359 | 362 | |
| 360 | 363 | // now print various additional information |
| 361 | 364 | output_bios(); |
| 362 | | output_rom(rom_first_source(m_drivlist.config())); |
| 365 | output_rom(m_drivlist.config().root_device()); |
| 363 | 366 | output_device_roms(); |
| 364 | 367 | output_sample(); |
| 365 | 368 | output_chips(); |
| r14546 | r14547 | |
| 379 | 382 | fprintf(m_output, "\t</%s>\n",emulator_info::get_xml_top()); |
| 380 | 383 | } |
| 381 | 384 | |
| 385 | |
| 382 | 386 | //------------------------------------------------ |
| 383 | 387 | // output_device_roms - print the device |
| 384 | 388 | // with roms, if appropriate |
| r14546 | r14547 | |
| 386 | 390 | |
| 387 | 391 | void info_xml_creator::output_device_roms() |
| 388 | 392 | { |
| 389 | | int cnt=0; |
| 390 | | for (const rom_source *source = rom_first_source(m_drivlist.config()); source != NULL; source = rom_next_source(*source)) |
| 391 | | { |
| 392 | | if (cnt!=0) { |
| 393 | | fprintf(m_output, "\t\t<device_ref name=\"%s\"/>\n", xml_normalize_string(source->shortname())); |
| 394 | | for(int i=0;i<m_device_count;i++) { |
| 395 | | if (source->type() == *s_devices_sorted[i]) m_device_used[i] = 1; |
| 396 | | } |
| 393 | device_iterator deviter(m_drivlist.config().root_device()); |
| 394 | for (device_t *device = deviter.first(); device != NULL; device = deviter.next()) |
| 395 | if (device->owner() != NULL) |
| 396 | { |
| 397 | fprintf(m_output, "\t\t<device_ref name=\"%s\"/>\n", xml_normalize_string(device->shortname())); |
| 398 | for (int devnum = 0; devnum < m_device_count; devnum++) |
| 399 | if (device->type() == *s_devices_sorted[devnum]) |
| 400 | m_device_used[devnum] = 1; |
| 397 | 401 | } |
| 398 | | cnt++; |
| 399 | | } |
| 400 | 402 | } |
| 401 | 403 | |
| 404 | |
| 402 | 405 | //------------------------------------------------ |
| 403 | 406 | // output_sampleof - print the 'sampleof' |
| 404 | 407 | // attribute, if appropriate |
| r14546 | r14547 | |
| 453 | 456 | // the XML output |
| 454 | 457 | //------------------------------------------------- |
| 455 | 458 | |
| 456 | | void info_xml_creator::output_rom(const rom_source *source) |
| 459 | void info_xml_creator::output_rom(device_t &device) |
| 457 | 460 | { |
| 458 | 461 | // iterate over 3 different ROM "types": BIOS, ROMs, DISKs |
| 459 | 462 | for (int rom_type = 0; rom_type < 3; rom_type++) |
| 460 | | { |
| 461 | | for (const rom_entry *region = rom_first_region(*source); region != NULL; region = rom_next_region(region)) |
| 463 | for (const rom_entry *region = rom_first_region(device); region != NULL; region = rom_next_region(region)) |
| 464 | { |
| 465 | bool is_disk = ROMREGION_ISDISKDATA(region); |
| 466 | |
| 467 | // disk regions only work for disks |
| 468 | if ((is_disk && rom_type != 2) || (!is_disk && rom_type == 2)) |
| 469 | continue; |
| 470 | |
| 471 | // iterate through ROM entries |
| 472 | for (const rom_entry *rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) |
| 462 | 473 | { |
| 463 | | bool is_disk = ROMREGION_ISDISKDATA(region); |
| 474 | bool is_bios = ROM_GETBIOSFLAGS(rom); |
| 475 | const char *name = ROM_GETNAME(rom); |
| 476 | int offset = ROM_GETOFFSET(rom); |
| 477 | const char *merge_name = NULL; |
| 478 | char bios_name[100]; |
| 464 | 479 | |
| 465 | | // disk regions only work for disks |
| 466 | | if ((is_disk && rom_type != 2) || (!is_disk && rom_type == 2)) |
| 480 | // BIOS ROMs only apply to bioses |
| 481 | if ((is_bios && rom_type != 0) || (!is_bios && rom_type == 0)) |
| 467 | 482 | continue; |
| 468 | 483 | |
| 469 | | // iterate through ROM entries |
| 470 | | for (const rom_entry *rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) |
| 484 | // if we have a valid ROM and we are a clone, see if we can find the parent ROM |
| 485 | hash_collection hashes(ROM_GETHASHDATA(rom)); |
| 486 | if (!hashes.flag(hash_collection::FLAG_NO_DUMP)) |
| 487 | merge_name = get_merge_name(hashes); |
| 488 | |
| 489 | // scan for a BIOS name |
| 490 | bios_name[0] = 0; |
| 491 | if (!is_disk && is_bios) |
| 471 | 492 | { |
| 472 | | bool is_bios = ROM_GETBIOSFLAGS(rom); |
| 473 | | const char *name = ROM_GETNAME(rom); |
| 474 | | int offset = ROM_GETOFFSET(rom); |
| 475 | | const char *merge_name = NULL; |
| 476 | | char bios_name[100]; |
| 493 | // scan backwards through the ROM entries |
| 494 | for (const rom_entry *brom = rom - 1; brom != m_drivlist.driver().rom; brom--) |
| 495 | if (ROMENTRY_ISSYSTEM_BIOS(brom)) |
| 496 | { |
| 497 | strcpy(bios_name, ROM_GETNAME(brom)); |
| 498 | break; |
| 499 | } |
| 500 | } |
| 477 | 501 | |
| 478 | | // BIOS ROMs only apply to bioses |
| 479 | | if ((is_bios && rom_type != 0) || (!is_bios && rom_type == 0)) |
| 480 | | continue; |
| 502 | // opening tag |
| 503 | if (!is_disk) |
| 504 | fprintf(m_output, "\t\t<rom"); |
| 505 | else |
| 506 | fprintf(m_output, "\t\t<disk"); |
| 481 | 507 | |
| 482 | | // if we have a valid ROM and we are a clone, see if we can find the parent ROM |
| 483 | | hash_collection hashes(ROM_GETHASHDATA(rom)); |
| 484 | | if (!hashes.flag(hash_collection::FLAG_NO_DUMP)) |
| 485 | | merge_name = get_merge_name(hashes); |
| 508 | // add name, merge, bios, and size tags */ |
| 509 | if (name != NULL && name[0] != 0) |
| 510 | fprintf(m_output, " name=\"%s\"", xml_normalize_string(name)); |
| 511 | if (merge_name != NULL) |
| 512 | fprintf(m_output, " merge=\"%s\"", xml_normalize_string(merge_name)); |
| 513 | if (bios_name[0] != 0) |
| 514 | fprintf(m_output, " bios=\"%s\"", xml_normalize_string(bios_name)); |
| 515 | if (!is_disk) |
| 516 | fprintf(m_output, " size=\"%d\"", rom_file_size(rom)); |
| 486 | 517 | |
| 487 | | // scan for a BIOS name |
| 488 | | bios_name[0] = 0; |
| 489 | | if (!is_disk && is_bios) |
| 490 | | { |
| 491 | | // scan backwards through the ROM entries |
| 492 | | for (const rom_entry *brom = rom - 1; brom != m_drivlist.driver().rom; brom--) |
| 493 | | if (ROMENTRY_ISSYSTEM_BIOS(brom)) |
| 494 | | { |
| 495 | | strcpy(bios_name, ROM_GETNAME(brom)); |
| 496 | | break; |
| 497 | | } |
| 498 | | } |
| 518 | // dump checksum information only if there is a known dump |
| 519 | if (!hashes.flag(hash_collection::FLAG_NO_DUMP)) |
| 520 | { |
| 521 | // iterate over hash function types and print m_output their values |
| 522 | astring tempstr; |
| 523 | fprintf(m_output, " %s", hashes.attribute_string(tempstr)); |
| 524 | } |
| 525 | else |
| 526 | fprintf(m_output, " status=\"nodump\""); |
| 499 | 527 | |
| 500 | | // opening tag |
| 501 | | if (!is_disk) |
| 502 | | fprintf(m_output, "\t\t<rom"); |
| 503 | | else |
| 504 | | fprintf(m_output, "\t\t<disk"); |
| 528 | // append a region name |
| 529 | fprintf(m_output, " region=\"%s\"", ROMREGION_GETTAG(region)); |
| 505 | 530 | |
| 506 | | // add name, merge, bios, and size tags */ |
| 507 | | if (name != NULL && name[0] != 0) |
| 508 | | fprintf(m_output, " name=\"%s\"", xml_normalize_string(name)); |
| 509 | | if (merge_name != NULL) |
| 510 | | fprintf(m_output, " merge=\"%s\"", xml_normalize_string(merge_name)); |
| 511 | | if (bios_name[0] != 0) |
| 512 | | fprintf(m_output, " bios=\"%s\"", xml_normalize_string(bios_name)); |
| 513 | | if (!is_disk) |
| 514 | | fprintf(m_output, " size=\"%d\"", rom_file_size(rom)); |
| 531 | // for non-disk entries, print offset |
| 532 | if (!is_disk) |
| 533 | fprintf(m_output, " offset=\"%x\"", offset); |
| 515 | 534 | |
| 516 | | // dump checksum information only if there is a known dump |
| 517 | | if (!hashes.flag(hash_collection::FLAG_NO_DUMP)) |
| 518 | | { |
| 519 | | // iterate over hash function types and print m_output their values |
| 520 | | astring tempstr; |
| 521 | | fprintf(m_output, " %s", hashes.attribute_string(tempstr)); |
| 522 | | } |
| 523 | | else |
| 524 | | fprintf(m_output, " status=\"nodump\""); |
| 535 | // for disk entries, add the disk index |
| 536 | else |
| 537 | { |
| 538 | fprintf(m_output, " index=\"%x\"", DISK_GETINDEX(rom)); |
| 539 | fprintf(m_output, " writable=\"%s\"", DISK_ISREADONLY(rom) ? "no" : "yes"); |
| 540 | } |
| 525 | 541 | |
| 526 | | // append a region name |
| 527 | | fprintf(m_output, " region=\"%s\"", ROMREGION_GETTAG(region)); |
| 542 | // add optional flag |
| 543 | if ((!is_disk && ROM_ISOPTIONAL(rom)) || (is_disk && DISK_ISOPTIONAL(rom))) |
| 544 | fprintf(m_output, " optional=\"yes\""); |
| 528 | 545 | |
| 529 | | // for non-disk entries, print offset |
| 530 | | if (!is_disk) |
| 531 | | fprintf(m_output, " offset=\"%x\"", offset); |
| 532 | | |
| 533 | | // for disk entries, add the disk index |
| 534 | | else |
| 535 | | { |
| 536 | | fprintf(m_output, " index=\"%x\"", DISK_GETINDEX(rom)); |
| 537 | | fprintf(m_output, " writable=\"%s\"", DISK_ISREADONLY(rom) ? "no" : "yes"); |
| 538 | | } |
| 539 | | |
| 540 | | // add optional flag |
| 541 | | if ((!is_disk && ROM_ISOPTIONAL(rom)) || (is_disk && DISK_ISOPTIONAL(rom))) |
| 542 | | fprintf(m_output, " optional=\"yes\""); |
| 543 | | |
| 544 | | fprintf(m_output, "/>\n"); |
| 545 | | } |
| 546 | fprintf(m_output, "/>\n"); |
| 546 | 547 | } |
| 547 | | } |
| 548 | } |
| 548 | 549 | } |
| 549 | 550 | |
| 550 | 551 | |
| r14546 | r14547 | |
| 1262 | 1263 | |
| 1263 | 1264 | const char *info_xml_creator::get_merge_name(const hash_collection &romhashes) |
| 1264 | 1265 | { |
| 1266 | // walk the parent chain |
| 1265 | 1267 | const char *merge_name = NULL; |
| 1266 | | // walk the parent chain |
| 1267 | 1268 | for (int clone_of = m_drivlist.find(m_drivlist.driver().parent); clone_of != -1; clone_of = m_drivlist.find(m_drivlist.driver(clone_of).parent)) |
| 1268 | | |
| 1269 | { |
| 1269 | 1270 | // look in the parent's ROMs |
| 1270 | | for (const rom_source *psource = rom_first_source(m_drivlist.config(clone_of,m_lookup_options)); psource != NULL; psource = rom_next_source(*psource)) |
| 1271 | | for (const rom_entry *pregion = rom_first_region(*psource); pregion != NULL; pregion = rom_next_region(pregion)) |
| 1271 | device_iterator deviter(m_drivlist.config(clone_of, m_lookup_options).root_device()); |
| 1272 | for (device_t *device = deviter.first(); device != NULL; device = deviter.next()) |
| 1273 | for (const rom_entry *pregion = rom_first_region(*device); pregion != NULL; pregion = rom_next_region(pregion)) |
| 1272 | 1274 | for (const rom_entry *prom = rom_first_file(pregion); prom != NULL; prom = rom_next_file(prom)) |
| 1273 | 1275 | { |
| 1274 | 1276 | hash_collection phashes(ROM_GETHASHDATA(prom)); |
| r14546 | r14547 | |
| 1279 | 1281 | break; |
| 1280 | 1282 | } |
| 1281 | 1283 | } |
| 1284 | } |
| 1282 | 1285 | |
| 1283 | 1286 | return merge_name; |
| 1284 | 1287 | } |