Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. cddump.c
  5. Abstract:
  6. dump cd tracks to wav files
  7. Environment:
  8. User mode only
  9. Revision History:
  10. 05-26-98 : Created
  11. --*/
  12. #include <windows.h>
  13. #include <stdio.h>
  14. #include "wav.h"
  15. ULONG32
  16. DumpWavHeader(
  17. HANDLE OutFile,
  18. ULONG32 Samples,
  19. ULONG32 SamplesPerSecond,
  20. USHORT Channels,
  21. USHORT BitsPerSample
  22. )
  23. {
  24. WAV_HEADER_CHUNK Header;
  25. ULONG32 temp;
  26. Header.ChunkId = ChunkIdRiff;
  27. Header.RiffType = RiffTypeWav;
  28. Header.Format.ChunkId = ChunkIdFormat;
  29. Header.Format.ChunkSize = sizeof(WAV_FORMAT_CHUNK) - (sizeof(ULONG)*2);
  30. Header.Format.FormatTag = FormatTagUncompressed;
  31. Header.Format.BitsPerSample = BitsPerSample;
  32. temp = (BitsPerSample+7)/8; // temp = bytes per sample rounded up
  33. Header.Format.Channels = Channels;
  34. temp *= Channels; // temp = bytes for all channels
  35. if (temp > (USHORT)-1) {
  36. fprintf(stderr, "Bytes for all channels exceeds MAXUSHORT, not a valid "
  37. "option for WAV file\n");
  38. return -1;
  39. }
  40. Header.Format.BlockAlign = (USHORT)temp;
  41. Header.Format.SamplesPerSec = SamplesPerSecond;
  42. Header.Format.AvgBytesPerSec = temp * SamplesPerSecond;
  43. temp *= Samples; // temp = number of total bytes
  44. temp *= 2; // unknown why this is needed.
  45. Header.Data.ChunkSize = temp;
  46. Header.Data.ChunkId = ChunkIdData;
  47. Header.ChunkSize = temp + sizeof(WAV_HEADER_CHUNK); // 54
  48. if (!WriteFile( OutFile, &Header, sizeof(Header), &temp, NULL ) ) {
  49. fprintf(stderr, "Unable to write header\n" );
  50. return -1;
  51. }
  52. return 0;
  53. }
  54. VOID
  55. ReadWavHeader(
  56. HANDLE InFile
  57. )
  58. {
  59. WAV_HEADER_CHUNK Header;
  60. ULONG temp;
  61. if (!ReadFile(InFile, &Header, sizeof(Header), &temp, NULL) ||
  62. temp != sizeof(Header)
  63. ) {
  64. fprintf(stderr, "Unable to read header %x\n", GetLastError());
  65. return;
  66. }
  67. if (Header.ChunkId != ChunkIdRiff) {
  68. printf("ChunkId is not RIFF (%x)\n", Header.ChunkId);
  69. return;
  70. }
  71. if (Header.RiffType != RiffTypeWav) {
  72. printf("RiffType is not RiffTypeWav (%x)\n", Header.RiffType);
  73. return;
  74. }
  75. if (Header.Format.ChunkId != ChunkIdFormat) {
  76. printf("Format.ChunkId is not ChunkIdFormat (%x)\n",
  77. Header.Format.ChunkId);
  78. return;
  79. }
  80. if (Header.Format.ChunkSize != sizeof(WAV_FORMAT_CHUNK) - (2*sizeof(ULONG))) {
  81. printf("Format.ChunkSize is not %x (%x)\n",
  82. sizeof(WAV_FORMAT_CHUNK) - (2*sizeof(ULONG)),
  83. Header.Format.ChunkSize);
  84. return;
  85. }
  86. if (Header.Format.FormatTag != FormatTagUncompressed) {
  87. printf("Format. is not Uncompressed (%x)\n", Header.Format.FormatTag);
  88. return;
  89. }
  90. if (Header.Data.ChunkId != ChunkIdData) {
  91. printf("Data.ChunkId is not ChunkIdData (%x)\n",
  92. Header.Data.ChunkId);
  93. return;
  94. }
  95. printf("Uncompressed RIFF/Wav File\n");
  96. printf("\t%2d bits per sample\n", Header.Format.BitsPerSample);
  97. printf("\t%2d channels\n", Header.Format.Channels);
  98. printf("\t%2d samples per second\n", Header.Format.SamplesPerSec);
  99. printf("\t%2d average bytes per second\n", Header.Format.AvgBytesPerSec);
  100. printf("Total data available to player: %d\n", Header.Data.ChunkSize);
  101. temp = Header.Data.ChunkSize / Header.Format.AvgBytesPerSec;
  102. printf("\t%d seconds of audio\n",
  103. temp
  104. );
  105. return;
  106. }